Class: Bookbinder::Subnav::TemplateCreator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fs, output_locations, html_doc_manipulator) ⇒ TemplateCreator

Returns a new instance of TemplateCreator.



8
9
10
11
12
# File 'lib/bookbinder/subnav/template_creator.rb', line 8

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

Instance Attribute Details

#fsObject (readonly)

Returns the value of attribute fs.



28
29
30
# File 'lib/bookbinder/subnav/template_creator.rb', line 28

def fs
  @fs
end

#html_doc_manipulatorObject (readonly)

Returns the value of attribute html_doc_manipulator.



28
29
30
# File 'lib/bookbinder/subnav/template_creator.rb', line 28

def html_doc_manipulator
  @html_doc_manipulator
end

#output_locationsObject (readonly)

Returns the value of attribute output_locations.



28
29
30
# File 'lib/bookbinder/subnav/template_creator.rb', line 28

def output_locations
  @output_locations
end

Instance Method Details

#create(props_filename, subnav_spec) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bookbinder/subnav/template_creator.rb', line 14

def create(props_filename, subnav_spec)
  template_content = fs.read(template_path)
  nav_with_props = html_doc_manipulator.set_attribute(document: template_content,
                                                      selector: 'div.nav-content',
                                                      attribute: 'data-props-location',
                                                      value: props_filename)

  nav_content = html_doc_manipulator.add_class(document: nav_with_props,
                                                   selector: 'div.nav-content',
                                                   classname: nav_type(subnav_spec))

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