jsus 0.1.19 → 0.1.20
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/CHANGELOG +11 -0
- data/VERSION +1 -1
- data/bin/jsus +14 -44
- data/jsus.gemspec +8 -3
- data/lib/jsus.rb +2 -1
- data/lib/jsus/documenter.rb +96 -0
- data/lib/jsus/pool.rb +36 -0
- data/lib/jsus/tree.rb +118 -0
- data/markup/index_template.haml +19 -0
- data/spec/jsus/documenter_spec.rb +31 -0
- data/spec/jsus/pool_spec.rb +24 -0
- data/spec/jsus/tree_spec.rb +172 -0
- metadata +10 -5
- data/markup/index.haml +0 -10
- data/markup/packages_index.haml +0 -10
data/CHANGELOG
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
= Jsus Changelog
|
2
|
+
== Version 0.1.20
|
3
|
+
* Better integration for murdoc (factored it into class Jsus::Documenter)
|
4
|
+
* Tree structure for future reuse
|
5
|
+
|
6
|
+
== Versions 0.1.11 to 0.1.19
|
7
|
+
* Murloc Documentation experimental support (a bit dirty for now)
|
8
|
+
* Verbose mode for command-line, showing some missing dependencies and redeclared
|
9
|
+
provides
|
10
|
+
* Miscellanous changes and tweaks (was too lazy to write changelogs, sorry)
|
11
|
+
|
12
|
+
|
2
13
|
== Version 0.1.10
|
3
14
|
* Package.json files are now supported too (with the same format as yaml packages)
|
4
15
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.20
|
data/bin/jsus
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
|
-
|
3
|
+
begin
|
4
|
+
require 'jsus'
|
5
|
+
rescue LoadError
|
6
|
+
$: << "./lib"
|
7
|
+
require "jsus"
|
8
|
+
end
|
9
|
+
|
4
10
|
require "fileutils"
|
5
11
|
require 'choice'
|
6
12
|
start_time = Time.now
|
@@ -54,7 +60,8 @@ Choice.options do
|
|
54
60
|
option "docs_classes", :required => false do
|
55
61
|
default []
|
56
62
|
long "--generate-docs *CLASSES"
|
57
|
-
desc "Generate documentation for classes via murdoc, e.g.:
|
63
|
+
desc "Generate documentation for classes via murdoc. You need to use FULL PATHS, e.g.: " <<
|
64
|
+
"/mootools/*, /LSD/*, /**/*"
|
58
65
|
|
59
66
|
end
|
60
67
|
|
@@ -99,48 +106,11 @@ if Choice.choices[:generate_includes]
|
|
99
106
|
end
|
100
107
|
|
101
108
|
# Generate documentation
|
102
|
-
unless Choice.choices[:docs_classes].empty?
|
103
|
-
|
104
|
-
|
105
|
-
sources
|
106
|
-
Choice.choices[:docs_classes].
|
107
|
-
regex = Regexp.new("^" + expr.gsub("*", ".*") + "$", Regexp::IGNORECASE)
|
108
|
-
sources.each {|s| documented_sources << s if s.provides.any? {|provided| provided.to_s =~ regex } }
|
109
|
-
end
|
110
|
-
|
111
|
-
doc_dir = Choice.choices[:output_directory] + "/docs"
|
112
|
-
FileUtils.mkdir_p(doc_dir)
|
113
|
-
template = File.dirname(__FILE__) + "/../markup/template.haml"
|
114
|
-
sources_index = {}
|
115
|
-
documented_sources.each do |source|
|
116
|
-
skipped_lines = 0
|
117
|
-
content = source.original_content.gsub(/\A\s*\/\*.*?\*\//m) {|w| skipped_lines += w.split("\n").size; "" } # deleting initial comment
|
118
|
-
annotator = Murdoc::Annotator.new(content, :javascript, :highlight_source => true)
|
119
|
-
header = source.header
|
120
|
-
sources_index[source.package.name] ||= []
|
121
|
-
source_dir = "#{doc_dir}/#{source.package.name}"
|
122
|
-
FileUtils.mkdir_p(source_dir)
|
123
|
-
File.open("#{source_dir}/#{File.basename(source.filename)}.html", "w+") do |f|
|
124
|
-
sources_index[source.package.name] << File.basename(source.filename)
|
125
|
-
f.puts Murdoc::Formatter.new(template).render(:paragraphs => annotator.paragraphs, :header => header, :source => source, :skipped_lines => skipped_lines)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
FileUtils.cp(File.dirname(__FILE__) + "/../markup/stylesheet.css", doc_dir)
|
130
|
-
|
131
|
-
# building indices
|
132
|
-
sources_index.each do |pkg, sources_names|
|
133
|
-
source_dir = "#{doc_dir}/#{pkg}"
|
134
|
-
FileUtils.cp("#{doc_dir}/stylesheet.css", source_dir)
|
135
|
-
File.open("#{source_dir}/index.html", "w+") do |f|
|
136
|
-
f.puts Haml::Engine.new(File.read(File.dirname(__FILE__) + "/../markup/index.haml")).render(self, :package => pkg, :sources => sources_names)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# building main index of packages
|
141
|
-
File.open("#{doc_dir}/index.html", "w+") do |f|
|
142
|
-
f.puts Haml::Engine.new(File.read(File.dirname(__FILE__) + "/../markup/packages_index.haml")).render(self, :packages => sources_index.keys)
|
143
|
-
end
|
109
|
+
unless Choice.choices[:docs_classes].empty?
|
110
|
+
documenter = Jsus::Documenter.new
|
111
|
+
package.source_files.each {|source| documenter << source }
|
112
|
+
pool.sources.each {|source| documenter << source } if pool
|
113
|
+
documenter.only(Choice.choices[:docs_classes]).generate(Choice.choices[:output_directory] + "/docs")
|
144
114
|
end
|
145
115
|
|
146
116
|
|
data/jsus.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jsus}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.20"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mark Abramov"]
|
@@ -35,13 +35,14 @@ Gem::Specification.new do |s|
|
|
35
35
|
"jsus.gemspec",
|
36
36
|
"lib/jsus.rb",
|
37
37
|
"lib/jsus/container.rb",
|
38
|
+
"lib/jsus/documenter.rb",
|
38
39
|
"lib/jsus/package.rb",
|
39
40
|
"lib/jsus/packager.rb",
|
40
41
|
"lib/jsus/pool.rb",
|
41
42
|
"lib/jsus/source_file.rb",
|
42
43
|
"lib/jsus/tag.rb",
|
43
|
-
"
|
44
|
-
"markup/
|
44
|
+
"lib/jsus/tree.rb",
|
45
|
+
"markup/index_template.haml",
|
45
46
|
"markup/stylesheet.css",
|
46
47
|
"markup/template.haml",
|
47
48
|
"spec/data/Basic/README",
|
@@ -93,11 +94,13 @@ Gem::Specification.new do |s|
|
|
93
94
|
"spec/data/bad_test_source_two.js",
|
94
95
|
"spec/data/test_source_one.js",
|
95
96
|
"spec/jsus/container_spec.rb",
|
97
|
+
"spec/jsus/documenter_spec.rb",
|
96
98
|
"spec/jsus/package_spec.rb",
|
97
99
|
"spec/jsus/packager_spec.rb",
|
98
100
|
"spec/jsus/pool_spec.rb",
|
99
101
|
"spec/jsus/source_file_spec.rb",
|
100
102
|
"spec/jsus/tag_spec.rb",
|
103
|
+
"spec/jsus/tree_spec.rb",
|
101
104
|
"spec/shared/class_stubs.rb",
|
102
105
|
"spec/spec_helper.rb"
|
103
106
|
]
|
@@ -108,11 +111,13 @@ Gem::Specification.new do |s|
|
|
108
111
|
s.summary = %q{Javascript packager and dependency resolver}
|
109
112
|
s.test_files = [
|
110
113
|
"spec/jsus/container_spec.rb",
|
114
|
+
"spec/jsus/documenter_spec.rb",
|
111
115
|
"spec/jsus/package_spec.rb",
|
112
116
|
"spec/jsus/packager_spec.rb",
|
113
117
|
"spec/jsus/pool_spec.rb",
|
114
118
|
"spec/jsus/source_file_spec.rb",
|
115
119
|
"spec/jsus/tag_spec.rb",
|
120
|
+
"spec/jsus/tree_spec.rb",
|
116
121
|
"spec/shared/class_stubs.rb",
|
117
122
|
"spec/spec_helper.rb"
|
118
123
|
]
|
data/lib/jsus.rb
CHANGED
@@ -0,0 +1,96 @@
|
|
1
|
+
module Jsus
|
2
|
+
class Documenter
|
3
|
+
def initialize
|
4
|
+
require "murdoc"
|
5
|
+
rescue LoadError
|
6
|
+
raise "You should install murdoc gem in order to produce documentation"
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate(doc_dir = Dir.pwd)
|
10
|
+
#FileUtils.rm_rf(doc_dir)
|
11
|
+
FileUtils.mkdir_p(doc_dir)
|
12
|
+
template_path = File.dirname(__FILE__) + "/../../markup"
|
13
|
+
template = File.read("#{template_path}/template.haml")
|
14
|
+
index_template = File.read("#{template_path}/index_template.haml")
|
15
|
+
stylesheet_path = "#{template_path}/stylesheet.css"
|
16
|
+
documented_sources.traverse(true) do |node|
|
17
|
+
if node.value # leaf
|
18
|
+
dir = doc_dir + File.dirname(node.full_path)
|
19
|
+
FileUtils.mkdir_p(dir)
|
20
|
+
file_from_contents(dir + "/#{node.name}.html", create_documentation_for_source(node.value, template))
|
21
|
+
else
|
22
|
+
dir = doc_dir + node.full_path
|
23
|
+
FileUtils.mkdir_p(dir)
|
24
|
+
FileUtils.cp(stylesheet_path, dir)
|
25
|
+
file_from_contents(dir + "/index.html", create_index_for_node(node, index_template))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_documentation_for_source(source, template)
|
31
|
+
skipped_lines = 0
|
32
|
+
content = source.original_content.gsub(/\A\s*\/\*.*?\*\//m) {|w| skipped_lines += w.split("\n").size; "" }
|
33
|
+
annotator = Murdoc::Annotator.new(content, :javascript, :highlight_source => true)
|
34
|
+
Murdoc::Formatter.new(template).render(:paragraphs => annotator.paragraphs, :header => source.header, :source => source, :skipped_lines => skipped_lines)
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_index_for_node(node, template)
|
38
|
+
Haml::Engine.new(template).render(self, :node => node)
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(source)
|
42
|
+
filename = File.basename(source.filename)
|
43
|
+
if source.package
|
44
|
+
tree.insert("/#{source.package.name}/#{filename}", source)
|
45
|
+
else
|
46
|
+
tree.insert("/#{filename}", source)
|
47
|
+
end
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def tree
|
52
|
+
@tree ||= Tree.new
|
53
|
+
end
|
54
|
+
|
55
|
+
def current_scope
|
56
|
+
@current_scope ||= default_scope
|
57
|
+
end
|
58
|
+
|
59
|
+
def default_scope
|
60
|
+
["/**/*"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def current_scope=(scope)
|
64
|
+
@current_scope = scope
|
65
|
+
end
|
66
|
+
|
67
|
+
# exclusive scope
|
68
|
+
def only(scope)
|
69
|
+
result = clone
|
70
|
+
result.current_scope = [scope].flatten
|
71
|
+
result
|
72
|
+
end
|
73
|
+
|
74
|
+
# additive scope
|
75
|
+
def or(scope)
|
76
|
+
result = clone
|
77
|
+
result.current_scope = current_scope + [scope].flatten
|
78
|
+
result
|
79
|
+
end
|
80
|
+
|
81
|
+
def documented_sources
|
82
|
+
@documented_sources ||= documented_sources!
|
83
|
+
end
|
84
|
+
|
85
|
+
def documented_sources!
|
86
|
+
doctree = Tree.new
|
87
|
+
current_scope.map {|pathspec| tree.glob(pathspec) }.flatten.each {|s| doctree.insert(s.full_path, s.value)}
|
88
|
+
doctree
|
89
|
+
end
|
90
|
+
|
91
|
+
protected
|
92
|
+
def file_from_contents(filename, contents)
|
93
|
+
File.open(filename, "w+") {|f| f << contents }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/jsus/pool.rb
CHANGED
@@ -166,6 +166,42 @@ module Jsus
|
|
166
166
|
Container.new(*result)
|
167
167
|
end
|
168
168
|
|
169
|
+
#
|
170
|
+
# Returs a tree, containing all the sources
|
171
|
+
#
|
172
|
+
def source_tree
|
173
|
+
@source_tree ||= source_tree!
|
174
|
+
end
|
175
|
+
|
176
|
+
def source_tree! # :nodoc:
|
177
|
+
tree = Tree.new
|
178
|
+
sources.each do |source|
|
179
|
+
if source.package
|
180
|
+
tree.insert("/" + source.package.name + "/" + File.basename(source.filename), source)
|
181
|
+
else
|
182
|
+
tree.insert("/" + File.basename(source.filename), source)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
tree
|
186
|
+
end
|
187
|
+
|
188
|
+
#
|
189
|
+
# Returns a tree containing all the provides tags
|
190
|
+
#
|
191
|
+
def provides_tree
|
192
|
+
@provides_tree ||= provides_tree!
|
193
|
+
end
|
194
|
+
|
195
|
+
def provides_tree!
|
196
|
+
tree = Tree.new
|
197
|
+
sources.each do |source|
|
198
|
+
source.provides.each do |tag|
|
199
|
+
tree.insert("/" + tag.to_s, source)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
tree
|
203
|
+
end
|
204
|
+
|
169
205
|
protected
|
170
206
|
|
171
207
|
def provides_map # :nodoc:
|
data/lib/jsus/tree.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
module Jsus
|
2
|
+
class Tree
|
3
|
+
PATH_SEPARATOR = "/"
|
4
|
+
|
5
|
+
# Utility functions
|
6
|
+
def self.get_path_components(path)
|
7
|
+
raise "Path should start with root (got: #{path})" unless path && path[0,1] == PATH_SEPARATOR
|
8
|
+
path = path.dup
|
9
|
+
path[0,1] = ""
|
10
|
+
path.split(PATH_SEPARATOR)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.path_from_components(components)
|
14
|
+
"#{PATH_SEPARATOR}#{components.join(PATH_SEPARATOR)}"
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
class Node
|
19
|
+
attr_accessor :value
|
20
|
+
attr_accessor :parent
|
21
|
+
attr_accessor :path_components
|
22
|
+
|
23
|
+
def initialize(full_path, value = nil)
|
24
|
+
self.full_path = full_path
|
25
|
+
self.value = value
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader :full_path
|
29
|
+
attr_reader :name
|
30
|
+
def full_path=(full_path)
|
31
|
+
@full_path = full_path
|
32
|
+
@path_components = Tree.get_path_components(full_path)
|
33
|
+
@name = @path_components[-1]
|
34
|
+
end
|
35
|
+
|
36
|
+
def children
|
37
|
+
@children ||= []
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_child(name)
|
41
|
+
children.detect {|child| child.name == name }
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_child(name, value = nil)
|
45
|
+
full_path = Tree.path_from_components(path_components + [name])
|
46
|
+
node = Node.new(full_path, value)
|
47
|
+
children << node
|
48
|
+
node.parent = self
|
49
|
+
node
|
50
|
+
end
|
51
|
+
|
52
|
+
def find_or_create_child(name, value = nil)
|
53
|
+
find_child(name) || create_child(name, value)
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_children_matching(pathspec)
|
57
|
+
case pathspec
|
58
|
+
when "**"
|
59
|
+
[self] + children.select {|child| child.has_children? }
|
60
|
+
when /\*/
|
61
|
+
regexp = Regexp.new("^" + Regexp.escape(pathspec).gsub("\\*", ".*") + "$")
|
62
|
+
children.select {|child| !child.has_children? && child.name =~ regexp }
|
63
|
+
else
|
64
|
+
[find_child(pathspec)].compact
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def has_children?
|
69
|
+
!children.empty?
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def root
|
75
|
+
@root ||= Node.new("/", nil)
|
76
|
+
end
|
77
|
+
|
78
|
+
def [](path)
|
79
|
+
path_components = self.class.get_path_components(path)
|
80
|
+
path_components.inject(root) do |result, component|
|
81
|
+
if result
|
82
|
+
result.find_child(component)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def glob(pathspec)
|
88
|
+
self.class.get_path_components(pathspec).inject([root]) do |nodes, component|
|
89
|
+
nodes.map {|node| node.find_children_matching(component) }.flatten
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def insert(full_path, value = nil)
|
94
|
+
node = create_all_nodes_if_needed(full_path)
|
95
|
+
node.value = value
|
96
|
+
node
|
97
|
+
end
|
98
|
+
|
99
|
+
def traverse(all_nodes = false)
|
100
|
+
node_list = [root]
|
101
|
+
while !node_list.empty?
|
102
|
+
node = node_list.shift
|
103
|
+
yield node if all_nodes || !node.has_children?
|
104
|
+
node.children.each {|child| node_list << child }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
def create_all_nodes_if_needed(full_path)
|
111
|
+
self.class.get_path_components(full_path).inject(root) do |result, component|
|
112
|
+
result.find_or_create_child(component)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
%html
|
2
|
+
%head
|
3
|
+
%title Documentation index for #{node.full_path}
|
4
|
+
%link{:rel => "stylesheet", :href => "stylesheet.css"}
|
5
|
+
%body
|
6
|
+
- subdirectories = node.children.select {|s| s.has_children? }
|
7
|
+
- unless subdirectories.empty?
|
8
|
+
%h2 List of subdirectories for #{node.full_path}:
|
9
|
+
%ul
|
10
|
+
- subdirectories.each do |child|
|
11
|
+
%li
|
12
|
+
%a{:href => "#{child.name}/index.html"}= child.name
|
13
|
+
- files = node.children.select {|s| s.value }
|
14
|
+
- unless files.empty?
|
15
|
+
%h2 List of files for #{node.full_path}:
|
16
|
+
%ul
|
17
|
+
- files.each do |child|
|
18
|
+
%li
|
19
|
+
%a{:href => "#{child.name}.html"}= child.name
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Jsus::Documenter do
|
4
|
+
subject { described_class.new }
|
5
|
+
let(:input_dir) { "#{File.dirname(__FILE__)}/../data/Basic/app/javascripts/Orwik" }
|
6
|
+
let(:pool) { Jsus::Pool.new(input_dir) }
|
7
|
+
|
8
|
+
describe "<<" do
|
9
|
+
it "should add source files to tree" do
|
10
|
+
pool.sources.each {|s| subject << s}
|
11
|
+
subject.tree["/Orwik/Color.js"].value.should be_a(Jsus::SourceFile)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#documented_sources" do
|
16
|
+
before(:each) { pool.sources.each {|s| subject << s} }
|
17
|
+
it "should return all sources by default" do
|
18
|
+
subject.documented_sources.glob("/**/*").should have(4).elements
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should accept #only scope as exclusive scope" do
|
22
|
+
subject.only("/Orwik/Wid*").documented_sources.glob("/**/*").should have(1).element # /Orwik/Widget.js
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should accept #or scope as additive scope" do
|
26
|
+
# /Orwik/Widget.js, /Orwik/Input.js, /Orwik/Input.Color.js
|
27
|
+
subject.only("/Orwik/Wid*").or("/Orwik/Inp*").documented_sources.glob("/**/*").should have(3).elements
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/jsus/pool_spec.rb
CHANGED
@@ -126,4 +126,28 @@ describe Jsus::Pool do
|
|
126
126
|
subject.lookup_extensions(Jsus::Tag["Core/Class"]).should have_exactly(1).item
|
127
127
|
end
|
128
128
|
end
|
129
|
+
|
130
|
+
describe "#source_tree" do
|
131
|
+
let(:input_dir) { "spec/data/Extensions/app/javascripts" }
|
132
|
+
subject { Jsus::Pool.new(input_dir) }
|
133
|
+
|
134
|
+
it "should return a tree with all the source elements in it" do
|
135
|
+
subject.source_tree["/Core/Class.js"].value.should be_a(Jsus::SourceFile)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should not choke when sources got no referenced package" do
|
139
|
+
subject.send(:sources).each {|s| s.package = nil}
|
140
|
+
lambda { subject.source_tree }.should_not raise_error
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "#provides_tree" do
|
145
|
+
let(:input_dir) { "spec/data/Extensions/app/javascripts" }
|
146
|
+
subject { Jsus::Pool.new(input_dir) }
|
147
|
+
|
148
|
+
it "should return a tree with all the source elements in it" do
|
149
|
+
subject.provides_tree.glob("/Core/Class")[0].value.should be_a(Jsus::SourceFile)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
129
153
|
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Jsus::Tree::Node do
|
4
|
+
describe "#initialize" do
|
5
|
+
it "should accept full path" do
|
6
|
+
described_class.new("/path/node", nil).full_path.should == "/path/node"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should extract node name" do
|
10
|
+
described_class.new("/path/node", nil).name.should == "node"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set value" do
|
14
|
+
described_class.new("/path/node", 123).value.should == 123
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#children" do
|
19
|
+
subject { described_class.new("/") }
|
20
|
+
|
21
|
+
it "should be initialized with an empty array" do
|
22
|
+
subject.children.should == []
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#find_children_matching" do
|
27
|
+
subject { described_class.new('/') }
|
28
|
+
let(:nodes) { [] }
|
29
|
+
before(:each) do
|
30
|
+
# [0] /one 1
|
31
|
+
# [1] /two 2
|
32
|
+
# [2] /one/three 3
|
33
|
+
# [3] /one/four 4
|
34
|
+
nodes << subject.create_child('one', 1) << subject.create_child('two', 2)
|
35
|
+
nodes << nodes[0].create_child('three', 3) << nodes[0].create_child('four', 4)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "if it matches a child name, it should return that child" do
|
39
|
+
subject.find_children_matching("one").should == [nodes[0]]
|
40
|
+
end
|
41
|
+
|
42
|
+
it "if it is *, it should return children, not containing other children" do
|
43
|
+
subject.find_children_matching("*").should == [nodes[1]]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "if it is **, it should return self and children, containing other children" do
|
47
|
+
subject.find_children_matching("**").should == [subject, nodes[0]]
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should search for occurences with wildcards" do
|
51
|
+
nodes[0].find_children_matching("thr*").should == [nodes[2]]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe Jsus::Tree do
|
57
|
+
subject { Jsus::Tree.new }
|
58
|
+
|
59
|
+
describe "#root" do
|
60
|
+
it "should create node if needed" do
|
61
|
+
subject.root.should be_a(Jsus::Tree::Node)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not recreate node" do
|
65
|
+
subject.root.should == subject.root
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#insert" do
|
70
|
+
it "should create a node and assign value to it" do
|
71
|
+
subject.insert("/hello", "Value")
|
72
|
+
subject.root.children.should have_exactly(1).element
|
73
|
+
subject.root.children[0].value.should == "Value"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should create all underlying nodes if needed" do
|
77
|
+
subject.insert("/hello/world", "value")
|
78
|
+
subject.root.children[0].children[0].value.should == "value"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should replace value of existing node if it already exists" do
|
82
|
+
subject.insert("/hello/world", "value")
|
83
|
+
subject.insert("/hello", "other_value")
|
84
|
+
subject.root.children.should have_exactly(1).element
|
85
|
+
subject.root.children[0].value.should == "other_value"
|
86
|
+
subject.root.children[0].children.should have_exactly(1).element
|
87
|
+
subject.root.children[0].children[0].value.should == "value"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should not replace value of existing parent nodes" do
|
91
|
+
subject.insert("/hello", "value")
|
92
|
+
subject.insert("/hello/world", "other")
|
93
|
+
subject.root.children[0].value.should == "value"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should return a node" do
|
97
|
+
subject.insert("/hello/world", "value").value.should == "value"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#[]" do
|
102
|
+
it "should raise error unless path starts with root" do
|
103
|
+
lambda { subject["hello"] }.should raise_error
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should allow to get node by path" do
|
107
|
+
subject.insert("/hello/world", 123)
|
108
|
+
subject["/hello/world"].value.should == 123
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should return nil if node is not found" do
|
112
|
+
subject["/hello"].should be_nil
|
113
|
+
subject["/hello/world"].should be_nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "#glob" do
|
118
|
+
subject { Jsus::Tree.new }
|
119
|
+
let(:nodes) { [] }
|
120
|
+
before(:each) do
|
121
|
+
nodes << subject.insert("/hello/world/one", 1) <<
|
122
|
+
subject.insert("/hello/world/two", 2) <<
|
123
|
+
subject.insert("/hello/three", 3) <<
|
124
|
+
subject.insert("/hello/four", 4)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return the node if exact path is given" do
|
128
|
+
subject.glob("/hello/four").should == [nodes[3]]
|
129
|
+
end
|
130
|
+
|
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]]
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should search for children matching wildcards" do
|
136
|
+
subject.glob("/hello/thr*").should == [nodes[2]]
|
137
|
+
end
|
138
|
+
|
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
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should not choke when it cannot find anything" do
|
144
|
+
subject.glob("/ololo").should == []
|
145
|
+
subject.glob("/ololo/mwahaha").should == []
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "#traverse" do
|
150
|
+
subject { Jsus::Tree.new }
|
151
|
+
let(:nodes) { [] }
|
152
|
+
before(:each) do
|
153
|
+
nodes << subject.insert("/hello/world/one", 1) <<
|
154
|
+
subject.insert("/hello/world/two", 2) <<
|
155
|
+
subject.insert("/hello/three", 3) <<
|
156
|
+
subject.insert("/hello/four", 4)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should traverse only leaves by default" do
|
160
|
+
counter = 0
|
161
|
+
subject.traverse { counter += 1 }
|
162
|
+
counter.should == 4
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should traverse all nodes if given a true argument" do
|
166
|
+
counter = 0
|
167
|
+
subject.traverse(true) { counter += 1 }
|
168
|
+
counter.should == 7
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 20
|
9
|
+
version: 0.1.20
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mark Abramov
|
@@ -199,13 +199,14 @@ files:
|
|
199
199
|
- jsus.gemspec
|
200
200
|
- lib/jsus.rb
|
201
201
|
- lib/jsus/container.rb
|
202
|
+
- lib/jsus/documenter.rb
|
202
203
|
- lib/jsus/package.rb
|
203
204
|
- lib/jsus/packager.rb
|
204
205
|
- lib/jsus/pool.rb
|
205
206
|
- lib/jsus/source_file.rb
|
206
207
|
- lib/jsus/tag.rb
|
207
|
-
-
|
208
|
-
- markup/
|
208
|
+
- lib/jsus/tree.rb
|
209
|
+
- markup/index_template.haml
|
209
210
|
- markup/stylesheet.css
|
210
211
|
- markup/template.haml
|
211
212
|
- spec/data/Basic/README
|
@@ -257,11 +258,13 @@ files:
|
|
257
258
|
- spec/data/bad_test_source_two.js
|
258
259
|
- spec/data/test_source_one.js
|
259
260
|
- spec/jsus/container_spec.rb
|
261
|
+
- spec/jsus/documenter_spec.rb
|
260
262
|
- spec/jsus/package_spec.rb
|
261
263
|
- spec/jsus/packager_spec.rb
|
262
264
|
- spec/jsus/pool_spec.rb
|
263
265
|
- spec/jsus/source_file_spec.rb
|
264
266
|
- spec/jsus/tag_spec.rb
|
267
|
+
- spec/jsus/tree_spec.rb
|
265
268
|
- spec/shared/class_stubs.rb
|
266
269
|
- spec/spec_helper.rb
|
267
270
|
has_rdoc: true
|
@@ -278,7 +281,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
278
281
|
requirements:
|
279
282
|
- - ">="
|
280
283
|
- !ruby/object:Gem::Version
|
281
|
-
hash: -
|
284
|
+
hash: -1317162541712808956
|
282
285
|
segments:
|
283
286
|
- 0
|
284
287
|
version: "0"
|
@@ -299,10 +302,12 @@ specification_version: 3
|
|
299
302
|
summary: Javascript packager and dependency resolver
|
300
303
|
test_files:
|
301
304
|
- spec/jsus/container_spec.rb
|
305
|
+
- spec/jsus/documenter_spec.rb
|
302
306
|
- spec/jsus/package_spec.rb
|
303
307
|
- spec/jsus/packager_spec.rb
|
304
308
|
- spec/jsus/pool_spec.rb
|
305
309
|
- spec/jsus/source_file_spec.rb
|
306
310
|
- spec/jsus/tag_spec.rb
|
311
|
+
- spec/jsus/tree_spec.rb
|
307
312
|
- spec/shared/class_stubs.rb
|
308
313
|
- spec/spec_helper.rb
|
data/markup/index.haml
DELETED
data/markup/packages_index.haml
DELETED