Class: Marble::RailsTemplateHandler
- Inherits:
-
Object
- Object
- Marble::RailsTemplateHandler
- Defined in:
- lib/marble/rails_template_handler.rb
Overview
Rails plugin for using Marble as a template handler.
Marble has three output formats: text, JSON, and YAML. The template
handler calls to_s
, to_json
, and to_yaml
for each format,
respectively.
Marble sets up a builder for you; simply use the marble
variable to
access the builder. To rename the builder to another, possibly shorter
variable in order to save keystrokes, put the new variable name as the
name of the block parameter:
marble.hash do |m|
m.free 'toast'
end
Marble loads this module only if it can find ActionView
.
Instance Method Summary collapse
-
#call(template) ⇒ String
Compile the Rails template.
Instance Method Details
#call(template) ⇒ String
Compile the Rails template.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/marble/rails_template_handler.rb', line 26 def call(template) compiled = "builder = Marble.new;" + "builder.build { |marble| #{template.source} }." if template.formats.include?(:yaml) compiled += 'to_yaml' elsif template.formats.include?(:json) compiled += 'to_json' else compiled += 'to_s' end compiled end |