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::Hooki, 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.



124
125
126
# File 'lib/amrita2/rails_bridge.rb', line 124

def initialize( action_view )
  @action_view = action_view
end

Instance Method Details

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



128
129
130
131
132
133
134
135
# File 'lib/amrita2/rails_bridge.rb', line 128

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



158
159
160
161
162
163
# File 'lib/amrita2/rails_bridge.rb', line 158

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



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/amrita2/rails_bridge.rb', line 165

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



137
138
139
# File 'lib/amrita2/rails_bridge.rb', line 137

def setup_template(template)
  setup_template_default(template)
end

#setup_template_default(template) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/amrita2/rails_bridge.rb', line 141

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