vedeu 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/docs/dsl/by_method/geometry.md +25 -1
  3. data/docs/dsl/by_method/geometry/align.md +13 -1
  4. data/docs/events/by_name/refresh_border.md +6 -2
  5. data/docs/events/by_name/refresh_view.md +3 -0
  6. data/docs/events/by_name/refresh_view_content.md +3 -0
  7. data/integrations/expected/dsl_app_021.out +1 -1
  8. data/integrations/expected/dsl_app_022.out +1 -1
  9. data/integrations/test_runner.sh +2 -0
  10. data/lib/vedeu/application/application_view.rb +1 -2
  11. data/lib/vedeu/borders/dsl.rb +1 -2
  12. data/lib/vedeu/borders/refresh.rb +2 -4
  13. data/lib/vedeu/buffers/empty.rb +10 -8
  14. data/lib/vedeu/buffers/refresh.rb +4 -8
  15. data/lib/vedeu/buffers/view.rb +6 -6
  16. data/lib/vedeu/coercers/alignment.rb +1 -2
  17. data/lib/vedeu/coercers/colour_attributes.rb +1 -0
  18. data/lib/vedeu/coercers/horizontal_alignment.rb +1 -1
  19. data/lib/vedeu/coercers/vertical_alignment.rb +1 -1
  20. data/lib/vedeu/colours/translator.rb +1 -3
  21. data/lib/vedeu/common.rb +12 -4
  22. data/lib/vedeu/configuration/api.rb +3 -5
  23. data/lib/vedeu/configuration/configuration.rb +0 -2
  24. data/lib/vedeu/cursors/coordinate.rb +1 -2
  25. data/lib/vedeu/dsl/border.rb +2 -4
  26. data/lib/vedeu/dsl/geometry.rb +4 -31
  27. data/lib/vedeu/dsl/helpers/wordwrap.rb +1 -1
  28. data/lib/vedeu/dsl/view.rb +4 -3
  29. data/lib/vedeu/error.rb +17 -0
  30. data/lib/vedeu/geometries/dsl/dsl.rb +2 -19
  31. data/lib/vedeu/groups/refresh.rb +1 -2
  32. data/lib/vedeu/input/dsl.rb +2 -6
  33. data/lib/vedeu/input/mapper.rb +1 -2
  34. data/lib/vedeu/input/read.rb +1 -0
  35. data/lib/vedeu/interfaces/dsl.rb +1 -0
  36. data/lib/vedeu/menus/dsl.rb +1 -2
  37. data/lib/vedeu/models/page.rb +1 -0
  38. data/lib/vedeu/output/output.rb +35 -44
  39. data/lib/vedeu/renderers/html.rb +1 -10
  40. data/lib/vedeu/renderers/options.rb +16 -21
  41. data/lib/vedeu/renderers/terminal.rb +4 -0
  42. data/lib/vedeu/repositories/defaults.rb +1 -2
  43. data/lib/vedeu/repositories/repository.rb +2 -3
  44. data/lib/vedeu/runtime/router.rb +3 -6
  45. data/lib/vedeu/support/point.rb +11 -0
  46. data/lib/vedeu/templating/template.rb +1 -2
  47. data/lib/vedeu/version.rb +1 -1
  48. data/lib/vedeu/views/chars.rb +1 -2
  49. data/lib/vedeu/views/lines.rb +1 -2
  50. data/lib/vedeu/views/streams.rb +1 -2
  51. data/lib/vedeu/views/view.rb +1 -2
  52. data/test/lib/vedeu/buffers/empty_test.rb +2 -2
  53. data/test/lib/vedeu/common_test.rb +22 -0
  54. data/test/lib/vedeu/output/output_test.rb +2 -2
  55. metadata +2 -2
@@ -51,7 +51,7 @@ module Vedeu
51
51
  # @param block [Proc] The directives you wish to send to this
52
52
  # view.
53
53
  # @macro raise_requires_block
54
- # @raise [Vedeu::Error::MissingRequired]
54
+ # @macro raise_missing_required
55
55
  # @return [Vedeu::Views::Views<Vedeu::Views::View>]
56
56
  # @todo More documentation required.
57
57
  def view(name, &block)
@@ -82,8 +82,9 @@ module Vedeu
82
82
  # use relative paths.
83
83
  # @param object [Object] The object for which the values of
84
84
  # template's variables can be obtained.
85
- # @param options [Hash<Symbol => void>] See {Vedeu::DSL::Wordwrap}
86
- # @raise [Vedeu::Error::MissingRequired]
85
+ # @param options [Hash<Symbol => void>] See
86
+ # {Vedeu::DSL::Wordwrap}
87
+ # @macro raise_missing_required
87
88
  # @return [Vedeu::Views::Views<Vedeu::Views::View>]
88
89
  def template_for(name, filename, object = nil, options = {})
89
90
  fail Vedeu::Error::MissingRequired,
@@ -45,6 +45,12 @@ module Vedeu
45
45
  # Raised when Vedeu attempts to parse a view or interface and
46
46
  # encounters a problem.
47
47
  #
48
+ # @!macro [new] raise_invalid_syntax
49
+ # @raise [Vedeu::Error::InvalidSyntax] When the value given for
50
+ # an argument or parameter cannot be used because it is not
51
+ # valid for the use case, unsupported or the method expects a
52
+ # different type.
53
+ #
48
54
  class InvalidSyntax < StandardError
49
55
 
50
56
  end # InvalidSyntax
@@ -53,6 +59,11 @@ module Vedeu
53
59
  # For example, when a name is not provided for a model when
54
60
  # attempting to store it in a repository.
55
61
  #
62
+ # @!macro [new] raise_missing_required
63
+ # @raise [Vedeu::Error::MissingRequired] When the required
64
+ # argument or parameter was given but without a meaningful or
65
+ # usable value (e.g. nil).
66
+ #
56
67
  class MissingRequired < StandardError
57
68
 
58
69
  end # MissingRequired
@@ -78,6 +89,12 @@ module Vedeu
78
89
  #
79
90
  # @see Vedeu::Colours::Translator
80
91
  #
92
+ # @!macro [new] raise_not_implemented
93
+ # @raise [Vedeu::Error::NotImplemented] When a subclass of the
94
+ # current class actually implements the method. Usually an
95
+ # indicator that the subclass should be used instead of the
96
+ # current class.
97
+ #
81
98
  class NotImplemented < StandardError
82
99
 
83
100
  end # NotImplemented
@@ -83,6 +83,7 @@ module Vedeu
83
83
  # Align the interface/view horizontally or vertically within
84
84
  # the terminal.
85
85
  #
86
+ # {include:file:docs/dsl/by_method/geometry/align.md}
86
87
  # @param vertical [Symbol] One of :bottom, :middle, :none, :top.
87
88
  # @param horizontal [Symbol] One of :center, :centre, :left,
88
89
  # :none, :right.
@@ -92,13 +93,7 @@ module Vedeu
92
93
  # @param height [Fixnum] The number of lines/rows tall; this is
93
94
  # required when the given value for vertical is any value
94
95
  # other than :none.
95
- # @raise [Vedeu::Error::InvalidSyntax]
96
- # - When the vertical is not given.
97
- # - When the horizontal is not given.
98
- # - When the horizontal is given (and not :none) and the width
99
- # is not given.
100
- # - When the vertical is given (and not :none) and the height
101
- # is not given.
96
+ # @macro raise_invalid_syntax
102
97
  # @return [Vedeu::Geometries::Geometry]
103
98
  def align(vertical: :none, horizontal: :none, width: nil, height: nil)
104
99
  horizontal_alignment(horizontal, width)
@@ -149,8 +144,6 @@ module Vedeu
149
144
  # default width of the terminal, this can be substituted for
150
145
  # your own positive integer.
151
146
  # @param height [Fixnum] The number of lines/rows.
152
- # @raise [Vedeu::Error::InvalidSyntax] When the height is not
153
- # given.
154
147
  # @return [Vedeu::Geometries::Geometry]
155
148
  def align_bottom(height = nil)
156
149
  vertical_alignment(:bottom, height)
@@ -178,8 +171,6 @@ module Vedeu
178
171
  # default height of the terminal, this can be substituted for
179
172
  # your own positive integer.
180
173
  # @param width [Fixnum] The number of characters/columns.
181
- # @raise [Vedeu::Error::InvalidSyntax] When the width is not
182
- # given.
183
174
  # @return [Vedeu::Geometries::Geometry]
184
175
  def align_centre(width = nil)
185
176
  horizontal_alignment(:centre, width)
@@ -206,8 +197,6 @@ module Vedeu
206
197
  # default height of the terminal, this can be substituted for
207
198
  # your own positive integer.
208
199
  # @param width [Fixnum] The number of characters/columns.
209
- # @raise [Vedeu::Error::InvalidSyntax] When the width is not
210
- # given.
211
200
  # @return [Vedeu::Geometries::Geometry]
212
201
  def align_left(width = nil)
213
202
  horizontal_alignment(:left, width)
@@ -234,8 +223,6 @@ module Vedeu
234
223
  # default width of the terminal, this can be substituted for
235
224
  # your own positive integer.
236
225
  # @param height [Fixnum] The number of lines/rows.
237
- # @raise [Vedeu::Error::InvalidSyntax] When the height is not
238
- # given.
239
226
  # @return [Vedeu::Geometries::Geometry]
240
227
  def align_middle(height = nil)
241
228
  vertical_alignment(:middle, height)
@@ -261,8 +248,6 @@ module Vedeu
261
248
  # default height of the terminal, this can be substituted for
262
249
  # your own positive integer.
263
250
  # @param width [Fixnum] The number of characters/columns.
264
- # @raise [Vedeu::Error::InvalidSyntax] When the width is not
265
- # given.
266
251
  # @return [Vedeu::Geometries::Geometry]
267
252
  def align_right(width = nil)
268
253
  horizontal_alignment(:right, width)
@@ -289,8 +274,6 @@ module Vedeu
289
274
  # default width of the terminal, this can be substituted for
290
275
  # your own positive integer.
291
276
  # @param height [Fixnum] The number of lines/rows.
292
- # @raise [Vedeu::Error::InvalidSyntax] When the height is not
293
- # given.
294
277
  # @return [Vedeu::Geometries::Geometry]
295
278
  def align_top(height = nil)
296
279
  vertical_alignment(:top, height)
@@ -52,8 +52,7 @@ module Vedeu
52
52
 
53
53
  private
54
54
 
55
- # @raise [Vedeu::Error::MissingRequired] When the name is empty
56
- # or nil.
55
+ # @macro raise_missing_required
57
56
  # @return [String]
58
57
  def group_name
59
58
  return name if present?(name)
@@ -61,8 +61,7 @@ module Vedeu
61
61
  # this keymap relates to.
62
62
  # @param block [Proc]
63
63
  # @macro raise_requires_block
64
- # @raise [Vedeu::Error::MissingRequired] When the name is not
65
- # given.
64
+ # @macro raise_missing_required
66
65
  # @return [Vedeu::Input::Keymap]
67
66
  def self.keymap(name, &block)
68
67
  fail Vedeu::Error::MissingRequired unless name
@@ -83,10 +82,7 @@ module Vedeu
83
82
  # defined, then the extras are treated as aliases.
84
83
  # @param block [Proc] The action to perform when this key is
85
84
  # pressed. Can be a method call or event triggered.
86
- # @raise [Vedeu::Error::InvalidSyntax]
87
- # When the required block is not given, the values parameter
88
- # is undefined, or when processing the collection, a member
89
- # is undefined.
85
+ # @macro raise_invalid_syntax
90
86
  # @return [Array] A collection containing the keypress(es).
91
87
  def key(*values, &block)
92
88
  fail Vedeu::Error::InvalidSyntax,
@@ -27,8 +27,7 @@ module Vedeu
27
27
 
28
28
  # @param key [String|Symbol] The keypress.
29
29
  # @param name [String|Symbol] The keymap name.
30
- # @raise [Vedeu::Error::MissingRequired] When the key or name
31
- # params are missing.
30
+ # @macro raise_missing_required
32
31
  # @return [Boolean]
33
32
  def registered?(key = nil, name = nil)
34
33
  fail Vedeu::Error::MissingRequired,
@@ -116,6 +116,7 @@ module Vedeu
116
116
  present?(@input)
117
117
  end
118
118
 
119
+ # @macro raise_invalid_syntax
119
120
  # @return [Symbol]
120
121
  def mode
121
122
  unless valid_mode?
@@ -35,6 +35,7 @@ module Vedeu
35
35
  # @param block [Proc] A set of attributes which define the
36
36
  # features of the interface.
37
37
  # @macro raise_requires_block
38
+ # @macro raise_missing_required
38
39
  # @return [Vedeu::Interfaces::Interface]
39
40
  # @todo More documentation required.
40
41
  def interface(name, &block)
@@ -35,8 +35,7 @@ module Vedeu
35
35
  # end
36
36
  #
37
37
  # @macro raise_requires_block
38
- # @raise [Vedeu::Error::MissingRequired] When a name is not
39
- # given.
38
+ # @macro raise_missing_required
40
39
  # @return [API::Menu]
41
40
  def menu(name, &block)
42
41
  fail Vedeu::Error::MissingRequired unless name
@@ -16,6 +16,7 @@ module Vedeu
16
16
 
17
17
  # @param value
18
18
  # [Vedeu::Models::Page|Vedeu::Models::Row|Array<void>|void]
19
+ # @macro raise_invalid_syntax
19
20
  # @return [Vedeu::Models::Page]
20
21
  def self.coerce(value)
21
22
  if value.is_a?(Vedeu::Models::Page)
@@ -11,61 +11,59 @@ module Vedeu
11
11
  #
12
12
  class Output
13
13
 
14
- # @param output (see #output)
15
- # @return [Array]
16
- def self.buffer_update(output)
17
- return nil if output.nil?
14
+ include Vedeu::Common
18
15
 
19
- new(output).buffer_update
20
- end
21
-
22
- # @param output (see #output)
23
- # @return [Array]
24
- def self.buffer_write(output)
25
- return nil if output.nil?
16
+ class << self
26
17
 
27
- new(output).buffer_write
28
- end
18
+ # @param (see #output)
19
+ # @return (see #buffer_update)
20
+ def buffer_update(output)
21
+ new(output).buffer_update
22
+ end
29
23
 
30
- # @param output (see #output)
31
- # @return [Array<String>]
32
- def self.direct_write(output)
33
- return nil if output.nil?
24
+ # @param (see #output)
25
+ # @return (see #buffer_write)
26
+ def buffer_write(output)
27
+ new(output).buffer_write
28
+ end
34
29
 
35
- new(output).direct_write
36
- end
30
+ # @param (see #output)
31
+ # @return (see #direct_write)
32
+ def direct_write(output)
33
+ new(output).direct_write
34
+ end
37
35
 
38
- # Writes output to the defined renderers.
39
- #
40
- # @param output (see #output)
41
- # @return [Array|NilClass|String]
42
- def self.render_output(output)
43
- return nil if output.nil?
36
+ # Writes output to the defined renderers.
37
+ #
38
+ # @param (see #output)
39
+ # @return (see #render_output)
40
+ def render_output(output)
41
+ new(output).render_output
42
+ end
44
43
 
45
- new(output).render_output
46
- end
44
+ end # Eigenclass
47
45
 
48
46
  # Return a new instance of Vedeu::Output::Output.
49
47
  #
50
- # @param output (see #output)
48
+ # @param (see #output)
51
49
  # @return [Vedeu::Output::Output]
52
50
  def initialize(output)
53
51
  @output = output
54
52
  end
55
53
 
56
- # @return [Array]
54
+ # @return (see #render_output)
57
55
  def buffer_update
58
- Vedeu::Buffers::Terminal.update(output)
56
+ Vedeu::Buffers::Terminal.update(output) if present?(output)
59
57
  end
60
58
 
61
- # @return [Array]
59
+ # @return (see #render_output)
62
60
  def buffer_write
63
- Vedeu::Buffers::Terminal.write(output)
61
+ Vedeu::Buffers::Terminal.write(output) if present?(output)
64
62
  end
65
63
 
66
- # @return [Array<String>]
64
+ # @return (see #render_output)
67
65
  def direct_write
68
- Vedeu::Terminal.output(output.to_s)
66
+ Vedeu::Terminal.output(output.to_s) if present?(output)
69
67
  end
70
68
 
71
69
  # Send the view to the renderers. If the output is a
@@ -75,9 +73,9 @@ module Vedeu
75
73
  # because escape sequences only make sense to the terminal and
76
74
  # not other renderers.
77
75
  #
78
- # @return [Array|String|NilClass]
76
+ # @return [Array<String>|String|NilClass]
79
77
  def render_output
80
- if escape_sequence?
78
+ if escape?(output)
81
79
  direct_write
82
80
 
83
81
  else
@@ -93,13 +91,6 @@ module Vedeu
93
91
  # NilClass|Vedeu::Cells::Escape|Vedeu::Cells::Cursor]
94
92
  attr_reader :output
95
93
 
96
- private
97
-
98
- # @return [Boolean]
99
- def escape_sequence?
100
- output.is_a?(Vedeu::Cells::Escape) || output.is_a?(Vedeu::Cells::Cursor)
101
- end
102
-
103
94
  end # Output
104
95
 
105
96
  end # Output
@@ -113,7 +104,7 @@ module Vedeu
113
104
  # Vedeu.render_output(output)
114
105
  #
115
106
  # @!method render_output
116
- # @return [Array|NilClass]
107
+ # @return (see Vedeu::Output::Output#render_output)
117
108
  def_delegators Vedeu::Output::Output,
118
109
  :buffer_update,
119
110
  :buffer_write,
@@ -41,18 +41,9 @@ module Vedeu
41
41
  end
42
42
  end
43
43
 
44
- # Returns a boolean indicating whether the output is a
45
- # {Vedeu::Cells::Escape}. If it is, it won't be rendered in
46
- # HTML.
47
- #
48
- # @return [Boolean]
49
- def escape?
50
- output.is_a?(Vedeu::Cells::Escape) || output.is_a?(Vedeu::Cells::Cursor)
51
- end
52
-
53
44
  # @return [Boolean]
54
45
  def valid?
55
- return false if string?(output) || escape?
46
+ return false if string?(output) || escape?(output)
56
47
 
57
48
  true
58
49
  end
@@ -17,6 +17,20 @@ module Vedeu
17
17
  # Returns a new instance of the class including this module.
18
18
  #
19
19
  # @param opts [Hash]
20
+ # @option opts content [String] Defaults to an empty string.
21
+ # @option opts end_tag [String] Defaults to '</td>'.
22
+ # @option opts end_row_tag [String] Defaults to '</tr>'.
23
+ # @option opts filename [String] Provide a filename for the
24
+ # output. Defaults to 'out'.
25
+ # @option opts start_tag [String] Defaults to '<td' (note the
26
+ # end of the tag is missing, this is so that inline styles can
27
+ # be added later).
28
+ # @option opts start_row_tag [String] Defaults to '<tr>'.
29
+ # @option opts template [String]
30
+ # @option opts timestamp [Boolean] Append a timestamp to the
31
+ # filename.
32
+ # @option opts write_file [Boolean] Whether to write the file
33
+ # to the given filename.
20
34
  # @return [void]
21
35
  def initialize(opts = {})
22
36
  @options = defaults.merge!(opts || {})
@@ -28,7 +42,6 @@ module Vedeu
28
42
  end
29
43
 
30
44
  # @param output [Vedeu::Models::Page]
31
- # @param opts [Hash]
32
45
  # @return [void]
33
46
  def render(output = '')
34
47
  options.merge!(output: output)
@@ -36,9 +49,7 @@ module Vedeu
36
49
  write
37
50
  end
38
51
 
39
- # @raise [Vedeu::Error::NotImplemented] Subclasses of this class
40
- # must implement this method.
41
- # @return [Vedeu::Error::NotImplemented]
52
+ # @macro raise_not_implemented
42
53
  def write
43
54
  fail Vedeu::Error::NotImplemented, 'Including classes implement this.'
44
55
  end
@@ -66,29 +77,13 @@ module Vedeu
66
77
  end
67
78
  end
68
79
 
69
- # @return [void]
80
+ # @macro raise_not_implemented
70
81
  def content
71
82
  fail Vedeu::Error::NotImplemented, 'Including classes implement this.'
72
83
  end
73
84
 
74
85
  # The default values for a new instance of this class.
75
86
  #
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
- #
92
87
  # @return [Hash<Symbol => void>]
93
88
  def defaults
94
89
  {
@@ -35,6 +35,10 @@ module Vedeu
35
35
 
36
36
  private
37
37
 
38
+ # Returns the output in a compressed form if the :compression
39
+ # option is true.
40
+ #
41
+ # @return [String]
38
42
  def content
39
43
  compression
40
44
  end
@@ -38,8 +38,7 @@ module Vedeu
38
38
  end
39
39
 
40
40
  # @param attributes [Hash]
41
- # @raise [Vedeu::Error::InvalidSyntax] When the :attributes
42
- # param is not a Hash.
41
+ # @macro raise_invalid_syntax
43
42
  # @return [Hash]
44
43
  def validate(attributes)
45
44
  fail Vedeu::Error::InvalidSyntax,