jsus 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,14 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Jsus::Documenter do
3
+ describe Jsus::Util::Documenter do
4
4
  subject { described_class.new }
5
- let(:input_dir) { "#{File.dirname(__FILE__)}/../data/Basic/app/javascripts/Orwik" }
5
+ let(:input_dir) { "spec/data/Basic/app/javascripts/Orwik" }
6
6
  let(:pool) { Jsus::Pool.new(input_dir) }
7
7
 
8
8
  describe "<<" do
9
9
  it "should add source files to tree" do
10
10
  pool.sources.each {|s| subject << s}
11
- subject.tree["/Orwik/Color.js"].value.should be_a(Jsus::SourceFile)
11
+ subject.tree["/Orwik/Color.js"].should be_a(Jsus::SourceFile)
12
12
  end
13
13
  end
14
14
 
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Jsus::Tree::Node do
3
+ describe Jsus::Util::Tree::Node do
4
4
  describe "#initialize" do
5
5
  it "should accept full path" do
6
6
  described_class.new("/path/node", nil).full_path.should == "/path/node"
@@ -17,7 +17,7 @@ describe Jsus::Tree::Node do
17
17
 
18
18
  describe "#children" do
19
19
  subject { described_class.new("/") }
20
-
20
+
21
21
  it "should be initialized with an empty array" do
22
22
  subject.children.should == []
23
23
  end
@@ -38,7 +38,7 @@ describe Jsus::Tree::Node do
38
38
  it "if it matches a child name, it should return that child" do
39
39
  subject.find_children_matching("one").should == [nodes[0]]
40
40
  end
41
-
41
+
42
42
  it "if it is *, it should return children, not containing other children" do
43
43
  subject.find_children_matching("*").should == [nodes[1]]
44
44
  end
@@ -53,12 +53,12 @@ describe Jsus::Tree::Node do
53
53
  end
54
54
  end
55
55
 
56
- describe Jsus::Tree do
57
- subject { Jsus::Tree.new }
56
+ describe Jsus::Util::Tree do
57
+ subject { described_class.new }
58
58
 
59
59
  describe "#root" do
60
60
  it "should create node if needed" do
61
- subject.root.should be_a(Jsus::Tree::Node)
61
+ subject.root.should be_a(Jsus::Util::Tree::Node)
62
62
  end
63
63
 
64
64
  it "should not recreate node" do
@@ -72,7 +72,7 @@ describe Jsus::Tree do
72
72
  subject.root.children.should have_exactly(1).element
73
73
  subject.root.children[0].value.should == "Value"
74
74
  end
75
-
75
+
76
76
  it "should create all underlying nodes if needed" do
77
77
  subject.insert("/hello/world", "value")
78
78
  subject.root.children[0].children[0].value.should == "value"
@@ -96,26 +96,76 @@ describe Jsus::Tree do
96
96
  it "should return a node" do
97
97
  subject.insert("/hello/world", "value").value.should == "value"
98
98
  end
99
+
100
+ it "should prepend leading slash" do
101
+ subject.insert("hello", "world")
102
+ subject.root.children[0].full_path.should == "/hello"
103
+ subject.root.children[0].value.should == "world"
104
+ end
105
+
106
+ it "should allow tags for nodes insertion" do
107
+ subject.insert(Jsus::Tag["hello"], "world")
108
+ subject.root.children[0].full_path.should == "/hello"
109
+ subject.root.children[0].value.should == "world"
110
+ end
99
111
  end
100
112
 
101
- describe "#[]" do
102
- it "should raise error unless path starts with root" do
103
- lambda { subject["hello"] }.should raise_error
113
+ describe "#lookup" do
114
+ it "should return nil if node is not found" do
115
+ subject.lookup("/hello").should be_nil
116
+ subject.lookup("/hello/world").should be_nil
104
117
  end
105
118
 
106
119
  it "should allow to get node by path" do
107
- subject.insert("/hello/world", 123)
108
- subject["/hello/world"].value.should == 123
120
+ subject["/hello/world"] = 123
121
+ subject.lookup("/hello/world").value.should == 123
122
+ end
123
+
124
+ it "should prepend leading slash if needed" do
125
+ subject["/hello"] = "world"
126
+ subject.lookup("hello").should_not be_nil
127
+ end
128
+
129
+ it "should raise error for empty paths" do
130
+ lambda { subject.lookup("") }.should raise_error
131
+ lambda { subject.lookup(nil) }.should raise_error
109
132
  end
110
133
 
134
+ it "should allow tags for node lookup" do
135
+ subject["/Core/Moo"] = "Tools"
136
+ subject.lookup(Jsus::Tag["Core/Moo"]).value.should == "Tools"
137
+ end
138
+ end
139
+
140
+ describe "#[]" do
111
141
  it "should return nil if node is not found" do
112
142
  subject["/hello"].should be_nil
113
143
  subject["/hello/world"].should be_nil
114
144
  end
145
+
146
+ it "should allow to get node value by path" do
147
+ subject["/hello/world"] = 123
148
+ subject["/hello/world"].should == 123
149
+ end
150
+
151
+ it "should prepend leading slash to path if needed" do
152
+ subject["/hello"] = "world"
153
+ subject["hello"].should == "world"
154
+ end
155
+
156
+ it "should raise error for empty paths" do
157
+ lambda { subject[""] }.should raise_error
158
+ lambda { subject[nil] }.should raise_error
159
+ end
160
+
161
+ it "should allow tags for node lookup" do
162
+ subject["/Core/Moo"] = "Tools"
163
+ subject[Jsus::Tag["Core/Moo"]].should == "Tools"
164
+ end
115
165
  end
116
166
 
117
- describe "#glob" do
118
- subject { Jsus::Tree.new }
167
+ describe "#find_nodes_matching" do
168
+ subject { described_class.new }
119
169
  let(:nodes) { [] }
120
170
  before(:each) do
121
171
  nodes << subject.insert("/hello/world/one", 1) <<
@@ -125,19 +175,53 @@ describe Jsus::Tree do
125
175
  end
126
176
 
127
177
  it "should return the node if exact path is given" do
128
- subject.glob("/hello/four").should == [nodes[3]]
178
+ subject.find_nodes_matching("/hello/four").should == [nodes[3]]
129
179
  end
130
180
 
131
- it "should return all nodes in given node AND WITHOUT CHILDREN if path with wildcard is given" do
132
- subject.glob("/hello/*").should =~ [nodes[2], nodes[3]]
181
+ it "should return all matching children of given node excluding subtrees if path with wildcard is given" do
182
+ subject.find_nodes_matching("/hello/*").should =~ [nodes[2], nodes[3]]
133
183
  end
134
184
 
135
185
  it "should search for children matching wildcards" do
136
- subject.glob("/hello/thr*").should == [nodes[2]]
186
+ subject.find_nodes_matching("/hello/thr*").should == [nodes[2]]
137
187
  end
138
188
 
139
- it "should return all nodes in all subtrees and in the given subtree if double wildcard is given" do
140
- subject.glob("/hello/**/*").should =~ nodes
189
+ it "should return all nodes in all subtrees of the prefix subtree if double wildcard is given" do
190
+ subject.find_nodes_matching("/hello/world/**/*").should =~ [nodes[0], nodes[1]]
191
+ subject.find_nodes_matching("/hello/**/*").should =~ nodes
192
+ end
193
+
194
+ it "should not choke when it cannot find anything" do
195
+ subject.find_nodes_matching("/ololo").should == []
196
+ subject.find_nodes_matching("/ololo/mwahaha").should == []
197
+ end
198
+ end
199
+
200
+ describe "#glob" do
201
+ subject { described_class.new }
202
+ let(:nodes) { [] }
203
+ before(:each) do
204
+ nodes << subject.insert("/hello/world/one", 1) <<
205
+ subject.insert("/hello/world/two", 2) <<
206
+ subject.insert("/hello/three", 3) <<
207
+ subject.insert("/hello/four", 4)
208
+ end
209
+
210
+ it "should return the node value if exact path is given" do
211
+ subject.glob("/hello/four").should == [4]
212
+ end
213
+
214
+ it "should return all matching children of given node excluding subtrees if path with wildcard is given" do
215
+ subject.glob("/hello/*").should =~ [3, 4]
216
+ end
217
+
218
+ it "should search for children matching wildcards" do
219
+ subject.glob("/hello/thr*").should == [3]
220
+ end
221
+
222
+ it "should return all node values in all subtrees of the prefix subtree if double wildcard is given" do
223
+ subject.glob("/hello/world/**/*").should =~ [1, 2]
224
+ subject.glob("/hello/**/*").should =~ [1, 2, 3, 4]
141
225
  end
142
226
 
143
227
  it "should not choke when it cannot find anything" do
@@ -147,7 +231,7 @@ describe Jsus::Tree do
147
231
  end
148
232
 
149
233
  describe "#traverse" do
150
- subject { Jsus::Tree.new }
234
+ subject { described_class.new }
151
235
  let(:nodes) { [] }
152
236
  before(:each) do
153
237
  nodes << subject.insert("/hello/world/one", 1) <<
@@ -165,12 +249,12 @@ describe Jsus::Tree do
165
249
  it "should traverse all nodes if given a true argument" do
166
250
  counter = 0
167
251
  subject.traverse(true) { counter += 1 }
168
- counter.should == 7
252
+ counter.should == 7
169
253
  end
170
254
  end
171
255
 
172
256
  describe "#leaves" do
173
- subject { Jsus::Tree.new }
257
+ subject { described_class.new }
174
258
  let(:nodes) { [] }
175
259
  before(:each) do
176
260
  nodes << subject.insert("/hello/world/one", 1) <<
@@ -178,16 +262,16 @@ describe Jsus::Tree do
178
262
  subject.insert("/hello/three", nil) <<
179
263
  subject.insert("/hello/four", 4)
180
264
  end
181
-
265
+
182
266
  it "should return only the leaves with content by default" do
183
267
  subject.leaves.should =~ [nodes[0], nodes[1], nodes[3]]
184
268
  end
185
-
186
-
269
+
270
+
187
271
  it "should return all the leaves if asked" do
188
272
  subject.leaves(false).should =~ nodes
189
273
  end
190
-
274
+
191
275
  end
192
276
 
193
277
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Jsus::Validator::Base do
3
+ describe Jsus::Util::Validator::Base do
4
4
  subject { described_class.new(pool) }
5
5
  let(:input_dir) { "spec/data/ChainDependencies/app/javascripts" }
6
6
  let!(:pool) { Jsus::Pool.new(input_dir) }
@@ -8,11 +8,11 @@ describe Jsus::Validator::Base do
8
8
  it "should accept pool as the first argument" do
9
9
  described_class.new(pool).source_files.should =~ pool.sources.to_a
10
10
  end
11
-
11
+
12
12
  it "should accept container as the first argument" do
13
13
  described_class.new(pool.sources).source_files.should =~ pool.sources.to_a
14
- end
15
-
14
+ end
15
+
16
16
  it "should accept array as the first argument" do
17
17
  described_class.new(pool.sources.to_a).source_files.should =~ pool.sources.to_a
18
18
  end
@@ -21,7 +21,7 @@ describe Jsus::Validator::Base do
21
21
  it "should respond to #validate method" do
22
22
  subject.should respond_to(:validate)
23
23
  end
24
-
24
+
25
25
  describe ".validate" do
26
26
  it "should be the same as calling new + validate" do
27
27
  validator = mock
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Jsus::Validator::Mooforge do
3
+ describe Jsus::Util::Validator::Mooforge do
4
4
  describe "#validate" do
5
5
  let(:input_dir) { "spec/data/MooforgeValidation/app/javascripts/Orwik/Source/Library" }
6
6
  let!(:sources) {
@@ -11,20 +11,20 @@ describe Jsus::Validator::Mooforge do
11
11
  described_class.validate([sources[0]]).should be_true
12
12
  described_class.new([sources[0]]).validation_errors.should == []
13
13
  end
14
-
14
+
15
15
  it "should return false for files without authors" do
16
16
  described_class.validate([sources[1]]).should be_false
17
17
  described_class.new([sources[1]]).validation_errors[0].should include(sources[1].filename)
18
18
  end
19
-
19
+
20
20
  it "should return false for files without license" do
21
21
  described_class.validate([sources[2]]).should be_false
22
22
  described_class.new([sources[2]]).validation_errors[0].should include(sources[2].filename)
23
- end
24
-
23
+ end
24
+
25
25
  it "should return false when some of the files fail" do
26
26
  described_class.validate(sources).should be_false
27
- described_class.new(sources).validation_errors.size.should == 2
28
- end
27
+ described_class.new(sources).validation_errors.size.should == 2
28
+ end
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsus
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 5
10
- version: 0.2.5
9
+ - 6
10
+ version: 0.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mark Abramov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-04 00:00:00 -05:00
18
+ date: 2011-03-07 00:00:00 -05:00
19
19
  default_executable: jsus
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -233,16 +233,17 @@ files:
233
233
  - jsus.gemspec
234
234
  - lib/jsus.rb
235
235
  - lib/jsus/container.rb
236
- - lib/jsus/documenter.rb
237
236
  - lib/jsus/package.rb
238
237
  - lib/jsus/packager.rb
239
238
  - lib/jsus/pool.rb
240
239
  - lib/jsus/source_file.rb
241
240
  - lib/jsus/tag.rb
242
- - lib/jsus/tree.rb
243
- - lib/jsus/validator.rb
244
- - lib/jsus/validator/base.rb
245
- - lib/jsus/validator/mooforge.rb
241
+ - lib/jsus/util.rb
242
+ - lib/jsus/util/documenter.rb
243
+ - lib/jsus/util/tree.rb
244
+ - lib/jsus/util/validator.rb
245
+ - lib/jsus/util/validator/base.rb
246
+ - lib/jsus/util/validator/mooforge.rb
246
247
  - markup/index_template.haml
247
248
  - markup/stylesheet.css
248
249
  - markup/template.haml
@@ -311,15 +312,15 @@ files:
311
312
  - spec/data/bad_test_source_two.js
312
313
  - spec/data/test_source_one.js
313
314
  - spec/jsus/container_spec.rb
314
- - spec/jsus/documenter_spec.rb
315
315
  - spec/jsus/package_spec.rb
316
316
  - spec/jsus/packager_spec.rb
317
317
  - spec/jsus/pool_spec.rb
318
318
  - spec/jsus/source_file_spec.rb
319
319
  - spec/jsus/tag_spec.rb
320
- - spec/jsus/tree_spec.rb
321
- - spec/jsus/validator/base_spec.rb
322
- - spec/jsus/validator/mooforge_spec.rb
320
+ - spec/jsus/util/documenter_spec.rb
321
+ - spec/jsus/util/tree_spec.rb
322
+ - spec/jsus/util/validator/base_spec.rb
323
+ - spec/jsus/util/validator/mooforge_spec.rb
323
324
  - spec/shared/class_stubs.rb
324
325
  - spec/spec_helper.rb
325
326
  has_rdoc: true
@@ -358,14 +359,14 @@ specification_version: 3
358
359
  summary: Javascript packager and dependency resolver
359
360
  test_files:
360
361
  - spec/jsus/container_spec.rb
361
- - spec/jsus/documenter_spec.rb
362
362
  - spec/jsus/package_spec.rb
363
363
  - spec/jsus/packager_spec.rb
364
364
  - spec/jsus/pool_spec.rb
365
365
  - spec/jsus/source_file_spec.rb
366
366
  - spec/jsus/tag_spec.rb
367
- - spec/jsus/tree_spec.rb
368
- - spec/jsus/validator/base_spec.rb
369
- - spec/jsus/validator/mooforge_spec.rb
367
+ - spec/jsus/util/documenter_spec.rb
368
+ - spec/jsus/util/tree_spec.rb
369
+ - spec/jsus/util/validator/base_spec.rb
370
+ - spec/jsus/util/validator/mooforge_spec.rb
370
371
  - spec/shared/class_stubs.rb
371
372
  - spec/spec_helper.rb
@@ -1,99 +0,0 @@
1
- module Jsus
2
- class Documenter
3
- attr_accessor :options
4
-
5
- def initialize(options = {:highlight_source => true})
6
- require "murdoc"
7
- self.options = options
8
- rescue LoadError
9
- raise "You should install murdoc gem in order to produce documentation"
10
- end
11
-
12
- def generate(doc_dir = Dir.pwd)
13
- #FileUtils.rm_rf(doc_dir)
14
- FileUtils.mkdir_p(doc_dir)
15
- template_path = File.dirname(__FILE__) + "/../../markup"
16
- template = File.read("#{template_path}/template.haml")
17
- index_template = File.read("#{template_path}/index_template.haml")
18
- stylesheet_path = "#{template_path}/stylesheet.css"
19
- documented_sources.traverse(true) do |node|
20
- if node.value # leaf
21
- dir = doc_dir + File.dirname(node.full_path)
22
- FileUtils.mkdir_p(dir)
23
- file_from_contents(dir + "/#{node.name}.html", create_documentation_for_source(node.value, template))
24
- else
25
- dir = doc_dir + node.full_path
26
- FileUtils.mkdir_p(dir)
27
- FileUtils.cp(stylesheet_path, dir)
28
- file_from_contents(dir + "/index.html", create_index_for_node(node, index_template))
29
- end
30
- end
31
- end
32
-
33
- def create_documentation_for_source(source, template)
34
- skipped_lines = 0
35
- content = source.original_content.gsub(/\A\s*\/\*.*?\*\//m) {|w| skipped_lines += w.split("\n").size; "" }
36
- annotator = Murdoc::Annotator.new(content, :javascript, options)
37
- Murdoc::Formatter.new(template).render(:paragraphs => annotator.paragraphs, :header => source.header, :source => source, :skipped_lines => skipped_lines)
38
- end
39
-
40
- def create_index_for_node(node, template)
41
- Haml::Engine.new(template).render(self, :node => node)
42
- end
43
-
44
- def <<(source)
45
- filename = File.basename(source.filename)
46
- if source.package
47
- tree.insert("/#{source.package.name}/#{filename}", source)
48
- else
49
- tree.insert("/#{filename}", source)
50
- end
51
- self
52
- end
53
-
54
- def tree
55
- @tree ||= Tree.new
56
- end
57
-
58
- def current_scope
59
- @current_scope ||= default_scope
60
- end
61
-
62
- def default_scope
63
- ["/**/*"]
64
- end
65
-
66
- def current_scope=(scope)
67
- @current_scope = scope
68
- end
69
-
70
- # exclusive scope
71
- def only(scope)
72
- result = clone
73
- result.current_scope = [scope].flatten
74
- result
75
- end
76
-
77
- # additive scope
78
- def or(scope)
79
- result = clone
80
- result.current_scope = current_scope + [scope].flatten
81
- result
82
- end
83
-
84
- def documented_sources
85
- @documented_sources ||= documented_sources!
86
- end
87
-
88
- def documented_sources!
89
- doctree = Tree.new
90
- current_scope.map {|pathspec| tree.glob(pathspec) }.flatten.each {|s| doctree.insert(s.full_path, s.value)}
91
- doctree
92
- end
93
-
94
- protected
95
- def file_from_contents(filename, contents)
96
- File.open(filename, "w+") {|f| f << contents }
97
- end
98
- end
99
- end