jsus 0.2.5 → 0.2.6

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 CHANGED
@@ -1,4 +1,8 @@
1
1
  = Jsus Changelog
2
+ == Version 0.2.6
3
+ * Moved support classes to Jsus::Util module namespace
4
+ * Now using autoload instead of require's for stuff
5
+
2
6
  == Version 0.2.5
3
7
  * Fixed Container#sort not dealing with wildcards, which made it slower but
4
8
  at least made it work
@@ -17,7 +21,7 @@ See jsus-examples repo or features dir for more information.
17
21
  * Minor CLI reworkings:
18
22
  * Deprecated -i and -o options (use plain arguments now)
19
23
  * Restored generate-includes customizable root option
20
-
24
+
21
25
  == Version 0.2.2
22
26
  * Fixed dupes in structure json files
23
27
 
@@ -66,7 +70,7 @@ See jsus-examples repo or features dir for more information.
66
70
  First robust solution handles this via Pool and eager dependency load.
67
71
 
68
72
  == Version 0.1.5
69
- * Introduced new concept, Tag, which is going to be used instead of
73
+ * Introduced new concept, Tag, which is going to be used instead of
70
74
  provides/requires strings
71
75
  * Introduced source extensions (monkey-patching, actually)
72
76
  * Wrote some basic documentation for the classes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
data/bin/jsus CHANGED
@@ -1,10 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
3
 
4
- if File.exists?('./lib/jsus.rb') # override with local version of jsus
5
- $:.unshift File.expand_path(Dir.pwd) + "/lib"
6
- elsif File.exists?(File.expand_path(File.dirname(__FILE__)) + "/../lib/jsus.rb")
7
- $:.unshift File.expand_path(File.dirname(__FILE__)) + "/../lib"
4
+ require 'pathname'
5
+ begin
6
+ gem_home = Pathname.new(ENV["GEM_HOME"]).realpath.to_s
7
+ current_dir = File.dirname(Pathname.new(__FILE__).realpath.to_s)
8
+ if current_dir.index(gem_home) != 0 && File.exists?(current_dir + '/../lib/jsus.rb')
9
+ # If we are outside gem home,
10
+ # override whatever they got there
11
+ # with local version of jsus
12
+ $:.unshift File.expand_path(current_dir + "/../lib")
13
+ end
14
+ rescue Exception => e
15
+ # Something weird happened during our checks,
16
+ # but it's probably nothing.
8
17
  end
9
18
  require 'jsus'
10
19
 
@@ -129,7 +138,7 @@ package.generate_scripts_info(output_dir) unless options[:without_scripts_info]
129
138
  package.generate_tree(output_dir) unless options[:without_tree_info]
130
139
 
131
140
  # Validations
132
- validators_map = {"mooforge" => Jsus::Validator::Mooforge}
141
+ validators_map = {"mooforge" => Jsus::Util::Validator::Mooforge}
133
142
  (options[:validators] || []).each do |validator_name|
134
143
  if validator = validators_map[validator_name]
135
144
  errors = validator.new(pool.sources.to_a & package.source_files.to_a).validation_errors
@@ -164,7 +173,7 @@ end
164
173
  docs_start_time = Time.now
165
174
  # Generate documentation
166
175
  if options[:documented_classes] && !options[:documented_classes].empty?
167
- documenter = Jsus::Documenter.new(:highlight_source => !options[:no_syntax_highlight])
176
+ documenter = Jsus::Util::Documenter.new(:highlight_source => !options[:no_syntax_highlight])
168
177
  package.source_files.each {|source| documenter << source }
169
178
  pool.sources.each {|source| documenter << source } if pool
170
179
  documenter.only(options[:documented_classes]).generate(output_dir + "/docs")
data/jsus.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jsus}
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
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"]
12
- s.date = %q{2011-03-04}
12
+ s.date = %q{2011-03-07}
13
13
  s.default_executable = %q{jsus}
14
14
  s.description = %q{Javascript packager and dependency resolver}
15
15
  s.email = %q{markizko@gmail.com}
@@ -84,16 +84,17 @@ Gem::Specification.new do |s|
84
84
  "jsus.gemspec",
85
85
  "lib/jsus.rb",
86
86
  "lib/jsus/container.rb",
87
- "lib/jsus/documenter.rb",
88
87
  "lib/jsus/package.rb",
89
88
  "lib/jsus/packager.rb",
90
89
  "lib/jsus/pool.rb",
91
90
  "lib/jsus/source_file.rb",
92
91
  "lib/jsus/tag.rb",
93
- "lib/jsus/tree.rb",
94
- "lib/jsus/validator.rb",
95
- "lib/jsus/validator/base.rb",
96
- "lib/jsus/validator/mooforge.rb",
92
+ "lib/jsus/util.rb",
93
+ "lib/jsus/util/documenter.rb",
94
+ "lib/jsus/util/tree.rb",
95
+ "lib/jsus/util/validator.rb",
96
+ "lib/jsus/util/validator/base.rb",
97
+ "lib/jsus/util/validator/mooforge.rb",
97
98
  "markup/index_template.haml",
98
99
  "markup/stylesheet.css",
99
100
  "markup/template.haml",
@@ -162,15 +163,15 @@ Gem::Specification.new do |s|
162
163
  "spec/data/bad_test_source_two.js",
163
164
  "spec/data/test_source_one.js",
164
165
  "spec/jsus/container_spec.rb",
165
- "spec/jsus/documenter_spec.rb",
166
166
  "spec/jsus/package_spec.rb",
167
167
  "spec/jsus/packager_spec.rb",
168
168
  "spec/jsus/pool_spec.rb",
169
169
  "spec/jsus/source_file_spec.rb",
170
170
  "spec/jsus/tag_spec.rb",
171
- "spec/jsus/tree_spec.rb",
172
- "spec/jsus/validator/base_spec.rb",
173
- "spec/jsus/validator/mooforge_spec.rb",
171
+ "spec/jsus/util/documenter_spec.rb",
172
+ "spec/jsus/util/tree_spec.rb",
173
+ "spec/jsus/util/validator/base_spec.rb",
174
+ "spec/jsus/util/validator/mooforge_spec.rb",
174
175
  "spec/shared/class_stubs.rb",
175
176
  "spec/spec_helper.rb"
176
177
  ]
@@ -181,15 +182,15 @@ Gem::Specification.new do |s|
181
182
  s.summary = %q{Javascript packager and dependency resolver}
182
183
  s.test_files = [
183
184
  "spec/jsus/container_spec.rb",
184
- "spec/jsus/documenter_spec.rb",
185
185
  "spec/jsus/package_spec.rb",
186
186
  "spec/jsus/packager_spec.rb",
187
187
  "spec/jsus/pool_spec.rb",
188
188
  "spec/jsus/source_file_spec.rb",
189
189
  "spec/jsus/tag_spec.rb",
190
- "spec/jsus/tree_spec.rb",
191
- "spec/jsus/validator/base_spec.rb",
192
- "spec/jsus/validator/mooforge_spec.rb",
190
+ "spec/jsus/util/documenter_spec.rb",
191
+ "spec/jsus/util/tree_spec.rb",
192
+ "spec/jsus/util/validator/base_spec.rb",
193
+ "spec/jsus/util/validator/mooforge_spec.rb",
193
194
  "spec/shared/class_stubs.rb",
194
195
  "spec/spec_helper.rb"
195
196
  ]
data/lib/jsus.rb CHANGED
@@ -10,32 +10,32 @@ require 'rgl/topsort'
10
10
  require 'fileutils'
11
11
  require 'pathname'
12
12
 
13
- require 'jsus/source_file'
14
- require 'jsus/package'
15
- require 'jsus/tag'
16
- require 'jsus/container'
17
- require 'jsus/packager'
18
- require 'jsus/pool'
19
- require 'jsus/tree'
20
- require 'jsus/documenter'
21
- require 'jsus/validator'
22
13
  #
23
- # Jsus a library for packaging up your source files.
14
+ # Jsus -- a library for packaging up your source files.
24
15
  #
25
16
  # For better understanding of jsus ideas start with http://github.com/Markiz/jsus-examples
26
17
  #
27
18
  #
28
-
29
-
30
19
  module Jsus
20
+ autoload :SourceFile, 'jsus/source_file'
21
+ autoload :Package, 'jsus/package'
22
+ autoload :Tag, 'jsus/tag'
23
+ autoload :Container, 'jsus/container'
24
+ autoload :Packager, 'jsus/packager'
25
+ autoload :Pool, 'jsus/pool'
26
+ autoload :Util, 'jsus/util'
27
+ # Returns whether or not jsus is in verbose mode
31
28
  def self.verbose?
32
29
  !!@verbose
33
30
  end
34
31
 
32
+ # Sets verbose mode to on. In verbose mode jsus shows a lot of warnings
33
+ # like missing dependencies.
35
34
  def self.verbose=(verbose)
36
35
  @verbose = verbose
37
36
  end
38
-
37
+
38
+ # Returns current version
39
39
  def self.version
40
40
  @version ||= File.read(File.dirname(__FILE__) + "/../VERSION")
41
41
  end
@@ -1,9 +1,9 @@
1
- #
2
- # Container is an array which contains source files. Main difference
3
- # between it and array is the fact that container maintains topological
4
- # sort for the source files.
5
- #
6
1
  module Jsus
2
+ #
3
+ # Container is an array that contains source files. Main difference
4
+ # from an array is the fact that container maintains topological
5
+ # sort for the source files.
6
+ #
7
7
  class Container
8
8
  #
9
9
  # Every argument for initializer is pushed into the container.
@@ -35,7 +35,9 @@ module Jsus
35
35
  map {|item| item.respond_to?(:flatten) ? item.flatten : item }.flatten
36
36
  end
37
37
 
38
- # Contains the source files in the correct order.
38
+ # Contains the source files. Please, don't use sources directly, if you
39
+ # depend on them to be topologically sorted. Use collection methods like
40
+ # inject/reject/map directly on the container instead.
39
41
  def sources
40
42
  @sources ||= []
41
43
  end
@@ -86,8 +88,11 @@ module Jsus
86
88
  # init edges
87
89
  items.each do |item|
88
90
  item.dependencies.each do |dependency|
89
- cache[dependency] ||= provides_tree.glob("/" + dependency.to_s).map {|node| node.value }
90
- cache[dependency].each do |required_item|
91
+ # If we can find items that provide the required dependency...
92
+ # (dependency could be a wildcard as well, hence items)
93
+ dependency_cache[dependency] ||= provides_tree.glob(dependency)
94
+ # ... we draw an edge from every required item to the dependant item
95
+ dependency_cache[dependency].each do |required_item|
91
96
  graph.add_edge(required_item, item)
92
97
  end
93
98
  end
@@ -97,50 +102,47 @@ module Jsus
97
102
  result
98
103
  end
99
104
 
100
- def cache # :nodoc:
101
- @cache ||= {}
105
+ def dependency_cache # :nodoc:
106
+ @dependency_cache ||= {}
102
107
  end
103
108
 
104
109
  def provides_tree # :nodoc:
105
110
  @provides_tree ||= provides_tree!
106
111
  end
107
112
 
113
+ # Provides tree contains
108
114
  def provides_tree! # :nodoc:
109
- tree = Tree.new
115
+ tree = Util::Tree.new
110
116
  # Provisions
111
117
  sources.each do |file|
112
118
  file.provides.each do |tag|
113
- tree["/#{tag}"] = file
119
+ tree[tag] = file
114
120
  end
115
121
  end
116
122
  # Replacements
117
123
  sources.each do |file|
118
124
  if file.replaces
119
- tree["/#{file.replaces}"] = file
125
+ tree[file.replaces] = file
120
126
  end
121
127
  end
122
128
  tree
123
129
  end
124
130
 
125
- def remove_replaced_files!
131
+ def remove_replaced_files! # :nodoc:
126
132
  sources.reject! do |sf|
127
- !sf.provides.empty? && sf.provides.any? { |tag|
128
- replacements_tree["/#{tag}"] &&
129
- replacements_tree["/#{tag}"].value &&
130
- replacements_tree["/#{tag}"].value != sf
131
- }
133
+ !sf.provides.empty? && sf.provides.any? { |tag| replacements_tree[tag] && replacements_tree[tag] != sf }
132
134
  end
133
135
  end
134
136
 
135
- def replacements_tree
137
+ def replacements_tree # :nodoc:
136
138
  @replacements_tree ||= replacements_tree!
137
139
  end
138
140
 
139
- def replacements_tree!
140
- tree = Tree.new
141
+ def replacements_tree! # :nodoc:
142
+ tree = Util::Tree.new
141
143
  sources.each do |file|
142
144
  if file.replaces
143
- tree["/#{file.replaces}"] = file
145
+ tree[file.replaces] = file
144
146
  end
145
147
  end
146
148
  tree
@@ -149,19 +151,20 @@ module Jsus
149
151
  def clear_cache! # :nodoc:
150
152
  @provides_tree = nil
151
153
  @replacements_tree = nil
152
- @cache = nil
153
- @sorted = nil
154
+ @dependency_cache = nil
155
+ @sorted = false
154
156
  end
155
157
 
156
158
 
157
159
  CACHE_CLEAR_METHODS = [
158
- "map!", "reject!", "inject!"
160
+ "map!", "reject!", "inject!", "collect!", "delete", "delete_at"
159
161
  ] # :nodoc:
160
162
 
161
163
  DELEGATED_METHODS = [
162
164
  "==", "to_a", "map", "map!", "each", "inject", "inject!",
163
- "reject", "reject!", "detect", "size", "length", "[]",
164
- "empty?", "index", "include?", "select", "-", "+", "|", "&"
165
+ "collect", "collect!", "reject", "reject!", "detect", "size",
166
+ "length", "[]", "empty?", "index", "include?", "select",
167
+ "delete_if", "delete", "-", "+", "|", "&"
165
168
  ] # :nodoc:
166
169
  # delegates most Enumerable methods to #sources
167
170
  (DELEGATED_METHODS).each do |m|
data/lib/jsus/package.rb CHANGED
@@ -1,9 +1,8 @@
1
- #
2
- # Package is basically a list of source files with some meta info.
3
- #
4
-
5
-
6
1
  module Jsus
2
+ #
3
+ # Package is a (self-contained) unit with all the info required to build
4
+ # a javascript package.
5
+ #
7
6
  class Package
8
7
  attr_accessor :directory # directory which this package resides in (full path)
9
8
  attr_accessor :pool # an instance of Pool
@@ -13,7 +12,7 @@ module Jsus
13
12
  # Creates a package from given directory.
14
13
  #
15
14
  # Accepts options:
16
- # * +:pool:+ which pool the package should belong to.
15
+ # * +:pool:+ -- which pool the package should belong to.
17
16
  #
18
17
  # Raises an error when the given directory doesn't contain a package.yml or package.json
19
18
  # file with meta info.
data/lib/jsus/packager.rb CHANGED
@@ -1,10 +1,10 @@
1
- #
2
- # Packager is a plain simple class accepting several source files
3
- # and joining their contents.
4
- #
5
- # It uses Container for storage which means it automatically sorts sources.
6
- #
7
1
  module Jsus
2
+ #
3
+ # Packager is a plain simple class accepting several source files
4
+ # and joining their contents.
5
+ #
6
+ # It uses Container for storage which means it automatically sorts sources.
7
+ #
8
8
  class Packager
9
9
  attr_accessor :container # :nodoc:
10
10
 
data/lib/jsus/pool.rb CHANGED
@@ -1,13 +1,10 @@
1
- #
2
- # Pool class is designed for three purposes:
3
- # * Maintain connections between SourceFiles and/or Packages
4
- # * Resolve dependencies
5
- # * Look up extensions
6
- #
7
- #
8
-
9
-
10
1
  module Jsus
2
+ #
3
+ # Pool class is designed for three purposes:
4
+ # * Maintain connections between SourceFiles and/or Packages
5
+ # * Resolve dependencies
6
+ # * Look up extensions
7
+ #
11
8
  class Pool
12
9
 
13
10
  # Constructors
@@ -160,7 +157,7 @@ module Jsus
160
157
  return [] unless source
161
158
 
162
159
  source.dependencies.map do |dependency|
163
- result = provides_tree.glob("/#{dependency}").map {|node| node.value }
160
+ result = provides_tree.glob("/#{dependency}")
164
161
  if (!result || (result.is_a?(Array) && result.empty?)) && Jsus.verbose?
165
162
  puts "#{source.filename} is missing #{dependency.is_a?(SourceFile) ? dependency.filename : dependency.to_s}"
166
163
  end
@@ -172,14 +169,14 @@ module Jsus
172
169
  # Returs a tree, containing all the sources
173
170
  #
174
171
  def source_tree
175
- @source_tree ||= Tree.new
172
+ @source_tree ||= Util::Tree.new
176
173
  end
177
174
 
178
175
  #
179
176
  # Returns a tree containing all the provides tags
180
177
  #
181
178
  def provides_tree
182
- @provides_tree ||= Tree.new
179
+ @provides_tree ||= Util::Tree.new
183
180
  end
184
181
 
185
182
 
@@ -1,12 +1,12 @@
1
- #
2
- # SourceFile is a base for any Jsus operation.
3
- #
4
- # It contains basic info about source as well as file content.
5
- #
6
- #
7
1
  module Jsus
2
+ # Generic exception for 'bad' source files (no yaml header, for example)
8
3
  class BadSourceFileException < Exception; end
9
4
 
5
+ #
6
+ # SourceFile is a base for any Jsus operation.
7
+ #
8
+ # It contains basic info about source as well as file content.
9
+ #
10
10
  class SourceFile
11
11
  attr_accessor :relative_filename, :filename, :package # :nodoc:
12
12
  # Constructors
@@ -16,11 +16,11 @@ module Jsus
16
16
  # You probably should use SourceFile.from_file instead.
17
17
  #
18
18
  # But if you know what you are doing, it accepts the following values:
19
- # * +package+ an instance of Package, normally passed by a parent
20
- # * +relative_filename+ used in Package, for generating tree structure of the source files
21
- # * +filename+ full filename for the given package
22
- # * +content+ file content of the source file
23
- # * +pool+ an instance of Pool
19
+ # * +package+ -- an instance of Package, normally passed by a parent
20
+ # * +relative_filename+ -- used in Package, for generating tree structure of the source files
21
+ # * +filename+ -- full filename for the given package
22
+ # * +content+ -- file content of the source file
23
+ # * +pool+ -- an instance of Pool
24
24
  def initialize(options = {})
25
25
  [:package, :header, :relative_filename, :filename, :content, :pool].each do |field|
26
26
  send("#{field}=", options[field]) if options[field]
@@ -31,8 +31,8 @@ module Jsus
31
31
  # Initializes a SourceFile given the filename and options
32
32
  #
33
33
  # options:
34
- # * <tt>:pool:</tt> an instance of Pool
35
- # * <tt>:package:</tt> an instance of Package
34
+ # * <tt>:pool:</tt> -- an instance of Pool
35
+ # * <tt>:package:</tt> -- an instance of Package
36
36
  #
37
37
  # returns either an instance of SourceFile or nil when it's not possible to parse the input
38
38
  #
@@ -89,7 +89,7 @@ module Jsus
89
89
  #
90
90
  # Returns an array with names of dependencies. Unordered.
91
91
  # Accepts options:
92
- # * <tt>:short:</tt> whether inner dependencies should not prepend package name
92
+ # * <tt>:short:</tt> -- whether inner dependencies should not prepend package name
93
93
  # e.g. 'Class' instead of 'Core/Class' when in package 'Core').
94
94
  # Doesn't change anything for external dependencies
95
95
  #
@@ -122,7 +122,7 @@ module Jsus
122
122
  #
123
123
  # Returns an array with provides names.
124
124
  # Accepts options:
125
- # * <tt>:short:</tt> whether provides should not prepend package name
125
+ # * <tt>:short:</tt> -- whether provides should not prepend package name
126
126
  # e.g. 'Class' instead of 'Core/Class' when in package 'Core')
127
127
  def provides_names(options = {})
128
128
  provides.map {|p| p.name(options)}