Class: Ottogen::Layout::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/ottogen/layout.rb

Constant Summary collapse

INCLUDES_DIR =
'_includes'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, site:, page:) ⇒ Context

Returns a new instance of Context.



47
48
49
50
51
# File 'lib/ottogen/layout.rb', line 47

def initialize(content:, site:, page:)
  @content = content
  @site = site
  @page = page
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



45
46
47
# File 'lib/ottogen/layout.rb', line 45

def content
  @content
end

#pageObject (readonly)

Returns the value of attribute page.



45
46
47
# File 'lib/ottogen/layout.rb', line 45

def page
  @page
end

#siteObject (readonly)

Returns the value of attribute site.



45
46
47
# File 'lib/ottogen/layout.rb', line 45

def site
  @site
end

Instance Method Details

#binding_for_erbObject



53
54
55
# File 'lib/ottogen/layout.rb', line 53

def binding_for_erb
  binding
end

#partial(name) ⇒ Object

Raises:



57
58
59
60
61
62
# File 'lib/ottogen/layout.rb', line 57

def partial(name)
  path = File.join(INCLUDES_DIR, name)
  raise Error, "include '#{name}' not found at #{path}" unless File.exist?(path)

  ERB.new(File.read(path), trim_mode: '-').result(binding_for_erb)
end