vedeu 0.4.27 → 0.4.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/bin/vedeu_drb_server +0 -2
  3. data/examples/borders_app.rb +2 -0
  4. data/examples/colours_app.rb +2 -0
  5. data/examples/drb_app.rb +2 -2
  6. data/examples/focus_app.rb +2 -0
  7. data/examples/geometry_app.rb +2 -0
  8. data/examples/material_colours_app.rb +2 -0
  9. data/examples/panel_app.rb +2 -0
  10. data/examples/view_templates_app/template.erb +8 -1
  11. data/examples/view_templates_app/view_templates_app.rb +2 -2
  12. data/lib/vedeu/all.rb +1 -0
  13. data/lib/vedeu/buffers/buffer.rb +31 -15
  14. data/lib/vedeu/configuration/api.rb +6 -30
  15. data/lib/vedeu/configuration/cli.rb +0 -10
  16. data/lib/vedeu/configuration/configuration.rb +0 -11
  17. data/lib/vedeu/distributed/templates/default_configuration.vedeu +0 -2
  18. data/lib/vedeu/dsl/composition.rb +9 -0
  19. data/lib/vedeu/models/char.rb +1 -7
  20. data/lib/vedeu/models/line.rb +1 -1
  21. data/lib/vedeu/models/stream.rb +10 -0
  22. data/lib/vedeu/output/border.rb +7 -5
  23. data/lib/vedeu/output/clear.rb +1 -1
  24. data/lib/vedeu/output/compressor.rb +1 -1
  25. data/lib/vedeu/output/refresh.rb +5 -9
  26. data/lib/vedeu/output/renderers/terminal.rb +1 -1
  27. data/lib/vedeu/output/viewport.rb +5 -12
  28. data/lib/vedeu/support/log.rb +1 -0
  29. data/lib/vedeu/support/template.rb +13 -7
  30. data/lib/vedeu/templating/all.rb +3 -0
  31. data/lib/vedeu/templating/directive.rb +43 -0
  32. data/lib/vedeu/templating/helpers.rb +63 -0
  33. data/lib/vedeu/templating/preprocessor.rb +72 -0
  34. data/test/lib/vedeu/configuration/api_test.rb +0 -55
  35. data/test/lib/vedeu/configuration/cli_test.rb +0 -7
  36. data/test/lib/vedeu/configuration/configuration_test.rb +0 -7
  37. data/test/lib/vedeu/geometry/coordinate_test.rb +11 -15
  38. data/test/lib/vedeu/models/stream_test.rb +14 -0
  39. data/test/lib/vedeu/support/timer_test.rb +42 -0
  40. data/test/lib/vedeu/templating/directive_test.rb +38 -0
  41. data/test/lib/vedeu/templating/helpers_test.rb +97 -0
  42. data/test/lib/vedeu/templating/preprocessor_test.rb +47 -0
  43. data/test/support/templates/simple_stuff.erb +6 -0
  44. data/vedeu.gemspec +1 -1
  45. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74b7a510a12140180d027df9a11090a30a05c9a6
4
- data.tar.gz: 22694b40928d66db21201bf4ba5e4db403b25d32
3
+ metadata.gz: af28147191fb71a62c5dafcafdfc482ba5197f96
4
+ data.tar.gz: ffba51b895e26f86fb0075b0880ee85dab52a31f
5
5
  SHA512:
6
- metadata.gz: 3559b8cbb66f263c3ae5ba69057003c076a471b64344356283fee0ea65f1a37517408c9b7efe7f256f79d03ebcf628534c71f7479a8a317a8d8d605438c6cdb7
7
- data.tar.gz: 62aa833e9ff4e93306294626b982da0b44bdcfbffe03d9cb77e227440d8c8872a13830a733a7408d5f3b4efb437d0d50e519ba1191463576b9b5db6be5861da6
6
+ metadata.gz: b710ffa6a3f5b5cb01ba0bc88ec1b5b24d0e4261f14530d39588fc00595dda35cb9318b610636f16e2ac71775af986edc4bc2fa0b622e36551d6843e93b0e0ba
7
+ data.tar.gz: cfa662925a0f62b56e942ff95ae0f8245cefb7384f27d00146378aa3eabd17c396cc7f565b637d88868c3f214ef96de403b2e37ecb4ed87d970ae66656a14cbc
data/bin/vedeu_drb_server CHANGED
@@ -26,8 +26,6 @@ class VedeuTestApplication
26
26
  # interactive!
27
27
  # standalone!
28
28
 
29
- # trace!
30
-
31
29
  # System keys can be redefined
32
30
  # exit_key 'q'
33
31
  # focus_next_key :tab
@@ -10,6 +10,8 @@ class VedeuBordersApp
10
10
 
11
11
  include Vedeu
12
12
 
13
+ # Be aware that running an application with debugging enabled will affect
14
+ # performance.
13
15
  configure do
14
16
  debug!
15
17
  log '/tmp/vedeu_borders_app.log'
@@ -10,6 +10,8 @@ class VedeuColoursApp
10
10
 
11
11
  include Vedeu
12
12
 
13
+ # Be aware that running an application with debugging enabled will affect
14
+ # performance.
13
15
  configure do
14
16
  debug!
15
17
  log '/tmp/vedeu_colours_app.log'
data/examples/drb_app.rb CHANGED
@@ -8,6 +8,8 @@ require 'vedeu'
8
8
  # An example application to demonstrate the DRb server.
9
9
  class VedeuTestApplication
10
10
 
11
+ # Be aware that running an application with debugging enabled will affect
12
+ # performance.
11
13
  Vedeu.configure do
12
14
  log '/tmp/vedeu_test_helper.log'
13
15
  debug!
@@ -25,8 +27,6 @@ class VedeuTestApplication
25
27
  # interactive!
26
28
  # standalone!
27
29
 
28
- # trace!
29
-
30
30
  # System keys can be redefined
31
31
  # exit_key 'q'
32
32
  # focus_next_key :tab
@@ -15,6 +15,8 @@ require 'vedeu'
15
15
  # Use 'space' to change focus, 'q' to exit.
16
16
  class VedeuFocusApp
17
17
 
18
+ # Be aware that running an application with debugging enabled will affect
19
+ # performance.
18
20
  Vedeu.configure do
19
21
  debug!
20
22
  log '/tmp/vedeu_focus_app.log'
@@ -10,6 +10,8 @@ class VedeuGeometryApp
10
10
 
11
11
  include Vedeu
12
12
 
13
+ # Be aware that running an application with debugging enabled will affect
14
+ # performance.
13
15
  configure do
14
16
  debug!
15
17
  log '/tmp/vedeu_geometry_app.log'
@@ -11,6 +11,8 @@ class VedeuMaterialColoursApp
11
11
 
12
12
  include Vedeu
13
13
 
14
+ # Be aware that running an application with debugging enabled will affect
15
+ # performance.
14
16
  configure do
15
17
  debug!
16
18
  log '/tmp/vedeu_material_colours_app.log'
@@ -11,6 +11,8 @@ class VedeuPanelApp
11
11
 
12
12
  include Vedeu
13
13
 
14
+ # Be aware that running an application with debugging enabled will affect
15
+ # performance.
14
16
  configure do
15
17
  debug!
16
18
  log '/tmp/vedeu_panel_app.log'
@@ -1 +1,8 @@
1
- Here's a simple example that will be displayed in the main interface of the application.
1
+ Here's a simple example that will be displayed in the main interface of the
2
+ application. It's a multi-line affair, composed of words, punctuation and
3
+ with no doubt, bad grammar. An empty line follows:
4
+
5
+ Now, this line contains a <%= colours({ fg: '#ff0000', bg: '#000000' }) { 'red' } %> word. Whilst
6
+ this has a <% foreground('#33aa33') do %>green foreground<% end %> or
7
+ <% background('#33aa33') do %>green background<% end %>. There's also a short
8
+ syntax being used <%= fg('#0000ff') { 'here' } %> and <%= bg('#0000ff') { 'here' } %>.
@@ -43,10 +43,10 @@ class VedeuViewTemplateApp
43
43
  colour foreground: '#aadd00', background: '#000000'
44
44
  end
45
45
  border('prune') do
46
- colour foreground: '#aadd00', background: '#000000'
46
+ colour foreground: '#00aadd', background: '#000000'
47
47
  end
48
48
  border('wrap') do
49
- colour foreground: '#aadd00', background: '#000000'
49
+ colour foreground: '#dd00aa', background: '#000000'
50
50
  end
51
51
 
52
52
  geometry('prune') do
data/lib/vedeu/all.rb CHANGED
@@ -26,6 +26,7 @@ require 'vedeu/events/all'
26
26
  require 'vedeu/input/all'
27
27
  require 'vedeu/output/all'
28
28
  require 'vedeu/support/all'
29
+ require 'vedeu/templating/all'
29
30
 
30
31
  require 'vedeu/main_loop'
31
32
  require 'vedeu/application'
@@ -68,6 +68,15 @@ module Vedeu
68
68
  true
69
69
  end
70
70
 
71
+ # Return a boolean indicating content presence on the buffer type.
72
+ #
73
+ # @return [Boolean] Whether the buffer targetted has content.
74
+ def back?
75
+ return false if back.nil? || back.content.empty?
76
+
77
+ true
78
+ end
79
+
71
80
  # Returns the front buffer or, if that is empty, the interface cleared.
72
81
  #
73
82
  # @return [void]
@@ -75,6 +84,24 @@ module Vedeu
75
84
  Vedeu::Output.render(clear_buffer)
76
85
  end
77
86
 
87
+ # Return a boolean indicating content presence on the buffer type.
88
+ #
89
+ # @return [Boolean] Whether the buffer targetted has content.
90
+ def front?
91
+ return false if front.nil? || front.content.empty?
92
+
93
+ true
94
+ end
95
+
96
+ # Return a boolean indicating content presence on the buffer type.
97
+ #
98
+ # @return [Boolean] Whether the buffer targetted has content.
99
+ def previous?
100
+ return false if previous.nil? || previous.content.empty?
101
+
102
+ true
103
+ end
104
+
78
105
  # Hide this buffer.
79
106
  #
80
107
  # @return [void]
@@ -118,12 +145,12 @@ module Vedeu
118
145
  #
119
146
  # @return [Array<Array<Array<Vedeu::Char>>>]
120
147
  def buffer
121
- swap if content_for?(:back)
148
+ swap if back?
122
149
 
123
- if content_for?(:front)
150
+ if front?
124
151
  [front.render]
125
152
 
126
- elsif content_for?(:previous)
153
+ elsif previous?
127
154
  [previous.render]
128
155
 
129
156
  else
@@ -165,17 +192,6 @@ module Vedeu
165
192
  true
166
193
  end
167
194
 
168
- # Return a boolean indicating content presence on the buffer type.
169
- #
170
- # @param buffer [Symbol] One of; :back, :front or :previous.
171
- # @return [Boolean] Whether the buffer targetted has content.
172
- def content_for?(buffer)
173
- return false if public_send(buffer).nil? ||
174
- public_send(buffer).content.empty?
175
-
176
- true
177
- end
178
-
179
195
  # Retrieve the interface by name.
180
196
  #
181
197
  # @return [Vedeu::Interface]
@@ -185,7 +201,7 @@ module Vedeu
185
201
 
186
202
  # @return [Vedeu::Interface]
187
203
  def view
188
- if content_for?(:front)
204
+ if front?
189
205
  front
190
206
 
191
207
  else
@@ -181,8 +181,11 @@ module Vedeu
181
181
 
182
182
  # Sets boolean to enable/disable debugging. Vedeu's default setting is
183
183
  # for debugging to be disabled. Using `debug!` or setting `debug` to true
184
- # will enable debugging. If `trace!` is used, or `trace` is set to true,
185
- # debugging will be enabled, overriding any setting here.
184
+ # will enable debugging.
185
+ #
186
+ # @note
187
+ # Be aware that running an application with debugging enabled will
188
+ # affect performance.
186
189
  #
187
190
  # @example
188
191
  # Vedeu.configure do
@@ -196,37 +199,10 @@ module Vedeu
196
199
  # @param value [Boolean]
197
200
  # @return [Boolean]
198
201
  def debug!(value = true)
199
- if options.key?(:trace) && options[:trace] != false
200
- options[:debug] = true
201
-
202
- else
203
- options[:debug] = value
204
-
205
- end
202
+ options[:debug] = value
206
203
  end
207
204
  alias_method :debug, :debug!
208
205
 
209
- # Sets boolean to enable/disable tracing. Vedeu's default setting is for
210
- # tracing to be disabled. Using `trace!` or setting `trace` to true will
211
- # enable tracing and debugging.
212
- #
213
- # @example
214
- # Vedeu.configure do
215
- # trace!
216
- # ...
217
- #
218
- # Vedeu.configure do
219
- # trace false
220
- # ...
221
- #
222
- # @param value [Boolean]
223
- # @return [Boolean]
224
- def trace!(value = true)
225
- options[:debug] = true if value
226
- options[:trace] = value
227
- end
228
- alias_method :trace, :trace!
229
-
230
206
  # Sets the colour mode of the terminal.
231
207
  #
232
208
  # @example
@@ -75,7 +75,6 @@ module Vedeu
75
75
  :run_many,
76
76
  :run_once,
77
77
  :standalone,
78
- :trace,
79
78
  ]
80
79
  end
81
80
 
@@ -202,15 +201,6 @@ module Vedeu
202
201
  end
203
202
  end
204
203
 
205
- # @return [OptionParser]
206
- def trace
207
- parser.on('-D', '--trace', 'Run application with debugging on with ' \
208
- 'method and event tracing (noisy!).') do
209
- options[:debug] = true
210
- options[:trace] = true
211
- end
212
- end
213
-
214
204
  end # CLI
215
205
 
216
206
  end # Config
@@ -178,16 +178,6 @@ module Vedeu
178
178
  instance.options[:terminal_mode]
179
179
  end
180
180
 
181
- # Returns whether tracing is enabled or disabled. Tracing is very noisy in
182
- # the log file (logging method calls and events trigger). Default is
183
- # false; meaning tracing is disabled.
184
- #
185
- # @return [Boolean]
186
- def trace?
187
- instance.options[:trace]
188
- end
189
- alias_method :trace, :trace?
190
-
191
181
  # Vedeu's default system keys. Use {Vedeu::Configuration.system_keys}.
192
182
  #
193
183
  # @return [Hash]
@@ -275,7 +265,6 @@ module Vedeu
275
265
  stderr: nil,
276
266
  system_keys: Vedeu::Configuration.default_system_keys,
277
267
  terminal_mode: :raw,
278
- trace: false,
279
268
  }
280
269
  end
281
270
 
@@ -16,8 +16,6 @@ Vedeu.configure do
16
16
  # interactive!
17
17
  # standalone!
18
18
 
19
- # trace!
20
-
21
19
  # System keys can be redefined
22
20
  # exit_key 'q'
23
21
  # focus_next_key :tab
@@ -71,6 +71,15 @@ module Vedeu
71
71
  model.add(new_model)
72
72
  end
73
73
 
74
+ # def content_for(name, filename, object = nil, options = {})
75
+ # lines = Vedeu::Template.parse(object, filename)
76
+
77
+ # _model = model.member.build(new_attributes(name).
78
+ # merge!({ lines: lines }))
79
+
80
+ # model.add(_model)
81
+ # end
82
+
74
83
  protected
75
84
 
76
85
  # @!attribute [r] client
@@ -84,13 +84,7 @@ module Vedeu
84
84
  # @param value [Vedeu::Position]
85
85
  # @return [Vedeu::Position]
86
86
  def position=(value)
87
- if value.is_a?(Vedeu::Position)
88
- @position = @attributes[:position] = value
89
-
90
- else
91
- @position = @attributes[:position] = Vedeu::Position.coerce(value)
92
-
93
- end
87
+ @position = @attributes[:position] = Vedeu::Position.coerce(value)
94
88
  end
95
89
 
96
90
  # @return [String]
@@ -51,7 +51,7 @@ module Vedeu
51
51
  def chars
52
52
  return [] if empty?
53
53
 
54
- streams.flat_map(&:chars)
54
+ @chars ||= streams.flat_map(&:chars)
55
55
  end
56
56
 
57
57
  # Returns a boolean indicating whether the line has content.
@@ -71,6 +71,16 @@ module Vedeu
71
71
  value.empty?
72
72
  end
73
73
 
74
+ # An object is equal when its values are the same.
75
+ #
76
+ # @param other [Vedeu::Char]
77
+ # @return [Boolean]
78
+ def eql?(other)
79
+ self.class == other.class && value == other.value &&
80
+ colour == other.colour && style == other.style && parent == other.parent
81
+ end
82
+ alias_method :==, :eql?
83
+
74
84
  # @return [NilClass|String]
75
85
  def name
76
86
  parent.name if parent
@@ -159,13 +159,15 @@ module Vedeu
159
159
  return [] unless visible?
160
160
  return [] unless enabled?
161
161
 
162
- out = [top, bottom]
162
+ Vedeu::Timer.for(:timer, "Rendering border: #{name}") do
163
+ out = [top, bottom]
163
164
 
164
- height.times do |y|
165
- out << [left(y), right(y)]
166
- end
165
+ height.times do |y|
166
+ out << [left(y), right(y)]
167
+ end
167
168
 
168
- out.flatten
169
+ out.flatten
170
+ end
169
171
  end
170
172
 
171
173
  # @return [String]
@@ -58,7 +58,7 @@ module Vedeu
58
58
  # @return [Array<Array<Vedeu::Char>>]
59
59
  def clear
60
60
  if visible?
61
- Vedeu::Timer.for(:debug, "Clearing: #{name}") do
61
+ Vedeu::Timer.for(:timer, "Clearing: #{name}") do
62
62
  y, x = *position
63
63
 
64
64
  @clear ||= Array.new(height) do |iy|
@@ -17,7 +17,7 @@ module Vedeu
17
17
  # @return [String]
18
18
  def render
19
19
  Array(output).flatten.map do |char|
20
- out = ''
20
+ out = ''
21
21
  out << char.position.to_s
22
22
  out << colour_for(char)
23
23
  out << style_for(char)
@@ -12,7 +12,7 @@ module Vedeu
12
12
  def all
13
13
  message = 'Refreshing all interfaces'
14
14
 
15
- Vedeu::Timer.for(:info, message) do
15
+ Vedeu::Timer.for(:timer, message) do
16
16
  Vedeu.interfaces.zindexed.each { |model| by_name(model.name) }
17
17
  end
18
18
  end
@@ -32,14 +32,10 @@ module Vedeu
32
32
  def by_group(group_name)
33
33
  message = "Refreshing group: '#{group_name}'"
34
34
 
35
- Vedeu::Timer.for(:info, message) do
36
- Vedeu.groups.find!(group_name).members.each do |name|
35
+ Vedeu::Timer.for(:timer, message) do
36
+ Vedeu.groups.find!(group_name).members.each { |name|
37
37
  Vedeu.interfaces.by_name(name)
38
- end.sort do |a, b|
39
- a.zindex <=> b.zindex
40
- end.each do |name|
41
- by_name(name)
42
- end
38
+ }.sort { |a, b| a.zindex <=> b.zindex }.each { |name| by_name(name) }
43
39
  end
44
40
  end
45
41
 
@@ -51,7 +47,7 @@ module Vedeu
51
47
  def by_name(name)
52
48
  message = "Refreshing interface: '#{name}'"
53
49
 
54
- Vedeu::Timer.for(:info, message) { Vedeu.buffers.by_name(name).render }
50
+ Vedeu::Timer.for(:timer, message) { Vedeu.buffers.by_name(name).render }
55
51
  end
56
52
 
57
53
  end # Refresh
@@ -35,7 +35,7 @@ module Vedeu
35
35
 
36
36
  # @return [String]
37
37
  def parsed
38
- Vedeu::Timer.for(:debug, 'Compression') do
38
+ Vedeu::Timer.for(:timer, 'Compression') do
39
39
  Vedeu::Compressor.new(output).render
40
40
  end
41
41
  end
@@ -52,11 +52,11 @@ module Vedeu
52
52
  def render
53
53
  return [] unless visible?
54
54
 
55
- Vedeu::Timer.for(:output, "Rendering: #{name}") do
55
+ Vedeu::Timer.for(:timer, "Rendering: #{name}") do
56
56
  out = []
57
57
 
58
- show[0...height].each_with_index do |line, iy|
59
- line[0...width].each_with_index do |column, ix|
58
+ show.each_with_index do |line, iy|
59
+ line.each_with_index do |column, ix|
60
60
  column.position = Vedeu::Position[by + iy, bx + ix]
61
61
  out << column
62
62
  end
@@ -106,7 +106,7 @@ module Vedeu
106
106
  #
107
107
  # @return [Range]
108
108
  def rows
109
- top..(top + (geometry.height - 1))
109
+ top...(top + height)
110
110
  end
111
111
 
112
112
  # Using the current cursor's x position, return a range of visible columns.
@@ -119,7 +119,7 @@ module Vedeu
119
119
  #
120
120
  # @return [Range]
121
121
  def columns
122
- left..(left + (geometry.width - 1))
122
+ left...(left + width)
123
123
  end
124
124
 
125
125
  # @return [Fixnum]
@@ -163,13 +163,6 @@ module Vedeu
163
163
  @cursor ||= Vedeu.cursors.by_name(name)
164
164
  end
165
165
 
166
- # Return the geometry associated with the interface we are drawing.
167
- #
168
- # @return (see Vedeu::Geometries#by_name)
169
- def geometry
170
- @geometry || Vedeu.geometries.by_name(name)
171
- end
172
-
173
166
  end # Viewport
174
167
 
175
168
  end # Vedeu
@@ -156,6 +156,7 @@ module Vedeu
156
156
  output: [:light_green, :green],
157
157
  store: [:light_cyan, :cyan],
158
158
  test: [:light_white, :white],
159
+ timer: [:light_yellow, :yellow],
159
160
  update: [:light_cyan, :cyan],
160
161
  }
161
162
  end
@@ -3,21 +3,23 @@ module Vedeu
3
3
  # Generic class to loading a template and parsing it via ERb.
4
4
  class Template
5
5
 
6
- # @param object [Class]
7
- # @param path [String]
6
+ # @param see Vedeu::Template#new
8
7
  # @return [void]
9
- def self.parse(object, path)
10
- new(object, path).parse
8
+ def self.parse(object, path, options = {})
9
+ new(object, path, options).parse
11
10
  end
12
11
 
13
12
  # Returns a new instance of Vedeu::Template.
14
13
  #
15
14
  # @param object [Class]
16
15
  # @param path [String]
16
+ # @param options [Hash]
17
+ # @option options name [String] The name of an interface.
17
18
  # @return [Template]
18
- def initialize(object, path)
19
- @object = object
20
- @path = path.to_s
19
+ def initialize(object, path, options = {})
20
+ @object = object
21
+ @path = path.to_s
22
+ @options = options
21
23
  end
22
24
 
23
25
  # @return [void]
@@ -31,6 +33,10 @@ module Vedeu
31
33
  # @return [Class]
32
34
  attr_reader :object
33
35
 
36
+ # @!attribute [r] options
37
+ # @return [Hash]
38
+ attr_reader :options
39
+
34
40
  private
35
41
 
36
42
  # @return [String]
@@ -0,0 +1,3 @@
1
+ require_relative 'helpers'
2
+ require_relative 'directive'
3
+ require_relative 'preprocessor'
@@ -0,0 +1,43 @@
1
+ module Vedeu
2
+
3
+ module Templating
4
+
5
+ # Converts a directive found in a template into a Vedeu::Stream object.
6
+ class Directive
7
+
8
+ include Vedeu::Templating::Helpers
9
+
10
+ # @param code [String]
11
+ # @return [Vedeu::Stream]
12
+ def self.process(code)
13
+ new(code).process
14
+ end
15
+
16
+ # @param code [String]
17
+ def initialize(code)
18
+ @code = code
19
+ end
20
+
21
+ # @return [Vedeu::Stream]
22
+ def process
23
+ eval(code, proc.binding)
24
+ end
25
+
26
+ protected
27
+
28
+ # @!attribute [r] code
29
+ # @return [String]
30
+ attr_reader :code
31
+
32
+ private
33
+
34
+ # @return [Proc]
35
+ def proc
36
+ @proc ||= Proc.new {}
37
+ end
38
+
39
+ end # Directive
40
+
41
+ end # Templating
42
+
43
+ end # Vedeu
@@ -0,0 +1,63 @@
1
+ module Vedeu
2
+
3
+ module Templating
4
+
5
+ module Helpers
6
+
7
+ # @param value [String] The HTML/CSS colour.
8
+ # @param block [Proc]
9
+ # @return [Vedeu::Stream]
10
+ # @raise [InvalidSyntax] The required block was not given.
11
+ def background(value, &block)
12
+ define_stream({ background: value }, &block)
13
+ end
14
+ alias_method :bg, :background
15
+
16
+ # @param attributes [Hash]
17
+ # @option attributes foreground [String] The HTML/CSS foreground colour.
18
+ # @option attributes background [String] The HTML/CSS background colour.
19
+ # @param block [Proc]
20
+ # @return [Vedeu::Stream]
21
+ # @raise [InvalidSyntax] The required block was not given.
22
+ def colour(attributes = {}, &block)
23
+ define_stream(attributes, &block)
24
+ end
25
+
26
+ # @example
27
+ # Roses are {{ foreground('#ff0000', 'red') }},
28
+ # violets are {{ fg('#0000ff', 'blue') }}
29
+ # {{ foreground('#00ff00'), 'The test suite is all green!' }}
30
+ #
31
+ # @param value [String] The HTML/CSS colour.
32
+ # @param block [Proc]
33
+ # @return [Vedeu::Stream]
34
+ # @raise [InvalidSyntax] The required block was not given.
35
+ def foreground(value, &block)
36
+ define_stream({ foreground: value }, &block)
37
+ end
38
+ alias_method :fg, :foreground
39
+
40
+ private
41
+
42
+ # @param see Vedeu::Templating::Helpers#colours
43
+ def define_colour(attributes = {})
44
+ attributes.delete_if do |k, v|
45
+ [:background, :foreground].include?(k) == false || v.nil? || v.empty?
46
+ end
47
+
48
+ Vedeu::Colour.new(attributes)
49
+ end
50
+
51
+ # @param see Vedeu::Templating::Helpers#colours
52
+ def define_stream(attributes = {}, &block)
53
+ fail InvalidSyntax, 'block not given' unless block_given?
54
+
55
+ Vedeu::Stream.build(colour: define_colour(attributes),
56
+ value: block.call)
57
+ end
58
+
59
+ end # Helpers
60
+
61
+ end # Templating
62
+
63
+ end # Vedeu
@@ -0,0 +1,72 @@
1
+ module Vedeu
2
+
3
+ module Templating
4
+
5
+ # preprocess
6
+ # takes a line at a time
7
+ # splits line into component parts e.g. text1, ruby, text1
8
+ # takes text1, adds to JSON stream
9
+ # processes ruby, adding to a new JSON stream
10
+ # takes text2, adds to a JSON stream
11
+ #
12
+ # process
13
+ # converts JSON streams into line/stream objects with correct attributes
14
+
15
+ # Pre-processes a template, to convert all lines and lines with directives
16
+ # into Vedeu::Streams.
17
+ class Preprocessor
18
+
19
+ # @param lines [Array<String>]
20
+ def self.process(lines)
21
+ new(lines).process
22
+ end
23
+
24
+ # @param lines [Array<String>]
25
+ def initialize(lines)
26
+ @lines = lines
27
+ end
28
+
29
+ # @return [Array<Vedeu::Stream>]
30
+ def process
31
+ lines.each_with_object([]) do |line, acc|
32
+ if line =~ markers?
33
+ code = line.gsub(markers, '').chomp
34
+
35
+ acc << Directive.process(code)
36
+
37
+ else
38
+ acc << Vedeu::Stream.new(value: line.chomp)
39
+
40
+ end
41
+ acc
42
+ end
43
+ end
44
+
45
+ protected
46
+
47
+ # @!attribute [r] lines
48
+ # @return [Array<String>]
49
+ attr_reader :lines
50
+
51
+ private
52
+
53
+ # Return a pattern to remove directive markers and spaces.
54
+ #
55
+ # @return [Regexp]
56
+ def markers
57
+ /({{\s*|\s*}})/
58
+ end
59
+
60
+ # @example
61
+ # line contains {{ or }}
62
+ #
63
+ # @return [Regexp]
64
+ def markers?
65
+ /^\s*({{)(.*?)(}})$/
66
+ end
67
+
68
+ end # Preprocessor
69
+
70
+ end # Templating
71
+
72
+ end # Vedeu
@@ -20,7 +20,6 @@ module Vedeu
20
20
  it { instance.must_respond_to(:cooked) }
21
21
  it { instance.must_respond_to(:raw) }
22
22
  it { instance.must_respond_to(:debug) }
23
- it { instance.must_respond_to(:trace) }
24
23
  end
25
24
 
26
25
  describe '.configure' do
@@ -177,60 +176,6 @@ module Vedeu
177
176
  configuration = Vedeu.configure { debug(false) }
178
177
  configuration.debug.must_equal(false)
179
178
  end
180
-
181
- it 'sets the option to the desired value' do
182
- configuration = Vedeu.configure { trace(true) }
183
- configuration.debug.must_equal(true)
184
- end
185
-
186
- it 'sets the option to the desired value' do
187
- configuration = Vedeu.configure do
188
- debug(false)
189
- trace(true)
190
- end
191
-
192
- configuration.debug.must_equal(true)
193
- end
194
-
195
- it 'sets the option to the desired value' do
196
- configuration = Vedeu.configure do
197
- debug(true)
198
- trace(false)
199
- end
200
-
201
- configuration.debug.must_equal(true)
202
- end
203
-
204
- it 'sets the option to the desired value' do
205
- configuration = Vedeu.configure do
206
- debug(false)
207
- trace(false)
208
- end
209
-
210
- configuration.debug.must_equal(false)
211
- end
212
- end
213
-
214
- describe '#trace!' do
215
- it 'sets the option to the desired value' do
216
- configuration = Vedeu.configure { trace! }
217
-
218
- configuration.trace.must_equal(true)
219
- end
220
-
221
- it 'sets the option to the desired value' do
222
- configuration = Vedeu.configure { trace(false) }
223
-
224
- configuration.trace.must_equal(false)
225
- configuration.debug.must_equal(false)
226
- end
227
-
228
- it 'sets the option to the desired value' do
229
- configuration = Vedeu.configure { trace(true) }
230
-
231
- configuration.trace.must_equal(true)
232
- configuration.debug.must_equal(true)
233
- end
234
179
  end
235
180
 
236
181
  describe '#colour_mode' do
@@ -131,13 +131,6 @@ module Vedeu
131
131
  end
132
132
  end
133
133
 
134
- describe '#trace?' do
135
- it '--trace' do
136
- Configuration.configure(['--trace'])
137
- Configuration.trace?.must_equal(true)
138
- end
139
- end
140
-
141
134
  end # CLI
142
135
 
143
136
  end # Config
@@ -14,7 +14,6 @@ module Vedeu
14
14
  it { described.must_respond_to(:drb) }
15
15
  it { described.must_respond_to(:interactive) }
16
16
  it { described.must_respond_to(:once) }
17
- it { described.must_respond_to(:trace) }
18
17
  end
19
18
 
20
19
  describe '.default_system_keys' do
@@ -74,12 +73,6 @@ module Vedeu
74
73
  end
75
74
  end
76
75
 
77
- describe '#trace?' do
78
- it 'returns the value of the trace option' do
79
- Configuration.trace?.must_equal(false)
80
- end
81
- end
82
-
83
76
  describe '.configure' do
84
77
  it 'returns the options configured' do
85
78
  Configuration.configure do
@@ -12,22 +12,18 @@ module Vedeu
12
12
  let(:x) { 7 }
13
13
  let(:y) { 5 }
14
14
 
15
- let(:borders) { mock('Vedeu::Borders') }
16
- let(:border) {
17
- Vedeu::Border.new({
18
- name: _name,
19
- enabled: true
20
- })
21
- }
22
-
23
15
  before do
24
- Vedeu::Geometry.new({name: _name,
25
- height: height,
26
- width: width,
27
- x: x,
28
- y: y}).store
29
- Vedeu.stubs(:borders).returns(borders)
30
- borders.stubs(:by_name).returns(border)
16
+ Vedeu::Border.new(name: _name,
17
+ enabled: true).store
18
+ Vedeu::Geometry.new(name: _name,
19
+ height: height,
20
+ width: width,
21
+ x: x,
22
+ y: y).store
23
+ end
24
+ after do
25
+ Vedeu.borders.reset
26
+ Vedeu.geometries.reset
31
27
  end
32
28
 
33
29
  describe '#initialize' do
@@ -76,6 +76,20 @@ module Vedeu
76
76
  end
77
77
  end
78
78
 
79
+ describe '#eql?' do
80
+ let(:other) { described.new(attributes) }
81
+
82
+ subject { instance.eql?(other) }
83
+
84
+ it { subject.must_equal(true) }
85
+
86
+ context 'when different to other' do
87
+ let(:other) { described.new(colour: Colour.coerce({ background: '#ff0000' })) }
88
+
89
+ it { subject.must_equal(false) }
90
+ end
91
+ end
92
+
79
93
  describe '#name' do
80
94
  subject { instance.name }
81
95
 
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe Timer do
6
+
7
+ let(:described) { Vedeu::Timer }
8
+ let(:instance) { described.new(type, _message) }
9
+ let(:type) { :debug }
10
+ let(:_message) { 'Testing' }
11
+ let(:_time) { mock('Time') }
12
+ let(:started) { 1434492219.5238185 }
13
+
14
+ before do
15
+ Time.stubs(:now).returns(_time)
16
+ _time.stubs(:to_f).returns(started)
17
+ end
18
+
19
+ describe '#initialize' do
20
+ it { instance.must_be_instance_of(described) }
21
+ it { instance.instance_variable_get('@type').must_equal(type) }
22
+ it { instance.instance_variable_get('@message').must_equal(_message) }
23
+ it { instance.instance_variable_get('@started').must_equal(started) }
24
+ end
25
+
26
+ describe '.for' do
27
+ it { described.must_respond_to(:for) }
28
+ end
29
+
30
+ describe '#measure' do
31
+ subject { instance.measure { } }
32
+
33
+ it {
34
+ Vedeu.expects(:log).with(type: :debug,
35
+ message: "Testing took 0ms.")
36
+ subject
37
+ }
38
+ end
39
+
40
+ end # Timer
41
+
42
+ end # Vedeu
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Templating
6
+
7
+ describe Directive do
8
+
9
+ let(:described) { Vedeu::Templating::Directive }
10
+ let(:instance) { described.new(code) }
11
+ let(:code) {
12
+ "colour(foreground: '#0f0') { 'Yay!' }"
13
+ }
14
+
15
+ describe '#initialize' do
16
+ it { instance.must_be_instance_of(described) }
17
+ it { instance.instance_variable_get('@code').must_equal(code) }
18
+ end
19
+
20
+ describe '.process' do
21
+ it { described.must_respond_to(:process) }
22
+ end
23
+
24
+ describe '#process' do
25
+ let(:colour) { Vedeu::Colour.coerce(foreground: '#0f0') }
26
+ let(:expected) { Vedeu::Stream.new(value: 'Yay!', colour: colour) }
27
+
28
+ subject { instance.process }
29
+
30
+ it { subject.must_be_instance_of(Vedeu::Stream) }
31
+ it { subject.must_equal(expected) }
32
+ end
33
+
34
+ end # Directive
35
+
36
+ end # Templating
37
+
38
+ end # Vedeu
@@ -0,0 +1,97 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Templating
6
+
7
+ class HelpersTestClass
8
+
9
+ include Vedeu::Templating::Helpers
10
+
11
+ end
12
+
13
+ describe Helpers do
14
+
15
+ let(:described) { Vedeu::Templating::Helpers }
16
+ let(:instance) { Vedeu::Templating::HelpersTestClass.new }
17
+
18
+ describe '#background' do
19
+ let(:expected) {
20
+ Vedeu::Stream.new(value: 'background text',
21
+ colour: Vedeu::Colour.coerce(background: '#000000'))
22
+ }
23
+
24
+ subject { instance.background('#000000') { 'background text' } }
25
+
26
+ it { subject.must_equal(expected) }
27
+ end
28
+
29
+ describe '#colour' do
30
+ let(:attributes) { {} }
31
+
32
+ subject { instance.colour(attributes) { 'colour text' } }
33
+
34
+ context 'with no attributes' do
35
+ it { subject.must_be_instance_of(Vedeu::Stream) }
36
+ end
37
+
38
+ context 'with a background attribute' do
39
+ let(:attributes) {
40
+ {
41
+ background: '#002200'
42
+ }
43
+ }
44
+ let(:expected) {
45
+ Vedeu::Stream.new(value: 'colour text',
46
+ colour: Vedeu::Colour.coerce(attributes))
47
+ }
48
+
49
+ it { subject.must_equal(expected) }
50
+ end
51
+
52
+ context 'with a foreground attribute' do
53
+ let(:attributes) {
54
+ {
55
+ foreground: '#ff0000'
56
+ }
57
+ }
58
+ let(:expected) {
59
+ Vedeu::Stream.new(value: 'colour text',
60
+ colour: Vedeu::Colour.coerce(attributes))
61
+ }
62
+
63
+ it { subject.must_equal(expected) }
64
+ end
65
+
66
+ context 'with both attributes' do
67
+ let(:attributes) {
68
+ {
69
+ background: '#000022',
70
+ foreground: '#ff7700',
71
+ }
72
+ }
73
+ let(:expected) {
74
+ Vedeu::Stream.new(value: 'colour text',
75
+ colour: Vedeu::Colour.coerce(attributes))
76
+ }
77
+
78
+ it { subject.must_equal(expected) }
79
+ end
80
+ end
81
+
82
+ describe '#foreground' do
83
+ let(:expected) {
84
+ Vedeu::Stream.new(value: 'foreground text',
85
+ colour: Vedeu::Colour.coerce(foreground: '#000000'))
86
+ }
87
+
88
+ subject { instance.foreground('#000000') { 'foreground text' } }
89
+
90
+ it { subject.must_equal(expected) }
91
+ end
92
+
93
+ end # Helpers
94
+
95
+ end # Templating
96
+
97
+ end # Vedeu
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Templating
6
+
7
+ describe Preprocessor do
8
+
9
+ let(:described) { Vedeu::Templating::Preprocessor }
10
+ let(:instance) { described.new(lines) }
11
+ let(:lines) {
12
+ [
13
+ "Some text here\n",
14
+ "{{ colour(foreground: '#0f0') { 'Yay!' } }}\n",
15
+ "More text here\n"
16
+ ]
17
+ }
18
+
19
+ describe '#initialize' do
20
+ it { instance.must_be_instance_of(described) }
21
+ it { instance.instance_variable_get('@lines').must_equal(lines) }
22
+ end
23
+
24
+ describe '.process' do
25
+ it { described.must_respond_to(:process) }
26
+ end
27
+
28
+ describe '#process' do
29
+ let(:expected) {
30
+ [
31
+ Vedeu::Stream.new(value: 'Some text here'),
32
+ Vedeu::Stream.new(value: 'Yay!',
33
+ colour: Vedeu::Colour.coerce({ foreground: '#0f0' })),
34
+ Vedeu::Stream.new(value: 'More text here')
35
+ ]
36
+ }
37
+
38
+ subject { instance.process }
39
+
40
+ it { subject.must_equal(expected) }
41
+ end
42
+
43
+ end # Preprocessor
44
+
45
+ end # Templating
46
+
47
+ end # Vedeu
@@ -0,0 +1,6 @@
1
+ Some text here {{ colour(background: '#ff0', foreground: '#000') { 'with colour' } }}, then more text, cool.
2
+ Here's the next line. All ready for parsing...
3
+
4
+ {{ colour(foreground: '#0f0') { 'Yay!' } }}
5
+
6
+ That was fun!
data/vedeu.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'vedeu'
7
- spec.version = '0.4.27'
7
+ spec.version = '0.4.28'
8
8
  spec.authors = ['Gavin Laking']
9
9
  spec.email = ['gavinlaking@gmail.com']
10
10
  spec.summary = 'A terminal case of wonderland.'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.27
4
+ version: 0.4.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-14 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -434,6 +434,10 @@ files:
434
434
  - lib/vedeu/support/terminal.rb
435
435
  - lib/vedeu/support/timer.rb
436
436
  - lib/vedeu/support/visibility.rb
437
+ - lib/vedeu/templating/all.rb
438
+ - lib/vedeu/templating/directive.rb
439
+ - lib/vedeu/templating/helpers.rb
440
+ - lib/vedeu/templating/preprocessor.rb
437
441
  - lib/vedeu/traps.rb
438
442
  - logs/.gitkeep
439
443
  - test/lib/vedeu/api_test.rb
@@ -551,12 +555,17 @@ files:
551
555
  - test/lib/vedeu/support/options_test.rb
552
556
  - test/lib/vedeu/support/template_test.rb
553
557
  - test/lib/vedeu/support/terminal_test.rb
558
+ - test/lib/vedeu/support/timer_test.rb
554
559
  - test/lib/vedeu/support/visibility_test.rb
560
+ - test/lib/vedeu/templating/directive_test.rb
561
+ - test/lib/vedeu/templating/helpers_test.rb
562
+ - test/lib/vedeu/templating/preprocessor_test.rb
555
563
  - test/lib/vedeu/traps_test.rb
556
564
  - test/lib/vedeu_test.rb
557
565
  - test/support/colour_test.sh
558
566
  - test/support/helpers/model_test_class.rb
559
567
  - test/support/stats.sh
568
+ - test/support/templates/simple_stuff.erb
560
569
  - test/test_helper.rb
561
570
  - vedeu.gemspec
562
571
  homepage: https://github.com/gavinlaking/vedeu
@@ -701,11 +710,16 @@ test_files:
701
710
  - test/lib/vedeu/support/options_test.rb
702
711
  - test/lib/vedeu/support/template_test.rb
703
712
  - test/lib/vedeu/support/terminal_test.rb
713
+ - test/lib/vedeu/support/timer_test.rb
704
714
  - test/lib/vedeu/support/visibility_test.rb
715
+ - test/lib/vedeu/templating/directive_test.rb
716
+ - test/lib/vedeu/templating/helpers_test.rb
717
+ - test/lib/vedeu/templating/preprocessor_test.rb
705
718
  - test/lib/vedeu/traps_test.rb
706
719
  - test/lib/vedeu_test.rb
707
720
  - test/support/colour_test.sh
708
721
  - test/support/helpers/model_test_class.rb
709
722
  - test/support/stats.sh
723
+ - test/support/templates/simple_stuff.erb
710
724
  - test/test_helper.rb
711
725
  has_rdoc: