Module: Vedeu::Renderers::Options

Includes:
Common
Included in:
Output::Compressor, Escape, File, HTML, JSON, Terminal, Text
Defined in:
lib/vedeu/renderers/support/options.rb

Overview

Provides shared functionality to Vedeu::Renderer classes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?

Instance Attribute Details

#optionsHash<Symbol => void>

Returns:

  • (Hash<Symbol => void>)


15
16
17
# File 'lib/vedeu/renderers/support/options.rb', line 15

def options
  @options
end

Instance Method Details

#clearString

Render a cleared output.

Returns:

  • (String)


42
43
44
# File 'lib/vedeu/renderers/support/options.rb', line 42

def clear
  render('')
end

#compressionString (private)

Compresses the output depending on configuration.

Returns:

  • (String)


72
73
74
75
76
77
78
79
80
# File 'lib/vedeu/renderers/support/options.rb', line 72

def compression
  if compression?
    Vedeu::Output::Compressor.render(output, options)

  else
    output

  end
end

#compression?Boolean (private)

Returns a boolean indicating whether the content should be compressed if compression is available.

Returns:



65
66
67
# File 'lib/vedeu/renderers/support/options.rb', line 65

def compression?
  boolean(options[:compression])
end

#contentObject (private)

Raises:

  • (Vedeu::Error::NotImplemented)

    When the method called should be handled by a subclass of the current class, or by the class including or extending the current module.



83
84
85
# File 'lib/vedeu/renderers/support/options.rb', line 83

def content
  raise Vedeu::Error::NotImplemented
end

#default_templateString (private)

Returns:

  • (String)


104
105
106
# File 'lib/vedeu/renderers/support/options.rb', line 104

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

#defaultsHash<Symbol => void> (private)

The default options/attributes for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/vedeu/renderers/support/options.rb', line 88

def defaults
  {
    compression:   Vedeu.config.compression?,
    end_tag:       '</td>',
    end_row_tag:   '</tr>',
    filename:      Dir.tmpdir + '/vedeu_out',
    output:        '',
    start_tag:     '<td',
    start_row_tag: '<tr>',
    template:      default_template,
    timestamp:     false,
    write_file:    false,
  }
end

#end_row_tagString (private)

Returns:

  • (String)


114
115
116
# File 'lib/vedeu/renderers/support/options.rb', line 114

def end_row_tag
  options[:end_row_tag]
end

#end_tagString (private)

Returns:

  • (String)


109
110
111
# File 'lib/vedeu/renderers/support/options.rb', line 109

def end_tag
  options[:end_tag]
end

#filenameString (private)

Return the filename given in the options, (or use the default), and append a timestamp if the :timestamp option was set to true.

Returns:

  • (String)


123
124
125
# File 'lib/vedeu/renderers/support/options.rb', line 123

def filename
  options[:filename] + timestamp
end

#initialize(opts = {}) ⇒ void

Returns a new instance of the class including this module.

Parameters:

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

Options Hash (opts):

  • 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.



35
36
37
# File 'lib/vedeu/renderers/support/options.rb', line 35

def initialize(opts = {})
  @options = defaults.merge!(opts || {})
end

#outputArray<void> (private)

Returns:

  • (Array<void>)


138
139
140
# File 'lib/vedeu/renderers/support/options.rb', line 138

def output
  options[:output]
end

#output?Boolean (private)

Returns:



143
144
145
# File 'lib/vedeu/renderers/support/options.rb', line 143

def output?
  present?(output)
end

#render(output = '') ⇒ void

This method returns an undefined value.

Parameters:



48
49
50
51
52
# File 'lib/vedeu/renderers/support/options.rb', line 48

def render(output = '')
  options[:output] = output

  write
end

#start_row_tagString (private)

Returns:

  • (String)


133
134
135
# File 'lib/vedeu/renderers/support/options.rb', line 133

def start_row_tag
  options[:start_row_tag]
end

#start_tagString (private)

Returns:

  • (String)


128
129
130
# File 'lib/vedeu/renderers/support/options.rb', line 128

def start_tag
  options[:start_tag]
end

#templateString (private)

Returns:

  • (String)


148
149
150
# File 'lib/vedeu/renderers/support/options.rb', line 148

def template
  options[:template]
end

#timestampString (private)

Return a timestamp for use as part of the filename if the :timestamp option was set to true, otherwise an empty string.

Returns:

  • (String)


161
162
163
164
165
# File 'lib/vedeu/renderers/support/options.rb', line 161

def timestamp
  return "_#{Vedeu.clock_time}" if timestamp?

  ''
end

#timestamp?Boolean (private)

Returns:



153
154
155
# File 'lib/vedeu/renderers/support/options.rb', line 153

def timestamp?
  boolean(options[:timestamp])
end

#writeObject

Raises:

  • (Vedeu::Error::NotImplemented)

    When the method called should be handled by a subclass of the current class, or by the class including or extending the current module.



55
56
57
# File 'lib/vedeu/renderers/support/options.rb', line 55

def write
  raise Vedeu::Error::NotImplemented
end

#write_fileString (private)

Render the output (either content or clearing) to a file.

Returns:

  • (String)


177
178
179
180
181
182
183
# File 'lib/vedeu/renderers/support/options.rb', line 177

def write_file
  data = content

  ::File.write(filename, data)

  data
end

#write_file?Boolean (private)

Returns a boolean indicating whether a file should be written.

Returns:



170
171
172
# File 'lib/vedeu/renderers/support/options.rb', line 170

def write_file?
  boolean(options[:write_file])
end