初始提交,未完全测试

This commit is contained in:
2026-02-27 14:37:10 +08:00
parent 76c0f469be
commit e270f02073
68 changed files with 5886 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env python3.9
# -*- coding: utf-8 -*-
"""
JFinal CallDirective - Call Directive
"""
from ...Directive import Directive
from ...Env import Env
from ...stat.Scope import Scope
class CallDirective(Directive):
"""Call directive for calling template functions"""
def exec(self, env: Env, scope: Scope, writer) -> None:
"""
Execute call directive
Args:
env: Template environment
scope: Execution scope
writer: Output writer
"""
if self.expr_list:
# Get function name
function_name = self.expr_list.eval(scope)
if function_name:
# Get function from env
func = env.get_function(str(function_name))
if func:
# Call function
func.exec(env, scope, writer)
def __repr__(self) -> str:
return "CallDirective()"

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env python3.9
# -*- coding: utf-8 -*-
"""
JFinal DateDirective - Date Directive
"""
from ...Directive import Directive
from ...Env import Env
from ...stat.Scope import Scope
class DateDirective(Directive):
"""Date directive for date formatting"""
def exec(self, env: Env, scope: Scope, writer) -> None:
"""
Execute date directive
Args:
env: Template environment
scope: Execution scope
writer: Output writer
"""
if self.expr_list:
# Get date value and pattern
values = self.expr_list.eval_expr_list(scope)
if values:
date_value = values[0]
pattern = values[1] if len(values) > 1 else "yyyy-MM-dd HH:mm"
# Format date
from ...kit.TimeKit import TimeKit
if date_value:
formatted_date = TimeKit.format(date_value, pattern)
if hasattr(writer, 'write'):
writer.write(formatted_date)
def __repr__(self) -> str:
return "DateDirective()"

View File

@@ -0,0 +1,34 @@
#!/usr/bin/env python3.9
# -*- coding: utf-8 -*-
"""
JFinal EscapeDirective - Escape Directive
"""
from ...Directive import Directive
from ...Env import Env
from ...stat.Scope import Scope
class EscapeDirective(Directive):
"""Escape directive for HTML escaping"""
def exec(self, env: Env, scope: Scope, writer) -> None:
"""
Execute escape directive
Args:
env: Template environment
scope: Execution scope
writer: Output writer
"""
if self.expr_list:
# Get value to escape
value = self.expr_list.eval(scope)
if value:
# Escape HTML special characters
escaped = str(value).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')
if hasattr(writer, 'write'):
writer.write(escaped)
def __repr__(self) -> str:
return "EscapeDirective()"

View File

@@ -0,0 +1,34 @@
#!/usr/bin/env python3.9
# -*- coding: utf-8 -*-
"""
JFinal NumberDirective - Number Directive
"""
from ...Directive import Directive
from ...Env import Env
from ...stat.Scope import Scope
class NumberDirective(Directive):
"""Number directive for number formatting"""
def exec(self, env: Env, scope: Scope, writer) -> None:
"""
Execute number directive
Args:
env: Template environment
scope: Execution scope
writer: Output writer
"""
if self.expr_list:
# Get number value
number_value = self.expr_list.eval(scope)
if number_value is not None:
# Format number
formatted = str(number_value)
if hasattr(writer, 'write'):
writer.write(formatted)
def __repr__(self) -> str:
return "NumberDirective()"

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env python3.9
# -*- coding: utf-8 -*-
"""
JFinal RandomDirective - Random Directive
"""
import random
from ...Directive import Directive
from ...Env import Env
from ...stat.Scope import Scope
class RandomDirective(Directive):
"""Random directive for generating random numbers"""
def exec(self, env: Env, scope: Scope, writer) -> None:
"""
Execute random directive
Args:
env: Template environment
scope: Execution scope
writer: Output writer
"""
if self.expr_list:
# Get parameters
values = self.expr_list.eval_expr_list(scope)
if len(values) == 0:
# No parameters, generate random float between 0 and 1
random_value = random.random()
elif len(values) == 1:
# One parameter, generate random int between 0 and max
max_value = int(values[0])
random_value = random.randint(0, max_value - 1)
elif len(values) == 2:
# Two parameters, generate random int between min and max
min_value = int(values[0])
max_value = int(values[1])
random_value = random.randint(min_value, max_value)
else:
# Too many parameters
random_value = random.random()
if hasattr(writer, 'write'):
writer.write(str(random_value))
def __repr__(self) -> str:
return "RandomDirective()"

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env python3.9
# -*- coding: utf-8 -*-
"""
JFinal RenderDirective - Render Directive
"""
from ...Directive import Directive
from ...Env import Env
from ...stat.Scope import Scope
class RenderDirective(Directive):
"""Render directive for template rendering"""
def exec(self, env: Env, scope: Scope, writer) -> None:
"""
Execute render directive
Args:
env: Template environment
scope: Execution scope
writer: Output writer
"""
# Simplified implementation
if self.expr_list:
# Get template name
template_name = self.expr_list.eval(scope)
if template_name:
# Get engine from env
from ...Engine import Engine
engine = Engine.use()
# Render template
template = engine.get_template(str(template_name))
template.render(scope.get_data(), writer)
def __repr__(self) -> str:
return "RenderDirective()"

View File

@@ -0,0 +1,33 @@
#!/usr/bin/env python3.9
# -*- coding: utf-8 -*-
"""
JFinal StringDirective - String Directive
"""
from ...Directive import Directive
from ...Env import Env
from ...stat.Scope import Scope
class StringDirective(Directive):
"""String directive for string operations"""
def exec(self, env: Env, scope: Scope, writer) -> None:
"""
Execute string directive
Args:
env: Template environment
scope: Execution scope
writer: Output writer
"""
if self.expr_list:
# Get string value
string_value = self.expr_list.eval(scope)
if string_value is not None:
# Output string
if hasattr(writer, 'write'):
writer.write(str(string_value))
def __repr__(self) -> str:
return "StringDirective()"

View File

@@ -0,0 +1 @@
# Python package initialization