Class: TinMan::Site::Context

Inherits:
Object
  • Object
show all
Includes:
Template
Defined in:
lib/tinman.rb

Instance Method Summary collapse

Methods included from Template

included, #redcloth, #to_html

Constructor Details

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

Returns a new instance of Context.



145
146
147
148
149
150
151
152
153
154
# File 'lib/tinman.rb', line 145

def initialize ctx = {}, config = {}, path = "/"
  @config, @context, @path = config, ctx, path
  @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
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



171
172
173
# File 'lib/tinman.rb', line 171

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

Instance Method Details

#render(page, type) ⇒ Object



160
161
162
163
# File 'lib/tinman.rb', line 160

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

#titleObject



156
157
158
# File 'lib/tinman.rb', line 156

def title
  @config[:title]
end

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



165
166
167
168
# File 'lib/tinman.rb', line 165

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