Class: Template::Html
- Inherits:
-
Object
- Object
- Template::Html
- Defined in:
- lib/template.rb
Overview
This Class handles creating and writing HTML output files
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Instance Method Summary collapse
-
#close ⇒ Object
Writes footer to file and closes it.
-
#initialize(dir, attr_labels) ⇒ Html
constructor
dir: basename of root directory attr_labels: array of attributes labels as strings.
-
#insert(img_attrs) ⇒ Object
Writes data row to file.
Constructor Details
#initialize(dir, attr_labels) ⇒ Html
dir: basename of root directory attr_labels: array of attributes labels as strings
38 39 40 41 42 43 |
# File 'lib/template.rb', line 38 def initialize(dir, attr_labels) @file_name = "tmp/output/#{dir}_#{Time.now.to_i}.html" @file = File.new(@file_name, 'w') @template_path = set_template_path append_header(dir, attr_labels) end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
34 35 36 |
# File 'lib/template.rb', line 34 def file_name @file_name end |
Instance Method Details
#close ⇒ Object
Writes footer to file and closes it
54 55 56 57 58 59 |
# File 'lib/template.rb', line 54 def close = File.read("#{@template_path}_footer.html.erb") partial = ERB.new().result(binding) @file.write(partial) @file.close end |
#insert(img_attrs) ⇒ Object
Writes data row to file
46 47 48 49 50 51 |
# File 'lib/template.rb', line 46 def insert(img_attrs) @img_attrs = img_attrs row = File.read("#{@template_path}_row.html.erb") partial = ERB.new(row, nil, '-').result(binding) @file.write(partial) end |