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



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

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

.clear_html(html) ⇒ Object



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

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
# 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
end

.pars(value) ⇒ Object



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

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