Class: Amrita2::Core::ErbNode

Inherits:
BaseNode show all
Includes:
Util
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

Attributes inherited from BaseNode

#parent

Instance Method Summary collapse

Methods included from Util

sanitize_attribute_value, sanitize_text, sanitize_url

Methods inherited from BaseNode

#module_src, #parent_de, #root

Constructor Details

#initialize(parent, node) ⇒ ErbNode

Returns a new instance of ErbNode.



798
799
800
801
802
# File 'lib/amrita2/template.rb', line 798

def initialize(parent, node)
  super(parent)
  @node = node
  @erb_trim_mode = nil
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



797
798
799
# File 'lib/amrita2/template.rb', line 797

def node
  @node
end

Instance Method Details

#dynamic?Boolean

Returns:

  • (Boolean)


804
805
806
# File 'lib/amrita2/template.rb', line 804

def dynamic?
  true
end

#get_erb_sourceObject



15
16
17
# File 'lib/amrita2/gettext.rb', line 15

def get_erb_source
  return @node.to_s
end

#has_ruby?Boolean

Returns:

  • (Boolean)


830
831
832
# File 'lib/amrita2/template.rb', line 830

def has_ruby?
  true
end

#render_me(cg) ⇒ Object



819
820
821
822
823
824
825
826
827
828
# File 'lib/amrita2/template.rb', line 819

def render_me(cg)
  src = @node.inner_text
  src.each do |s|
    cg.code("# #{s.chomp}")
  end
  erb = cg.define_constant %[ERB.new(#{with_context_value_erb(src).inspect}, nil, #{@erb_trim_mode.inspect}).src]
  cg.code("amrita_set_context_value($_)")
  cg.eval_and_print(erb)
  cg.code("$_ = amrita_get_context_value")
end

#render_me_old(cg) ⇒ Object



808
809
810
811
812
813
814
815
816
817
# File 'lib/amrita2/template.rb', line 808

def render_me_old(cg)
  src = @node.inner_text
  src.each do |s|
    cg.code("# #{s.chomp}")
  end
  erb = cg.define_constant %[ERB.new(#{with_context_value_erb(src).inspect}, nil, #{@erb_trim_mode.inspect})]
  cg.code("amrita_set_context_value($_)")
  cg.put_string_expression %[#{erb}.result(__binding__)]
  cg.code("$_ = amrita_get_context_value")
end