Class: Toto::Site::Context
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
-
#initialize(ctx = {}, config = {}, path = "/", env = {}) ⇒ Context
constructor
A new instance of Context.
- #method_missing(m, *args, &blk) ⇒ Object
- #render(page, type) ⇒ Object
- #title ⇒ Object
- #to_xml(page) ⇒ Object (also: #to_atom)
Methods included from Template
Constructor Details
#initialize(ctx = {}, config = {}, path = "/", env = {}) ⇒ Context
Returns a new instance of Context.
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/toto.rb', line 152 def initialize ctx = {}, config = {}, path = "/", env = {} @config, @context, @path, @env = config, ctx, path, env @articles = Site.articles(@config[:ext]).reverse.map do |a| Article.new(a, @config) end ctx.each do |k, v| (k) { ctx.instance_of?(Hash) ? v : ctx.send(k) } end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &blk) ⇒ Object
178 179 180 |
# File 'lib/toto.rb', line 178 def method_missing m, *args, &blk @context.respond_to?(m) ? @context.send(m, *args, &blk) : super end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
150 151 152 |
# File 'lib/toto.rb', line 150 def env @env end |
Instance Method Details
#render(page, type) ⇒ Object
167 168 169 170 |
# File 'lib/toto.rb', line 167 def render page, type content = to_html page, @config type == :html ? to_html(:layout, @config, &Proc.new { content }) : send(:"to_#{type}", page) end |
#title ⇒ Object
163 164 165 |
# File 'lib/toto.rb', line 163 def title @config[:title] end |