gitara 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.yardopts +5 -0
- data/CHANGELOG.markdown +5 -0
- data/README.markdown +135 -99
- data/examples/tab-with-repeats.ly +117 -0
- data/examples/tab-with-repeats.rb +19 -0
- data/gitara.gemspec +3 -0
- data/lib/gitara.rb +5 -3
- data/lib/gitara/dsl.rb +13 -0
- data/lib/gitara/node/alternative.rb +14 -0
- data/lib/gitara/node/bar.rb +3 -1
- data/lib/gitara/node/base.rb +22 -24
- data/lib/gitara/node/base/chorded_version.rb +1 -4
- data/lib/gitara/node/base/node_version.rb +35 -0
- data/lib/gitara/node/base/stanza_version.rb +1 -4
- data/lib/gitara/node/base/voiced_version.rb +5 -6
- data/lib/gitara/node/repeat.rb +10 -0
- data/lib/gitara/node/tab.rb +3 -5
- data/lib/gitara/utilities.rb +8 -0
- data/lib/gitara/version.rb +1 -1
- data/lib/gitara/voice.rb +2 -0
- data/spec/factories.rb +6 -0
- data/spec/lib/gitara/app_spec.rb +12 -28
- data/spec/lib/gitara/dsl_spec.rb +218 -173
- data/spec/lib/gitara/node/alternative_spec.rb +15 -0
- data/spec/lib/gitara/node/bar/chorded_version_spec.rb +2 -2
- data/spec/lib/gitara/node/bar/stanza_version_spec.rb +2 -2
- data/spec/lib/gitara/node/bar/voiced_version_spec.rb +2 -2
- data/spec/lib/gitara/node/bar_spec.rb +7 -7
- data/spec/lib/gitara/node/base/chorded_version_spec.rb +1 -1
- data/spec/lib/gitara/node/base/node_version_spec.rb +66 -0
- data/spec/lib/gitara/node/base/voiced_version_spec.rb +5 -5
- data/spec/lib/gitara/node/base_spec.rb +36 -42
- data/spec/lib/gitara/node/chord_set/chorded_version_spec.rb +2 -2
- data/spec/lib/gitara/node/chord_set_spec.rb +1 -1
- data/spec/lib/gitara/node/note_set_spec.rb +1 -1
- data/spec/lib/gitara/node/repeat_spec.rb +15 -0
- data/spec/lib/gitara/node/stanza_spec.rb +2 -2
- data/spec/lib/gitara/node/tab_spec.rb +6 -6
- data/spec/lib/gitara/voice_spec.rb +9 -9
- data/spec/lib/gitara_spec.rb +3 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/app_tester.rb +22 -0
- metadata +70 -29
- data/lib/gitara/is_node_version.rb +0 -23
- data/lib/gitara/pow/base.rb +0 -11
- data/spec/lib/gitara/is_node_version_spec.rb +0 -58
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitara::Node::Alternative do
|
4
|
+
describe "#call_value" do
|
5
|
+
it "should be a call to lilypond's alternative command" do
|
6
|
+
alternative = FactoryGirl.build(:alternative, :children => [
|
7
|
+
FactoryGirl.build(:bar, :name => 'First'),
|
8
|
+
FactoryGirl.build(:bar, :name => 'Second')
|
9
|
+
])
|
10
|
+
|
11
|
+
version = Node::Base::NodeVersion.new(:node => alternative)
|
12
|
+
alternative.call_value(version).should == "\\alternative { { \\nBarFirst } { \\nBarSecond } }"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe "value" do
|
3
|
+
describe Gitara::Node::Bar::ChordedVersion do
|
4
|
+
describe "#value" do
|
5
5
|
it "should be the call names of the chord sets in the bar, if available" do
|
6
6
|
bar = FactoryGirl.build(:bar, :children => [FactoryGirl.build(:chord_set, :name => :Am, :value => 'r-"Am"')])
|
7
7
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe "value" do
|
3
|
+
describe Gitara::Node::Bar::StanzaVersion do
|
4
|
+
describe "#value" do
|
5
5
|
it "should be the stanza heading of the bar" do
|
6
6
|
bar = FactoryGirl.build(:bar)
|
7
7
|
stanza = FactoryGirl.build(:stanza, :name => 'Intro', :children => [bar])
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe "matching_note_set" do
|
3
|
+
describe Gitara::Node::Bar::VoicedVersion do
|
4
|
+
describe "#matching_note_set" do
|
5
5
|
it "should be the note_set matching this voiced bar" do
|
6
6
|
note_set = FactoryGirl.build(:note_set)
|
7
7
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe "note_sets" do
|
3
|
+
describe Gitara::Node::Bar do
|
4
|
+
describe "#note_sets" do
|
5
5
|
it "should be the note sets of its definition" do
|
6
6
|
definition_bar = FactoryGirl.build(:bar, :name => 'Intro').tap {|bar|
|
7
7
|
bar.children = [
|
@@ -18,7 +18,7 @@ describe 'Bar' do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe "stanza_heading" do
|
21
|
+
describe "#stanza_heading" do
|
22
22
|
it "should be a whole rest with the stanza name if the bar is the first node of a stanza" do
|
23
23
|
bar = FactoryGirl.build(:bar)
|
24
24
|
stanza = FactoryGirl.build(:stanza, :name => 'Intro', :children => [bar])
|
@@ -32,7 +32,7 @@ describe 'Bar' do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe "with a special_duration" do
|
35
|
+
describe "#with a special_duration" do
|
36
36
|
subject { FactoryGirl.build(:bar, :specified_duration => 8) }
|
37
37
|
|
38
38
|
it "should be a partial with the stanza name if the bar is the first node of a stanza" do
|
@@ -46,7 +46,7 @@ describe 'Bar' do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
describe "first_bar_of_stanza?" do
|
49
|
+
describe "#first_bar_of_stanza?" do
|
50
50
|
it "should be true if the bar is the first bar of a stanza" do
|
51
51
|
bar = FactoryGirl.build(:bar)
|
52
52
|
stanza = FactoryGirl.build(:stanza, :name => 'Intro', :children => [bar])
|
@@ -66,7 +66,7 @@ describe 'Bar' do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
describe "specified_duration_as_lilypond" do
|
69
|
+
describe "#specified_duration_as_lilypond" do
|
70
70
|
it "should be \\partial specified_duration if present" do
|
71
71
|
bar = FactoryGirl.build(:bar, :specified_duration => 8)
|
72
72
|
bar.specified_duration_as_lilypond.should == '\partial 8'
|
@@ -78,7 +78,7 @@ describe 'Bar' do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
describe "duration" do
|
81
|
+
describe "#duration" do
|
82
82
|
it "should be 1 if there is no specified duration" do
|
83
83
|
FactoryGirl.build(:bar, :specified_duration => nil).duration.should == 1
|
84
84
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitara::Node::Base::NodeVersion do
|
4
|
+
describe "#prefix" do
|
5
|
+
it "should be by default the first letter of the class" do
|
6
|
+
version = Node::Base::NodeVersion.new
|
7
|
+
version.prefix.should == 'n'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#definition_name" do
|
12
|
+
it "should include the node's class and the node's name" do
|
13
|
+
version = Node::Base::NodeVersion.new(:node => FactoryGirl.build(:base, :name => 'some node'))
|
14
|
+
version.definition_name.should == 'nBaseSomeNode'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#call_name" do
|
19
|
+
it "should be the call version of the definition name" do
|
20
|
+
version = Node::Base::NodeVersion.new(:node => FactoryGirl.build(:base, :name => 'some node'))
|
21
|
+
version.call_name.should == '\nBaseSomeNode'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#value" do
|
26
|
+
it "should be the call values of its definition_children" do
|
27
|
+
node = FactoryGirl.build(:base, :children => [
|
28
|
+
FactoryGirl.build(:base, :name => :First),
|
29
|
+
FactoryGirl.build(:base, :name => :Second)
|
30
|
+
])
|
31
|
+
node_version = Node::Base::NodeVersion.new(:node => node)
|
32
|
+
node_version.value.should == '\nBaseFirst \nBaseSecond'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#definition_children" do
|
37
|
+
it "should be versionized versions of the node's definition_children" do
|
38
|
+
parent = FactoryGirl.build(:base, :name => 'parent')
|
39
|
+
child = FactoryGirl.build(:base, :name => 'child')
|
40
|
+
parent.add child
|
41
|
+
|
42
|
+
node_version = Node::Base::NodeVersion.new(:node => parent)
|
43
|
+
|
44
|
+
children = node_version.definition_children
|
45
|
+
children.should have(1).child
|
46
|
+
children[0].node.should == child
|
47
|
+
children[0].should be_a(Node::Base::NodeVersion)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#call_value" do
|
52
|
+
it "should be the call name if we want to render the node's definition name in the lilypond output" do
|
53
|
+
node = FactoryGirl.build(:base, :name => 'parent')
|
54
|
+
node_version = Node::Base::NodeVersion.new(:node => node)
|
55
|
+
node_version.call_value.should == '\nBaseParent'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be the call value of the node if we don't want to render the node's definition name in the lilypond output" do
|
59
|
+
node = FactoryGirl.build(:base, :name => 'name')
|
60
|
+
node_version = Node::Base::NodeVersion.new(:node => node)
|
61
|
+
node.should_receive(:call_value).with(node_version).and_return("todo { }")
|
62
|
+
node_version.call_value.should == "todo { }"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe "prefix" do
|
3
|
+
describe Gitara::Node::Base::VoicedVersion do
|
4
|
+
describe "#prefix" do
|
5
5
|
it "should be based on the voice's id" do
|
6
6
|
voiced_version = FactoryGirl.build(:voiced_version, :node => FactoryGirl.build(:base, :name => 'Intro'), :voice => FactoryGirl.build(:voice, :id => 1))
|
7
7
|
voiced_version.prefix.should == 'vOne'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
describe "
|
12
|
-
it "should be voiced versions of the node's
|
11
|
+
describe "#definition_children" do
|
12
|
+
it "should be voiced versions of the node's definition_children" do
|
13
13
|
parent = FactoryGirl.build(:base, :name => 'parent')
|
14
14
|
child = FactoryGirl.build(:base, :name => 'child')
|
15
15
|
parent.add child
|
@@ -18,7 +18,7 @@ describe 'VoicedVersion' do
|
|
18
18
|
|
19
19
|
voiced_version = FactoryGirl.build(:voiced_version, :node => parent, :voice => voice)
|
20
20
|
|
21
|
-
children = voiced_version.
|
21
|
+
children = voiced_version.definition_children
|
22
22
|
children.should have(1).voiced_version
|
23
23
|
children[0].node.should == child
|
24
24
|
children[0].voice.should == voice
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Node::Base do
|
4
|
-
describe "
|
3
|
+
describe Gitara::Node::Base do
|
4
|
+
describe "#definition_children" do
|
5
5
|
it "should be its own children if they exist" do
|
6
6
|
child = FactoryGirl.build(:base, :id => nil)
|
7
7
|
|
8
8
|
parent = FactoryGirl.build(:base)
|
9
9
|
parent.children = [child]
|
10
|
-
parent.
|
10
|
+
parent.definition_children.should == [child]
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should be the children of its definition if the node is not a definition" do
|
@@ -20,11 +20,11 @@ describe Node::Base do
|
|
20
20
|
|
21
21
|
tab = FactoryGirl.build(:tab, :children => [definition_bar, call_bar])
|
22
22
|
|
23
|
-
call_bar.
|
23
|
+
call_bar.definition_children.should == [child]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe "children=
|
27
|
+
describe "#children=" do
|
28
28
|
it "should set the ids and parents of the children" do
|
29
29
|
parent = FactoryGirl.build(:base)
|
30
30
|
parent.children = [FactoryGirl.build(:base, :id => nil)]
|
@@ -33,7 +33,7 @@ describe Node::Base do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe "add
|
36
|
+
describe "#add" do
|
37
37
|
it "should set the id and parent of the child" do
|
38
38
|
parent = FactoryGirl.build(:base)
|
39
39
|
|
@@ -63,7 +63,7 @@ describe Node::Base do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
describe "definition" do
|
66
|
+
describe "#definition" do
|
67
67
|
it "should be the definition node which matches this node's name" do
|
68
68
|
definition_bar = FactoryGirl.build(:bar, :name => 'Intro').tap {|bar|
|
69
69
|
bar.children = [
|
@@ -80,7 +80,7 @@ describe Node::Base do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
describe "definition?" do
|
83
|
+
describe "#definition?" do
|
84
84
|
it "should be true if this node has children" do
|
85
85
|
definition_bar = FactoryGirl.build(:bar, :name => 'Intro').tap {|bar|
|
86
86
|
bar.add FactoryGirl.build(:note_set)
|
@@ -91,26 +91,31 @@ describe Node::Base do
|
|
91
91
|
|
92
92
|
it "should be true if the node has a value" do
|
93
93
|
chord_set = FactoryGirl.build(:chord_set, :name => :Am, :value =>'r4-"Am" r r r')
|
94
|
-
chord_set.
|
94
|
+
chord_set.children.should be_empty
|
95
95
|
chord_set.should be_definition
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should be false if this node does not have children and it does not have a value" do
|
99
99
|
call_bar = FactoryGirl.build(:bar, :name => 'Intro', :children => [])
|
100
|
-
call_bar.
|
100
|
+
call_bar.children.should be_empty
|
101
101
|
call_bar.value.should be_nil
|
102
102
|
call_bar.should_not be_definition
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
describe "value" do
|
106
|
+
describe "#value" do
|
107
107
|
it "should convert slashes to backslashes" do
|
108
108
|
node = FactoryGirl.build(:base, :value => %q|notes "<g'/1>8 <a/3>8 <g'/1>8 <a/3>16 <g'/1>8 <g/3>16 <e'/1>4 <g/3>8"|)
|
109
109
|
node.value.should == %q|notes "<g'\1>8 <a\3>8 <g'\1>8 <a\3>16 <g'\1>8 <g\3>16 <e'\1>4 <g\3>8"|
|
110
110
|
end
|
111
|
+
|
112
|
+
it "should work with non-strings" do
|
113
|
+
node = FactoryGirl.build(:base, :value => 1)
|
114
|
+
node.value.should == 1
|
115
|
+
end
|
111
116
|
end
|
112
117
|
|
113
|
-
describe "voiced_as
|
118
|
+
describe "#voiced_as" do
|
114
119
|
it "should return the voiced version of the node, if arg is a voice" do
|
115
120
|
node = FactoryGirl.build(:base)
|
116
121
|
voice = FactoryGirl.build(:voice)
|
@@ -138,7 +143,7 @@ describe Node::Base do
|
|
138
143
|
end
|
139
144
|
end
|
140
145
|
|
141
|
-
describe "definitions
|
146
|
+
describe "#definitions" do
|
142
147
|
it "should be itself if it is an instance of the klass" do
|
143
148
|
node = FactoryGirl.build(:bar)
|
144
149
|
node.add FactoryGirl.build(:note_set)
|
@@ -157,26 +162,7 @@ describe Node::Base do
|
|
157
162
|
end
|
158
163
|
end
|
159
164
|
|
160
|
-
describe "
|
161
|
-
it "should be itself if it has no parent" do
|
162
|
-
node = FactoryGirl.build(:base)
|
163
|
-
node.root.should == node
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should be the ancentor of the node which has no parent of its own" do
|
167
|
-
note_set = FactoryGirl.build(:note_set)
|
168
|
-
|
169
|
-
bar = FactoryGirl.build(:bar)
|
170
|
-
bar.add note_set
|
171
|
-
|
172
|
-
root = FactoryGirl.build(:base)
|
173
|
-
root.add bar
|
174
|
-
|
175
|
-
note_set.root.should == root
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe "name" do
|
165
|
+
describe "#name" do
|
180
166
|
it "should be the given name, if available" do
|
181
167
|
FactoryGirl.build(:bar, :name => :Intro).name.should == :Intro
|
182
168
|
end
|
@@ -194,28 +180,28 @@ describe Node::Base do
|
|
194
180
|
end
|
195
181
|
end
|
196
182
|
|
197
|
-
describe "id" do
|
183
|
+
describe "#id" do
|
198
184
|
it "should be 1 by default" do
|
199
185
|
child = FactoryGirl.build(:note_set)
|
200
186
|
child.id.should == 1
|
201
187
|
end
|
202
188
|
end
|
203
189
|
|
204
|
-
describe "id_as_word" do
|
190
|
+
describe "#id_as_word" do
|
205
191
|
it "should camelize if necessary" do
|
206
192
|
node = FactoryGirl.build(:base, :id => 24)
|
207
193
|
node.id_as_word.should == "TwentyFour"
|
208
194
|
end
|
209
195
|
end
|
210
196
|
|
211
|
-
describe "definition_name" do
|
197
|
+
describe "#definition_name" do
|
212
198
|
it "should turn the name to a lilypond acceptable name" do
|
213
199
|
node = FactoryGirl.build(:base, :name => "Verse 1 line-2")
|
214
200
|
node.definition_name.should == "VerseOneLineTwo"
|
215
201
|
end
|
216
202
|
end
|
217
203
|
|
218
|
-
describe "descendants
|
204
|
+
describe "#descendants" do
|
219
205
|
it "should be itself if it is an instance of the klass" do
|
220
206
|
tab = FactoryGirl.build(:tab, :children => [FactoryGirl.build(:bar)])
|
221
207
|
tab.descendants(Node::Tab).should == [tab]
|
@@ -244,14 +230,14 @@ describe Node::Base do
|
|
244
230
|
])
|
245
231
|
])
|
246
232
|
|
247
|
-
bar = tab.
|
233
|
+
bar = tab.children[0]
|
248
234
|
|
249
|
-
stanza = tab.
|
235
|
+
stanza = tab.children[2]
|
250
236
|
stanza.descendants(Node::Bar).should == [bar]
|
251
237
|
end
|
252
238
|
end
|
253
239
|
|
254
|
-
describe "chorded" do
|
240
|
+
describe "#chorded" do
|
255
241
|
it "should return the chorded version of the node" do
|
256
242
|
node = FactoryGirl.build(:base)
|
257
243
|
chorded_version = node.chorded
|
@@ -260,7 +246,7 @@ describe Node::Base do
|
|
260
246
|
end
|
261
247
|
end
|
262
248
|
|
263
|
-
describe "stanza_version" do
|
249
|
+
describe "#stanza_version" do
|
264
250
|
it "should be a stanza version of the node" do
|
265
251
|
node = FactoryGirl.build(:base)
|
266
252
|
stanza_version = node.stanza_version
|
@@ -269,7 +255,7 @@ describe Node::Base do
|
|
269
255
|
end
|
270
256
|
end
|
271
257
|
|
272
|
-
describe "ancestor
|
258
|
+
describe "#ancestor" do
|
273
259
|
it "should be the first ancestor of the node matching the node class" do
|
274
260
|
bar = FactoryGirl.build(:bar)
|
275
261
|
line = FactoryGirl.build(:line, :name => 'Intro', :children => [bar])
|
@@ -283,4 +269,12 @@ describe Node::Base do
|
|
283
269
|
bar.ancestor(Node::Stanza).should be_nil
|
284
270
|
end
|
285
271
|
end
|
272
|
+
|
273
|
+
describe "#call_value" do
|
274
|
+
it "should be the call name by default" do
|
275
|
+
node = FactoryGirl.build(:base, :name => 'MyNode')
|
276
|
+
node_version = Node::Base::NodeVersion.new(:node => node)
|
277
|
+
node.call_value(node_version).should == '\nBaseMyNode'
|
278
|
+
end
|
279
|
+
end
|
286
280
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
describe "value" do
|
3
|
+
describe Gitara::Node::ChordSet::ChordedVersion do
|
4
|
+
describe "#value" do
|
5
5
|
it "should be the chord set's value" do
|
6
6
|
chorded_version = FactoryGirl.build(:chorded_chord_set, :node => FactoryGirl.build(:chord_set, :name => :Am, :value => '4r-"Am" r r r'))
|
7
7
|
chorded_version.value.should == '4r-"Am" r r r'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gitara::Node::Repeat do
|
4
|
+
describe "#call_value" do
|
5
|
+
it "should be a call to lilypond's repeat command" do
|
6
|
+
repeat = FactoryGirl.build(:repeat, :value => 2, :children => [
|
7
|
+
FactoryGirl.build(:bar)
|
8
|
+
])
|
9
|
+
|
10
|
+
version = Node::Base::NodeVersion.new(:node => repeat)
|
11
|
+
repeat.call_value(version).should == "\\repeat volta 2 { \\nBarRepeatOneBarOne }"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|