vedeu 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/views/_interfaces.rb +127 -0
- data/examples/views/empty_template.rb +10 -0
- data/examples/views/expected/vedeu_full_screen.html +140 -0
- data/examples/views/expected/vedeu_full_screen.json +96050 -0
- data/examples/views/expected/vedeu_full_screen.out +1 -0
- data/examples/views/expected/vedeu_full_screen.txt +50 -0
- data/examples/views/expected/vedeu_line.html +140 -0
- data/examples/views/expected/vedeu_line.json +96050 -0
- data/examples/views/expected/vedeu_line.out +1 -0
- data/examples/views/expected/vedeu_line.txt +58 -0
- data/examples/views/expected/vedeu_lines.html +140 -0
- data/examples/views/expected/vedeu_lines.json +96050 -0
- data/examples/views/expected/{lines.out → vedeu_lines.out} +1 -1
- data/examples/views/expected/vedeu_lines_alignment.html +80 -0
- data/examples/views/expected/vedeu_lines_alignment.json +46370 -0
- data/examples/views/expected/vedeu_lines_alignment.out +1 -0
- data/examples/views/full_screen.rb +10 -0
- data/examples/views/line.rb +11 -106
- data/examples/views/lines.rb +8 -127
- data/examples/views/lines_alignment.rb +17 -125
- data/examples/views/runner.sh +65 -19
- data/lib/vedeu/borders/border.rb +6 -6
- data/lib/vedeu/borders/refresh.rb +4 -6
- data/lib/vedeu/buffers/buffer.rb +1 -1
- data/lib/vedeu/buffers/terminal.rb +4 -4
- data/lib/vedeu/buffers/view.rb +2 -2
- data/lib/vedeu/cells/all.rb +2 -2
- data/lib/vedeu/cells/border.rb +5 -0
- data/lib/vedeu/cells/borders/all.rb +2 -8
- data/lib/vedeu/cells/borders/edges/all.rb +6 -0
- data/lib/vedeu/cells/borders/{bottom_horizontal.rb → edges/bottom_horizontal.rb} +0 -0
- data/lib/vedeu/cells/borders/{left_vertical.rb → edges/left_vertical.rb} +0 -0
- data/lib/vedeu/cells/borders/{right_vertical.rb → edges/right_vertical.rb} +0 -0
- data/lib/vedeu/cells/borders/{top_horizontal.rb → edges/top_horizontal.rb} +0 -0
- data/lib/vedeu/cells/borders/horizontal.rb +5 -0
- data/lib/vedeu/cells/borders/vertical.rb +5 -0
- data/lib/vedeu/cells/borders/vertices/all.rb +6 -0
- data/lib/vedeu/cells/borders/{bottom_left.rb → vertices/bottom_left.rb} +5 -0
- data/lib/vedeu/cells/borders/{bottom_right.rb → vertices/bottom_right.rb} +5 -0
- data/lib/vedeu/cells/borders/{top_left.rb → vertices/top_left.rb} +5 -0
- data/lib/vedeu/cells/borders/{top_right.rb → vertices/top_right.rb} +5 -0
- data/lib/vedeu/cells/char.rb +16 -0
- data/lib/vedeu/cells/clear.rb +5 -0
- data/lib/vedeu/cells/cursor.rb +70 -0
- data/lib/vedeu/cells/empty.rb +24 -14
- data/lib/vedeu/cells/escape.rb +8 -7
- data/lib/vedeu/cells/support/all.rb +3 -0
- data/lib/vedeu/cells/support/html.rb +98 -0
- data/lib/vedeu/colours/background.rb +21 -1
- data/lib/vedeu/colours/colour.rb +10 -2
- data/lib/vedeu/colours/foreground.rb +21 -1
- data/lib/vedeu/colours/translator.rb +17 -24
- data/lib/vedeu/colours/validator.rb +9 -9
- data/lib/vedeu/configuration/api.rb +1 -1
- data/lib/vedeu/cursors/cursor.rb +5 -5
- data/lib/vedeu/dsl/elements.rb +22 -79
- data/lib/vedeu/dsl/string/text.rb +3 -3
- data/lib/vedeu/editor/cropper.rb +2 -2
- data/lib/vedeu/editor/cursor.rb +1 -1
- data/lib/vedeu/editor/document.rb +1 -1
- data/lib/vedeu/geometries/area/dimension.rb +1 -1
- data/lib/vedeu/geometries/position.rb +5 -2
- data/lib/vedeu/interfaces/clear.rb +5 -5
- data/lib/vedeu/models/row.rb +4 -3
- data/lib/vedeu/output/compressor.rb +7 -7
- data/lib/vedeu/output/output.rb +8 -13
- data/lib/vedeu/output/viewport.rb +1 -1
- data/lib/vedeu/presentation/background.rb +2 -2
- data/lib/vedeu/presentation/colour.rb +0 -4
- data/lib/vedeu/presentation/foreground.rb +2 -2
- data/lib/vedeu/presentation/style.rb +1 -1
- data/lib/vedeu/presentation/styles.rb +0 -3
- data/lib/vedeu/renderers/file.rb +10 -68
- data/lib/vedeu/renderers/html.rb +28 -96
- data/lib/vedeu/renderers/json.rb +15 -31
- data/lib/vedeu/renderers/options.rb +160 -14
- data/lib/vedeu/renderers/templates/html_renderer.vedeu +1 -0
- data/lib/vedeu/renderers/terminal.rb +16 -17
- data/lib/vedeu/renderers/text.rb +32 -41
- data/lib/vedeu/version.rb +1 -1
- data/lib/vedeu/views/all.rb +0 -2
- data/lib/vedeu/views/chars.rb +6 -3
- data/lib/vedeu/views/stream.rb +3 -2
- data/test/lib/vedeu/borders/caption_test.rb +17 -17
- data/test/lib/vedeu/borders/title_test.rb +12 -12
- data/test/lib/vedeu/cells/border_test.rb +6 -0
- data/test/lib/vedeu/cells/borders/{bottom_horizontal_test.rb → edges/bottom_horizontal_test.rb} +0 -0
- data/test/lib/vedeu/cells/borders/{left_vertical_test.rb → edges/left_vertical_test.rb} +0 -0
- data/test/lib/vedeu/cells/borders/{right_vertical_test.rb → edges/right_vertical_test.rb} +0 -0
- data/test/lib/vedeu/cells/borders/{top_horizontal_test.rb → edges/top_horizontal_test.rb} +0 -0
- data/test/lib/vedeu/cells/borders/horizontal_test.rb +6 -0
- data/test/lib/vedeu/cells/borders/vertical_test.rb +6 -0
- data/test/lib/vedeu/cells/borders/{bottom_left_test.rb → vertices/bottom_left_test.rb} +6 -0
- data/test/lib/vedeu/cells/borders/{bottom_right_test.rb → vertices/bottom_right_test.rb} +6 -0
- data/test/lib/vedeu/cells/borders/{top_left_test.rb → vertices/top_left_test.rb} +6 -0
- data/test/lib/vedeu/cells/borders/{top_right_test.rb → vertices/top_right_test.rb} +6 -0
- data/test/lib/vedeu/cells/char_test.rb +18 -0
- data/test/lib/vedeu/cells/clear_test.rb +6 -0
- data/test/lib/vedeu/cells/cursor_test.rb +113 -0
- data/test/lib/vedeu/cells/empty_test.rb +100 -7
- data/test/lib/vedeu/cells/escape_test.rb +29 -13
- data/test/lib/vedeu/cells/support/html_test.rb +100 -0
- data/test/lib/vedeu/colours/background_test.rb +35 -3
- data/test/lib/vedeu/colours/colour_test.rb +66 -0
- data/test/lib/vedeu/colours/foreground_test.rb +35 -3
- data/test/lib/vedeu/colours/translator_test.rb +0 -34
- data/test/lib/vedeu/colours/validator_test.rb +84 -6
- data/test/lib/vedeu/cursors/cursor_test.rb +4 -4
- data/test/lib/vedeu/cursors/refresh_test.rb +4 -1
- data/test/lib/vedeu/dsl/string/text_test.rb +36 -36
- data/test/lib/vedeu/editor/cropper_test.rb +15 -15
- data/test/lib/vedeu/geometries/position_test.rb +14 -1
- data/test/lib/vedeu/models/page_test.rb +10 -10
- data/test/lib/vedeu/models/row_test.rb +7 -7
- data/test/lib/vedeu/output/compressor_test.rb +63 -50
- data/test/lib/vedeu/renderers/file_test.rb +64 -35
- data/test/lib/vedeu/renderers/html_test.rb +15 -12
- data/test/lib/vedeu/renderers/json_test.rb +79 -56
- data/test/lib/vedeu/renderers/options_test.rb +74 -26
- data/test/lib/vedeu/renderers/terminal_test.rb +34 -4
- data/test/lib/vedeu/renderers/text_test.rb +35 -3
- data/test/lib/vedeu/views/chars_test.rb +6 -0
- metadata +50 -41
- data/examples/views/expected/line.out +0 -1
- data/examples/views/expected/lines_alignment.out +0 -1
- data/lib/vedeu/cells/html.rb +0 -21
- data/lib/vedeu/cells/json.rb +0 -21
- data/lib/vedeu/views/char.rb +0 -180
- data/lib/vedeu/views/html_char.rb +0 -133
- data/test/lib/vedeu/cells/html_test.rb +0 -15
- data/test/lib/vedeu/cells/json_test.rb +0 -15
- data/test/lib/vedeu/views/char_test.rb +0 -283
- data/test/lib/vedeu/views/html_char_test.rb +0 -125
@@ -24,8 +24,8 @@ module Vedeu
|
|
24
24
|
@background ||= if colour && present?(colour.background)
|
25
25
|
colour.background
|
26
26
|
|
27
|
-
elsif
|
28
|
-
|
27
|
+
elsif named_colour?
|
28
|
+
named_colour.background
|
29
29
|
|
30
30
|
elsif parent && present?(parent.background)
|
31
31
|
parent.background
|
@@ -25,10 +25,6 @@ module Vedeu
|
|
25
25
|
elsif named_colour?
|
26
26
|
Vedeu::Colours::Colour.coerce(named_colour)
|
27
27
|
|
28
|
-
elsif self.is_a?(Vedeu::Views::Char) && name
|
29
|
-
# Currently used by Vedeu::Output::Viewport
|
30
|
-
Vedeu::Colours::Colour.coerce(interface.colour)
|
31
|
-
|
32
28
|
else
|
33
29
|
Vedeu::Colours::Colour.new
|
34
30
|
|
@@ -24,8 +24,8 @@ module Vedeu
|
|
24
24
|
@foreground ||= if colour && present?(colour.foreground)
|
25
25
|
colour.foreground
|
26
26
|
|
27
|
-
elsif
|
28
|
-
|
27
|
+
elsif named_colour?
|
28
|
+
named_colour.foreground
|
29
29
|
|
30
30
|
elsif parent && present?(parent.foreground)
|
31
31
|
parent.foreground
|
@@ -20,9 +20,6 @@ module Vedeu
|
|
20
20
|
@_style ||= if @style
|
21
21
|
Vedeu::Presentation::Style.coerce(@style)
|
22
22
|
|
23
|
-
elsif self.is_a?(Vedeu::Views::Char) && name
|
24
|
-
Vedeu::Presentation::Style.coerce(interface.style)
|
25
|
-
|
26
23
|
elsif parent && present?(parent.style)
|
27
24
|
Vedeu::Presentation::Style.coerce(parent.style)
|
28
25
|
|
data/lib/vedeu/renderers/file.rb
CHANGED
@@ -10,90 +10,32 @@ module Vedeu
|
|
10
10
|
|
11
11
|
include Vedeu::Renderers::Options
|
12
12
|
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
# @option options filename [String] Provide a filename for the
|
17
|
-
# output. Defaults to 'out'.
|
18
|
-
# @option options timestamp [Boolean] Append a timestamp to the
|
19
|
-
# filename.
|
20
|
-
# @option options write_file [Boolean] Whether to write the file
|
21
|
-
# to the given filename.
|
22
|
-
# @return [Vedeu::Renderers::File]
|
23
|
-
def initialize(options = {})
|
24
|
-
@options = options || {}
|
13
|
+
# @return [String]
|
14
|
+
def clear
|
15
|
+
render('')
|
25
16
|
end
|
26
17
|
|
27
18
|
# Render the output (either content or clearing) to a file.
|
28
19
|
#
|
29
|
-
# @param output [Vedeu::Models::Page]
|
30
|
-
# @param opts [Hash]
|
31
20
|
# @return [String]
|
32
|
-
def
|
33
|
-
|
21
|
+
def write
|
22
|
+
data = content
|
34
23
|
|
35
|
-
::File.write(filename,
|
24
|
+
::File.write(filename, data)
|
36
25
|
|
37
|
-
|
26
|
+
data
|
38
27
|
end
|
39
|
-
alias_method :clear, :render
|
40
28
|
|
41
29
|
private
|
42
30
|
|
43
|
-
# Compresses the output depending on configuration.
|
44
|
-
#
|
45
|
-
# @param output [Vedeu::Models::Page]
|
46
|
-
# @return [String]
|
47
|
-
def out(output)
|
48
|
-
if compress?
|
49
|
-
Vedeu::Output::Compressor.render(output, options)
|
50
|
-
|
51
|
-
else
|
52
|
-
output
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Return the filename given in the options, (or use the
|
58
|
-
# default), and append a timestamp if the :timestamp option was
|
59
|
-
# set to true.
|
60
|
-
#
|
61
31
|
# @return [String]
|
62
|
-
def
|
63
|
-
|
32
|
+
def content
|
33
|
+
output
|
64
34
|
end
|
65
35
|
|
66
|
-
# Return a timestamp for use as part of the filename if the
|
67
|
-
# :timestamp option was set to true, otherwise an empty string.
|
68
|
-
#
|
69
|
-
# @return [Float]
|
70
|
-
def timestamp
|
71
|
-
if options[:timestamp]
|
72
|
-
"_#{Vedeu.clock_time}"
|
73
|
-
|
74
|
-
else
|
75
|
-
''
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# Returns a boolean indicating whether a file should be written.
|
81
|
-
#
|
82
36
|
# @return [Boolean]
|
83
37
|
def write_file?
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
# Returns the default options/attributes for this class.
|
88
|
-
#
|
89
|
-
# @return [Hash]
|
90
|
-
def defaults
|
91
|
-
{
|
92
|
-
compression: Vedeu.config.compression?,
|
93
|
-
filename: 'out',
|
94
|
-
timestamp: false,
|
95
|
-
write_file: true,
|
96
|
-
}
|
38
|
+
true
|
97
39
|
end
|
98
40
|
|
99
41
|
end # File
|
data/lib/vedeu/renderers/html.rb
CHANGED
@@ -9,120 +9,52 @@ module Vedeu
|
|
9
9
|
#
|
10
10
|
class HTML < Vedeu::Renderers::File
|
11
11
|
|
12
|
-
|
13
|
-
#
|
14
|
-
# @param options [Hash]
|
15
|
-
# @option options content [String] Defaults to an empty string.
|
16
|
-
# @option options end_tag [String] Defaults to '</td>'.
|
17
|
-
# @option options end_row_tag [String] Defaults to '</tr>'.
|
18
|
-
# @option options filename [String] Provide a filename for the
|
19
|
-
# output. Defaults to 'out'.
|
20
|
-
# @option options start_tag [String] Defaults to '<td' (note the
|
21
|
-
# end of the tag is missing, this is so that inline styles can
|
22
|
-
# be added later).
|
23
|
-
# @option options start_row_tag [String] Defaults to '<tr>'.
|
24
|
-
# @option options template [String]
|
25
|
-
# @option options timestamp [Boolean] Append a timestamp to the
|
26
|
-
# filename.
|
27
|
-
# @option options write_file [Boolean] Whether to write the file
|
28
|
-
# to the given filename.
|
29
|
-
# @return [Vedeu::Renderers::HTML]
|
30
|
-
def initialize(options = {})
|
31
|
-
@options = options || {}
|
32
|
-
@output = nil
|
33
|
-
end
|
12
|
+
include Vedeu::Renderers::Options
|
34
13
|
|
35
|
-
# Render a cleared output.
|
36
|
-
#
|
37
14
|
# @return [String]
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
15
|
+
def html_body
|
16
|
+
if valid?
|
17
|
+
output.inject([]) do |acc, line|
|
18
|
+
acc << "#{start_row_tag}\n"
|
19
|
+
line.each do |char|
|
20
|
+
acc << char.to_html(options)
|
21
|
+
end
|
22
|
+
acc << "#{end_row_tag}\n"
|
23
|
+
end.join
|
24
|
+
|
25
|
+
else
|
26
|
+
''
|
27
|
+
|
28
|
+
end
|
42
29
|
end
|
43
30
|
|
44
|
-
|
31
|
+
private
|
32
|
+
|
45
33
|
# @return [String]
|
46
|
-
def
|
47
|
-
|
34
|
+
def content
|
35
|
+
if valid?
|
36
|
+
Vedeu::Templating::Template.parse(self, template)
|
48
37
|
|
49
|
-
|
50
|
-
|
38
|
+
else
|
39
|
+
''
|
51
40
|
|
52
|
-
|
53
|
-
def html_body
|
54
|
-
return '' if output.is_a?(Vedeu::Cells::Escape)
|
55
|
-
|
56
|
-
output.inject([]) do |acc, line|
|
57
|
-
acc << "#{start_row_tag}\n"
|
58
|
-
line.each do |char|
|
59
|
-
acc << char.to_html(options)
|
60
|
-
end
|
61
|
-
acc << "#{end_row_tag}\n"
|
62
|
-
end.join
|
41
|
+
end
|
63
42
|
end
|
64
43
|
|
65
|
-
private
|
66
|
-
|
67
44
|
# Returns a boolean indicating whether the output is a
|
68
45
|
# {Vedeu::Cells::Escape}. If it is, it won't be rendered in
|
69
46
|
# HTML.
|
70
47
|
#
|
71
48
|
# @return [Boolean]
|
72
49
|
def escape?
|
73
|
-
output.is_a?(Vedeu::Cells::Escape)
|
74
|
-
end
|
75
|
-
|
76
|
-
# @return [Array<Array<Vedeu::Views::Char>>]
|
77
|
-
def output
|
78
|
-
@output || options[:output]
|
79
|
-
end
|
80
|
-
|
81
|
-
# @return [String]
|
82
|
-
def end_tag
|
83
|
-
options[:end_tag]
|
50
|
+
output.is_a?(Vedeu::Cells::Escape) || output.is_a?(Vedeu::Cells::Cursor)
|
84
51
|
end
|
85
52
|
|
86
|
-
# @return [
|
87
|
-
def
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
# @return [String]
|
92
|
-
def start_tag
|
93
|
-
options[:start_tag]
|
94
|
-
end
|
95
|
-
|
96
|
-
# @return [String]
|
97
|
-
def start_row_tag
|
98
|
-
options[:start_row_tag]
|
99
|
-
end
|
100
|
-
|
101
|
-
# @return [String]
|
102
|
-
def template
|
103
|
-
options[:template]
|
104
|
-
end
|
105
|
-
|
106
|
-
# The default values for a new instance of this class.
|
107
|
-
#
|
108
|
-
# @return [Hash<Symbol => void>]
|
109
|
-
def defaults
|
110
|
-
{
|
111
|
-
content: '',
|
112
|
-
end_tag: '</td>',
|
113
|
-
end_row_tag: '</tr>',
|
114
|
-
filename: 'out',
|
115
|
-
start_tag: '<td',
|
116
|
-
start_row_tag: '<tr>',
|
117
|
-
template: default_template,
|
118
|
-
timestamp: false,
|
119
|
-
write_file: true,
|
120
|
-
}
|
121
|
-
end
|
53
|
+
# @return [Boolean]
|
54
|
+
def valid?
|
55
|
+
return false if string?(output) || escape?
|
122
56
|
|
123
|
-
|
124
|
-
def default_template
|
125
|
-
::File.dirname(__FILE__) + '/../templates/html_renderer.vedeu'
|
57
|
+
true
|
126
58
|
end
|
127
59
|
|
128
60
|
end # HTML
|
data/lib/vedeu/renderers/json.rb
CHANGED
@@ -8,49 +8,33 @@ module Vedeu
|
|
8
8
|
#
|
9
9
|
class JSON < Vedeu::Renderers::File
|
10
10
|
|
11
|
-
|
12
|
-
#
|
13
|
-
# @param options [Hash]
|
14
|
-
# @return [Vedeu::Renderers::JSON]
|
15
|
-
def initialize(options = {})
|
16
|
-
@options = options || {}
|
17
|
-
end
|
11
|
+
include Vedeu::Renderers::Options
|
18
12
|
|
19
13
|
# Render a cleared output.
|
20
14
|
#
|
21
|
-
# @return [
|
15
|
+
# @return [void]
|
22
16
|
def clear
|
23
|
-
|
24
|
-
|
25
|
-
super(json, { compression: false })
|
26
|
-
|
27
|
-
json
|
17
|
+
render({})
|
28
18
|
end
|
29
19
|
|
30
|
-
|
31
|
-
# @return [String]
|
32
|
-
def render(output)
|
33
|
-
json = parse(output)
|
34
|
-
|
35
|
-
super(json, { compression: false })
|
20
|
+
private
|
36
21
|
|
37
|
-
|
22
|
+
# @return [Array]
|
23
|
+
def as_hash
|
24
|
+
output.content.map(&:to_h)
|
38
25
|
end
|
39
26
|
|
40
|
-
private
|
41
|
-
|
42
|
-
# @param output [Vedeu::Models::Page]
|
43
27
|
# @return [String]
|
44
|
-
def
|
45
|
-
|
46
|
-
|
28
|
+
def content
|
29
|
+
if hash?(output)
|
30
|
+
::JSON.pretty_generate(output)
|
47
31
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
return output if output.is_a?(Hash)
|
32
|
+
else
|
33
|
+
Vedeu.log(type: :render,
|
34
|
+
message: "#{self.class.name}#content: #{output.class.name}")
|
52
35
|
|
53
|
-
|
36
|
+
::JSON.pretty_generate(as_hash)
|
37
|
+
end
|
54
38
|
end
|
55
39
|
|
56
40
|
end # JSON
|
@@ -8,38 +8,184 @@ module Vedeu
|
|
8
8
|
#
|
9
9
|
module Options
|
10
10
|
|
11
|
-
|
11
|
+
include Vedeu::Common
|
12
12
|
|
13
|
-
# @!attribute [
|
13
|
+
# @!attribute [rw] options
|
14
14
|
# @return [Hash<Symbol => void>]
|
15
|
-
|
15
|
+
attr_accessor :options
|
16
|
+
|
17
|
+
# Returns a new instance of the class including this module.
|
18
|
+
#
|
19
|
+
# @param opts [Hash]
|
20
|
+
# @return [void]
|
21
|
+
def initialize(opts = {})
|
22
|
+
@options = defaults.merge!(opts || {})
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [void]
|
26
|
+
def clear
|
27
|
+
render('')
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param output [Vedeu::Models::Page]
|
31
|
+
# @param opts [Hash]
|
32
|
+
# @return [void]
|
33
|
+
def render(output = '')
|
34
|
+
options.merge!(output: output)
|
35
|
+
|
36
|
+
write
|
37
|
+
end
|
38
|
+
|
39
|
+
# @raise [Vedeu::Error::NotImplemented] Subclasses of this class
|
40
|
+
# must implement this method.
|
41
|
+
# @return [Vedeu::Error::NotImplemented]
|
42
|
+
def write
|
43
|
+
fail Vedeu::Error::NotImplemented, 'Including classes implement this.'
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
16
47
|
|
17
48
|
# Returns a boolean indicating whether the content should be
|
18
49
|
# compressed if compression is available.
|
19
50
|
#
|
20
51
|
# @return [Boolean]
|
21
|
-
def
|
22
|
-
options[:compression]
|
52
|
+
def compression?
|
53
|
+
boolean(options[:compression])
|
23
54
|
end
|
24
55
|
|
25
|
-
|
26
|
-
|
27
|
-
# Combines the options provided at instantiation with the
|
28
|
-
# default values.
|
56
|
+
# Compresses the output depending on configuration.
|
29
57
|
#
|
30
|
-
# @return [
|
31
|
-
def
|
32
|
-
|
58
|
+
# @return [String]
|
59
|
+
def compression
|
60
|
+
if compression?
|
61
|
+
Vedeu::Output::Compressor.render(output, options)
|
62
|
+
|
63
|
+
else
|
64
|
+
output
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [void]
|
70
|
+
def content
|
71
|
+
fail Vedeu::Error::NotImplemented, 'Including classes implement this.'
|
33
72
|
end
|
34
73
|
|
35
74
|
# The default values for a new instance of this class.
|
36
75
|
#
|
76
|
+
# @param options [Hash]
|
77
|
+
# @option options content [String] Defaults to an empty string.
|
78
|
+
# @option options end_tag [String] Defaults to '</td>'.
|
79
|
+
# @option options end_row_tag [String] Defaults to '</tr>'.
|
80
|
+
# @option options filename [String] Provide a filename for the
|
81
|
+
# output. Defaults to 'out'.
|
82
|
+
# @option options start_tag [String] Defaults to '<td' (note the
|
83
|
+
# end of the tag is missing, this is so that inline styles can
|
84
|
+
# be added later).
|
85
|
+
# @option options start_row_tag [String] Defaults to '<tr>'.
|
86
|
+
# @option options template [String]
|
87
|
+
# @option options timestamp [Boolean] Append a timestamp to the
|
88
|
+
# filename.
|
89
|
+
# @option options write_file [Boolean] Whether to write the file
|
90
|
+
# to the given filename.
|
91
|
+
#
|
37
92
|
# @return [Hash<Symbol => void>]
|
38
93
|
def defaults
|
39
|
-
{
|
94
|
+
{
|
95
|
+
compression: Vedeu.config.compression?,
|
96
|
+
end_tag: '</td>',
|
97
|
+
end_row_tag: '</tr>',
|
98
|
+
filename: 'out',
|
99
|
+
output: '',
|
100
|
+
start_tag: '<td',
|
101
|
+
start_row_tag: '<tr>',
|
102
|
+
template: default_template,
|
103
|
+
timestamp: false,
|
104
|
+
write_file: false,
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
# @return [String]
|
109
|
+
def default_template
|
110
|
+
::File.dirname(__FILE__) + '/./templates/html_renderer.vedeu'
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [String]
|
114
|
+
def end_tag
|
115
|
+
options[:end_tag]
|
40
116
|
end
|
41
117
|
|
42
|
-
#
|
118
|
+
# @return [String]
|
119
|
+
def end_row_tag
|
120
|
+
options[:end_row_tag]
|
121
|
+
end
|
122
|
+
|
123
|
+
# Return the filename given in the options, (or use the
|
124
|
+
# default), and append a timestamp if the :timestamp option was
|
125
|
+
# set to true.
|
126
|
+
#
|
127
|
+
# @return [String]
|
128
|
+
def filename
|
129
|
+
options[:filename] + timestamp
|
130
|
+
end
|
131
|
+
|
132
|
+
# @return [String]
|
133
|
+
def start_tag
|
134
|
+
options[:start_tag]
|
135
|
+
end
|
136
|
+
|
137
|
+
# @return [String]
|
138
|
+
def start_row_tag
|
139
|
+
options[:start_row_tag]
|
140
|
+
end
|
141
|
+
|
142
|
+
# @return [void]
|
143
|
+
def output
|
144
|
+
options[:output]
|
145
|
+
end
|
146
|
+
|
147
|
+
# @return [Boolean]
|
148
|
+
def output?
|
149
|
+
present?(output)
|
150
|
+
end
|
151
|
+
|
152
|
+
# @return [String]
|
153
|
+
def template
|
154
|
+
options[:template]
|
155
|
+
end
|
156
|
+
|
157
|
+
# @return [Boolean]
|
158
|
+
def timestamp?
|
159
|
+
boolean(options[:timestamp])
|
160
|
+
end
|
161
|
+
|
162
|
+
# Return a timestamp for use as part of the filename if the
|
163
|
+
# :timestamp option was set to true, otherwise an empty string.
|
164
|
+
#
|
165
|
+
# @return [String]
|
166
|
+
def timestamp
|
167
|
+
return "_#{Vedeu.clock_time}" if timestamp?
|
168
|
+
|
169
|
+
''
|
170
|
+
end
|
171
|
+
|
172
|
+
# Returns a boolean indicating whether a file should be written.
|
173
|
+
#
|
174
|
+
# @return [Boolean]
|
175
|
+
def write_file?
|
176
|
+
boolean(options[:write_file])
|
177
|
+
end
|
178
|
+
|
179
|
+
# Render the output (either content or clearing) to a file.
|
180
|
+
#
|
181
|
+
# @return [String]
|
182
|
+
def write_file
|
183
|
+
data = content
|
184
|
+
|
185
|
+
::File.write(filename, data)
|
186
|
+
|
187
|
+
data
|
188
|
+
end
|
43
189
|
|
44
190
|
end # Options
|
45
191
|
|