初始提交,未完全测试
This commit is contained in:
1
template/ext/__init__.py
Normal file
1
template/ext/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# Python package initialization
|
||||
36
template/ext/directive/CallDirective.py
Normal file
36
template/ext/directive/CallDirective.py
Normal 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()"
|
||||
39
template/ext/directive/DateDirective.py
Normal file
39
template/ext/directive/DateDirective.py
Normal 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()"
|
||||
34
template/ext/directive/EscapeDirective.py
Normal file
34
template/ext/directive/EscapeDirective.py
Normal 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('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''')
|
||||
if hasattr(writer, 'write'):
|
||||
writer.write(escaped)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "EscapeDirective()"
|
||||
34
template/ext/directive/NumberDirective.py
Normal file
34
template/ext/directive/NumberDirective.py
Normal 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()"
|
||||
48
template/ext/directive/RandomDirective.py
Normal file
48
template/ext/directive/RandomDirective.py
Normal 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()"
|
||||
38
template/ext/directive/RenderDirective.py
Normal file
38
template/ext/directive/RenderDirective.py
Normal 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()"
|
||||
33
template/ext/directive/StringDirective.py
Normal file
33
template/ext/directive/StringDirective.py
Normal 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()"
|
||||
1
template/ext/directive/__init__.py
Normal file
1
template/ext/directive/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# Python package initialization
|
||||
27
template/ext/sharedmethod/SharedMethodLib.py
Normal file
27
template/ext/sharedmethod/SharedMethodLib.py
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3.9
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
JFinal SharedMethodLib - Shared Method Library
|
||||
"""
|
||||
|
||||
class SharedMethodLib:
|
||||
"""Shared method library for template functions"""
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize shared method library"""
|
||||
pass
|
||||
|
||||
def add_shared_method(self, method_name: str, method):
|
||||
"""Add shared method"""
|
||||
pass
|
||||
|
||||
def get_shared_method(self, method_name: str):
|
||||
"""Get shared method by name"""
|
||||
return None
|
||||
|
||||
def has_shared_method(self, method_name: str) -> bool:
|
||||
"""Check if shared method exists"""
|
||||
return False
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "SharedMethodLib()"
|
||||
1
template/ext/sharedmethod/__init__.py
Normal file
1
template/ext/sharedmethod/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# Python package initialization
|
||||
Reference in New Issue
Block a user