Class: Malt::Formats::Ruby
- Defined in:
- lib/malt/formats/ruby.rb
Overview
Yes, pure Ruby as a template format.
The ruby code is run through eval and whatever is returned is given as the rendering.
The Ruby format is a polyglot format –it accepts all conversion types and assumes the end-user knows it will be the result.
The Ruby type is also used for “precompiling” other formats such as ERB.
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#method_missing(sym, *args, &yld) ⇒ Object
Ruby templates can be any type.
- #rb ⇒ Object (also: #ruby)
-
#render(*type_and_data, &yld) ⇒ Object
def render_to(to, db, &yld) malt_engine.render(text, file, db, &yld) end.
- #to(type, data = nil, &yld) ⇒ Object
- #to_rb ⇒ Object (also: #to_ruby)
Methods inherited from Abstract
#default, engine, #engine, #extensions, extensions, #file, #parse_type_and_data, #refile, register, #subtype, #text, #to_s, #type
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &yld) ⇒ Object
Ruby templates can be any type.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/malt/formats/ruby.rb', line 40 def method_missing(sym, *args, &yld) if Malt.registry.key?(sym) return to(sym, *args, &yld).to_s elsif md = /^to_/.match(sym.to_s) type = md.post_match.to_sym if Malt.registry.key?(type) return to(type, *args, &yld) end end super(sym, *args, &yld) end |
Instance Method Details
#rb ⇒ Object Also known as: ruby
23 |
# File 'lib/malt/formats/ruby.rb', line 23 def rb ; text ; end |
#render(*type_and_data, &yld) ⇒ Object
def render_to(to, db, &yld)
malt_engine.render(text, file, db, &yld)
end
57 58 59 60 |
# File 'lib/malt/formats/ruby.rb', line 57 def render(*type_and_data, &yld) type, data = parse_type_and_data(type_and_data) render_engine.render(:text=>text, :file=>file, :data=>data, &yld) end |
#to(type, data = nil, &yld) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/malt/formats/ruby.rb', line 31 def to(type, data=nil, &yld) new_class = Malt.registry[type.to_sym] new_text = render(data, &yld) new_file = refile(type) = .merge(:text=>new_text, :file=>new_file) new_class.new() end |
#to_rb ⇒ Object Also known as: to_ruby
27 |
# File 'lib/malt/formats/ruby.rb', line 27 def to_rb ; self ; end |