Module: Vedeu::Renderers::Options
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
#options ⇒ Hash<Symbol => void>
15
16
17
|
# File 'lib/vedeu/renderers/support/options.rb', line 15
def options
@options
end
|
Instance Method Details
#clear ⇒ String
42
43
44
|
# File 'lib/vedeu/renderers/support/options.rb', line 42
def clear
render('')
end
|
#compression ⇒ String
Compresses the output depending on configuration.
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
Returns a boolean indicating whether the content should be compressed if compression is available.
65
66
67
|
# File 'lib/vedeu/renderers/support/options.rb', line 65
def compression?
boolean(options[:compression])
end
|
#default_template ⇒ String
104
105
106
|
# File 'lib/vedeu/renderers/support/options.rb', line 104
def default_template
::File.dirname(__FILE__) + '/../templates/html_renderer.vedeu'
end
|
#defaults ⇒ Hash<Symbol => void>
The default options/attributes for a new instance of this class.
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_tag ⇒ String
114
115
116
|
# File 'lib/vedeu/renderers/support/options.rb', line 114
def end_row_tag
options[:end_row_tag]
end
|
#end_tag ⇒ String
109
110
111
|
# File 'lib/vedeu/renderers/support/options.rb', line 109
def end_tag
options[:end_tag]
end
|
#filename ⇒ String
Return the filename given in the options, (or use the default), and append a timestamp if the :timestamp option was set to true.
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.
35
36
37
|
# File 'lib/vedeu/renderers/support/options.rb', line 35
def initialize(opts = {})
@options = defaults.merge!(opts || {})
end
|
#output ⇒ Array<void>
138
139
140
|
# File 'lib/vedeu/renderers/support/options.rb', line 138
def output
options[:output]
end
|
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.
48
49
50
51
52
|
# File 'lib/vedeu/renderers/support/options.rb', line 48
def render(output = '')
options[:output] = output
write
end
|
#start_row_tag ⇒ String
133
134
135
|
# File 'lib/vedeu/renderers/support/options.rb', line 133
def start_row_tag
options[:start_row_tag]
end
|
#start_tag ⇒ String
128
129
130
|
# File 'lib/vedeu/renderers/support/options.rb', line 128
def start_tag
options[:start_tag]
end
|
#template ⇒ String
148
149
150
|
# File 'lib/vedeu/renderers/support/options.rb', line 148
def template
options[:template]
end
|
#timestamp ⇒ String
Return a timestamp for use as part of the filename if the :timestamp option was set to true, otherwise an empty string.
161
162
163
164
165
|
# File 'lib/vedeu/renderers/support/options.rb', line 161
def timestamp
return "_#{Vedeu.clock_time}" if timestamp?
''
end
|
153
154
155
|
# File 'lib/vedeu/renderers/support/options.rb', line 153
def timestamp?
boolean(options[:timestamp])
end
|
#write_file ⇒ String
Render the output (either content or clearing) to a file.
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
Returns a boolean indicating whether a file should be written.
170
171
172
|
# File 'lib/vedeu/renderers/support/options.rb', line 170
def write_file?
boolean(options[:write_file])
end
|