Class: Bookwatch::Subnav::TemplateCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/bookwatch/subnav/template_creator.rb

Defined Under Namespace

Classes: LinkHolder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fs, output_locations) ⇒ TemplateCreator

Returns a new instance of TemplateCreator.



7
8
9
10
# File 'lib/bookwatch/subnav/template_creator.rb', line 7

def initialize(fs, output_locations)
  @fs = fs
  @output_locations = output_locations
end

Instance Attribute Details

#fsObject (readonly)

Returns the value of attribute fs.



21
22
23
# File 'lib/bookwatch/subnav/template_creator.rb', line 21

def fs
  @fs
end

#html_doc_manipulatorObject (readonly)

Returns the value of attribute html_doc_manipulator.



21
22
23
# File 'lib/bookwatch/subnav/template_creator.rb', line 21

def html_doc_manipulator
  @html_doc_manipulator
end

#output_locationsObject (readonly)

Returns the value of attribute output_locations.



21
22
23
# File 'lib/bookwatch/subnav/template_creator.rb', line 21

def output_locations
  @output_locations
end

Instance Method Details

#create(navigation_entries, subnav_spec) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/bookwatch/subnav/template_creator.rb', line 12

def create(navigation_entries, subnav_spec)
  template_content = fs.read(template_path)
  links_template = ERB.new(fs.read(subnavs_path.join('_nav-links.erb')))

  populated_nav = ERB.new(template_content).result(LinkHolder.new(navigation_entries, links_template).get_binding)

  fs.write(text: populated_nav, to: subnav_destination(subnav_spec.subnav_name))
end