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.



683
684
685
686
687
# File 'lib/amrita2/template.rb', line 683

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

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



682
683
684
# File 'lib/amrita2/template.rb', line 682

def node
  @node
end

Instance Method Details

#dynamic?Boolean

Returns:

  • (Boolean)


689
690
691
# File 'lib/amrita2/template.rb', line 689

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)


715
716
717
# File 'lib/amrita2/template.rb', line 715

def has_ruby?
  true
end

#render_me(cg) ⇒ Object



704
705
706
707
708
709
710
711
712
713
# File 'lib/amrita2/template.rb', line 704

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



693
694
695
696
697
698
699
700
701
702
# File 'lib/amrita2/template.rb', line 693

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