Class: Vedeu::Renderers::HTML

Inherits:
File
  • Object
show all
Defined in:
lib/vedeu/output/renderers/html.rb

Overview

Renders a Terminal::Buffer as a HTML snippet; a table by default.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Vedeu::Renderers::HTML

Returns a new instance of Vedeu::Renderers::HTML.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • content (String)

    Defaults to an empty string.

  • end_tag (String)

    Defaults to ‘</td>’.

  • end_row_tag (String)

    Defaults to ‘</tr>’.

  • filename (String)

    Provide a filename for the output. Defaults to ‘out’.

  • start_tag (String)

    Defaults to ‘<td’ (note the end of the tag is missing, this is so that inline styles can be added later).

  • start_row_tag (String)

    Defaults to ‘<tr>’.

  • template (String)
  • timestamp (Boolean)

    Append a timestamp to the filename.

  • write_file (Boolean)

    Whether to write the file to the given filename.



28
29
30
31
# File 'lib/vedeu/output/renderers/html.rb', line 28

def initialize(options = {})
  @options = options || {}
  @output  = nil
end

Instance Attribute Details

#optionsHash<Symbol => void> (private) Originally defined in module Options

Combines the options provided at instantiation with the default values.

Returns:

  • (Hash<Symbol => void>)

Instance Method Details

#clearString

Render a cleared output.

Returns:

  • (String)


36
37
38
39
40
# File 'lib/vedeu/output/renderers/html.rb', line 36

def clear
  @output = Vedeu::Models::Escape.new

  ''
end

#default_templateString (private)

Returns:

  • (String)


124
125
126
# File 'lib/vedeu/output/renderers/html.rb', line 124

def default_template
  ::File.dirname(__FILE__) + '/../templates/html_renderer.vedeu'
end

#defaultsHash<Symbol => void> (private)

The default values for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/vedeu/output/renderers/html.rb', line 109

def defaults
  {
    content:       '',
    end_tag:       '</td>',
    end_row_tag:   '</tr>',
    filename:      'out',
    start_tag:     '<td',
    start_row_tag: '<tr>',
    template:      default_template,
    timestamp:     false,
    write_file:    true,
  }
end

#end_row_tagString (private)

Returns:

  • (String)


87
88
89
# File 'lib/vedeu/output/renderers/html.rb', line 87

def end_row_tag
  options[:end_row_tag]
end

#end_tagString (private)

Returns:

  • (String)


82
83
84
# File 'lib/vedeu/output/renderers/html.rb', line 82

def end_tag
  options[:end_tag]
end

#escape?Boolean (private)

Returns a boolean indicating whether the output is a Models::Escape. If it is, it won’t be rendered in HTML.

Returns:

  • (Boolean)


72
73
74
# File 'lib/vedeu/output/renderers/html.rb', line 72

def escape?
  output.is_a?(Vedeu::Models::Escape)
end

#html_bodyString

Returns:

  • (String)


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vedeu/output/renderers/html.rb', line 51

def html_body
  return '' if output.is_a?(Vedeu::Models::Escape)

  out = ''

  output.each do |line|
    out << "#{start_row_tag}\n"
    line.each { |char| out << char.to_html(options) }
    out << "#{end_row_tag}\n"
  end

  out
end

#outputArray<Array<Vedeu::Views::Char>> (private)

Returns:



77
78
79
# File 'lib/vedeu/output/renderers/html.rb', line 77

def output
  @output || options[:output]
end

#render(output) ⇒ String

Parameters:

Returns:

  • (String)


44
45
46
47
48
# File 'lib/vedeu/output/renderers/html.rb', line 44

def render(output)
  @output = output

  super(Vedeu::Templating::Template.parse(self, template)) unless escape?
end

#start_row_tagString (private)

Returns:

  • (String)


97
98
99
# File 'lib/vedeu/output/renderers/html.rb', line 97

def start_row_tag
  options[:start_row_tag]
end

#start_tagString (private)

Returns:

  • (String)


92
93
94
# File 'lib/vedeu/output/renderers/html.rb', line 92

def start_tag
  options[:start_tag]
end

#templateString (private)

Returns:

  • (String)


102
103
104
# File 'lib/vedeu/output/renderers/html.rb', line 102

def template
  options[:template]
end