Class: HtmlRender

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, template, outputFile) ⇒ HtmlRender

Returns a new instance of HtmlRender.



14
15
16
17
18
19
20
21
22
23
# File 'lib/almirah/html_render.rb', line 14

def initialize(document, template, outputFile)

    @template = template
    @outputFile = outputFile
    @htmlRows = Array.new
    @document = document

    self.render()
    self.saveRenderToFile()
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



12
13
14
# File 'lib/almirah/html_render.rb', line 12

def document
  @document
end

#htmlRowsObject

Returns the value of attribute htmlRows.



10
11
12
# File 'lib/almirah/html_render.rb', line 10

def htmlRows
  @htmlRows
end

#outputFileObject

Returns the value of attribute outputFile.



11
12
13
# File 'lib/almirah/html_render.rb', line 11

def outputFile
  @outputFile
end

#templateObject

Returns the value of attribute template.



9
10
11
# File 'lib/almirah/html_render.rb', line 9

def template
  @template
end

Instance Method Details

#renderObject



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

def render()
    self.htmlRows.append('')

    self.document.docItems.each do |item|    
        a = item.to_html
        self.htmlRows.append a
    end
end

#saveRenderToFileObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/almirah/html_render.rb', line 34

def saveRenderToFile()

    file = File.open( self.template )
    file_data = file.readlines
    file.close

    file = File.open( self.outputFile, "w" )
    file_data.each do |s|
        if s.include?('{{CONTENT}}')
            self.htmlRows.each do |r|
                file.puts r
            end
        else
            file.puts s
        end
    end
    file.close
end