Class: RSX::TemplateHandler
- Inherits:
-
Object
- Object
- RSX::TemplateHandler
- Defined in:
- lib/rsx/template_handler.rb
Overview
ActionView handler for .rsx templates: app/views/users/show.html.rsx
The handler returns Ruby source, which ActionView compiles into a method on
the view context. That means a .rsx view is compiled once per process and
every Rails helper (url helpers, t, form builders, CSRF tags) is available
directly, because self inside the template is the view.
Class Method Summary collapse
-
.call(template, source = nil) ⇒ Object
ActionView passes (template) on older versions and (template, source) on 6.0+.
- .compile(source, identifier = nil) ⇒ Object
-
.handles_encoding? ⇒ Boolean
Templates render markup, not a component, so there is nothing to escape on the way out.
Class Method Details
.call(template, source = nil) ⇒ Object
ActionView passes (template) on older versions and (template, source) on 6.0+.
14 15 16 17 18 |
# File 'lib/rsx/template_handler.rb', line 14 def call(template, source = nil) source ||= template.source identifier = template.respond_to?(:identifier) ? template.identifier : nil compile(source, identifier) end |
.compile(source, identifier = nil) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/rsx/template_handler.rb', line 20 def compile(source, identifier = nil) ruby = RSX.compile(source, path: identifier) # Everything is kept on one line up to the body so that line numbers in # the compiled method still match the .rsx file. +"__rsx_value = begin;" << ruby << "\nend\n::RSX.template_result(__rsx_value)\n" end |
.handles_encoding? ⇒ Boolean
Templates render markup, not a component, so there is nothing to escape on the way out.
30 31 32 |
# File 'lib/rsx/template_handler.rb', line 30 def handles_encoding? true end |