vedeu 0.4.64 → 0.4.65

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: a32a9c9990ac18d631952547ac6fb6270fce65d3
4
- data.tar.gz: c246ba1065c2cc51e843d8bac331fff26752ac0e
3
+ metadata.gz: 75b2e5231b8b3902b1efb1235d1b3713452d65d7
4
+ data.tar.gz: 70bdf955c10a76f9c7fdd5e42720dca9468a1102
5
5
  SHA512:
6
- metadata.gz: f122e786688becea11c0709cbbb31f246d4beb9a9b37a0238d48e43fafa94e1282ee333942457ecff92096b2341684df300ef1b7d009dcd0acd7d37c507258e8
7
- data.tar.gz: 2eccc4215c84e205cddf9bd6823bb3df16f0c380beb048d97c070d84fd69a70e7323e0e890df9050ff9f33851a309bb947daac9db04721494a8493f259681ac3
6
+ metadata.gz: 1dfccfc1a1954962f7db2b419b8ff9def9ebba98d90445c8092291738b7ade467e60264dc86ca7f8fb4874f34c7588ae4581054dafadb075c3ab5d49deda1add
7
+ data.tar.gz: e766f3d3564dd8eab71731127885474c122cf2c9d7c1741b9dcef5338644e8a144c1eb05ddead0b4d9c369f96390b26c76da15ba8653ba3c4def96cd16ca4cf5
data/lib/vedeu/all.rb CHANGED
@@ -106,9 +106,9 @@ require 'vedeu/templating/all'
106
106
  require 'vedeu/templating/encoder'
107
107
  require 'vedeu/templating/decoder'
108
108
  require 'vedeu/templating/helpers'
109
- require 'vedeu/templating/directive'
110
- require 'vedeu/templating/post_processor'
109
+ require 'vedeu/templating/view_helpers'
111
110
  require 'vedeu/templating/template'
111
+ require 'vedeu/templating/view_template'
112
112
 
113
113
  require 'vedeu/application/controller'
114
114
  require 'vedeu/application/helper'
@@ -104,7 +104,7 @@ module Vedeu
104
104
  fail Vedeu::MissingRequired,
105
105
  'Cannot render template without a filename.' unless filename
106
106
 
107
- content = Vedeu::Templating::Template.parse(object, filename)
107
+ content = Vedeu::Templating::ViewTemplate.parse(object, filename)
108
108
  lines = Vedeu::Wordwrap.for(content, options)
109
109
 
110
110
  new_model = model.member.build(template_attributes(name, lines))
@@ -72,6 +72,7 @@ module Vedeu
72
72
  def add(child)
73
73
  @lines = lines.add(child)
74
74
  end
75
+ alias_method :<<, :add
75
76
 
76
77
  # Hide a named interface buffer, or without a name, the buffer of the
77
78
  # currently focussed interface.
@@ -39,6 +39,7 @@ module Vedeu
39
39
  def add(child)
40
40
  @_streams = @streams = collection.coerce(streams, self).add(child)
41
41
  end
42
+ alias_method :<<, :add
42
43
 
43
44
  # Returns an array of all the characters with formatting for this line.
44
45
  #
@@ -57,6 +58,15 @@ module Vedeu
57
58
  streams.empty?
58
59
  end
59
60
 
61
+ # An object is equal when its values are the same.
62
+ #
63
+ # @param other [Vedeu::Collection]
64
+ # @return [Boolean]
65
+ def eql?(other)
66
+ self.class == other.class && streams == other.streams
67
+ end
68
+ alias_method :==, :eql?
69
+
60
70
  # @return [NilClass|String]
61
71
  def name
62
72
  parent.name if parent
@@ -46,6 +46,7 @@ module Vedeu
46
46
  def add(child)
47
47
  parent.add(child)
48
48
  end
49
+ alias_method :<<, :add
49
50
 
50
51
  # Returns an array of characters, each element is the escape sequences of
51
52
  # colours and styles for this stream, the character itself, and the escape
@@ -52,7 +52,14 @@ module Vedeu
52
52
  #
53
53
  # @return [String]
54
54
  def decode64
55
- Base64.strict_decode64(data)
55
+ Base64.strict_decode64(unwrap)
56
+ end
57
+
58
+ # Removes '{{' and '}}' from the start and end of the data.
59
+ #
60
+ # @return [String]
61
+ def unwrap
62
+ data.gsub(/({{)|(}})/, '')
56
63
  end
57
64
 
58
65
  end # Decoder
@@ -22,7 +22,7 @@ module Vedeu
22
22
 
23
23
  # @return [String]
24
24
  def process
25
- encode64
25
+ wrap
26
26
  end
27
27
 
28
28
  protected
@@ -33,6 +33,13 @@ module Vedeu
33
33
 
34
34
  private
35
35
 
36
+ # Adds '{{' and '}}' to the start and end of the data.
37
+ #
38
+ # @return [String]
39
+ def wrap
40
+ "{{#{encode64}}}"
41
+ end
42
+
36
43
  # Encode the compressed, marshalled object or objects into a Base64
37
44
  # string.
38
45
  #
@@ -0,0 +1,33 @@
1
+ module Vedeu
2
+
3
+ module Templating
4
+
5
+ # Provide helpers to be used with your Vedeu templates.
6
+ #
7
+ module ViewHelpers
8
+
9
+ include Vedeu::Templating::Helpers
10
+
11
+ private
12
+
13
+ # @see Vedeu::Templating::Helpers#colour
14
+ def define_stream(attributes = {}, &block)
15
+ fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
16
+
17
+ encode(
18
+ Vedeu::Stream.build(colour: Vedeu::Colour.new(attributes),
19
+ style: Vedeu::Style.new(attributes[:style]),
20
+ value: block.call))
21
+ end
22
+
23
+ # @param data [String]
24
+ # @return [String]
25
+ def encode(data)
26
+ Vedeu::Templating::Encoder.process(data)
27
+ end
28
+
29
+ end # ViewHelpers
30
+
31
+ end # Templating
32
+
33
+ end # Vedeu
@@ -0,0 +1,69 @@
1
+ module Vedeu
2
+
3
+ module Templating
4
+
5
+ # Extend Template to provide client application view specific parsing.
6
+ #
7
+ class ViewTemplate < Template
8
+
9
+ include Vedeu::Common
10
+ include Vedeu::Templating::ViewHelpers
11
+
12
+ # @return [Vedeu::Lines]
13
+ def parse
14
+ lines_collection = Vedeu::Lines.new
15
+
16
+ lines.each do |line|
17
+ line_object = Vedeu::Line.new
18
+
19
+ streams_for(line).each do |stream|
20
+ next unless present?(stream)
21
+
22
+ line_object << if stream =~ /({{)|(}})/
23
+ Vedeu::Templating::Decoder.process(stream)
24
+
25
+ else
26
+ Vedeu::Stream.new(value: stream)
27
+
28
+ end
29
+ end
30
+
31
+ lines_collection << line_object
32
+ end
33
+
34
+ lines_collection
35
+ end
36
+
37
+ protected
38
+
39
+ # @!attribute [r] object
40
+ # @return [Class]
41
+ attr_reader :object
42
+
43
+ # @!attribute [r] options
44
+ # @return [Hash]
45
+ attr_reader :options
46
+
47
+ private
48
+
49
+ # @param line [String]
50
+ # @return [Array<String>]
51
+ def streams_for(line)
52
+ line.split(/({{.*}})/)
53
+ end
54
+
55
+ # @return [Array<String>]
56
+ def lines
57
+ content.lines.map(&:chomp)
58
+ end
59
+
60
+ # @return [String]
61
+ def content
62
+ ERB.new(load, nil, '-').result(binding)
63
+ end
64
+
65
+ end # ViewTemplate
66
+
67
+ end # Templating
68
+
69
+ end # Vedeu
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.64'
4
+ VERSION = '0.4.65'
5
5
 
6
6
  end
@@ -57,7 +57,7 @@ module Vedeu
57
57
  let(:filename) { 'my_interface.erb' }
58
58
 
59
59
  before do
60
- Vedeu::Templating::Template.expects(:parse).
60
+ Vedeu::Templating::ViewTemplate.expects(:parse).
61
61
  with(object, filename).returns(content)
62
62
  end
63
63
 
@@ -71,6 +71,8 @@ module Vedeu
71
71
  subject { instance.add(child) }
72
72
 
73
73
  it { instance.must_respond_to(:add) }
74
+
75
+ it { instance.must_respond_to(:<<) }
74
76
  end
75
77
 
76
78
  describe '#hide' do
@@ -58,6 +58,10 @@ module Vedeu
58
58
 
59
59
  describe '#add' do
60
60
  subject { instance.add(child) }
61
+
62
+ it { instance.must_respond_to(:add) }
63
+
64
+ it { instance.must_respond_to(:<<) }
61
65
  end
62
66
 
63
67
  describe '#chars' do
@@ -90,6 +94,20 @@ module Vedeu
90
94
  end
91
95
  end
92
96
 
97
+ describe '#eql?' do
98
+ let(:other) { instance }
99
+
100
+ subject { instance.eql?(other) }
101
+
102
+ it { subject.must_equal(true) }
103
+
104
+ context 'when different to other' do
105
+ let(:other) { described.new(streams: [:other]) }
106
+
107
+ it { subject.must_equal(false) }
108
+ end
109
+ end
110
+
93
111
  describe '#name' do
94
112
  subject { instance.name }
95
113
 
@@ -53,6 +53,8 @@ module Vedeu
53
53
  subject { instance.add(child) }
54
54
 
55
55
  it { subject.must_be_instance_of(Vedeu::Streams) }
56
+
57
+ it { instance.must_respond_to(:<<) }
56
58
  end
57
59
 
58
60
  describe '#chars' do
@@ -12,8 +12,8 @@ module Vedeu
12
12
  Vedeu::Colour.new(background: '#ff0000', foreground: '#00ff00')
13
13
  }
14
14
  let(:expected) {
15
- "eJxj4ci3EgpLTUkttbJyzs/JLy1itxJwSEpMzk4vyi/NS8m3EoPKOsHF2Kx4HJLBaj" \
16
- "2VeJTT0gyAgM2KzTUEqDMtvygVXacbXIzNmgOkxcAApInNmjMEAAMcJsQ="
15
+ "{{eJxj4ci3EgpLTUkttbJyzs/JLy1itxJwSEpMzk4vyi/NS8m3EoPKOsHF2Kx4HJLBaj" \
16
+ "2VeJTT0gyAgM2KzTUEqDMtvygVXacbXIzNmgOkxcAApInNmjMEAAMcJsQ=}}"
17
17
  }
18
18
 
19
19
  describe '#initialize' do
@@ -40,6 +40,10 @@ module Vedeu
40
40
  end
41
41
  end
42
42
 
43
+ describe '#parse' do
44
+ it { instance.must_respond_to(:parse) }
45
+ end
46
+
43
47
  end # Templating
44
48
 
45
49
  end # Template
@@ -0,0 +1,139 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Templating
6
+
7
+ class ViewHelpersTestClass
8
+
9
+ include Vedeu::Templating::ViewHelpers
10
+
11
+ end
12
+
13
+ describe ViewHelpers do
14
+
15
+ let(:described) { Vedeu::Templating::ViewHelpers }
16
+ let(:instance) { Vedeu::Templating::ViewHelpersTestClass.new }
17
+
18
+ describe '#background' do
19
+ let(:expected) {
20
+ "{{" \
21
+ "eJxdj00LwjAMhj1Ip7aKX3iW+Qd2zi5BUdhZ8d5tUYZzla4VxT9vrTrBXJI34UnetD" \
22
+ "sKxnvKyQJsjSZ5FjBEaYwuUmuofnDgWVlQZSJXqFJZ/QNWXgcOSGV2Omplq1zB7DNd" \
23
+ "Nj0GAt9sEopF5IMBW+8ceVCa/slN02OxSMIWi/s74BepvY1ebe4lKRg1tp1kwPEqS0" \
24
+ "tu7nMSTn+m5oZuxm/pVvJM35XO1fu1WGDg1PcCR38CRTzBPvTwxeDgCdSbXHg=" \
25
+ "}}"
26
+ }
27
+
28
+ subject { instance.background('#000000') { 'background text' } }
29
+
30
+ it { instance.must_respond_to(:bg) }
31
+
32
+ it { subject.must_equal(expected) }
33
+ end
34
+
35
+ describe '#colour' do
36
+ let(:attributes) { {} }
37
+
38
+ subject { instance.colour(attributes) { 'colour text' } }
39
+
40
+ context 'with no attributes' do
41
+ it { subject.must_be_instance_of(String) }
42
+ end
43
+
44
+ context 'with a background attribute' do
45
+ let(:attributes) {
46
+ {
47
+ background: '#002200'
48
+ }
49
+ }
50
+ let(:expected) {
51
+ "{{" \
52
+ "eJxdj08LwjAMxT1Ip7aKf8CzzC9QPGaXoCjsrHjvNMpwrlJbUfzy1k4neEpewu/l" \
53
+ "pdnSMNzSnhzA2hpSZwF9VNaaPHOWrk8OfFfkVFrpG11oZ37AIujIA5nanY5Gu3Kv" \
54
+ "YfzZzusZA4EVm8ZiKuVsJiUDttx48qAN/ZOresYSkcYNlnQ3wC/KhBidq30UpGFQ" \
55
+ "x/aSAcebKhz5fahp3K9OTizdbXBol+pMXzufqHorERh59XXnGOxRJCPsQgffDPZe" \
56
+ "Rsda7A==" \
57
+ "}}"
58
+ }
59
+
60
+ it { subject.must_equal(expected) }
61
+ end
62
+
63
+ context 'with a foreground attribute' do
64
+ let(:attributes) {
65
+ {
66
+ foreground: '#ff0000'
67
+ }
68
+ }
69
+ let(:expected) {
70
+ "{{" \
71
+ "eJxdj08LwjAMxT1I/dMqU8GzzC/gOb0ERWFnh/dOMxHnKrUVxS9v1+kEc2lewu/l" \
72
+ "td3VMN7RgRzA1hpSFwERKmvNKXOWbi8OfF+cqLQL3+hCO/MDVkF3PJCp/flotCsP" \
73
+ "Gqaf7bKZMRBYs0ncYsDWqUdybegf2TQzJkUSi3meL3wxOUiBX5UJMfo3+yxIw6iJ" \
74
+ "7SUDjndVOPL78CZxVJ+cWXrY4NAr1YWqBJXwiepvSYEdr77uHIM9CjnBAfSxYnD4" \
75
+ "BqMMW1Q=" \
76
+ "}}"
77
+ }
78
+
79
+ it { subject.must_equal(expected) }
80
+ end
81
+
82
+ context 'with both attributes' do
83
+ let(:attributes) {
84
+ {
85
+ background: '#000022',
86
+ foreground: '#ff7700',
87
+ }
88
+ }
89
+ let(:expected) {
90
+ "{{" \
91
+ "eJxdj0sLwjAQhD1IfCSKD/As+geKF2F7WRQFz4r3VLci1kZiIop/3jXVCuaSzCzf" \
92
+ "7KRaN9Db0p48wNpZ0mcFHdTO2WPiHV2fEuQuO1LuIn6YzHj7A+ZB1xhI9O50sMbn" \
93
+ "ewODz3RWegIUFuxqpMYRn8lEgFhsmEyNpX9yWXoiVm8kTafTKBJxawPyom1o07y6" \
94
+ "R0YGumV7lgIk3nTmiefhXo06xeaho7sLCY1cn9mvBMHFit/FCmusvukSQzyquI8t" \
95
+ "aOKbwfYLqERctQ==" \
96
+ "}}"
97
+ }
98
+
99
+ it { subject.must_equal(expected) }
100
+ end
101
+ end
102
+
103
+ describe '#foreground' do
104
+ let(:expected) {
105
+ "{{" \
106
+ "eJxdj08PATEQxR2ki3bFvzjL+gLOs5cJIdkzcS87ZKO2Uq0QX163WIm5dN5MfvNemy" \
107
+ "0Ngy3l5ADW1pA8C+ihtNYUO2fp+uTA96qg0s58o5V25gcsgo48sJP709FoV+Yaxp/t" \
108
+ "vJ4xEPhms6TBgC03HjloQ//Iqp6xVGSJmM5CsTTeAL9IE2J0rvahSEO/ju0lA443qR" \
109
+ "z5fXizZPRzmFi623ClXcozVSkq4VO9v5YKjLz6OnAMFijSIcbQwYrB7gsCxlyT" \
110
+ "}}"
111
+ }
112
+
113
+ subject { instance.foreground('#000000') { 'foreground text' } }
114
+
115
+ it { instance.must_respond_to(:fg) }
116
+
117
+ it { subject.must_equal(expected) }
118
+ end
119
+
120
+ describe '#style' do
121
+ let(:expected) {
122
+ "{{" \
123
+ "eJxdj08LwjAMxT1I59b6HzzLPoHn7BIUBc+K926LItZVaiuKX96u6gRveUl+7yXtjo" \
124
+ "bRjkpyABtrSJ4FDFBaa465s3R9cuCFOlJlZ77QSjvzAxZBRx7IZXE6GO2qUsPkM503" \
125
+ "PQYC3+w6bTFgy61H9trQP7JqeiwT9W7W3QK/SBPyk6t9KNIwbO71kgHHm1SOIM61Ki" \
126
+ "EJYp32w/LU0t0Gl7iSZ/pa+nPeP2UCI6++CRwDhSIbYxcSrBnsvQDMNVrp" \
127
+ "}}"
128
+ }
129
+
130
+ subject { instance.style(:bold) { 'style text' } }
131
+
132
+ it { subject.must_equal(expected) }
133
+ end
134
+
135
+ end # ViewHelpers
136
+
137
+ end # Templating
138
+
139
+ end # Vedeu
@@ -0,0 +1,129 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Templating
6
+
7
+ describe ViewTemplate do
8
+
9
+ let(:described) { Vedeu::Templating::ViewTemplate }
10
+ let(:instance) { described.new(object, path) }
11
+ let(:object) {}
12
+ let(:path) {}
13
+
14
+ describe '.parse' do
15
+ subject { described.parse(object, path) }
16
+
17
+ context 'with a plain text file' do
18
+ let(:path) { 'test/support/templates/plain.erb' }
19
+
20
+ let(:expected) {
21
+ Vedeu::Lines.new([
22
+ Vedeu::Line.new(streams: Vedeu::Stream.new(value: 'This is a test.'))
23
+ ])
24
+ }
25
+
26
+ it { subject.must_equal(expected) }
27
+ end
28
+
29
+ context 'with a plain text file with multiple lines' do
30
+ let(:path) { 'test/support/templates/multiple.erb' }
31
+
32
+ let(:expected) {
33
+ Vedeu::Lines.new([
34
+ Vedeu::Line.new(streams: Vedeu::Stream.new(value: 'This is a test.')),
35
+ Vedeu::Line.new(streams: Vedeu::Stream.new(value: 'And so is this.')),
36
+ ])
37
+ }
38
+
39
+ it { subject.must_equal(expected) }
40
+ end
41
+
42
+ context 'with a background colour directive' do
43
+ let(:path) { 'test/support/templates/background.erb' }
44
+ let(:colour) {
45
+ Vedeu::Colour.new(background: '#ff0000', foreground: '')
46
+ }
47
+
48
+ let(:expected) {
49
+ Vedeu::Lines.new([
50
+ Vedeu::Line.new(streams: [
51
+ Vedeu::Stream.new(value: 'This is a '),
52
+ Vedeu::Stream.new(value: 'test', colour: colour),
53
+ Vedeu::Stream.new(value: '.'),
54
+ ])
55
+ ])
56
+ }
57
+
58
+ it { subject.must_equal(expected) }
59
+ end
60
+
61
+ context 'with a foreground colour directive' do
62
+ let(:path) { 'test/support/templates/foreground.erb' }
63
+ let(:colour) {
64
+ Vedeu::Colour.new(background: '', foreground: '#00ff00')
65
+ }
66
+
67
+ let(:expected) {
68
+ Vedeu::Lines.new([
69
+ Vedeu::Line.new(streams: [
70
+ Vedeu::Stream.new(value: 'This is a '),
71
+ Vedeu::Stream.new(value: 'test', colour: colour),
72
+ Vedeu::Stream.new(value: '.'),
73
+ ])
74
+ ])
75
+ }
76
+
77
+ it { subject.must_equal(expected) }
78
+ end
79
+
80
+ context 'with a colour directive' do
81
+ let(:path) { 'test/support/templates/colour.erb' }
82
+
83
+ let(:colour) {
84
+ Vedeu::Colour.new(background: '#003300', foreground: '#aadd00')
85
+ }
86
+
87
+ let(:expected) {
88
+ Vedeu::Lines.new([
89
+ Vedeu::Line.new(streams: [
90
+ Vedeu::Stream.new(value: 'This is a '),
91
+ Vedeu::Stream.new(value: 'test', colour: colour),
92
+ Vedeu::Stream.new(value: '.'),
93
+ ])
94
+ ])
95
+ }
96
+
97
+ it { subject.must_equal(expected) }
98
+ end
99
+
100
+ context 'with a style directive' do
101
+ let(:path) { 'test/support/templates/style.erb' }
102
+
103
+ let(:style) {
104
+ Vedeu::Style.new(:bold)
105
+ }
106
+
107
+ let(:expected) {
108
+ Vedeu::Lines.new([
109
+ Vedeu::Line.new(streams: [
110
+ Vedeu::Stream.new(value: 'This is a '),
111
+ Vedeu::Stream.new(value: 'test', style: style),
112
+ Vedeu::Stream.new(value: '.'),
113
+ ])
114
+ ])
115
+ }
116
+
117
+ it { subject.must_equal(expected) }
118
+ end
119
+ end
120
+
121
+ describe '#parse' do
122
+ it { instance.must_respond_to(:parse) }
123
+ end
124
+
125
+ end # ViewTemplate
126
+
127
+ end # Templating
128
+
129
+ end # Vedeu
@@ -0,0 +1 @@
1
+ This is a <%= background('#ff0000') { 'test' } %>.
@@ -0,0 +1 @@
1
+ This is a <%= colour(background: '#003300', foreground: '#aadd00') { 'test' } %>.
@@ -0,0 +1 @@
1
+ This is a <%= foreground('#00ff00') { 'test' } %>.
@@ -0,0 +1,2 @@
1
+ This is a test.
2
+ And so is this.
@@ -0,0 +1 @@
1
+ This is a <%= style(:bold) { 'test' } %>.
data/vedeu.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_development_dependency 'guard', '2.12.9'
23
+ spec.add_development_dependency 'guard', '2.13.0'
24
24
  spec.add_development_dependency 'guard-minitest', '2.4.4'
25
25
  spec.add_development_dependency 'minitest', '5.7.0'
26
26
  spec.add_development_dependency 'minitest-reporters', '1.0.19'
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.64
4
+ version: 0.4.65
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-07-27 00:00:00.000000000 Z
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.12.9
19
+ version: 2.13.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.12.9
26
+ version: 2.13.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: guard-minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -439,11 +439,11 @@ files:
439
439
  - lib/vedeu/runtime/router.rb
440
440
  - lib/vedeu/templating/all.rb
441
441
  - lib/vedeu/templating/decoder.rb
442
- - lib/vedeu/templating/directive.rb
443
442
  - lib/vedeu/templating/encoder.rb
444
443
  - lib/vedeu/templating/helpers.rb
445
- - lib/vedeu/templating/post_processor.rb
446
444
  - lib/vedeu/templating/template.rb
445
+ - lib/vedeu/templating/view_helpers.rb
446
+ - lib/vedeu/templating/view_template.rb
447
447
  - lib/vedeu/terminal.rb
448
448
  - lib/vedeu/terminal_mode.rb
449
449
  - lib/vedeu/timer.rb
@@ -593,11 +593,11 @@ files:
593
593
  - test/lib/vedeu/runtime/main_loop_test.rb
594
594
  - test/lib/vedeu/runtime/router_test.rb
595
595
  - test/lib/vedeu/templating/decoder_test.rb
596
- - test/lib/vedeu/templating/directive_test.rb
597
596
  - test/lib/vedeu/templating/encoder_test.rb
598
597
  - test/lib/vedeu/templating/helpers_test.rb
599
- - test/lib/vedeu/templating/post_processor_test.rb
600
598
  - test/lib/vedeu/templating/template_test.rb
599
+ - test/lib/vedeu/templating/view_helpers_test.rb
600
+ - test/lib/vedeu/templating/view_template_test.rb
601
601
  - test/lib/vedeu/terminal_mode_test.rb
602
602
  - test/lib/vedeu/terminal_test.rb
603
603
  - test/lib/vedeu/timer_test.rb
@@ -607,8 +607,13 @@ files:
607
607
  - test/support/coverage.rb
608
608
  - test/support/helpers/model_test_class.rb
609
609
  - test/support/stats.sh
610
+ - test/support/templates/background.erb
611
+ - test/support/templates/colour.erb
612
+ - test/support/templates/foreground.erb
613
+ - test/support/templates/multiple.erb
610
614
  - test/support/templates/plain.erb
611
615
  - test/support/templates/simple_stuff.erb
616
+ - test/support/templates/style.erb
612
617
  - test/test_helper.rb
613
618
  - vedeu.gemspec
614
619
  homepage: https://github.com/gavinlaking/vedeu
@@ -780,11 +785,11 @@ test_files:
780
785
  - test/lib/vedeu/runtime/main_loop_test.rb
781
786
  - test/lib/vedeu/runtime/router_test.rb
782
787
  - test/lib/vedeu/templating/decoder_test.rb
783
- - test/lib/vedeu/templating/directive_test.rb
784
788
  - test/lib/vedeu/templating/encoder_test.rb
785
789
  - test/lib/vedeu/templating/helpers_test.rb
786
- - test/lib/vedeu/templating/post_processor_test.rb
787
790
  - test/lib/vedeu/templating/template_test.rb
791
+ - test/lib/vedeu/templating/view_helpers_test.rb
792
+ - test/lib/vedeu/templating/view_template_test.rb
788
793
  - test/lib/vedeu/terminal_mode_test.rb
789
794
  - test/lib/vedeu/terminal_test.rb
790
795
  - test/lib/vedeu/timer_test.rb
@@ -794,7 +799,12 @@ test_files:
794
799
  - test/support/coverage.rb
795
800
  - test/support/helpers/model_test_class.rb
796
801
  - test/support/stats.sh
802
+ - test/support/templates/background.erb
803
+ - test/support/templates/colour.erb
804
+ - test/support/templates/foreground.erb
805
+ - test/support/templates/multiple.erb
797
806
  - test/support/templates/plain.erb
798
807
  - test/support/templates/simple_stuff.erb
808
+ - test/support/templates/style.erb
799
809
  - test/test_helper.rb
800
810
  has_rdoc:
@@ -1,43 +0,0 @@
1
- module Vedeu
2
-
3
- module Templating
4
-
5
- # Converts a directive found in a template into a Vedeu::Stream object.
6
- #
7
- class Directive
8
-
9
- include Vedeu::Templating::Helpers
10
-
11
- # @param code [String]
12
- # @return [Vedeu::Stream]
13
- def self.process(code)
14
- new(code).process
15
- end
16
-
17
- # Returns a new instance of Vedeu::Templating::Directive.
18
- #
19
- # @param code [String]
20
- # @return [Vedeu::Templating::Directive]
21
- def initialize(code)
22
- @code = code
23
- end
24
-
25
- # Evaluate the code/text in the template; converting any recognised
26
- # directives as they are encountered.
27
- #
28
- # @return [Vedeu::Stream]
29
- def process
30
- eval(code, proc {}.binding)
31
- end
32
-
33
- protected
34
-
35
- # @!attribute [r] code
36
- # @return [String]
37
- attr_reader :code
38
-
39
- end # Directive
40
-
41
- end # Templating
42
-
43
- end # Vedeu
@@ -1,81 +0,0 @@
1
- module Vedeu
2
-
3
- module Templating
4
-
5
- # Pre-processes a template, to convert all lines and lines with directives
6
- # into Vedeu::Streams.
7
- #
8
- class PostProcessor
9
-
10
- # @param content [String]
11
- # @return [Array<Vedeu::Stream>]
12
- def self.process(content)
13
- new(content).process
14
- end
15
-
16
- # Returns a new instance of Vedeu::Templating::PostProcessor.
17
- #
18
- # @param content [String]
19
- # @return [Vedeu::Templating::PostProcessor]
20
- def initialize(content)
21
- @content = content
22
- end
23
-
24
- # @return [Vedeu::Streams]
25
- def process
26
- lines.each_with_object(Vedeu::Streams.new) do |line, acc|
27
- if line =~ markers?
28
- acc << Vedeu::Templating::Directive.process(unmark(line))
29
-
30
- else
31
- acc << Vedeu::Stream.new(value: line.chomp)
32
-
33
- end
34
- acc
35
- end
36
- end
37
-
38
- protected
39
-
40
- # @!attribute [r] content
41
- # @return [String]
42
- attr_reader :content
43
-
44
- private
45
-
46
- # @return [Array<String>]
47
- def lines
48
- content.lines
49
- end
50
-
51
- # Return a pattern to remove directive markers and spaces.
52
- #
53
- # @example
54
- # line containing {{ or }}
55
- #
56
- # @return [Regexp]
57
- def markers
58
- /({{\s*|\s*}})/
59
- end
60
-
61
- # @example
62
- # line contains {{ or }}
63
- #
64
- # @return [Regexp]
65
- def markers?
66
- /^\s*({{)(.*?)(}})$/
67
- end
68
-
69
- # Removes the markers and any line returns from the given line.
70
- #
71
- # @param line [String]
72
- # @return [String]
73
- def unmark(line)
74
- line.gsub(markers, '').chomp
75
- end
76
-
77
- end # PostProcessor
78
-
79
- end # Templating
80
-
81
- end # Vedeu
@@ -1,38 +0,0 @@
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
@@ -1,44 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- module Templating
6
-
7
- describe PostProcessor do
8
-
9
- let(:described) { Vedeu::Templating::PostProcessor }
10
- let(:instance) { described.new(content) }
11
- let(:content) {
12
- "Some text here\n" \
13
- "{{ colour(foreground: '#0f0') { 'Yay!' } }}\n" \
14
- "More text here\n"
15
- }
16
- let(:expected) {
17
- Vedeu::Streams.new([
18
- Vedeu::Stream.new(value: 'Some text here'),
19
- Vedeu::Stream.new(value: 'Yay!',
20
- colour: Vedeu::Colour.coerce(foreground: '#0f0')),
21
- Vedeu::Stream.new(value: 'More text here')
22
- ])
23
- }
24
-
25
- describe '#initialize' do
26
- it { instance.must_be_instance_of(described) }
27
- it { instance.instance_variable_get('@content').must_equal(content) }
28
- end
29
-
30
- describe '.process' do
31
- subject { described.process(content) }
32
-
33
- it { subject.must_equal(expected) }
34
- end
35
-
36
- describe '#process' do
37
- it { instance.must_respond_to(:process) }
38
- end
39
-
40
- end # PostProcessor
41
-
42
- end # Templating
43
-
44
- end # Vedeu