Class: Amrita2::Core::RootElement
- Inherits:
-
DynamicElement
- Object
- BaseNode
- ParentNode
- DynamicElement
- Amrita2::Core::RootElement
- Includes:
- Filters
- Defined in:
- lib/amrita2/gettext.rb,
lib/amrita2/template.rb
Overview
:nodoc: all
Constant Summary
Constants included from Util
Util::AMP_WITHOUT_REFRENCE, Util::DefaultAllowedScheme, Util::NAME, Util::NAMECHAR, Util::NOT_REFERENCE, Util::UrlInvalidChar
Instance Attribute Summary collapse
-
#doctype ⇒ Object
readonly
Returns the value of attribute doctype.
-
#text_domain ⇒ Object
Returns the value of attribute text_domain.
-
#xml_decl ⇒ Object
readonly
Returns the value of attribute xml_decl.
Attributes inherited from DynamicElement
#attrs, #children, #element, #filter, #name, #parent, #renderers
Attributes inherited from ParentNode
Attributes inherited from BaseNode
Instance Method Summary collapse
- #compile(cg) ⇒ Object
- #compile_filters(element, name, *args) ⇒ Object
-
#initialize(elements, opt = {}, &block) ⇒ RootElement
constructor
A new instance of RootElement.
- #parse_filter(src) ⇒ Object
- #root ⇒ Object
Methods inherited from DynamicElement
#[], #am_for_value, #am_skipif_value, #am_v_value, #class_name, delegate_to_filter, #dynamic?, #get_erb_source, #has_ruby?, #instance_name, #module_src, #parent_de, #render_me, #setup_filter
Methods included from Util
sanitize_attribute_value, sanitize_text, sanitize_url
Methods inherited from ParentNode
#dynamic?, #each, #has_dynamic?, #has_ruby?, #module_src
Methods inherited from BaseNode
#dynamic?, #has_ruby?, #module_src, #parent_de, #render_me
Constructor Details
#initialize(elements, opt = {}, &block) ⇒ RootElement
Returns a new instance of RootElement.
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 |
# File 'lib/amrita2/template.rb', line 1026 def initialize(elements, opt={}, &block) @xml_decl = @doctype = nil parse_opt(opt) if block_given? @filter_proc = block else @filter_proc = proc do |e, src, filters| end end e = Hpricot.make("<root />", :xml=>true).first elements.each do |c| case c when Hpricot::Elem, Hpricot::Text, Hpricot::Comment, Hpricot::BogusETag e.insert_after(c, nil) when Hpricot::XMLDecl @xml_decl = c when Hpricot::DocType @doctype = c else raise "#{c.class}" end end filters = [] @filter_proc.call(e,nil, filters) super(nil, nil, e, filters) end |
Instance Attribute Details
#doctype ⇒ Object (readonly)
Returns the value of attribute doctype.
1024 1025 1026 |
# File 'lib/amrita2/template.rb', line 1024 def doctype @doctype end |
#text_domain ⇒ Object
Returns the value of attribute text_domain.
30 31 32 |
# File 'lib/amrita2/gettext.rb', line 30 def text_domain @text_domain end |
#xml_decl ⇒ Object (readonly)
Returns the value of attribute xml_decl.
1024 1025 1026 |
# File 'lib/amrita2/template.rb', line 1024 def xml_decl @xml_decl end |
Instance Method Details
#compile(cg) ⇒ Object
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 |
# File 'lib/amrita2/template.rb', line 1057 def compile(cg) cg.code " include Amrita2\n include Amrita2::Runtime\n" super(cg) @children.each do |c| c.module_src(cg) end end |
#compile_filters(element, name, *args) ⇒ Object
1068 1069 1070 1071 1072 1073 1074 |
# File 'lib/amrita2/template.rb', line 1068 def compile_filters(element, name, *args) src = args.compact.join('|') #filters = src.split('|').collect { |f| parse_filter(f) } filters = parse_filter(src) @filter_proc.call(element, name, filters) filters end |
#parse_filter(src) ⇒ Object
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
# File 'lib/amrita2/template.rb', line 1076 def parse_filter(src) src.gsub!("\n", " ") case src when "",nil [] else case ret = eval(src, @opt[:compiletime_binding]) when Class [ret.new] when Module [ModuleExtendFilter[ret]] when Filters::Base [ret] when Array case ret.first when Symbol [FunctionFilter[*ret]] else ret end when Symbol [FunctionFilter[ret]] when nil [] else raise TemplateError, "unknown Filter type #{ret.class}" end end rescue ScriptError, NameError raise TemplateError, "error in filters #{src.inspect} #$!" end |
#root ⇒ Object
1053 1054 1055 |
# File 'lib/amrita2/template.rb', line 1053 def root self end |