vedeu 0.4.34 → 0.4.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 627cd72e48091fbe2959ffc08efac5353a7af4cb
4
- data.tar.gz: f027bb4b0648c2dce85949bdb8b381ba7eb09408
3
+ metadata.gz: 84b194d5028029767ac815eb90fee5806af559ed
4
+ data.tar.gz: ecce8b75baa7b87fd03f18ffb491034659febff9
5
5
  SHA512:
6
- metadata.gz: 05fdee8984b672ea21e8fd03b29139dfcaa237ec93db32c2d7d4afa63ba421656caff81caa6cf580682cb66184e8fbbc67b331c96c9c2a16a67bb4d725b853d0
7
- data.tar.gz: 50e6af9ada7c570262c426c493a330ab39897d4218e635bd151540d5c3a719a1eb0233d2280aef038ebd2b2aaa396030968ba068e9e51c5bcec8828bc6dcd4a0
6
+ metadata.gz: cf0641babb32ff61b8511a02c7898cabc04c0622b16557c72a5b61590caf7dea14b5eae9c3b5ebfcfb4ef8d51dd988f41a79b92cecb589e0be45c54cd1d68484
7
+ data.tar.gz: a9c5358c3c7b08293b26b8f57f3d3f69ed352b58184a684a54b8b16bfdf3349e0784ba62750ef8b82d51549fed272ffd3b339bd1f3bd1a4e3cd8a4b2ed09f487
@@ -0,0 +1,4 @@
1
+ This example shows the 'default' mode.
2
+ Content is not pruned or wrapped.
3
+
4
+ <%= time_now %>
@@ -0,0 +1,4 @@
1
+ This example shows the 'prune' mode.
2
+ Content is pruned at 22 characters.
3
+
4
+ <%= time_now %>
@@ -8,73 +8,79 @@ require 'vedeu'
8
8
  # An example application to demonstrate templates.
9
9
  class VedeuViewTemplateApp
10
10
 
11
- include Vedeu
12
-
13
- configure do
11
+ Vedeu.configure do
14
12
  debug!
15
13
  log '/tmp/vedeu_view_templates_app.log'
16
14
  end
17
15
 
18
- bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
16
+ Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
19
17
 
20
- interface 'default' do
18
+ Vedeu.interface 'default' do
21
19
  colour foreground: '#ff0000', background: '#000000'
22
20
  cursor!
23
21
  end
24
22
 
25
- interface 'prune' do
23
+ Vedeu.interface 'prune' do
26
24
  colour foreground: '#00ff00', background: '#000000'
27
25
  cursor!
28
26
  end
29
27
 
30
- interface 'wrap' do
28
+ Vedeu.interface 'wrap' do
31
29
  colour foreground: '#0000ff', background: '#000000'
32
30
  cursor!
33
31
  end
34
32
 
35
- keymap('_global_') do
33
+ Vedeu.keymap('_global_') do
36
34
  key(:up, 'k') { Vedeu.trigger(:_cursor_up_) }
37
35
  key(:right, 'l') { Vedeu.trigger(:_cursor_right_) }
38
36
  key(:down, 'j') { Vedeu.trigger(:_cursor_down_) }
39
37
  key(:left, 'h') { Vedeu.trigger(:_cursor_left_) }
40
38
  end
41
39
 
42
- border('default') do
40
+ Vedeu.border('default') do
43
41
  colour foreground: '#aadd00', background: '#000000'
44
42
  end
45
- border('prune') do
43
+ Vedeu.border('prune') do
46
44
  colour foreground: '#00aadd', background: '#000000'
47
45
  end
48
- border('wrap') do
46
+ Vedeu.border('wrap') do
49
47
  colour foreground: '#dd00aa', background: '#000000'
50
48
  end
51
49
 
52
- geometry('prune') do
50
+ Vedeu.geometry('prune') do
53
51
  centred!
54
52
  height 6
55
53
  width 25
56
54
  end
57
55
 
58
- geometry 'default' do
56
+ Vedeu.geometry 'default' do
59
57
  height 6
60
58
  width 25
61
59
  x use('prune').left
62
60
  y use('prune').north(7)
63
61
  end
64
62
 
65
- geometry 'wrap' do
63
+ Vedeu.geometry 'wrap' do
66
64
  height 6
67
65
  width 25
68
66
  x use('prune').left
69
67
  y use('prune').south(1)
70
68
  end
71
69
 
72
- renders do
73
- template_for('default', (File.dirname(__FILE__) + '/template.erb'), nil)
74
- template_for('prune', (File.dirname(__FILE__) + '/template.erb'), nil,
75
- mode: :prune, width: 22)
76
- template_for('wrap', (File.dirname(__FILE__) + '/template.erb'), nil,
77
- mode: :wrap, width: 25)
70
+ def self.default_template
71
+ File.dirname(__FILE__) + '/default.erb'
72
+ end
73
+ def self.prune_template
74
+ File.dirname(__FILE__) + '/prune.erb'
75
+ end
76
+ def self.wrap_template
77
+ File.dirname(__FILE__) + '/wrap.erb'
78
+ end
79
+
80
+ Vedeu.renders do
81
+ template_for('default', default_template, nil)
82
+ template_for('prune', prune_template, nil, mode: :prune, width: 22)
83
+ template_for('wrap', wrap_template, nil, mode: :wrap, width: 25)
78
84
  end
79
85
 
80
86
  def self.start(argv = ARGV)
@@ -0,0 +1,4 @@
1
+ This example shows the 'wrap' mode.
2
+ Content is wrapped at 25 characters.
3
+
4
+ <%= time_now %>
@@ -17,3 +17,4 @@ require_relative 'output'
17
17
  require_relative 'viewport'
18
18
  require_relative 'virtual_terminal'
19
19
  require_relative 'wordwrap'
20
+ require_relative 'view_helpers/all'
@@ -40,22 +40,7 @@ module Vedeu
40
40
  # @param value []
41
41
  # @return [Object]
42
42
  def self.coerce(value)
43
- return value if value.is_a?(self)
44
- return new unless value.is_a?(Hash)
45
-
46
- if value[:colour]
47
- return value[:colour] if value[:colour].is_a?(self)
48
- return new unless value[:colour].is_a?(Hash)
49
- return new(value[:colour]) if value[:colour][:background] ||
50
- value[:colour][:foreground]
51
-
52
- elsif value[:background] || value[:foreground]
53
- new(value)
54
-
55
- else
56
- new
57
-
58
- end
43
+ Vedeu::ColourCoercer.coerce(value)
59
44
  end
60
45
 
61
46
  # Returns a new instance of Vedeu::Colour.
@@ -0,0 +1,7 @@
1
+ require 'vedeu/output/view_helpers/view_helpers'
2
+
3
+ module Vedeu
4
+
5
+
6
+
7
+ end # Vedeu
@@ -0,0 +1,14 @@
1
+ module Vedeu
2
+
3
+ # This module can be included client application classes to provide various
4
+ # further functionality and simplify Vedeu view construction.
5
+ #
6
+ module ViewHelpers
7
+
8
+ def time_now
9
+ Time.now.strftime('%a %e %b %k:%M')
10
+ end
11
+
12
+ end # ViewHelpers
13
+
14
+ end # Vedeu
@@ -55,7 +55,7 @@ module Vedeu
55
55
  # @return [String]
56
56
  def wrap
57
57
  processed = []
58
- text.split(/\n/).map do |unprocessed|
58
+ split_lines.map do |unprocessed|
59
59
  line_length = 0
60
60
  reformatted = []
61
61
 
@@ -1,3 +1,4 @@
1
+ require_relative 'colour_coercer'
1
2
  require_relative 'common'
2
3
  require_relative 'options'
3
4
  require_relative 'template'
@@ -0,0 +1,97 @@
1
+ module Vedeu
2
+
3
+ class ColourCoercer
4
+
5
+ # @param value [Vedeu::Colour|Hash<Symbol => Fixnum|String|Symbol>]
6
+ # @return [Vedeu::Colour]
7
+ def self.coerce(value)
8
+ new(value).coerce
9
+ end
10
+
11
+ # @param value [Hash<Symbol => Fixnum|String|Symbol>]
12
+ def self.from_hash(value)
13
+ new(value).from_hash
14
+ end
15
+
16
+ # @param value [Vedeu::Colour|Hash<Symbol => Fixnum|String|Symbol]
17
+ # @return [Vedeu::ColourCoercer]
18
+ def initialize(value)
19
+ @value = value
20
+ end
21
+
22
+ # @return [Vedeu::Colour]
23
+ def coerce
24
+ return value if colour?
25
+
26
+ if hash?
27
+ Vedeu::ColourCoercer.from_hash(value)
28
+
29
+ else
30
+ build
31
+
32
+ end
33
+ end
34
+
35
+ # @return [Vedeu::Colour]
36
+ def from_hash
37
+ return build unless value
38
+
39
+ if colour_key?
40
+ Vedeu::ColourCoercer.coerce(value[:colour])
41
+
42
+ elsif background? || foreground?
43
+ build_from_hash(value)
44
+
45
+ else
46
+ build
47
+
48
+ end
49
+ end
50
+
51
+ protected
52
+
53
+ # @!attribute [r] colour
54
+ # @return [void]
55
+ attr_reader :value
56
+
57
+ private
58
+
59
+ # @return [Vedeu::Colour]
60
+ def build
61
+ Vedeu::Colour.new
62
+ end
63
+
64
+ # @param value [Hash<Symbol => Fixnum|String|Symbol>]
65
+ # @return [Vedeu::Colour]
66
+ def build_from_hash(value)
67
+ Vedeu::Colour.new(value)
68
+ end
69
+
70
+ # @return [Boolean]
71
+ def colour?
72
+ value.is_a?(Vedeu::Colour)
73
+ end
74
+
75
+ # @return [Boolean]
76
+ def hash?
77
+ value.is_a?(Hash)
78
+ end
79
+
80
+ # @return [Boolean]
81
+ def background?
82
+ value.key?(:background)
83
+ end
84
+
85
+ # @return [Boolean]
86
+ def colour_key?
87
+ value.key?(:colour)
88
+ end
89
+
90
+ # @return [Boolean]
91
+ def foreground?
92
+ value.key?(:foreground)
93
+ end
94
+
95
+ end # ColourCoercer
96
+
97
+ end # Vedeu
@@ -5,6 +5,8 @@ module Vedeu
5
5
  # @api private
6
6
  class Template
7
7
 
8
+ include Vedeu::ViewHelpers
9
+
8
10
  # @param (see Vedeu::Template#new)
9
11
  # @return [void]
10
12
  def self.parse(object, path, options = {})
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.4.34'
4
+ VERSION = '0.4.35'
5
5
 
6
6
  end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ class ViewHelpersTestClass
6
+
7
+ include Vedeu::ViewHelpers
8
+
9
+ end
10
+
11
+ describe ViewHelpers do
12
+
13
+ let(:described) { ViewHelpers }
14
+ let(:instance) { ViewHelpersTestClass.new }
15
+
16
+ describe '#time_now' do
17
+ let(:_time) { Time.new(2015, 6, 23, 22, 25, 17) }
18
+
19
+ before { Time.stubs(:now).returns(_time) }
20
+
21
+ subject { instance.time_now }
22
+
23
+ it 'returns a formatted time' do
24
+ subject.must_equal('Tue 23 Jun 22:25')
25
+ end
26
+ end
27
+
28
+ end # ViewHelpers
29
+
30
+ end # Vedeu
@@ -0,0 +1,85 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe ColourCoercer do
6
+
7
+ let(:described) { Vedeu::ColourCoercer }
8
+ let(:instance) { described.new(_value) }
9
+ let(:_value) { }
10
+
11
+ describe '#initialize' do
12
+ subject { instance }
13
+ end
14
+
15
+ describe '.coerce' do
16
+ it { described.must_respond_to(:coerce) }
17
+ end
18
+
19
+ describe '.from_hash' do
20
+ it { described.must_respond_to(:from_hash) }
21
+ end
22
+
23
+ describe '#coerce' do
24
+ subject { instance.coerce }
25
+
26
+ context 'when no value is given' do
27
+ it { subject.must_be_instance_of(Vedeu::Colour) }
28
+ end
29
+
30
+ context 'when a value is given' do
31
+ context 'when the value is a Vedeu::Colour' do
32
+ let(:_value) { Vedeu::Colour.new }
33
+
34
+ it { subject.must_equal(_value) }
35
+ end
36
+
37
+ context 'when the value is a Hash' do
38
+ let(:_value) { { } }
39
+
40
+ it {
41
+ Vedeu::ColourCoercer.expects(:from_hash).with(_value)
42
+ subject
43
+ }
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '#from_hash' do
49
+ subject { instance.from_hash }
50
+
51
+ context 'when no value is given' do
52
+ it { subject.must_be_instance_of(Vedeu::Colour) }
53
+ end
54
+
55
+ context 'when a value is given' do
56
+ context 'when the value has a :colour key' do
57
+ let(:_value) { { colour: colour_value } }
58
+ let(:colour_value) { Vedeu::Colour.new }
59
+
60
+ it {
61
+ Vedeu::ColourCoercer.expects(:coerce).with(colour_value)
62
+ subject
63
+ }
64
+ end
65
+
66
+ context 'when the value has a :background or :foreground key' do
67
+ let(:_value) { { background: '#000000', foreground: '#ffffff' } }
68
+
69
+ it {
70
+ Vedeu::Colour.expects(:new).with(_value)
71
+ subject
72
+ }
73
+ end
74
+
75
+ context 'when the value is empty or has unhandled keys' do
76
+ let(:_value) { { unhandled: :some_value } }
77
+
78
+ it { subject.must_be_instance_of(Vedeu::Colour) }
79
+ end
80
+ end
81
+ end
82
+
83
+ end # ColourCoercer
84
+
85
+ end # Vedeu
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.34
4
+ version: 0.4.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -282,8 +282,10 @@ files:
282
282
  - examples/typed_commands/output.erb
283
283
  - examples/typed_commands/status.erb
284
284
  - examples/typed_commands/typed_commands_app.rb
285
- - examples/view_templates_app/template.erb
285
+ - examples/view_templates_app/default.erb
286
+ - examples/view_templates_app/prune.erb
286
287
  - examples/view_templates_app/view_templates_app.rb
288
+ - examples/view_templates_app/wrap.erb
287
289
  - features/start_stop.feature
288
290
  - features/support/env.rb
289
291
  - inch.yml
@@ -395,6 +397,8 @@ files:
395
397
  - lib/vedeu/output/templates/html_renderer.vedeu
396
398
  - lib/vedeu/output/text.rb
397
399
  - lib/vedeu/output/translator.rb
400
+ - lib/vedeu/output/view_helpers/all.rb
401
+ - lib/vedeu/output/view_helpers/view_helpers.rb
398
402
  - lib/vedeu/output/viewport.rb
399
403
  - lib/vedeu/output/virtual_buffer.rb
400
404
  - lib/vedeu/output/virtual_terminal.rb
@@ -424,6 +428,7 @@ files:
424
428
  - lib/vedeu/storage/fifo_store.rb
425
429
  - lib/vedeu/storage/store.rb
426
430
  - lib/vedeu/support/all.rb
431
+ - lib/vedeu/support/colour_coercer.rb
427
432
  - lib/vedeu/support/common.rb
428
433
  - lib/vedeu/support/log.rb
429
434
  - lib/vedeu/support/options.rb
@@ -521,6 +526,7 @@ files:
521
526
  - test/lib/vedeu/output/style_test.rb
522
527
  - test/lib/vedeu/output/text_test.rb
523
528
  - test/lib/vedeu/output/translator_test.rb
529
+ - test/lib/vedeu/output/view_helpers/view_helpers_test.rb
524
530
  - test/lib/vedeu/output/viewport_test.rb
525
531
  - test/lib/vedeu/output/virtual_buffer_test.rb
526
532
  - test/lib/vedeu/output/virtual_terminal_test.rb
@@ -547,6 +553,7 @@ files:
547
553
  - test/lib/vedeu/storage/conveyor_store_test.rb
548
554
  - test/lib/vedeu/storage/fifo_store_test.rb
549
555
  - test/lib/vedeu/storage/store_test.rb
556
+ - test/lib/vedeu/support/colour_coercer_test.rb
550
557
  - test/lib/vedeu/support/common_test.rb
551
558
  - test/lib/vedeu/support/log_test.rb
552
559
  - test/lib/vedeu/support/options_test.rb
@@ -675,6 +682,7 @@ test_files:
675
682
  - test/lib/vedeu/output/style_test.rb
676
683
  - test/lib/vedeu/output/text_test.rb
677
684
  - test/lib/vedeu/output/translator_test.rb
685
+ - test/lib/vedeu/output/view_helpers/view_helpers_test.rb
678
686
  - test/lib/vedeu/output/viewport_test.rb
679
687
  - test/lib/vedeu/output/virtual_buffer_test.rb
680
688
  - test/lib/vedeu/output/virtual_terminal_test.rb
@@ -701,6 +709,7 @@ test_files:
701
709
  - test/lib/vedeu/storage/conveyor_store_test.rb
702
710
  - test/lib/vedeu/storage/fifo_store_test.rb
703
711
  - test/lib/vedeu/storage/store_test.rb
712
+ - test/lib/vedeu/support/colour_coercer_test.rb
704
713
  - test/lib/vedeu/support/common_test.rb
705
714
  - test/lib/vedeu/support/log_test.rb
706
715
  - test/lib/vedeu/support/options_test.rb
@@ -1,8 +0,0 @@
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' } %>.