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 Method Summary collapse

Methods included from Vedeu::RendererOptions

#options

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.



26
27
28
29
# File 'lib/vedeu/output/renderers/html.rb', line 26

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

Instance Method Details

#default_templateString (private)

Returns:

  • (String)


113
114
115
# File 'lib/vedeu/output/renderers/html.rb', line 113

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>)


98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/vedeu/output/renderers/html.rb', line 98

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)


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

def end_row_tag
  options[:end_row_tag]
end

#end_tagString (private)

Returns:

  • (String)


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

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)


61
62
63
# File 'lib/vedeu/output/renderers/html.rb', line 61

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

#html_bodyString

Returns:

  • (String)


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vedeu/output/renderers/html.rb', line 40

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:



66
67
68
# File 'lib/vedeu/output/renderers/html.rb', line 66

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

#render(output) ⇒ String

Parameters:

Returns:

  • (String)


33
34
35
36
37
# File 'lib/vedeu/output/renderers/html.rb', line 33

def render(output)
  @output = output

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

#start_row_tagString (private)

Returns:

  • (String)


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

def start_row_tag
  options[:start_row_tag]
end

#start_tagString (private)

Returns:

  • (String)


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

def start_tag
  options[:start_tag]
end

#templateString (private)

Returns:

  • (String)


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

def template
  options[:template]
end