vedeu 0.7.4 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/docs/api.md +5 -1
- data/docs/borders.md +2 -26
- data/docs/dsl.md +4 -4
- data/docs/dsl_elements.md +100 -0
- data/docs/events/by_name/action.md +3 -0
- data/docs/events/by_name/cursor_hide.md +3 -0
- data/docs/events/by_name/cursor_reset.md +3 -0
- data/docs/events/by_name/cursor_show.md +3 -0
- data/docs/events/by_name/geometry_down.md +3 -0
- data/docs/events/by_name/geometry_left.md +3 -0
- data/docs/events/by_name/geometry_right.md +3 -0
- data/docs/events/by_name/geometry_up.md +3 -0
- data/docs/events/by_name/hide_view.md +3 -0
- data/docs/events/by_name/set_border_caption.md +13 -0
- data/docs/events/by_name/set_border_title.md +13 -0
- data/docs/events/by_name/show_view.md +3 -0
- data/docs/events/by_name/standalone.md +3 -0
- data/docs/events/by_name/toggle_view.md +3 -0
- data/docs/events/by_name/view_down.md +4 -0
- data/docs/events/by_name/view_left.md +4 -0
- data/docs/events/by_name/view_right.md +4 -0
- data/docs/events/by_name/view_up.md +4 -0
- data/examples/views/empty_template.rb +46 -0
- data/examples/views/expected/line.out +1 -0
- data/examples/views/expected/lines.out +1 -0
- data/examples/views/expected/lines_alignment.out +1 -0
- data/examples/views/line.rb +220 -0
- data/examples/views/lines.rb +281 -0
- data/examples/views/lines_alignment.rb +231 -0
- data/examples/views/lines_line_stream.rb +99 -0
- data/examples/views/lines_line_streams.rb +73 -0
- data/examples/views/lines_line_streams_stream.rb +83 -0
- data/examples/views/lines_line_streams_stream_stream.rb +53 -0
- data/examples/views/lines_streams.rb +50 -0
- data/examples/views/lines_streams_stream.rb +51 -0
- data/examples/views/runner.sh +27 -0
- data/lib/vedeu/all.rb +6 -2
- data/lib/vedeu/application/controller.rb +1 -1
- data/lib/vedeu/boolean.rb +35 -0
- data/lib/vedeu/borders/border.rb +3 -3
- data/lib/vedeu/borders/caption.rb +1 -1
- data/lib/vedeu/borders/dsl.rb +1 -20
- data/lib/vedeu/borders/title.rb +6 -8
- data/lib/vedeu/buffers/buffer.rb +2 -2
- data/lib/vedeu/buffers/refresh.rb +1 -1
- data/lib/vedeu/cells/border.rb +0 -11
- data/lib/vedeu/cells/empty.rb +4 -4
- data/lib/vedeu/{geometries/alignment → coercers}/alignment.rb +50 -53
- data/lib/vedeu/coercers/all.rb +16 -0
- data/lib/vedeu/coercers/colour.rb +78 -0
- data/lib/vedeu/coercers/colour_attributes.rb +122 -0
- data/lib/vedeu/coercers/horizontal_alignment.rb +28 -0
- data/lib/vedeu/coercers/vertical_alignment.rb +27 -0
- data/lib/vedeu/colours/all.rb +1 -0
- data/lib/vedeu/colours/background.rb +13 -2
- data/lib/vedeu/colours/colour.rb +16 -31
- data/lib/vedeu/colours/foreground.rb +13 -2
- data/lib/vedeu/colours/translator.rb +21 -59
- data/lib/vedeu/colours/validator.rb +84 -0
- data/lib/vedeu/common.rb +52 -0
- data/lib/vedeu/configuration/api.rb +4 -10
- data/lib/vedeu/configuration/configuration.rb +4 -4
- data/lib/vedeu/cursors/coordinate.rb +1 -1
- data/lib/vedeu/cursors/cursor.rb +1 -1
- data/lib/vedeu/cursors/dsl.rb +1 -28
- data/lib/vedeu/dsl/all.rb +7 -7
- data/lib/vedeu/dsl/attributes.rb +224 -0
- data/lib/vedeu/dsl/border.rb +127 -0
- data/lib/vedeu/dsl/cursors.rb +44 -0
- data/lib/vedeu/dsl/dsl.rb +9 -0
- data/lib/vedeu/dsl/elements.rb +335 -0
- data/lib/vedeu/dsl/geometry.rb +113 -0
- data/lib/vedeu/dsl/string/align.rb +127 -0
- data/lib/vedeu/dsl/string/all.rb +14 -0
- data/lib/vedeu/dsl/string/text.rb +107 -0
- data/lib/vedeu/dsl/string/truncate.rb +111 -0
- data/lib/vedeu/{output → dsl/string}/wordwrap.rb +10 -6
- data/lib/vedeu/dsl/view.rb +124 -248
- data/lib/vedeu/dsl/views.rb +244 -0
- data/lib/vedeu/editor/cursor.rb +1 -1
- data/lib/vedeu/editor/delete.rb +3 -1
- data/lib/vedeu/editor/insert.rb +22 -6
- data/lib/vedeu/editor/line.rb +15 -9
- data/lib/vedeu/editor/lines.rb +27 -18
- data/lib/vedeu/esc/actions.rb +73 -26
- data/lib/vedeu/esc/all.rb +2 -0
- data/lib/vedeu/esc/background.rb +219 -0
- data/lib/vedeu/esc/borders.rb +72 -26
- data/lib/vedeu/esc/colours.rb +26 -27
- data/lib/vedeu/esc/esc.rb +4 -4
- data/lib/vedeu/esc/foreground.rb +219 -0
- data/lib/vedeu/esc/mouse.rb +16 -13
- data/lib/vedeu/events/aliases.rb +2 -2
- data/lib/vedeu/events/event.rb +1 -1
- data/lib/vedeu/geometries/all.rb +0 -1
- data/lib/vedeu/geometries/area/dimension.rb +2 -2
- data/lib/vedeu/geometries/dsl/dsl.rb +3 -51
- data/lib/vedeu/geometries/dsl/validator.rb +4 -4
- data/lib/vedeu/geometries/geometry.rb +10 -10
- data/lib/vedeu/geometries/move.rb +4 -4
- data/lib/vedeu/groups/dsl.rb +1 -0
- data/lib/vedeu/groups/group.rb +1 -1
- data/lib/vedeu/input/all.rb +1 -0
- data/lib/vedeu/input/capture.rb +14 -10
- data/lib/vedeu/input/dsl.rb +20 -26
- data/lib/vedeu/input/key.rb +0 -6
- data/lib/vedeu/input/keymap.rb +4 -9
- data/lib/vedeu/input/keys.rb +13 -0
- data/lib/vedeu/input/mapper.rb +29 -14
- data/lib/vedeu/input/read.rb +4 -2
- data/lib/vedeu/interfaces/dsl.rb +23 -22
- data/lib/vedeu/interfaces/interface.rb +2 -2
- data/lib/vedeu/logging/debug.rb +33 -0
- data/lib/vedeu/logging/log.rb +42 -33
- data/lib/vedeu/menus/dsl.rb +7 -18
- data/lib/vedeu/menus/menu.rb +1 -1
- data/lib/vedeu/models/focus.rb +1 -1
- data/lib/vedeu/models/toggleable.rb +4 -4
- data/lib/vedeu/null/generic.rb +2 -2
- data/lib/vedeu/output/all.rb +0 -2
- data/lib/vedeu/output/compressor_cache.rb +1 -1
- data/lib/vedeu/output/output.rb +5 -20
- data/lib/vedeu/presentation/colour.rb +39 -7
- data/lib/vedeu/presentation/style.rb +25 -11
- data/lib/vedeu/renderers/html.rb +11 -11
- data/lib/vedeu/repositories/assemblage.rb +9 -0
- data/lib/vedeu/repositories/collection.rb +1 -0
- data/lib/vedeu/repositories/defaults.rb +4 -1
- data/lib/vedeu/repositories/model.rb +7 -37
- data/lib/vedeu/repositories/parent.rb +6 -6
- data/lib/vedeu/repositories/registerable.rb +16 -2
- data/lib/vedeu/repositories/repositories.rb +1 -1
- data/lib/vedeu/repositories/repository.rb +2 -12
- data/lib/vedeu/runtime/flags.rb +1 -1
- data/lib/vedeu/terminal/terminal.rb +7 -2
- data/lib/vedeu/version.rb +1 -1
- data/lib/vedeu/views/all.rb +4 -1
- data/lib/vedeu/views/char.rb +5 -4
- data/lib/vedeu/views/chars.rb +42 -0
- data/lib/vedeu/views/composition.rb +15 -30
- data/lib/vedeu/views/default_attributes.rb +74 -0
- data/lib/vedeu/views/html_char.rb +2 -2
- data/lib/vedeu/views/line.rb +27 -53
- data/lib/vedeu/views/lines.rb +31 -0
- data/lib/vedeu/views/stream.rb +31 -78
- data/lib/vedeu/views/streams.rb +42 -0
- data/lib/vedeu/views/value.rb +150 -0
- data/lib/vedeu/views/view.rb +32 -36
- data/lib/vedeu/views/{view_collection.rb → views.rb} +2 -2
- data/test/lib/vedeu/application/application_controller_test.rb +5 -0
- data/test/lib/vedeu/application/controller_test.rb +22 -28
- data/test/lib/vedeu/boolean_test.rb +57 -0
- data/test/lib/vedeu/borders/border_test.rb +130 -36
- data/test/lib/vedeu/borders/dsl_test.rb +63 -10
- data/test/lib/vedeu/borders/title_test.rb +16 -5
- data/test/lib/vedeu/buffers/buffer_test.rb +26 -10
- data/test/lib/vedeu/buffers/empty_test.rb +1 -1
- data/test/lib/vedeu/cells/border_test.rb +0 -6
- data/test/lib/vedeu/cells/clear_test.rb +2 -0
- data/test/lib/vedeu/cells/empty_test.rb +12 -2
- data/test/lib/vedeu/cells/escape_test.rb +7 -2
- data/test/lib/vedeu/{geometries/alignment → coercers}/alignment_test.rb +44 -19
- data/test/lib/vedeu/coercers/colour_attributes_test.rb +168 -0
- data/test/lib/vedeu/coercers/colour_test.rb +75 -0
- data/test/lib/vedeu/{geometries/alignment → coercers}/horizontal_alignment_test.rb +6 -6
- data/test/lib/vedeu/{geometries/alignment → coercers}/vertical_alignment_test.rb +6 -6
- data/test/lib/vedeu/colours/background_test.rb +17 -1
- data/test/lib/vedeu/colours/colour_test.rb +74 -2
- data/test/lib/vedeu/colours/foreground_test.rb +17 -1
- data/test/lib/vedeu/colours/repository_test.rb +1 -1
- data/test/lib/vedeu/colours/translator_test.rb +8 -1
- data/test/lib/vedeu/colours/validator_test.rb +60 -0
- data/test/lib/vedeu/common_test.rb +138 -0
- data/test/lib/vedeu/configuration/api_test.rb +96 -51
- data/test/lib/vedeu/cursors/coordinate_test.rb +58 -117
- data/test/lib/vedeu/cursors/cursor_test.rb +46 -17
- data/test/lib/vedeu/cursors/dsl_test.rb +19 -5
- data/test/lib/vedeu/distributed/client_test.rb +8 -3
- data/test/lib/vedeu/distributed/server_test.rb +8 -0
- data/test/lib/vedeu/distributed/test_application_test.rb +62 -19
- data/test/lib/vedeu/distributed/uri_test.rb +4 -2
- data/test/lib/vedeu/dsl/attributes_test.rb +212 -0
- data/test/lib/vedeu/dsl/border_test.rb +51 -0
- data/test/lib/vedeu/dsl/{lines_test.rb → cursors_test.rb} +2 -2
- data/test/lib/vedeu/dsl/dsl_test.rb +44 -0
- data/test/lib/vedeu/dsl/elements_test.rb +118 -0
- data/test/lib/vedeu/dsl/geometry_test.rb +35 -0
- data/test/lib/vedeu/dsl/presentation_test.rb +52 -11
- data/test/lib/vedeu/dsl/string/align_test.rb +147 -0
- data/test/lib/vedeu/dsl/string/text_test.rb +213 -0
- data/test/lib/vedeu/dsl/string/truncate_test.rb +97 -0
- data/test/lib/vedeu/{output → dsl/string}/wordwrap_test.rb +3 -3
- data/test/lib/vedeu/dsl/view_test.rb +30 -42
- data/test/lib/vedeu/dsl/views_test.rb +61 -0
- data/test/lib/vedeu/editor/cursor_test.rb +30 -12
- data/test/lib/vedeu/editor/document_test.rb +18 -10
- data/test/lib/vedeu/editor/line_test.rb +4 -1
- data/test/lib/vedeu/editor/lines_test.rb +11 -3
- data/test/lib/vedeu/esc/actions_test.rb +42 -4
- data/test/lib/vedeu/esc/background_test.rb +185 -0
- data/test/lib/vedeu/esc/borders_test.rb +37 -9
- data/test/lib/vedeu/esc/colours_test.rb +0 -59
- data/test/lib/vedeu/esc/foreground_test.rb +185 -0
- data/test/lib/vedeu/esc/mouse_test.rb +9 -4
- data/test/lib/vedeu/geometries/area/area_test.rb +34 -11
- data/test/lib/vedeu/geometries/dsl/dsl_test.rb +52 -61
- data/test/lib/vedeu/geometries/geometry_test.rb +62 -18
- data/test/lib/vedeu/geometries/position_test.rb +14 -7
- data/test/lib/vedeu/groups/dsl_test.rb +24 -15
- data/test/lib/vedeu/groups/group_test.rb +18 -8
- data/test/lib/vedeu/input/dsl_test.rb +33 -16
- data/test/lib/vedeu/input/key_test.rb +8 -1
- data/test/lib/vedeu/input/keymap_test.rb +4 -1
- data/test/lib/vedeu/input/keys_test.rb +16 -0
- data/test/lib/vedeu/interfaces/dsl_test.rb +24 -30
- data/test/lib/vedeu/interfaces/interface_test.rb +79 -24
- data/test/lib/vedeu/logging/ips_test.rb +10 -1
- data/test/lib/vedeu/menus/dsl_test.rb +24 -23
- data/test/lib/vedeu/menus/menu_test.rb +18 -8
- data/test/lib/vedeu/models/page_test.rb +5 -1
- data/test/lib/vedeu/models/row_test.rb +4 -0
- data/test/lib/vedeu/models/toggleable_test.rb +10 -6
- data/test/lib/vedeu/null/generic_test.rb +90 -1
- data/test/lib/vedeu/output/viewport_test.rb +11 -10
- data/test/lib/vedeu/plugins/plugin_test.rb +22 -9
- data/test/lib/vedeu/presentation/colour_test.rb +2 -1
- data/test/lib/vedeu/presentation/presentation_test.rb +13 -8
- data/test/lib/vedeu/presentation/style_test.rb +28 -13
- data/test/lib/vedeu/renderers/file_test.rb +4 -2
- data/test/lib/vedeu/renderers/options_test.rb +1 -1
- data/test/lib/vedeu/repositories/assemblage_test.rb +18 -0
- data/test/lib/vedeu/repositories/collection_test.rb +34 -10
- data/test/lib/vedeu/repositories/defaults_test.rb +6 -0
- data/test/lib/vedeu/repositories/model_test.rb +4 -13
- data/test/lib/vedeu/repositories/repository_test.rb +12 -5
- data/test/lib/vedeu/repositories/store_test.rb +9 -0
- data/test/lib/vedeu/runtime/flags_test.rb +6 -4
- data/test/lib/vedeu/runtime/launcher_test.rb +1 -1
- data/test/lib/vedeu/templating/helpers_test.rb +93 -65
- data/test/lib/vedeu/templating/view_template_test.rb +26 -26
- data/test/lib/vedeu/views/char_test.rb +36 -11
- data/test/lib/vedeu/views/chars_test.rb +71 -0
- data/test/lib/vedeu/views/composition_test.rb +17 -16
- data/test/lib/vedeu/views/default_attributes_test.rb +97 -0
- data/test/lib/vedeu/views/line_test.rb +20 -75
- data/test/lib/vedeu/views/lines_test.rb +47 -0
- data/test/lib/vedeu/views/stream_test.rb +38 -63
- data/test/lib/vedeu/views/streams_test.rb +9 -0
- data/test/lib/vedeu/views/value_test.rb +112 -0
- data/test/lib/vedeu/views/view_test.rb +67 -45
- data/test/lib/vedeu/views/views_test.rb +22 -0
- data/test/support/examples/material_colours_app.rb +2 -2
- data/test/support/helpers/model_test_class.rb +1 -0
- data/test/test_helper.rb +3 -1
- data/vedeu.gemspec +2 -2
- metadata +124 -58
- data/lib/vedeu/dsl/composition.rb +0 -150
- data/lib/vedeu/dsl/line.rb +0 -119
- data/lib/vedeu/dsl/lines.rb +0 -23
- data/lib/vedeu/dsl/shared.rb +0 -85
- data/lib/vedeu/dsl/stream.rb +0 -40
- data/lib/vedeu/dsl/streams.rb +0 -23
- data/lib/vedeu/dsl/text.rb +0 -98
- data/lib/vedeu/geometries/alignment/all.rb +0 -11
- data/lib/vedeu/geometries/alignment/horizontal_alignment.rb +0 -27
- data/lib/vedeu/geometries/alignment/vertical_alignment.rb +0 -27
- data/lib/vedeu/output/text.rb +0 -275
- data/test/lib/vedeu/dsl/composition_test.rb +0 -67
- data/test/lib/vedeu/dsl/line_test.rb +0 -85
- data/test/lib/vedeu/dsl/shared_test.rb +0 -66
- data/test/lib/vedeu/dsl/stream_test.rb +0 -30
- data/test/lib/vedeu/dsl/streams_test.rb +0 -13
- data/test/lib/vedeu/dsl/text_test.rb +0 -122
- data/test/lib/vedeu/output/text_test.rb +0 -156
- data/test/lib/vedeu/views/view_collection_test.rb +0 -13
data/lib/vedeu/dsl/text.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
|
2
|
-
module Vedeu
|
3
|
-
|
4
|
-
module DSL
|
5
|
-
|
6
|
-
# Provides helper methods for building views.
|
7
|
-
#
|
8
|
-
module Text
|
9
|
-
|
10
|
-
# Specify the content for a view. Provides the means to align a
|
11
|
-
# string (or object responding to `to_s`), and add it as a Line
|
12
|
-
# or to the Stream.
|
13
|
-
#
|
14
|
-
# @note If using the convenience methods; left, centre, center
|
15
|
-
# or right, then a specified anchor will be ignored.
|
16
|
-
#
|
17
|
-
# @example
|
18
|
-
# lines do
|
19
|
-
# centre '...'
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# line do
|
23
|
-
# right '...'
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# line do
|
27
|
-
# stream do
|
28
|
-
# text '...'
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# left 'This will be left aligned.', width: 35
|
33
|
-
# # => 'This will be left aligned. '
|
34
|
-
#
|
35
|
-
# centre 'This will be aligned centrally.', width: 35
|
36
|
-
# # => ' This will be aligned centrally. '
|
37
|
-
# # centre is also aliased to center
|
38
|
-
#
|
39
|
-
# right 'This will be right aligned.', width: 35
|
40
|
-
# # => ' This will be right aligned.'
|
41
|
-
#
|
42
|
-
# right 'This will be right aligned.', width: 35,
|
43
|
-
# anchor: centre
|
44
|
-
#
|
45
|
-
# text 'This will be truncated here. More text here.',
|
46
|
-
# width: 28 # => 'This will be truncated here.'
|
47
|
-
#
|
48
|
-
# text 'Padded with hyphens.', width: 25, pad: '-',
|
49
|
-
# anchor: :right # => '-----Padded with hyphens.'
|
50
|
-
#
|
51
|
-
# @param value [String|Object] A string or object that responds
|
52
|
-
# to `to_s`.
|
53
|
-
# @param options [Hash<Symbol => void>] Text options.
|
54
|
-
# @option options :anchor [Symbol] One of `:left`,
|
55
|
-
# `:centre`/`:center`, or `:right`.
|
56
|
-
# @option options :width [Integer|NilClass] The width of the
|
57
|
-
# text stream to add. If the `string` provided is longer than
|
58
|
-
# this value, the string will be truncated. If no width is
|
59
|
-
# provided in the context of 'lines', then the interface width
|
60
|
-
# is used. If no width is provided in the context of a
|
61
|
-
# 'stream', then no alignment will occur.
|
62
|
-
# @option options :pad [String] The character to use to pad the
|
63
|
-
# width, by default uses an empty space (0x20). Only when the
|
64
|
-
# string is shorter than the specified width.
|
65
|
-
# @return [String]
|
66
|
-
def text(value = '', options = {})
|
67
|
-
options.merge!(text_options).merge!(anchor: __callee__)
|
68
|
-
|
69
|
-
Vedeu::Output::Text.add(value, options)
|
70
|
-
end
|
71
|
-
alias_method :text=, :text
|
72
|
-
alias_method :align, :text
|
73
|
-
alias_method :center, :text
|
74
|
-
alias_method :centre, :text
|
75
|
-
alias_method :left, :text
|
76
|
-
alias_method :right, :text
|
77
|
-
alias_method :align=, :text
|
78
|
-
alias_method :center=, :text
|
79
|
-
alias_method :centre=, :text
|
80
|
-
alias_method :left=, :text
|
81
|
-
alias_method :right=, :text
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
# @return [Hash<Symbol => void>]
|
86
|
-
def text_options
|
87
|
-
{
|
88
|
-
client: client,
|
89
|
-
model: model,
|
90
|
-
name: model.name,
|
91
|
-
}
|
92
|
-
end
|
93
|
-
|
94
|
-
end # Text
|
95
|
-
|
96
|
-
end # DSL
|
97
|
-
|
98
|
-
end # Vedeu
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
module Geometries
|
4
|
-
|
5
|
-
# Provides the mechanism to align an interface/view horizontally
|
6
|
-
# within the available terminal space.
|
7
|
-
#
|
8
|
-
# @api private
|
9
|
-
#
|
10
|
-
class HorizontalAlignment < Vedeu::Geometries::Alignment
|
11
|
-
|
12
|
-
# @raise [Vedeu::Error::InvalidSyntax] When the value is not one
|
13
|
-
# of :bottom, :centre, :left, :middle, :right, :top.
|
14
|
-
# @return [Symbol]
|
15
|
-
def align
|
16
|
-
return value if valid?
|
17
|
-
|
18
|
-
fail Vedeu::Error::InvalidSyntax,
|
19
|
-
'No horizontal alignment value given. Valid values are :center, ' \
|
20
|
-
':centre, :left, :none, :right.'.freeze
|
21
|
-
end
|
22
|
-
|
23
|
-
end # HorizontalAlignment
|
24
|
-
|
25
|
-
end # Geometries
|
26
|
-
|
27
|
-
end # Vedeu
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
module Geometries
|
4
|
-
|
5
|
-
# Provides the mechanism to align an interface/view vertically
|
6
|
-
# within the available terminal space.
|
7
|
-
#
|
8
|
-
# @api private
|
9
|
-
#
|
10
|
-
class VerticalAlignment < Vedeu::Geometries::Alignment
|
11
|
-
|
12
|
-
# @raise [Vedeu::Error::InvalidSyntax] When the value is not one
|
13
|
-
# of :bottom, :centre, :left, :middle, :right, :top.
|
14
|
-
# @return [Symbol]
|
15
|
-
def align
|
16
|
-
return value if valid?
|
17
|
-
|
18
|
-
fail Vedeu::Error::InvalidSyntax,
|
19
|
-
'No vertical alignment value given. Valid values are :bottom, ' \
|
20
|
-
':middle, :none, :top.'.freeze
|
21
|
-
end
|
22
|
-
|
23
|
-
end # VerticalAlignment
|
24
|
-
|
25
|
-
end # Geometries
|
26
|
-
|
27
|
-
end # Vedeu
|
data/lib/vedeu/output/text.rb
DELETED
@@ -1,275 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
|
3
|
-
module Output
|
4
|
-
|
5
|
-
# Present a string (or object responding to `to_s`).
|
6
|
-
#
|
7
|
-
class Text
|
8
|
-
|
9
|
-
include Vedeu::Common
|
10
|
-
|
11
|
-
# @see Vedeu::DSL::Text#text
|
12
|
-
def self.add(value = '', options = {})
|
13
|
-
new(value, options).add
|
14
|
-
end
|
15
|
-
|
16
|
-
# @see Vedeu::DSL::Text#text
|
17
|
-
def self.with(value = '', options = {})
|
18
|
-
new(value, options).aligned
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns a new instance of Vedeu::Output::Text.
|
22
|
-
#
|
23
|
-
# @param value [String]
|
24
|
-
# @param options [Hash]
|
25
|
-
# @option options anchor [Symbol] See {Text#anchor}
|
26
|
-
# @option options background [String]
|
27
|
-
# @option options colour [Hash|NilClass]
|
28
|
-
# @option options foreground [String]
|
29
|
-
# @option options model
|
30
|
-
# [Vedeu::Views::View|Vedeu::Views::Line|Vedeu::Views::Stream]
|
31
|
-
# @option options mode (see Vedeu::Output::Wordwrap#mode)
|
32
|
-
# @option options name [String|Symbol]
|
33
|
-
# @option options pad [String]
|
34
|
-
# @option options width [Integer]
|
35
|
-
# @return [Vedeu::Output::Text]
|
36
|
-
def initialize(value = '', options = {})
|
37
|
-
@value = value
|
38
|
-
@options = defaults.merge!(options)
|
39
|
-
end
|
40
|
-
|
41
|
-
# Aligns the value.
|
42
|
-
#
|
43
|
-
# @return [String]
|
44
|
-
def aligned
|
45
|
-
return string unless width
|
46
|
-
|
47
|
-
return truncated if truncate?
|
48
|
-
|
49
|
-
case anchor
|
50
|
-
when :align, :left, :text then left
|
51
|
-
when :centre, :center then centre
|
52
|
-
when :right then right
|
53
|
-
else
|
54
|
-
left
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Adds the content to the model.
|
59
|
-
#
|
60
|
-
# @return [void]
|
61
|
-
def add
|
62
|
-
if wrap?
|
63
|
-
model.add(wrapped)
|
64
|
-
|
65
|
-
else
|
66
|
-
model.add(content)
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
protected
|
72
|
-
|
73
|
-
# @!attribute [r] value
|
74
|
-
# @return [String]
|
75
|
-
attr_reader :value
|
76
|
-
|
77
|
-
# @!attribute [r] options
|
78
|
-
# @return [Hash]
|
79
|
-
attr_reader :options
|
80
|
-
|
81
|
-
private
|
82
|
-
|
83
|
-
# @return [Symbol] One of :align, :centre, :center, :left,
|
84
|
-
# :right, :text
|
85
|
-
def anchor
|
86
|
-
options[:anchor]
|
87
|
-
end
|
88
|
-
|
89
|
-
# The string padded to width, centralized.
|
90
|
-
#
|
91
|
-
# @return [String]
|
92
|
-
def centre
|
93
|
-
string.center(width, pad)
|
94
|
-
end
|
95
|
-
|
96
|
-
# @return [Object]
|
97
|
-
def client
|
98
|
-
options[:client]
|
99
|
-
end
|
100
|
-
|
101
|
-
# If a colour, background or foreground option is set, use them
|
102
|
-
# as the colour settings for the new Vedeu::Views::Stream.
|
103
|
-
#
|
104
|
-
# @return [void]
|
105
|
-
def colour
|
106
|
-
if options[:colour] || options[:background] || options[:foreground]
|
107
|
-
Vedeu::Colours::Colour.coerce(options)
|
108
|
-
|
109
|
-
else
|
110
|
-
model.colour
|
111
|
-
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Returns either a Vedeu::Views::Line or Vedeu::Views::Stream
|
116
|
-
# containing the text value.
|
117
|
-
#
|
118
|
-
# @return [Vedeu::Views::Line|Vedeu::Views::Stream]
|
119
|
-
def content
|
120
|
-
return stream unless model.is_a?(Vedeu::Views::View)
|
121
|
-
|
122
|
-
stream.parent = line
|
123
|
-
line.add(stream)
|
124
|
-
line
|
125
|
-
end
|
126
|
-
|
127
|
-
# The default values for a new instance of this class.
|
128
|
-
#
|
129
|
-
# @return [Hash<Symbol => NilClass, String, Symbol>]
|
130
|
-
def defaults
|
131
|
-
{
|
132
|
-
client: nil,
|
133
|
-
anchor: :left,
|
134
|
-
colour: nil,
|
135
|
-
model: nil,
|
136
|
-
mode: :default,
|
137
|
-
name: '',
|
138
|
-
pad: ' ',
|
139
|
-
width: nil,
|
140
|
-
}
|
141
|
-
end
|
142
|
-
|
143
|
-
# @return [NilClass|Vedeu::Geometries::Geometry]
|
144
|
-
def geometry
|
145
|
-
Vedeu.geometries.by_name(name)
|
146
|
-
end
|
147
|
-
|
148
|
-
# The string padded to width, left justified.
|
149
|
-
#
|
150
|
-
# @return [String]
|
151
|
-
def left
|
152
|
-
string.ljust(width, pad)
|
153
|
-
end
|
154
|
-
|
155
|
-
# @return [Vedeu::Views::Line]
|
156
|
-
def line
|
157
|
-
@line ||= Vedeu::Views::Line.build(parent: parent, client: client)
|
158
|
-
end
|
159
|
-
|
160
|
-
# Returns the model option when set.
|
161
|
-
#
|
162
|
-
# @return [Vedeu::Views::View|
|
163
|
-
# Vedeu::Views::Line|
|
164
|
-
# Vedeu::Null::Generic|
|
165
|
-
# Vedeu::Views::Stream]
|
166
|
-
def model
|
167
|
-
@model ||= options[:model] || Vedeu::Null::Generic.new
|
168
|
-
end
|
169
|
-
|
170
|
-
# @see Vedeu::Output::Wordwrap#mode
|
171
|
-
# @return [Symbol]
|
172
|
-
def mode
|
173
|
-
options[:mode]
|
174
|
-
end
|
175
|
-
|
176
|
-
# @return [String|Symbol]
|
177
|
-
def name
|
178
|
-
options[:name]
|
179
|
-
end
|
180
|
-
|
181
|
-
# The character to use for padding the string.
|
182
|
-
#
|
183
|
-
# @return [String]
|
184
|
-
def pad
|
185
|
-
options[:pad]
|
186
|
-
end
|
187
|
-
|
188
|
-
# Returns the parent for the new Vedeu::Views::Stream.
|
189
|
-
#
|
190
|
-
# @return [void]
|
191
|
-
def parent
|
192
|
-
model.is_a?(Vedeu::Views::Stream) ? model.parent : model
|
193
|
-
end
|
194
|
-
|
195
|
-
# The string padded to width, right justified.
|
196
|
-
#
|
197
|
-
# @return [String]
|
198
|
-
def right
|
199
|
-
string.rjust(width, pad)
|
200
|
-
end
|
201
|
-
|
202
|
-
# Builds and returns a new Vedeu::Views::Stream.
|
203
|
-
#
|
204
|
-
# @return [void]
|
205
|
-
def stream
|
206
|
-
@stream ||= Vedeu::Views::Stream.build(client: client,
|
207
|
-
colour: colour,
|
208
|
-
parent: parent,
|
209
|
-
style: style,
|
210
|
-
value: aligned)
|
211
|
-
end
|
212
|
-
|
213
|
-
# The string, coerced.
|
214
|
-
#
|
215
|
-
# @return [String]
|
216
|
-
def string
|
217
|
-
value.to_s
|
218
|
-
end
|
219
|
-
|
220
|
-
# Returns the model's styles.
|
221
|
-
#
|
222
|
-
# @return [void]
|
223
|
-
def style
|
224
|
-
model.style
|
225
|
-
end
|
226
|
-
|
227
|
-
# Return a boolean indicating that the string is greater than
|
228
|
-
# the width.
|
229
|
-
#
|
230
|
-
# @return [Boolean]
|
231
|
-
def truncate?
|
232
|
-
string.size > width
|
233
|
-
end
|
234
|
-
|
235
|
-
# Return the string truncated to the width.
|
236
|
-
#
|
237
|
-
# @return [String]
|
238
|
-
def truncated
|
239
|
-
string.slice(0, width)
|
240
|
-
end
|
241
|
-
|
242
|
-
# Return the width of the interface when a name is given,
|
243
|
-
# otherwise use the given width.
|
244
|
-
#
|
245
|
-
# @return [Fixnum]
|
246
|
-
def width
|
247
|
-
if present?(options[:width])
|
248
|
-
options[:width]
|
249
|
-
|
250
|
-
elsif present?(options[:name])
|
251
|
-
geometry.bordered_width
|
252
|
-
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
# Return a boolean indicating whether the string should be
|
257
|
-
# wrapped.
|
258
|
-
#
|
259
|
-
# @return [Boolean]
|
260
|
-
def wrap?
|
261
|
-
options[:mode] == :wrap
|
262
|
-
end
|
263
|
-
|
264
|
-
# Return the content as wrapped lines.
|
265
|
-
#
|
266
|
-
# @return [Vedeu::Views::Lines]
|
267
|
-
def wrapped
|
268
|
-
Vedeu::Output::Wordwrap.for(string, options)
|
269
|
-
end
|
270
|
-
|
271
|
-
end # Text
|
272
|
-
|
273
|
-
end # Output
|
274
|
-
|
275
|
-
end # Vedeu
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Vedeu
|
4
|
-
|
5
|
-
module DSL
|
6
|
-
|
7
|
-
describe Composition do
|
8
|
-
|
9
|
-
let(:described) { Vedeu::DSL::Composition }
|
10
|
-
let(:instance) { described.new(model) }
|
11
|
-
let(:model) { Vedeu::Views::Composition.new }
|
12
|
-
let(:client) {}
|
13
|
-
|
14
|
-
describe '#view' do
|
15
|
-
subject {
|
16
|
-
instance.view('dysprosium') do
|
17
|
-
# ...
|
18
|
-
end
|
19
|
-
}
|
20
|
-
|
21
|
-
it { subject.must_be_instance_of(Vedeu::Views::ViewCollection) }
|
22
|
-
it { subject[0].must_be_instance_of(Vedeu::Views::View) }
|
23
|
-
|
24
|
-
context 'when the block is not given' do
|
25
|
-
it { proc { instance.view }.must_raise(Vedeu::Error::RequiresBlock) }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#template_for' do
|
30
|
-
let(:_name) {}
|
31
|
-
let(:filename) {}
|
32
|
-
let(:object) {}
|
33
|
-
let(:content) { "Hydrogen\nCarbon\nOxygen\nNitrogen" }
|
34
|
-
let(:options) { {} }
|
35
|
-
|
36
|
-
subject { instance.template_for(_name, filename, object, options) }
|
37
|
-
|
38
|
-
context 'when the name of the view is not given' do
|
39
|
-
let(:filename) { 'my_interface.erb' }
|
40
|
-
|
41
|
-
it { proc { subject }.must_raise(Vedeu::Error::MissingRequired) }
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when the filename of the template is not given' do
|
45
|
-
let(:_name) { 'my_interface' }
|
46
|
-
|
47
|
-
it { proc { subject }.must_raise(Vedeu::Error::MissingRequired) }
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when the name and filename are given' do
|
51
|
-
let(:_name) { 'my_interface' }
|
52
|
-
let(:filename) { 'my_interface.erb' }
|
53
|
-
|
54
|
-
before do
|
55
|
-
Vedeu::Templating::ViewTemplate.expects(:parse).
|
56
|
-
with(object, filename, options).returns(content)
|
57
|
-
end
|
58
|
-
|
59
|
-
it { subject.must_be_instance_of(Vedeu::Views::ViewCollection) }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
end # Composition
|
64
|
-
|
65
|
-
end # DSL
|
66
|
-
|
67
|
-
end # Vedeu
|