Class: Bookbinder::DitaHtmlToMiddlemanFormatter
- Inherits:
-
Object
- Object
- Bookbinder::DitaHtmlToMiddlemanFormatter
- Defined in:
- lib/bookbinder/dita_html_to_middleman_formatter.rb
Instance Method Summary collapse
- #format_html(src, dest) ⇒ Object
- #format_subnav(path_to_dita_section, subnav_template_text, json_props_location, unformatted_subnav_text) ⇒ Object
-
#initialize(file_system_accessor, subnav_formatter, html_document_manipulator) ⇒ DitaHtmlToMiddlemanFormatter
constructor
A new instance of DitaHtmlToMiddlemanFormatter.
Constructor Details
#initialize(file_system_accessor, subnav_formatter, html_document_manipulator) ⇒ DitaHtmlToMiddlemanFormatter
Returns a new instance of DitaHtmlToMiddlemanFormatter.
6 7 8 9 10 |
# File 'lib/bookbinder/dita_html_to_middleman_formatter.rb', line 6 def initialize(file_system_accessor, , html_document_manipulator) @file_system_accessor = file_system_accessor = @html_document_manipulator = html_document_manipulator end |
Instance Method Details
#format_html(src, dest) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bookbinder/dita_html_to_middleman_formatter.rb', line 12 def format_html(src, dest) all_files_with_ext = file_system_accessor.find_files_with_ext('html', src) all_files_with_ext.map do |filepath| file_text = file_system_accessor.read filepath file_title_text = html_document_manipulator.read_html_in_tag(document: file_text, tag: 'title') file_body_text = html_document_manipulator.read_html_in_tag(document: file_text, tag: 'body') relative_path_to_file = file_system_accessor.relative_path_from(src, filepath) new_filepath = File.join dest, "#{relative_path_to_file}.erb" output_text = frontmatter(file_title_text) + file_body_text file_system_accessor.write(to: new_filepath, text: output_text) end end |
#format_subnav(path_to_dita_section, subnav_template_text, json_props_location, unformatted_subnav_text) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bookbinder/dita_html_to_middleman_formatter.rb', line 32 def (path_to_dita_section, , json_props_location, ) formatted_json_links = .get_links_as_json(, path_to_dita_section) nav_text = html_document_manipulator.set_attribute(document: , selector: 'div.nav-content', attribute: 'data-props-location', value: json_props_location) Subnav.new(formatted_json_links, nav_text) end |