Class: RubySlippers::Engine::Context
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Template
included, #markdown, #to_html
Constructor Details
#initialize(ctx = {}, config = {}, path = "/", env = {}) ⇒ Context
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/ruby_slippers/context.rb', line 7
def initialize ctx = {}, config = {}, path = "/", env = {}
@config, @context, @path, @env = config, ctx, path, env
@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
33
34
35
|
# File 'lib/ruby_slippers/context.rb', line 33
def method_missing m, *args, &blk
@context.respond_to?(m) ? @context.send(m, *args, &blk) : super
end
|
Instance Attribute Details
Returns the value of attribute env.
5
6
7
|
# File 'lib/ruby_slippers/context.rb', line 5
def env
@env
end
|
Instance Method Details
#render(page, type) ⇒ Object
22
23
24
25
|
# File 'lib/ruby_slippers/context.rb', line 22
def render page, type
content = to_html page, @config
type == :html ? to_html(:layout, @config, &Proc.new { content }) : send(:"to_#{type}", page)
end
|
18
19
20
|
# File 'lib/ruby_slippers/context.rb', line 18
def title
@config[:title]
end
|
#to_xml(page) ⇒ Object
Also known as:
to_atom
27
28
29
30
|
# File 'lib/ruby_slippers/context.rb', line 27
def to_xml page
xml = Builder::XmlMarkup.new(:indent => 2)
instance_eval File.read("#{Paths[:templates]}/#{page}.builder")
end
|