Module: TotoBongo::Template

Included in:
Archives, Article, Site::Context
Defined in:
lib/toto-bongo.rb

Overview

Handles all templating options Is responsible for:

  1. Calling the Haml engine on pages to render them to html

  2. Calling the markdown engine on markdown text to render them to html

  3. Registering All the classes at initialization

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Intercept any method missing



92
93
94
95
# File 'lib/toto-bongo.rb', line 92

def method_missing m, *args, &blk
  TotoBongo::logger.debug("Called method_missing: method = #{method_missin}")
  self.keys.include?(m) ? self[m] : super
end

Class Method Details

.included(obj) ⇒ Object

define the following methods during initialization TotoBongo::Site::Context TotoBongo::Repo TotoBongo::Archives TotoBongo::Article



104
105
106
107
108
109
# File 'lib/toto-bongo.rb', line 104

def self.included obj
  TotoBongo::logger.debug("Called Template::include: obj = #{obj}")
  obj.class_eval do
    define_method(obj.to_s.split('::').last.downcase) { self }
  end
end

Instance Method Details

#markdown(text) ⇒ Object

Converst a markdown text into html



78
79
80
81
82
83
84
85
86
87
# File 'lib/toto-bongo.rb', line 78

def markdown text
 TotoBongo::logger.debug("Called Template::Markdown")
 if (options = @config[:markdown])
    Markdown.new(text.to_s.strip, *(options.eql?(true) ? [] : options)).to_html
  else
    text.strip
  end
 
 Markdown.new(text.to_s.strip).to_html
end

#to_html(page, config, &blk) ⇒ Object

This will call Haml render Call the config block to make convert the page to html



69
70
71
72
73
# File 'lib/toto-bongo.rb', line 69

def to_html page, config, &blk
  TotoBongo::logger.debug("Called Template::to_html")
  path = ([:layout, :repo].include?(page) ? Paths[:templates] : Paths[:pages])
  result = config[:to_html].call(path, page, binding)
end