jim 0.1.0 → 0.1.1

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/README.rdoc CHANGED
@@ -22,6 +22,18 @@ The goals are simple:
22
22
 
23
23
  So far I've accomplished the goals, but this is all very very very beta and the API is sure to change and thing straight-up might not work.
24
24
 
25
+ == Install
26
+
27
+ jim is a rubygem:
28
+
29
+ $ gem install jim
30
+
31
+ You can also clone the source from github and use jeweler to install locally (requires jeweler):
32
+
33
+ $ git clone git://github.com/quirkey/jim.git
34
+ $ cd jim
35
+ $ rake install
36
+
25
37
  == Usage
26
38
 
27
39
  From anywhere, install a project:
@@ -43,8 +55,8 @@ Which create an empty "Jimfile". Open it up and add your requirements:
43
55
 
44
56
  jquery 1.4.2
45
57
  jquery-metadata 2.0
46
- // a local file (comments are fine)
47
- app.js
58
+ // a local file, js/app.js (comments are fine)
59
+ js/app
48
60
 
49
61
  If its a rack project, mount the Jim::Rack middleware which gives you live updates of your bundled and compressed js files:
50
62
 
@@ -58,6 +70,8 @@ Otherwise and also before deploys, etc, use the command line tool from your proj
58
70
  // or
59
71
  $ jim compress
60
72
 
73
+ In order for compress to work, you need either the yui-compressor gem or the closure-compiler gem. Closure is the default, add
74
+
61
75
  Run `jim commands` for a full list of commands.
62
76
 
63
77
  == You're probably wondering
@@ -72,6 +86,10 @@ With that said, I would gladly welcome anyone cloning the API in CommonJS (I'm j
72
86
 
73
87
  Probably?? Its all very new at this point so please test it out and let me know.
74
88
 
89
+ == Thanks
90
+
91
+ Thanks to Yehuda Katz for talking through some of the ideas with me.
92
+
75
93
  == Note on Patches/Pull Requests
76
94
 
77
95
  * Fork the project.
@@ -80,7 +98,7 @@ Probably?? Its all very new at this point so please test it out and let me know.
80
98
  future version unintentionally.
81
99
  * Commit, do not mess with rakefile, version, or history.
82
100
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
83
- * Send me a pull request. Bonus points for topic branches.
101
+ * Send me a pull request. Bonus points for topic branches
84
102
 
85
103
  == Copyright
86
104
 
data/Rakefile CHANGED
@@ -16,7 +16,10 @@ begin
16
16
  gem.homepage = "http://github.com/quirkey/jim"
17
17
  gem.authors = ["Aaron Quint"]
18
18
  gem.add_dependency "downlow", ">= 0.1.1"
19
+ gem.add_dependency "yajl-ruby"
19
20
  gem.add_development_dependency "shoulda", ">= 0"
21
+ gem.add_development_dependency "fakeweb", ">= 1.2.8"
22
+ gem.add_development_dependency "mocha"
20
23
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
24
  end
22
25
  Jeweler::GemcutterTasks.new
data/jim.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jim}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Quint"]
12
- s.date = %q{2010-02-19}
12
+ s.date = %q{2010-02-20}
13
13
  s.default_executable = %q{jim}
14
14
  s.description = %q{jim is your friendly javascript library manager. He downloads, stores, bundles, vendors and compresses.}
15
15
  s.email = %q{aaron@quirkey.com}
@@ -70,14 +70,23 @@ Gem::Specification.new do |s|
70
70
 
71
71
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
72
72
  s.add_runtime_dependency(%q<downlow>, [">= 0.1.1"])
73
+ s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
73
74
  s.add_development_dependency(%q<shoulda>, [">= 0"])
75
+ s.add_development_dependency(%q<fakeweb>, [">= 1.2.8"])
76
+ s.add_development_dependency(%q<mocha>, [">= 0"])
74
77
  else
75
78
  s.add_dependency(%q<downlow>, [">= 0.1.1"])
79
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
76
80
  s.add_dependency(%q<shoulda>, [">= 0"])
81
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
82
+ s.add_dependency(%q<mocha>, [">= 0"])
77
83
  end
78
84
  else
79
85
  s.add_dependency(%q<downlow>, [">= 0.1.1"])
86
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
80
87
  s.add_dependency(%q<shoulda>, [">= 0"])
88
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
89
+ s.add_dependency(%q<mocha>, [">= 0"])
81
90
  end
82
91
  end
83
92
 
data/lib/jim/bundler.rb CHANGED
@@ -1,10 +1,29 @@
1
1
  module Jim
2
+ # Bundler takes parses a Jimfile that specifies requirements as names and
3
+ # versions and then can bundle, compress, or copy those files into specific dirs
4
+ # or files.
5
+ #
6
+ # A Jimfile has a really simple format:
7
+ #
8
+ # // comments look like JS comments
9
+ # // you can set options by adding comments that look like JSON pairs
10
+ # // bundle_path: /path/to/bundle.js
11
+ #
12
+ # // A requirement is just a name and an optional version
13
+ # // requirements are resolved and bundled in order of specification
14
+ # jquery 1.4.2
15
+ # jquery.color
16
+ # sammy 0.5.0
17
+ #
18
+ #
2
19
  class Bundler
3
20
  class MissingFile < Jim::Error; end
4
-
21
+
5
22
  attr_accessor :jimfile, :index, :requirements, :paths, :options
6
-
7
- def initialize(jimfile, index, options = {})
23
+
24
+ # create a new bundler instance passing in the Jimfile as a `Pathname` or a
25
+ # string. `index` is a Jim::Index
26
+ def initialize(jimfile, index = nil, options = {})
8
27
  self.jimfile = jimfile.is_a?(Pathname) ? jimfile.read : jimfile
9
28
  self.index = index || Jim::Index.new
10
29
  self.options = {}
@@ -14,7 +33,8 @@ module Jim
14
33
  self.add(options[:vendor_dir]) if options[:vendor_dir]
15
34
  self.paths = []
16
35
  end
17
-
36
+
37
+ # resove the requirements specified into Jimfile or raise a MissingFile error
18
38
  def resolve!
19
39
  self.requirements.each do |search|
20
40
  name, version = search.strip.split(/\s+/)
@@ -27,7 +47,9 @@ module Jim
27
47
  end
28
48
  paths
29
49
  end
30
-
50
+
51
+ # concatenate all the requirements into a single file and write to `to` or to the
52
+ # path specified in the :bundled_path option
31
53
  def bundle!(to = nil)
32
54
  resolve! if paths.empty?
33
55
  to = options[:bundled_path] if to.nil? && options[:bundled_path]
@@ -38,7 +60,10 @@ module Jim
38
60
  end
39
61
  io
40
62
  end
41
-
63
+
64
+ # concatenate all the requirements into a single file then run through a JS
65
+ # then write to `to` or to the path specified in the :bundled_path option.
66
+ # You can also use the YUI compressor by setting the option :compressor to 'yui'
42
67
  def compress!(to = nil)
43
68
  to = options[:compressed_path] if to.nil? && options[:compressed_path]
44
69
  io = io_for_path(to)
@@ -46,7 +71,9 @@ module Jim
46
71
  io << js_compress(bundle!(false))
47
72
  io
48
73
  end
49
-
74
+
75
+ # copy each of the requirements into the dir specified with `dir` or the path
76
+ # specified with the :vendor_dir option
50
77
  def vendor!(dir = nil)
51
78
  resolve! if paths.empty?
52
79
  dir ||= options[:vendor_dir]
@@ -56,7 +83,7 @@ module Jim
56
83
  Jim::Installer.new(path, dir, :shallow => true).install
57
84
  end
58
85
  end
59
-
86
+
60
87
  private
61
88
  def io_for_path(to)
62
89
  case to
@@ -72,7 +99,7 @@ module Jim
72
99
  ""
73
100
  end
74
101
  end
75
-
102
+
76
103
  def parse_jimfile
77
104
  jimfile.each_line do |line|
78
105
  if /^\/\/\s?([^\:]+)\:\s(.*)$/.match line
@@ -82,21 +109,29 @@ module Jim
82
109
  end
83
110
  end
84
111
  end
85
-
112
+
86
113
  def js_compress(uncompressed)
87
114
  if options[:compressor] == 'yui'
88
- require "yui/compressor"
115
+ begin
116
+ require "yui/compressor"
117
+ rescue LoadError
118
+ raise "You must install the yui compressor gem to use the compressor\ngem install yui-compressor"
119
+ end
89
120
  compressor = ::YUI::JavaScriptCompressor.new
90
121
  else
91
- require 'closure-compiler'
122
+ begin
123
+ require 'closure-compiler'
124
+ rescue LoadError
125
+ raise "You must install the closure compiler gem to use the compressor\ngem install closure-compiler"
126
+ end
92
127
  compressor = ::Closure::Compiler.new
93
128
  end
94
129
  compressor.compress(uncompressed)
95
130
  end
96
-
131
+
97
132
  def logger
98
133
  Jim.logger
99
134
  end
100
-
135
+
101
136
  end
102
137
  end
data/lib/jim/cli.rb CHANGED
@@ -1,8 +1,15 @@
1
+ require 'optparse'
2
+
1
3
  module Jim
4
+
5
+ # CLI handles the command line interface for the `jim` binary.
6
+ # The layout is farily simple. Options are parsed using optparse.rb and
7
+ # the different public methods represent 1-1 the commands provided by the bin.
2
8
  class CLI
3
9
 
4
10
  attr_accessor :jimfile, :jimhome, :force
5
11
 
12
+ # create a new instance with the args passed from the command line i.e. ARGV
6
13
  def initialize(args)
7
14
  @output = ""
8
15
  # set the default jimhome
@@ -13,6 +20,7 @@ module Jim
13
20
  ## try to run based on args
14
21
  end
15
22
 
23
+ # method called by the bin directly after initialization.
16
24
  def run
17
25
  command = @args.shift
18
26
  if command && respond_to?(command)
@@ -29,12 +37,14 @@ module Jim
29
37
  @output << e.message + " (#{e.class})"
30
38
  end
31
39
 
40
+ # list the possible commands to the logger
32
41
  def commands
33
42
  logger.info "Usage: jim [options] [command] [args]\n"
34
43
  logger.info "Commands:"
35
44
  logger.info template('commands')
36
45
  end
37
46
 
47
+ # list the possible commands without detailed descriptions
38
48
  def cheat
39
49
  logger.info "Usage: jim [options] [command] [args]\n"
40
50
  logger.info "Commands:"
@@ -42,6 +52,7 @@ module Jim
42
52
  logger.info "run commands for details"
43
53
  end
44
54
 
55
+ # initialize the current dir with a new Jimfile
45
56
  def init(dir = nil)
46
57
  dir = Pathname.new(dir || '')
47
58
  jimfile_path = dir + 'Jimfile'
@@ -55,34 +66,40 @@ module Jim
55
66
  end
56
67
  end
57
68
 
69
+ # install the file/project `url` into `jimhome`
58
70
  def install(url, name = false, version = false)
59
71
  Jim::Installer.new(url, jimhome, :force => force, :name => name, :version => version).install
60
72
  end
61
73
 
74
+ # bundle the files specified in Jimfile into `to`
62
75
  def bundle(to = nil)
63
76
  path = bundler.bundle!(to)
64
77
  end
65
78
 
79
+ # compress the files specified in Jimfile into `to`
66
80
  def compress(to = nil)
67
81
  path = bundler.compress!(to)
68
82
  end
69
83
 
84
+ # copy/vendor all the files specified in Jimfile to `dir`
85
+ def vendor(dir = nil)
86
+ bundler.vendor!(dir)
87
+ end
88
+
89
+ # list the installed projects and versions
70
90
  def list
71
91
  logger.info "Getting list of installed files in #{index.directories.join(':')}"
72
92
  list = index.list
73
93
  logger.info "Installed:\n#{list.collect {|i| "#{i[0]} (#{i[1].join(', ')})"}.join("\n")}"
74
94
  end
75
95
 
96
+ # list the files and their resolved paths specified in the Jimfile
76
97
  def resolve
77
98
  resolved = bundler.resolve!
78
99
  logger.info "Files:\n#{resolved.join("\n")}"
79
100
  resolved
80
101
  end
81
-
82
- def vendor(dir = nil)
83
- bundler.vendor!(dir)
84
- end
85
-
102
+
86
103
  private
87
104
  def parse_options(runtime_args)
88
105
  OptionParser.new("", 24, ' ') do |opts|
@@ -124,7 +141,7 @@ module Jim
124
141
  end
125
142
 
126
143
  def index
127
- @index ||= Jim::Index.new(jimhome + 'lib')
144
+ @index ||= Jim::Index.new(jimhome + 'lib', Dir.pwd)
128
145
  end
129
146
 
130
147
  def bundler
data/lib/jim/index.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module Jim
2
+ # Index managages a list of directories which are searched to find requirements
2
3
  class Index
3
4
  attr_reader :directories
4
5
 
data/lib/jim/rack.rb CHANGED
@@ -1,6 +1,14 @@
1
1
  require 'jim'
2
2
 
3
3
  module Jim
4
+ # Jim::Rack is a Rack middleware for allowing live bundling and compression
5
+ # of the requirements in your Jimfile without having to rebundle using the command
6
+ # line. You can specify a number of options:
7
+ #
8
+ # :jimfile: Path to your Jimfile (default ./Jimfile)
9
+ # :jimhome: Path to your JIMHOME directory (default ENV['JIMHOME'] or ~/.jim)
10
+ # :bundled_uri: URI to serve the bundled requirements
11
+ # :compressed_uri: URI to serve the compressed requirements
4
12
  class Rack
5
13
 
6
14
  def initialize(app, options = {})
data/lib/jim.rb CHANGED
@@ -2,8 +2,9 @@ require 'downlow'
2
2
  require 'logger'
3
3
  require 'yajl'
4
4
 
5
+
5
6
  module Jim
6
- VERSION = '0.1.0'
7
+ VERSION = '0.1.1'
7
8
 
8
9
  class Error < RuntimeError; end
9
10
  class FileExists < Error; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Quint
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-19 00:00:00 -05:00
12
+ date: 2010-02-20 00:00:00 -05:00
13
13
  default_executable: jim
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.1.1
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: yajl-ruby
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: shoulda
27
37
  type: :development
@@ -32,6 +42,26 @@ dependencies:
32
42
  - !ruby/object:Gem::Version
33
43
  version: "0"
34
44
  version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: fakeweb
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.8
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
35
65
  description: jim is your friendly javascript library manager. He downloads, stores, bundles, vendors and compresses.
36
66
  email: aaron@quirkey.com
37
67
  executables: