Class: TotoBongo::Site::Context

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Template

included, #markdown, #to_html

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|
    meta_def(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

#method_missing(m, *args, &blk) ⇒ Object



307
308
309
310
# File 'lib/toto-bongo.rb', line 307

def method_missing m, *args, &blk
  TotoBongo::logger.debug("Context::missing_method #{m}")
  @context.respond_to?(m) ? @context.send(m, *args, &blk) : super
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



262
263
264
# File 'lib/toto-bongo.rb', line 262

def env
  @env
end

Instance Method Details

#descriptionObject



283
284
285
286
# File 'lib/toto-bongo.rb', line 283

def description
  TotoBongo::logger.debug("Context::desciption")
  @config[:description]
end

#keywordsObject



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

#titleObject



278
279
280
281
# File 'lib/toto-bongo.rb', line 278

def title
  TotoBongo::logger.debug("Context::title")
  @config[:title]
end

#to_xml(page) ⇒ Object Also known as: to_atom



300
301
302
303
304
# File 'lib/toto-bongo.rb', line 300

def to_xml page
  TotoBongo::logger.debug("Context::to_xml")
  xml = Builder::XmlMarkup.new(:indent => 2)
  instance_eval File.read("#{Paths[:templates]}/#{page}.builder")
end