Class: TotoBongo::Site::Context
- Includes:
- Template
- Defined in:
- lib/toto-bongo.rb
Overview
This class holds all the context to set the scope during rendering The context has access to the config and the article and defines all the article and archive method
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(ctx = {}, config = {}, path = "/", env = {}) ⇒ Context
constructor
A new instance of Context.
- #keywords ⇒ Object
- #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.
264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/toto-bongo.rb', line 264 def initialize ctx = {}, config = {}, path = "/", env = {} TotoBongo::logger.debug("Initialize context") @config, @context, @path, @env = config, ctx, path, env #for each article, initialize an article object @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 TotoBongo::logger.debug("End of initialize context") end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
262 263 264 |
# File 'lib/toto-bongo.rb', line 262 def env @env end |
Instance Method Details
#description ⇒ Object
283 284 285 286 |
# File 'lib/toto-bongo.rb', line 283 def description TotoBongo::logger.debug("Context::desciption") @config[:description] end |
#keywords ⇒ Object
288 289 290 291 |
# File 'lib/toto-bongo.rb', line 288 def keywords TotoBongo::logger.debug("Context::keywords") @config[:keywords] end |
#render(page, type) ⇒ Object
294 295 296 297 298 |
# File 'lib/toto-bongo.rb', line 294 def render page, type TotoBongo::logger.debug("Context::render") content = to_html page, @config type == :html ? to_html(:layout, @config, &Proc.new { content }) : send(:"to_#{type}", page) end |