Module: Vedeu::Renderers::Options

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

Overview

Provides shared functionality to Vedeu::Renderer classes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsHash<Symbol => void>

Returns:

  • (Hash<Symbol => void>)


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

def options
  @options
end

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#become(klass, attributes) ⇒ Class Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

#boolean(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the value was a boolean.

Parameters:

  • value (void)

Returns:

#boolean?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Boolean.

Parameters:

Returns:

#clearvoid

This method returns an undefined value.



40
41
42
# File 'lib/vedeu/renderers/options.rb', line 40

def clear
  render('')
end

#compressionString (private)

Compresses the output depending on configuration.

Returns:

  • (String)


70
71
72
73
74
75
76
77
78
# File 'lib/vedeu/renderers/options.rb', line 70

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:



63
64
65
# File 'lib/vedeu/renderers/options.rb', line 63

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

#contentObject (private)

Raises:

  • (Vedeu::Error::NotImplemented)

    When a subclass of the current class actually implements the method. Usually an indicator that the subclass should be used instead of the current class.



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

def content
  fail Vedeu::Error::NotImplemented, 'Including classes implement this.'
end

#default_templateString (private)

Returns:

  • (String)


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

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


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

def defaults
  {
    compression:   Vedeu.config.compression?,
    end_tag:       '</td>',
    end_row_tag:   '</tr>',
    filename:      '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/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/options.rb', line 109

def end_tag
  options[:end_tag]
end

#escape?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

#falsy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered false.

Parameters:

  • value (void)

Returns:

#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/options.rb', line 123

def filename
  options[:filename] + timestamp
end

#hash?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

#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/options.rb', line 35

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

#line_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Line.

Returns:

#numeric?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

#outputvoid (private)

This method returns an undefined value.



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

def output
  options[:output]
end

#output?Boolean (private)

Returns:



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

def output?
  present?(output)
end

#present?(variable) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#render(output = '') ⇒ void

This method returns an undefined value.

Parameters:



46
47
48
49
50
# File 'lib/vedeu/renderers/options.rb', line 46

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

  write
end

#snake_case(klass) ⇒ String Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

snake_case('MyClassName') # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

#start_row_tagString (private)

Returns:

  • (String)


133
134
135
# File 'lib/vedeu/renderers/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/options.rb', line 128

def start_tag
  options[:start_tag]
end

#stream_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::Stream.

Returns:

#string?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

#templateString (private)

Returns:

  • (String)


148
149
150
# File 'lib/vedeu/renderers/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/options.rb', line 161

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

  ''
end

#timestamp?Boolean (private)

Returns:



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

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

#truthy?(value) ⇒ Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating whether the value should be considered true.

Parameters:

  • value (void)

Returns:

#view_model?Boolean Originally defined in module Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the model is a Views::View.

Returns:

#writeObject

Raises:

  • (Vedeu::Error::NotImplemented)

    When a subclass of the current class actually implements the method. Usually an indicator that the subclass should be used instead of the current class.



53
54
55
# File 'lib/vedeu/renderers/options.rb', line 53

def write
  fail Vedeu::Error::NotImplemented, 'Including classes implement this.'
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/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/options.rb', line 170

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