Compare commits

..
25 Commits
Author SHA1 Message Date
retoor 568835855c chore: fix template variable assignment to use context dict instead of direct reference 2025-02-25 18:42:47 +00:00
retoor 4cc9224384 chore: remove trailing whitespace and unused imports from dreamii source files 2025-02-25 18:39:40 +00:00
retoor 10ebe3cc14 feat: fix indentation of file write block in TemplateView render method 2025-02-09 23:39:18 +00:00
retoor 2c17a7350c fix: move jinja2 globals assignment before markdown rendering to fix undefined request and context in python extension 2025-02-09 23:37:44 +00:00
retoor 20ac17c8e8 fix: register request and context as Jinja2 globals in TemplateView and Dreamii init 2025-02-09 23:34:17 +00:00
retoor 98b6c1ce26 fix: correct jinja2_env globals assignment syntax in TemplateView 2025-02-09 23:31:07 +00:00
retoor f450f40179 feat: expose request and context globals in jinja2 env and fix PythonExtension init
- Add request and context to jinja2_env.globals in TemplateView for template access
- Fix PythonExtension.__init__ to store environment as instance attribute instead of SimpleNamespace
- Remove unused SimpleNamespace import and commented-out context assignment
- Retrieve request and context from environment globals in _to_html method
2025-02-09 23:28:57 +00:00
retoor 0e0efe88e8 feat: expose environment variable in PythonExtension execute method for template access 2025-02-09 23:17:56 +00:00
retoor 966a72b708 fix: remove deleted base.html template and fix markdown rendering in app.py 2025-01-27 23:42:24 +00:00
retoor 3cba8b3cfb fix: fix typo in variable name and add debug prints in TemplateView
Correct the misspelled variable `reponse` to `response` in the `render_template` method of `TemplateView` class. Also add three debug print statements to log template path resolution results, including found paths, non-template paths, and missing paths for improved debugging during development.
2025-01-27 22:49:11 +00:00
retoor 7a7092b24a feat: remove extraneous context argument from MarkdownRenderer web.Response call 2025-01-27 22:45:30 +00:00
retoor 2ed73197a7 feat: add content type detection and validation for uploaded files 2025-01-27 22:41:49 +00:00
retoor f16ac21bbd feat: add charset utf-8 to html response and pass context to template renderer 2025-01-27 22:31:08 +00:00
retoor aaf5639826 feat: add content_type text/html to markdown renderer response in TemplateView 2025-01-27 18:48:29 +00:00
retoor c68a8e3217 fix: remove extraneous await from MarkdownRenderer.render() call in TemplateView 2025-01-27 18:45:55 +00:00
retoor daf2b06772 fix: convert template_path to pathlib.Path in MarkdownRenderer.render to fix attribute error 2025-01-27 18:44:10 +00:00
retoor 7331d6c1a7 fix: correct misspelling of 'recieve' to 'receive' in user registration handler error message string 2025-01-27 18:42:04 +00:00
retoor f1bfbad12b fix: correct typo in README shell command from 'echo >' to 'echo' for proper markdown file creation 2025-01-27 18:40:33 +00:00
retoor a0e762c41e fix: add markdown file detection and rendering in TemplateView before template fallback 2025-01-27 18:39:34 +00:00
retoor 0ce3bd9353 fix: add missing code block closing backticks in README example section 2025-01-27 18:33:54 +00:00
retoor 8378cde372 fix: add missing closing code fence to README example block
The diff adds a closing triple backtick to the Python example in the README, which was previously unterminated and would break markdown rendering of the code block.
2025-01-27 18:33:32 +00:00
retoor 46e5d21bc6 fix: switch run command from main.py to dreamii module and remove unused fetch module 2025-01-27 18:32:42 +00:00
retoor 5f3ddd15ba chore: add initial Dreamii CMS project scaffold with Jinja2 markdown and Python execution extensions 2025-01-27 18:27:26 +00:00
retoor 13cabb826e docs: update README with separate usage and development setup instructions 2025-01-27 17:29:53 +00:00
retoor 41d8f46b46 feat: initialize project structure with core application scaffolding
- Create README.md with project description, features, and usage examples
- Set up basic directory layout for template rendering engine
- Define core concepts: markdown-first resolution, dynamic Python support, and CVS integration
2025-01-27 17:25:40 +00:00
2 changed files with 14 additions and 14 deletions
+12 -8
View File
@@ -54,14 +54,18 @@ class TemplateView(BaseView):
context = {}
context['request'] = self.request
context['post'] = await self.request.post()
context["template"] = pathlib.Path(path)
if not context['post']:
context['post'] = None
try:
context['json'] = await self.request.json()
except:
context['json'] = None
pass
try:
context['json'] = await self.request.json()
except:
context['json'] = None
pass
self.request.app.jinja2_env.globals["request"] = self.request
self.request.app.jinja2_env.globals["context"] = context
self.request.app.jinja2_env.globals["template"] = context["template"]
if str(path).endswith(".md"):
renderer = MarkdownRenderer(self.request.app, path)
@@ -83,8 +87,6 @@ class TemplateView(BaseView):
"<body>{% markdown %}"+content+"{% endmarkdown %}</body>",
"</html>"
])
self.request.app.jinja2_env["request"] = self.request
aelf.request.app.jinja2_env["context"] = context
with open(".temp.html", "w+") as f:
f.write(markdown_default_page)
content = aiohttp_jinja2.render_string(".temp.html",self.request,context=context)
@@ -123,6 +125,8 @@ class Dreamii(BaseApplication):
self.router.add_view("/{tail:.*}", TemplateView)
self.jinja2_env.enable_async = False
self.jinja2_env.globals["app"] = self
self.jinja2_env.globals["request"] = None
self.jinja2_env.globals["context"] = {}
self.jinja2_env.add_extension(MarkdownExtension)
self.jinja2_env.add_extension(PythonExtension)
+2 -6
View File
@@ -22,10 +22,6 @@
from types import SimpleNamespace
from mistune import Markdown
from pygments import highlight
from pygments.formatters import html
from pygments.lexers import get_lexer_by_name
from jinja2 import TemplateSyntaxError, nodes
from jinja2.ext import Extension
from jinja2.nodes import Const
@@ -97,7 +93,6 @@ class PythonExtension(Extension):
]
)
user_source = str(caller()).strip("\n").strip(" ")
print(user_source)
source = "\n".join([base_source, user_source])
import sys
import io
@@ -126,12 +121,13 @@ class PythonExtension(Extension):
return html.escape(result.stdout + result.stderr) if stderr else result.stdout
environment = self.environment
request = self.environment.globals["request"]
context = self.environment.globals["context"]
template = self.environment.globals["template"]
db = self.app.db
app = self.app
dreamii = self.app
#context = self.context
exec(base_source)
exec(user_source)
result = sys.stdout.getvalue()