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.
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 |
# File 'lib/amrita2/template.rb', line 911 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.
909 910 911 |
# File 'lib/amrita2/template.rb', line 909 def doctype @doctype end |
#text_domain ⇒ Object
Returns the value of attribute text_domain.
35 36 37 |
# File 'lib/amrita2/gettext.rb', line 35 def text_domain @text_domain end |
#xml_decl ⇒ Object (readonly)
Returns the value of attribute xml_decl.
909 910 911 |
# File 'lib/amrita2/template.rb', line 909 def xml_decl @xml_decl end |
Instance Method Details
#compile(cg) ⇒ Object
942 943 944 945 946 947 948 949 950 951 |
# File 'lib/amrita2/template.rb', line 942 def compile(cg) cg.code <<-END include Amrita2 include Amrita2::Runtime END super(cg) @children.each do |c| c.module_src(cg) end end |
#compile_filters(element, name, *args) ⇒ Object
953 954 955 956 957 958 |
# File 'lib/amrita2/template.rb', line 953 def compile_filters(element, name, *args) src = args.compact.join('|') filters = parse_filter(src) @filter_proc.call(element, name, filters) filters end |
#parse_filter(src) ⇒ Object
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 |
# File 'lib/amrita2/template.rb', line 960 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 |