Class: Comatose::ProcessingContext

Inherits:
Object
  • Object
show all
Defined in:
lib/comatose/processing_context.rb

Overview

This is the rendering context object you have access to in text processing…

Constant Summary collapse

@@supported_methods =
%w(page include)

Instance Method Summary collapse

Constructor Details

#initialize(page, locals = {}) ⇒ ProcessingContext

Returns a new instance of ProcessingContext.



5
6
7
8
# File 'lib/comatose/processing_context.rb', line 5

def initialize( page, locals={} )
  @locals = locals.stringify_keys if locals.respond_to? :stringify_keys
  @page = Comatose::PageWrapper.new(page, @locals)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/comatose/processing_context.rb', line 54

def method_missing(method_id, *args)
  method_name = method_id.to_s
  if @locals.has_key? method_name
    @locals[method_name]
  elsif Comatose.registered_drops.has_key? method_name
    Comatose.registered_drops[method_name].context = self
    Comatose.registered_drops[method_name]
  else
    "<!-- ProcessingContext: Couldn't find #{method_id} -->"
  end
end

Instance Method Details

#[](key) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/comatose/processing_context.rb', line 32

def [](key)
  if key.to_s.downcase == 'page'
    @page
  elsif @locals.has_key? key
    @locals[key]
  elsif Comatose.registered_drops.has_key? key
    Comatose.registered_drops[key]
  end
end

#find_by_path(path) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/comatose/processing_context.rb', line 23

def find_by_path(path)
  begin
    page = ComatosePage.find_by_path(path)
    Comatose::PageWrapper.new(page, @locals)
  rescue
    "<p>Page at <tt>#{path}</tt> could not be found.</p>"
  end
end

#get_bindingObject



50
51
52
# File 'lib/comatose/processing_context.rb', line 50

def get_binding
  binding
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/comatose/processing_context.rb', line 42

def has_key?(key)
  @@supported_methods.include?(key) or @locals.has_key?(key) or Comatose.registered_drops.has_key?(key)
end

#include(path, locals = {}) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/comatose/processing_context.rb', line 14

def include(path, locals={})
  begin
    page = ComatosePage.find_by_path(path)
    page.to_html( @locals.merge(locals) )
  rescue
    "<p>Page at <tt>#{path}</tt> could not be found.</p>"
  end
end

#pageObject



10
11
12
# File 'lib/comatose/processing_context.rb', line 10

def page
  @page
end

#to_liquidObject



46
47
48
# File 'lib/comatose/processing_context.rb', line 46

def to_liquid
  self
end