Class: Amrita2::Core::DynamicElement
- Inherits:
-
ParentNode
show all
- Includes:
- Util, OptionSupport
- Defined in:
- lib/amrita2/gettext.rb,
lib/amrita2/template.rb
Overview
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
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util
sanitize_attribute_value, sanitize_text, sanitize_url
Methods inherited from ParentNode
#each, #has_dynamic?
Methods inherited from BaseNode
#root
Constructor Details
#initialize(parent, name, element, filters = []) ⇒ DynamicElement
Returns a new instance of DynamicElement.
792
793
794
795
796
797
798
799
800
801
802
803
|
# File 'lib/amrita2/template.rb', line 792
def initialize(parent, name, element, filters=[])
@parent,@name,@element = parent, name, element
parse_opt(root.opt)
@attrs = {}
delete_am_attrs
setup_filter(filters)
@element = filter_element(@element)
@renderers = []
super(parent, element)
setup_type_renderer
end
|
Instance Attribute Details
Returns the value of attribute attrs.
779
780
781
|
# File 'lib/amrita2/template.rb', line 779
def attrs
@attrs
end
|
Returns the value of attribute children.
779
780
781
|
# File 'lib/amrita2/template.rb', line 779
def children
@children
end
|
Returns the value of attribute element.
779
780
781
|
# File 'lib/amrita2/template.rb', line 779
def element
@element
end
|
Returns the value of attribute filter.
779
780
781
|
# File 'lib/amrita2/template.rb', line 779
def filter
@filter
end
|
Returns the value of attribute name.
779
780
781
|
# File 'lib/amrita2/template.rb', line 779
def name
@name
end
|
Returns the value of attribute parent.
779
780
781
|
# File 'lib/amrita2/template.rb', line 779
def parent
@parent
end
|
#renderers ⇒ Object
Returns the value of attribute renderers.
779
780
781
|
# File 'lib/amrita2/template.rb', line 779
def renderers
@renderers
end
|
Class Method Details
.delegate_to_filter(name) ⇒ Object
780
781
782
783
784
785
786
|
# File 'lib/amrita2/template.rb', line 780
def self.delegate_to_filter(name)
module_eval <<-END
def #{name}(*args,&block)
@filter.#{name}(self, *args,&block)
end
END
end
|
Instance Method Details
805
806
807
|
# File 'lib/amrita2/template.rb', line 805
def [](key)
@attrs[key]
end
|
#am_for_value ⇒ Object
877
878
879
|
# File 'lib/amrita2/template.rb', line 877
def am_for_value
@attrs[am_for.intern]
end
|
#am_skipif_value ⇒ Object
881
882
883
|
# File 'lib/amrita2/template.rb', line 881
def am_skipif_value
@attrs[am_skipif.intern]
end
|
#am_v_value ⇒ Object
885
886
887
|
# File 'lib/amrita2/template.rb', line 885
def am_v_value
@attrs[am_v.intern]
end
|
#class_name ⇒ Object
837
838
839
840
841
842
843
|
# File 'lib/amrita2/template.rb', line 837
def class_name
if name
"XX" + name.capitalize.gsub(/[^\w\d]/, "_")
else
"XX%d" % [object_id.abs]
end
end
|
#compile(cg = CodeGenerator.new) ⇒ Object
849
850
851
852
853
854
855
|
# File 'lib/amrita2/template.rb', line 849
def compile(cg = CodeGenerator.new)
define_element_method(cg) do
cg.code("$_ = value")
loop_check_code(cg)
method_body_code(cg)
end
end
|
#dynamic? ⇒ Boolean
813
814
815
|
# File 'lib/amrita2/template.rb', line 813
def dynamic?
true
end
|
#get_erb_source ⇒ Object
21
22
23
24
25
|
# File 'lib/amrita2/gettext.rb', line 21
def get_erb_source
@children.collect do |c|
c.get_erb_source
end.join("\n")
end
|
#has_ruby? ⇒ Boolean
817
818
819
|
# File 'lib/amrita2/template.rb', line 817
def has_ruby?
super or am_for_value or am_skipif_value or am_v_value
end
|
#instance_name ⇒ Object
845
846
847
|
# File 'lib/amrita2/template.rb', line 845
def instance_name
class_name + "Instance"
end
|
#module_src(cg) ⇒ Object
865
866
867
868
869
870
871
872
873
874
875
|
# File 'lib/amrita2/template.rb', line 865
def module_src(cg)
cg.define_class(class_name) do
cg.code <<-END
include Amrita2
include Amrita2::Runtime
END
compile(cg)
super
end
cg.code("#{instance_name} = #{class_name}.new")
end
|
#parent_de ⇒ Object
809
810
811
|
# File 'lib/amrita2/template.rb', line 809
def parent_de
self
end
|
#render_me(cg, n = name) ⇒ Object
857
858
859
860
861
862
863
|
# File 'lib/amrita2/template.rb', line 857
def render_me(cg, n = name)
if (n)
cg.put_string_expression("#{instance_name}.render_with($_.amrita_value(#{n.inspect}), __binding__)")
else
cg.put_string_expression("#{instance_name}.render_with($_, __binding__)")
end
end
|
#setup_filter(filters) ⇒ Object
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
|
# File 'lib/amrita2/template.rb', line 821
def setup_filter(filters)
default_filter = DefaultFilter.new
default_filter.parse_opt(opt)
if filters.size > 0
@filter = current = filters.first
for f in filters do
current.next_ = f
current = f
end
current.next_ = default_filter
else
@filter = default_filter
end
end
|