Class: Erbside::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/erbside/context.rb

Overview

Tilling Context

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, resources = []) ⇒ Context

Returns a new instance of Context.



13
14
15
16
17
# File 'lib/erbside/context.rb', line 13

def initialize(file, resources=[])
  @filename  = file
  @directory = File.dirname(file)
  @metadata  = Metadata.new(resources)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(s) ⇒ Object



20
21
22
# File 'lib/erbside/context.rb', line 20

def method_missing(s)
  @metadata.send(s)
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



10
11
12
# File 'lib/erbside/context.rb', line 10

def 
  @metadata
end

Instance Method Details

#render(text) ⇒ Object

Processes through erb.



35
36
37
38
39
40
41
# File 'lib/erbside/context.rb', line 35

def render(text)
  Dir.chdir(@directory) do
    erb = ERB.new(text)
    erb.filename = @filename.to_s
    erb.result(binding)
  end
end

#rootObject



25
26
27
# File 'lib/erbside/context.rb', line 25

def root
  .root
end

#to_hObject



30
31
32
# File 'lib/erbside/context.rb', line 30

def to_h
  @metadata.to_h
end