Class: UndriveGoogle::Transformations::FixHtml

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(unzip) ⇒ FixHtml

Returns a new instance of FixHtml.



20
21
22
23
24
# File 'lib/undrive_google/transformations/fix_html.rb', line 20

def initialize(unzip)
  @unzip = unzip
  @lang = Options.instance.lang
  @title = Options.instance.title
end

Instance Attribute Details

#langObject

Returns the value of attribute lang.



16
17
18
# File 'lib/undrive_google/transformations/fix_html.rb', line 16

def lang
  @lang
end

#titleObject

Returns the value of attribute title.



16
17
18
# File 'lib/undrive_google/transformations/fix_html.rb', line 16

def title
  @title
end

#unzipObject

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

#processObject

Returns nil.

Returns:

  • nil



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/undrive_google/transformations/fix_html.rb', line 27

def process
  return unless lang || title

  puts "Checking html in #{html_path}" if Options.instance.verbose
  file = File.open(html_path)
  html = file.read
  return unless html

  puts "Fixing html in #{html_path}" if Options.instance.verbose
  html.sub!("<html>", "<html lang=\"#{lang}\">") if lang
  html.sub!("<head>", "<head><title>#{title}</title>") if title
  File.write(html_path, html)

  nil
end