class Bookwatch::DitaHtmlForMiddlemanFormatter
Attributes
file_system_accessor[R]
html_document_manipulator[R]
Public Class Methods
new(file_system_accessor, html_document_manipulator)
click to toggle source
# 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
Public Instance Methods
format_html(src, dest)
click to toggle source
# 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
Private Instance Methods
frontmatter(title)
click to toggle source
# File lib/bookwatch/dita_html_for_middleman_formatter.rb, line 36 def frontmatter(title) sanitized_title = title.gsub('"', '\"') "---\ntitle: \"#{sanitized_title}\"\ndita: true\n---\n" end
revert_to_erb(text)
click to toggle source
# File lib/bookwatch/dita_html_for_middleman_formatter.rb, line 41 def revert_to_erb(text) text.gsub('<%', '<%').gsub('%>', '%>').gsub('<\%', '<%') end