Class: Amrita2View::Base

Inherits:
Object show all
Includes:
Amrita2, Amrita2::Filters, Amrita2::Runtime, Amrita2::Util
Defined in:
lib/amrita2/rails_bridge.rb

Constant Summary collapse

CompileTimeBinding =
binding
@@compiled_amrita2_templates =
{}
@@text_domain =
nil

Constants included from Amrita2::Util

Amrita2::Util::AMP_WITHOUT_REFRENCE, Amrita2::Util::DefaultAllowedScheme, Amrita2::Util::NAME, Amrita2::Util::NAMECHAR, Amrita2::Util::NOT_REFERENCE, Amrita2::Util::UrlInvalidChar

Constants included from Amrita2

Amrita2::FilterMethods, Amrita2::SanitizedString

Instance Method Summary collapse

Methods included from Amrita2::Util

sanitize_attribute_value, sanitize_text, sanitize_url

Methods included from Amrita2::Runtime

#amrita_get_context_value, #amrita_set_context_value, #end_tag, #new_element, #start_tag

Constructor Details

#initialize(action_view) ⇒ Base

Returns a new instance of Base.



41
42
43
# File 'lib/amrita2/rails_bridge.rb', line 41

def initialize( action_view )
  @action_view = action_view
end

Instance Method Details

#render(template, local_assigns = {}) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/amrita2/rails_bridge.rb', line 45

def render(template, local_assigns={})
  Thread::current[:amrita_rails_view] = @action_view
  if template.kind_of?(String)
    render_amrita(template, local_assigns)
  else
    @action_view.render(template, local_assigns)
  end
end

#render_amrita(template, local_assigns) ⇒ Object



75
76
77
78
79
80
# File 'lib/amrita2/rails_bridge.rb', line 75

def render_amrita(template, local_assigns)
  @@compiled_amrita2_templates[template] ||= setup_template(template)
  tmpl = @@compiled_amrita2_templates[template]
  b = setup_binding_of_view(local_assigns)
  tmpl.render_with(b)
end

#setup_binding_of_view(local_assigns) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/amrita2/rails_bridge.rb', line 82

def setup_binding_of_view(local_assigns)
  @action_view.instance_eval do
    evaluate_assigns
    b = binding
    local_assigns.each do |k, v|
      amrita_set_context_value(v)
      eval "#{k}=amrita_get_context_value",b
    end
    b
  end
end

#setup_template(template) ⇒ Object



54
55
56
# File 'lib/amrita2/rails_bridge.rb', line 54

def setup_template(template)
  setup_template_default(template)
end

#setup_template_default(template) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/amrita2/rails_bridge.rb', line 58

def setup_template_default(template)
  if Amrita2::const_defined?(:GetTextBridge)
    t = Amrita2::Template.new(template) do |e, src, filters|
      filters << Amrita2::Filters::GetTextFilter.new
    end
    t.text_domain = text_domain
    bindtextdomain(t.text_domain)
    #t.set_trace(STDOUT)
    t.compiletime_binding = CompileTimeBinding
    t
  else
    t = Amrita2::Template.new(template)
    t.compiletime_binding = CompileTimeBinding
    t
  end
end