Class: Toto::Site::Context

Inherits:
Object show all
Includes:
Template
Defined in:
lib/toto-haml.rb

Instance Method Summary collapse

Methods included from Template

included, #markdown, #to_html

Constructor Details

#initialize(ctx = {}, config = {}, path = "/") ⇒ Context

Returns a new instance of Context.



152
153
154
155
156
157
158
159
160
161
# File 'lib/toto-haml.rb', line 152

def initialize ctx = {}, config = {}, path = "/"
  @config, @context, @path = config, ctx, path
  @articles = Site.articles(@config[:ext]).reverse.map do |a|
    Article.new(File.new(a), @config)
  end

  ctx.each do |k, v|
    meta_def(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



177
178
179
# File 'lib/toto-haml.rb', line 177

def method_missing m, *args, &blk
  @context.respond_to?(m) ? @context.send(m) : super
end

Instance Method Details

#render(page, type) ⇒ Object



167
168
169
# File 'lib/toto-haml.rb', line 167

def render page, type
  type == :html ? to_html(:layout, &Proc.new { to_html page }) : send(:"to_#{type}", :feed)
end

#titleObject



163
164
165
# File 'lib/toto-haml.rb', line 163

def title
  @config[:title]
end

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



171
172
173
174
# File 'lib/toto-haml.rb', line 171

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