Class: Madride::Context

Inherits:
Sprockets::Context
  • Object
show all
Defined in:
lib/madride/context.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.localsObject



6
7
8
# File 'lib/madride/context.rb', line 6

def self.locals
  @locals ||= {}
end

Instance Method Details

#evaluate(path, options = {}, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/madride/context.rb', line 22

def evaluate(path, options = {}, &block)
  pathname   = resolve(path)
  attributes = environment.attributes_for(pathname)
  processors = options[:processors] || attributes.processors

  if options[:data]
    result = options[:data]
  else
    if environment.respond_to?(:default_external_encoding)
      mime_type = environment.mime_types(pathname.extname)
      encoding  = environment.encoding_for_mime_type(mime_type)
      result    = Sprockets::Utils.read_unicode(pathname, encoding)
    else
      result = Sprockets::Utils.read_unicode(pathname)
    end
  end

  processors.each do |processor|
    begin
      template  = processor.new(pathname.to_s) { result }
      result    = template.render(self, locals){ options[:yield] }
    rescue Exception => e
      annotate_exception! e
      raise
    end
  end

  if @layout
    begin
      layout = self.class.new(environment, @layout, resolve(@layout))
      result = layout.evaluate(@layout, :yield => result)
    rescue Exception => e
      annotate_exception! e
      raise
    end
  end

  result
end

#layout=(path) ⇒ Object



16
17
18
19
# File 'lib/madride/context.rb', line 16

def layout= path
  depend_on_asset path
  @layout = path
end

#localsObject



11
12
13
# File 'lib/madride/context.rb', line 11

def locals
  self.class.locals
end