Class: CreateHtmlPage

Inherits:
Object
  • Object
show all
Defined in:
lib/create_html_page.rb

Overview

create html page

Class Method Summary collapse

Class Method Details

.add_content(page, content) ⇒ Object



19
20
21
# File 'lib/create_html_page.rb', line 19

def self.add_content(page, content)
  page.insert(page.index('</body>'), "&nbsp;&nbsp;#{content}").join("\n")
end

.clear_html(html) ⇒ Object



23
24
25
# File 'lib/create_html_page.rb', line 23

def self.clear_html(html)
  Sanitize.fragment(html, Sanitize::Config::RELAXED)
end

.create_page(content: '', name: 'index.html', bypass_html: false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/create_html_page.rb', line 6

def self.create_page(content: '', name: 'index.html', bypass_html: false)
  page = ['<!DOCTYPE html>', '<html lang="en">', '<head>', '<meta charset="UTF-8">', '<title>New page</title>',
          '</head>', '<body>', '</body>', '</html>']
  file_html = File.new(name, 'w+')
  pars = CreateHtmlPage.pars(content)
  if bypass_html
    file_html.write(CreateHtmlPage.add_content(page, pars))
  else
    file_html.write(CreateHtmlPage.add_content(page, CreateHtmlPage.clear_html(pars)))
  end
  file_html.close
end

.pars(value) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/create_html_page.rb', line 27

def self.pars(value)
  if value.is_a?(Hash)
    value.map { |k, v| "<div>\n<p>#{k} = #{v}</p>\n</div>\n" }.join
  else
    value
  end
end