Class: UndriveGoogle::Transformations::FixHtml
- Inherits:
-
Object
- Object
- UndriveGoogle::Transformations::FixHtml
- Extended by:
- Forwardable
- Defined in:
- lib/undrive_google/transformations/fix_html.rb
Overview
In Google Doc generated HTML, optionally replace:
<html><head>
with
<html lang="en"><head><title>Peter Boling's Bounce to the Ounce</title>
Instance Attribute Summary collapse
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#title ⇒ Object
Returns the value of attribute title.
-
#unzip ⇒ Object
Returns the value of attribute unzip.
Instance Method Summary collapse
-
#initialize(unzip) ⇒ FixHtml
constructor
A new instance of FixHtml.
- #lang_valid? ⇒ Boolean
-
#process ⇒ Object
Nil.
- #title_valid? ⇒ Boolean
Constructor Details
Instance Attribute Details
#lang ⇒ Object
Returns the value of attribute lang.
16 17 18 |
# File 'lib/undrive_google/transformations/fix_html.rb', line 16 def lang @lang end |
#title ⇒ Object
Returns the value of attribute title.
16 17 18 |
# File 'lib/undrive_google/transformations/fix_html.rb', line 16 def title @title end |
#unzip ⇒ Object
Returns the value of attribute unzip.
16 17 18 |
# File 'lib/undrive_google/transformations/fix_html.rb', line 16 def unzip @unzip end |
Instance Method Details
#lang_valid? ⇒ Boolean
45 46 47 |
# File 'lib/undrive_google/transformations/fix_html.rb', line 45 def lang_valid? lang && lang.length >= 2 end |
#process ⇒ Object
Returns nil.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/undrive_google/transformations/fix_html.rb', line 28 def process return unless lang_valid? || title_valid? raise UndriveGoogle::Error, "No file at #{html_path}" unless File.exist?(html_path) puts "Checking html in #{html_path}" if Options.instance.verbose file = File.open(html_path) html = file.read return unless html.length >= 12 # open & close <html> or <head> is at least 12 chars puts "Fixing html in #{html_path}" if Options.instance.verbose html.sub!("<html>", "<html lang=\"#{lang}\">") if lang_valid? html.sub!("<head>", "<head><title>#{title}</title>") if title_valid? File.write(html_path, html) nil end |
#title_valid? ⇒ Boolean
49 50 51 |
# File 'lib/undrive_google/transformations/fix_html.rb', line 49 def title_valid? title && title.length >= 1 end |