Class: Amrita2::Core::DefaultFilter
Instance Attribute Summary
#opt
#next_
Instance Method Summary
collapse
-
#define_element_method(de, cg, &block) ⇒ Object
-
#element_render_code(de, cg, element, &block) ⇒ Object
-
#filter_element(de, element) ⇒ Object
-
#generate_dynamic_element(de, e) ⇒ Object
-
#loop_check_code(de, cg) ⇒ Object
-
#method_body_code(de, cg) ⇒ Object
-
#parse_element(de, element) ⇒ Object
-
#parse_node(de, node) ⇒ Object
-
#renderer_code(de, cg, element) ⇒ Object
-
#setup_type_renderer(de) ⇒ Object
-
#value_filter_code(de, cg, value_name) ⇒ Object
#[], #method_missing, #parse_opt
filter_method, inherited, #parse_filter_a, #|
Instance Method Details
#define_element_method(de, cg, &block) ⇒ Object
1050
1051
1052
|
# File 'lib/amrita2/template.rb', line 1050
def define_element_method(de, cg, &block)
cg.def_method("render_with", "value", "__binding__", "__cnt__ = -1 ", &block)
end
|
#element_render_code(de, cg, element, &block) ⇒ Object
1092
1093
1094
1095
1096
1097
1098
|
# File 'lib/amrita2/template.rb', line 1092
def element_render_code(de, cg, element, &block)
if ((element.name == 'span' or element.name == '_' or element.name == 'root') and element.attributes.size == 0)
yield
else
cg.put_static_element(element, &block)
end
end
|
#filter_element(de, element) ⇒ Object
998
999
1000
|
# File 'lib/amrita2/template.rb', line 998
def filter_element(de, element)
element
end
|
#generate_dynamic_element(de, e) ⇒ Object
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
|
# File 'lib/amrita2/template.rb', line 1025
def generate_dynamic_element(de, e)
src = e.attributes[de.am_src]
filters_src = e.attributes[de.am_filter]
if src
name, fs = src.split('|', 2)
name.strip!
filters = de.root.compile_filters(e, name, fs, filters_src)
DynamicElement.new(de, name , e, filters)
elsif filters_src
filters = de.root.compile_filters(e, nil, filters_src)
DynamicElement.new(de, nil , e, filters)
else
nil
end
end
|
#loop_check_code(de, cg) ⇒ Object
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
|
# File 'lib/amrita2/template.rb', line 1054
def loop_check_code(de, cg)
cg.if_ "$_.kind_of?(Amrita2::Enum) and not $_.kind_of?(ScalarData)" do
cg.code("$_.each_with_index do |v, i| ")
cg.level_up do
cg.put_string_expression("render_with(v, __binding__, i) ")
end
cg.code("end")
cg.code("return __stream__")
end
end
|
#method_body_code(de, cg) ⇒ Object
1065
1066
1067
1068
1069
1070
|
# File 'lib/amrita2/template.rb', line 1065
def method_body_code(de, cg)
de.value_filter_code(cg, "value")
de.renderer_code(cg, de.element)
end
|
#parse_element(de, element) ⇒ Object
1002
1003
1004
1005
1006
|
# File 'lib/amrita2/template.rb', line 1002
def parse_element(de, element)
element.enum_for(:each_child).collect do |node|
de.parse_node(node)
end
end
|
#parse_node(de, node) ⇒ Object
#renderer_code(de, cg, element) ⇒ Object
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
|
# File 'lib/amrita2/template.rb', line 1075
def renderer_code(de, cg, element)
r = de.renderers
case r.size
when 0
when 1
r.first.generate_body(cg, de, element)
else
cg.case_("$_") do
r.each do |r1|
r1.generate_when(cg) do
r1.generate_body(cg, de, element)
end
end
end
end
end
|
#setup_type_renderer(de) ⇒ Object
1041
1042
1043
1044
1045
1046
1047
1048
|
# File 'lib/amrita2/template.rb', line 1041
def setup_type_renderer(de)
if de.has_dynamic?
de.renderers << HashRenderer.new unless de.renderers.find {|r| r.kind_of?(HashRenderer) }
else
de.renderers << ScalarRenderer.new
end
de.renderers << ElseRenderer.new
end
|
#value_filter_code(de, cg, value_name) ⇒ Object
1072
1073
|
# File 'lib/amrita2/template.rb', line 1072
def value_filter_code(de, cg, value_name)
end
|