Class: Bookwatch::DitaHtmlForMiddlemanFormatter
- Inherits:
-
Object
- Object
- Bookwatch::DitaHtmlForMiddlemanFormatter
- Defined in:
- lib/bookwatch/dita_html_for_middleman_formatter.rb
Instance Method Summary collapse
- #format_html(src, dest) ⇒ Object
-
#initialize(file_system_accessor, html_document_manipulator) ⇒ DitaHtmlForMiddlemanFormatter
constructor
A new instance of DitaHtmlForMiddlemanFormatter.
Constructor Details
#initialize(file_system_accessor, html_document_manipulator) ⇒ DitaHtmlForMiddlemanFormatter
Returns a new instance of DitaHtmlForMiddlemanFormatter.
4 5 6 7 |
# File 'lib/bookwatch/dita_html_for_middleman_formatter.rb', line 4 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
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bookwatch/dita_html_for_middleman_formatter.rb', line 9 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') cleansed_body_text = revert_to_erb(file_body_text) 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) + cleansed_body_text file_system_accessor.write(to: new_filepath, text: output_text) end end |