paste 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'sprockets'
4
+ gem 'closure-compiler'
4
5
  gem 'paste', :path => '.'
5
6
  gem 'activesupport', '>= 3.0.0.beta4'
6
7
 
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paste (0.1.0)
4
+ paste (0.1.1)
5
5
  activesupport (>= 3.0.0.beta4)
6
+ closure-compiler
6
7
  paste
7
8
  sprockets
8
9
 
@@ -10,6 +11,7 @@ GEM
10
11
  remote: http://rubygems.org/
11
12
  specs:
12
13
  activesupport (3.0.0.rc)
14
+ closure-compiler (0.3.2)
13
15
  diff-lcs (1.1.2)
14
16
  gemcutter (0.6.1)
15
17
  git (1.2.5)
@@ -37,6 +39,7 @@ PLATFORMS
37
39
 
38
40
  DEPENDENCIES
39
41
  activesupport (>= 3.0.0.beta4)
42
+ closure-compiler
40
43
  jeweler
41
44
  paste!
42
45
  rake
data/README.rdoc CHANGED
@@ -1,97 +1,110 @@
1
- Sprockets for Rails 3
2
- =================
1
+ = Paste
3
2
 
4
- This gem lets you make use of [Sprockets](http://github.com/sstephenson/sprockets).
3
+ This gem simplifies dependencies between javascript and easily allows requiring of javascript.
5
4
 
6
- ## Installing
5
+ == Installing
7
6
 
8
- In your Gemfile: `gem 'sprockets-packager'`
7
+ In your Gemfile: <tt>gem 'paste'</tt>
9
8
 
10
- Then, `bundle install`
9
+ Then, <tt>bundle install</tt>
11
10
 
12
- ## Usage
13
- Read up on how [Sprockets](http://github.com/sstephenson/sprockets) works to start taking advantage of it.
14
-
15
- Put all of your javascript files in `app/javascripts`. You can even make erb javascript files to interpolate constants and such.
11
+ == Usage
12
+ Put all of your javascript files in <tt>app/javascripts</tt>. You can even make erb javascript files to interpolate constants and such.
16
13
 
17
14
  Now in your views, whenever you need javascript, just call
18
-
19
- <% include_sprocket 'foobar' %>
20
-
21
- or
22
-
23
- <% include_sprockets 'foo/bar', 'foo', 'baz' %>
15
+ <% javascript 'some/javascript/file' %>
16
+ <% css 'some/css/file' %>
17
+ or
18
+ <% javascript 'foo/bar', 'foo', 'baz' %>
24
19
 
25
20
  And then in your layout file,
26
21
 
27
- <%= sprockets_include_tag %>
22
+ <%= paste_js_tags %>
23
+ <%= paste_css_tags %>
28
24
 
29
- And that's it! As long as you've got your dependencies in your JS managed all right, the sprockets themselves will be automatically generated for you
25
+ And that's it!
30
26
 
31
- I would recommend you add `public/javascripts/*` to your gitignore. I find it silly to check in generated files anyway.
27
+ I would recommend you add <tt>public/javascripts/*</tt> to the ignore list of your VCS.
32
28
 
33
- ### Environments (default behavior)
34
- #### Production
35
- In production, whenever `sprockets_include_tag` is called, the unique filename is generated, and if the file does not exist, it is generated via `Sprockets::Secretary`.
36
- Subsequent calls to `sprockets_include_tag` will never update the generated sprocket, and there is no other way that the sprocket will be generated.
29
+ == Behaviour
37
30
 
38
- For deployment, you probably don't want the first request to every page spend time rebuild the sprocket for that page. This gem caches all of the built sprockets to the file `tmp/sprockets-cache/sprockets.yml`. You probably want to symlink the entire directory to your deployment, but you can also just symlink this file.
31
+ Paste uses +stylesheet_link_tag+ with a <tt>:cache</tt> option set to a hash of the included CSS files. Normally this means that in production all CSS is concatenated into one file.
39
32
 
40
- You then need to run the `rake sprockets:rebuild` before your deployment goes live to rebuild everything
33
+ === Production
34
+ For a Rails app, in production, <tt>Paste::JS::Unify</tt> is used to concatenate javascript. This means that +paste_js_tags+ will output only one tag. This tag will have the concatenation of all javascript required, including all of the dependencies (in the correct order).
41
35
 
42
- #### Development
43
- Here, whenever `sprockets_include_tag` is called, the files are examined and the dependency tree is determined. The files are then included in the order which satisfies the dependency tree.
44
- Every request will trigger a refresh of the generated files in addition to them being generated when `sprockets_include_tag` is called.
36
+ This is not compressed originally because it's generated on the fly. A cache file is written, however, so on a re-deploy you can rebuild all of the previously generated concatenations and Google's closure compiler is used for compression.
45
37
 
46
- ## Example
38
+ === Development
39
+ For a Rails app in development, <tt>Paste::JS::Chain</tt> is used to paste javascripts together. This paster simply takes the list of javascripts and determines the dependencies and then generates a separate tag for each javascript file. This proves useful for debugging.
47
40
 
48
- Assume that `app/javascripts/jquery.js` exists and we have these files:
41
+ == Example
49
42
 
50
- ### app/javascripts/foo.js
43
+ Assume that <tt>app/javascripts/jquery.js</tt> exists and we have these files:
51
44
 
52
- //= require <jquery>
53
- //= require <foo/bar>
45
+ ==== app/javascripts/foo.js
46
+
47
+ //= require <jquery>
48
+ //= require <foo/bar>
54
49
 
55
- $(function() {
56
- $('#foo').fadeIn().html($['BAR_VALUE']);
57
- });
50
+ $(function() {
51
+ $('#foo').fadeIn().html($['BAR_VALUE']);
52
+ });
58
53
 
59
- ### app/javascripts/foo/bar.js.erb
54
+ ==== app/javascripts/foo/bar.js.erb
60
55
 
61
- //= require <jquery>
56
+ //= require <jquery>
62
57
 
63
- $['BAR_VALUE'] = <%= Bar::BAR_VALUE %>;
58
+ $['BAR_VALUE'] = <%= Bar::BAR_VALUE %>;
64
59
 
65
- ### app/views/foo/index.html.erb
60
+ ==== app/views/foo/index.html.erb
66
61
 
67
- <% include_sprocket 'foo' %>
62
+ <% javascript 'foo' %>
63
+ <% css 'foo' %>
68
64
 
69
- <div id='bar'>
70
- And the bar value for today is: <div id='foo'></div>
71
- </div>
72
-
73
- And as long as your template has `<%= sprockets_include_tag %>`, the right javascript concatenation will be generated for you.
74
-
75
- See configuration below for details, but if `:expand_includes` is true, then `sprockets_include_tag` is equivalent to `javascript_include_tag 'jquery', 'foo/bar', 'foo'`.
76
- Otherwise, if `:expand_includes` is false, the three files will be concatenated into a file with a unique name, and it will be the only one served on the page
77
-
78
- ## Configuration
79
-
80
- You can configure the packager through `Sprockets::Packager.options`. The following are recognized options:
81
-
82
- * `:load_path` - an array of relative/absolute paths of where to load the sprockets from. Sprockets are interpreted as relative from any one of these paths. Default: `['app/javascripts']`
83
- * `:destination` - This is the destination of generated sprockets to go. Default: `'public/javascripts'`
84
- * `:root` - This is the root option passed to Sprockets::Secretary. Default: `Rails.root`
85
- * `:tmp_path` - This is the absolute/relative place to place any generated files like ERB templates. Default `'tmp/sprockets-cache'`
86
- * `:watch_changes` - Values as to whether to watch the file system for changes. If `true`, this will regenerate all necessary sprockets on each request. Default: `Rails.env.development?`
87
- * `:expand_includes` - Value as to whether to expand javascript includes or to compact them into one asset. Default: `Rails.env.development?`
88
- * `:serve_assets` - Value as to whether a Rack component should be installed to serve all static assets. This is useful for deployments on Heroku where the `public/` directory is not writeable. If this is used, the `:destination` is changed to `tmp/javascripts` and assets are served from there. Default: `false`
89
-
90
- All configuration should be done in `config/application.rb` or `config/environments/*.rb`.
91
-
92
- ## License
93
-
94
- Copyright &copy; 2009 Alex Crichton.
65
+ <div id='bar'>
66
+ And the bar value for today is: <div id='foo'></div>
67
+ </div>
68
+
69
+ For this example, whenever +foo/index.html.erb+ is rendered, the stylesheet +public/stylesheets/foo+ will be included and so will both +app/javascripts/foo.js+ and +app/javascripts/bar.js.erb+ with +bar+ before +foo+.
70
+
71
+ == Configuration
72
+
73
+ The following are recognized options:
74
+
75
+ # These options are read by both Paste::JS and Paste::CSS
76
+ Paste::Glue.configure do |config|
77
+ config.root # the root directory (defaults to Rails.root or the pwd)
78
+
79
+ config.tmp_path # a temporary directory to use. Can be relative to the root
80
+ # or it can be an absolute path. Default: 'tmp/paste-cache'
81
+ end
82
+
83
+ Paste::JS.configure do |config|
84
+ config.destination # relative or absolute path of where to put javascripts.
85
+ # Default: 'public/javascripts'
86
+
87
+ config.load_path # The load path for javascripts. This is where to find
88
+ # the source files. Default: ['app/javascripts']
89
+
90
+ config.erb_path # relative or absolute path of where to generate the
91
+ # ERB results to. Default: 'tmp/paste-cache/erb'
92
+
93
+ config.cache_file # The cache file for when pastes are made. This allows
94
+ # the same pastes to be persisted through deployments
95
+ # without regenerating on the first request. This is
96
+ # a location relative to config.tmp_path
97
+ # Default: sprockets.yml
98
+
99
+ config.parser # The parser class to use when determining dependencies
100
+ # of javascripts. Default: Paste::Parser::Sprockets
101
+ end
102
+
103
+ All configuration should be done in <tt>config/application.rb</tt> or <tt>config/environments/*.rb</tt>.
104
+
105
+ == License
106
+
107
+ Copyright 2009 Alex Crichton.
95
108
 
96
109
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
97
110
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -1,9 +1,6 @@
1
1
  module Paste
2
2
  module CSS
3
3
  class Base < Glue
4
- extend Resolver
5
-
6
- include Resolver
7
4
  end
8
5
  end
9
- end
6
+ end
@@ -1,4 +1,5 @@
1
- require 'active_support/core_ext/hash/reverse_merge'
1
+ require 'closure-compiler'
2
+ require 'active_support/core_ext/hash/except'
2
3
 
3
4
  module Paste
4
5
  module JS
@@ -20,7 +21,7 @@ module Paste
20
21
  def compress result, options = {}
21
22
  case options[:compress]
22
23
  when 'google'
23
- google_compress result, options
24
+ google_compress result, options.except(:compress)
24
25
  when nil, false
25
26
  # Compression not asked for
26
27
  else
@@ -31,20 +32,13 @@ module Paste
31
32
  protected
32
33
 
33
34
  def google_compress result, options = {}
34
- file = destination result
35
- uri = URI.parse('http://closure-compiler.appspot.com/compile')
36
- req = Net::HTTP.post_form(uri,
37
- :js_code => File.read(file),
38
- :compilation_level => options[:level] || 'SIMPLE_OPTIMIZATIONS',
39
- :output_format => 'text',
40
- :output_info => 'compiled_code'
41
- )
42
-
43
- if req.is_a? Net::HTTPSuccess
44
- File.open(file, 'w') { |f| f << req.body.chomp }
45
- else
46
- raise "Google couldn't compile #{result}!"
35
+ file, output = destination(result), ''
36
+ handle = File.open(file, 'a+')
37
+ File.open(file, 'r') do |f|
38
+ output = Closure::Compiler.new(options).compile f
47
39
  end
40
+
41
+ File.open(file, 'w+') { |f| f << output.chomp }
48
42
  end
49
43
 
50
44
  end
data/paste.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{paste}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Crichton"]
12
- s.date = %q{2010-08-12}
12
+ s.date = %q{2010-08-17}
13
13
  s.description = %q{Asset Management for Rails}
14
14
  s.email = ["alex@alexcrichton.com"]
15
15
  s.extra_rdoc_files = [
@@ -79,6 +79,7 @@ Gem::Specification.new do |s|
79
79
 
80
80
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
81
81
  s.add_runtime_dependency(%q<sprockets>, [">= 0"])
82
+ s.add_runtime_dependency(%q<closure-compiler>, [">= 0"])
82
83
  s.add_runtime_dependency(%q<paste>, [">= 0"])
83
84
  s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
84
85
  s.add_development_dependency(%q<jeweler>, [">= 0"])
@@ -87,6 +88,7 @@ Gem::Specification.new do |s|
87
88
  s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
88
89
  else
89
90
  s.add_dependency(%q<sprockets>, [">= 0"])
91
+ s.add_dependency(%q<closure-compiler>, [">= 0"])
90
92
  s.add_dependency(%q<paste>, [">= 0"])
91
93
  s.add_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
92
94
  s.add_dependency(%q<jeweler>, [">= 0"])
@@ -96,6 +98,7 @@ Gem::Specification.new do |s|
96
98
  end
97
99
  else
98
100
  s.add_dependency(%q<sprockets>, [">= 0"])
101
+ s.add_dependency(%q<closure-compiler>, [">= 0"])
99
102
  s.add_dependency(%q<paste>, [">= 0"])
100
103
  s.add_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
101
104
  s.add_dependency(%q<jeweler>, [">= 0"])
@@ -30,7 +30,8 @@ describe Paste::JS::Unify, 'compression' do
30
30
  result = subject.paste('foo', 'bar')[:javascript].first
31
31
 
32
32
  begin
33
- subject.rebuild! :compress => 'google', :level => 'ADVANCED_OPTIMIZATIONS'
33
+ subject.rebuild! :compress => 'google',
34
+ :compilation_level => 'ADVANCED_OPTIMIZATIONS'
34
35
  rescue SocketError
35
36
  pending 'Error connecting to google'
36
37
  end
data/spec/spec_helper.rb CHANGED
@@ -11,9 +11,6 @@ end
11
11
 
12
12
  Paste::JS.config.load_path = ['js_sources']
13
13
  Paste::JS.config.destination = 'destination'
14
- Paste::CSS.config.load_path = ['css_sources']
15
- Paste::CSS.config.destination = 'destination'
16
-
17
14
 
18
15
  RSpec.configure do |c|
19
16
  c.color_enabled = true
@@ -61,12 +61,14 @@ module Paste
61
61
  'js'
62
62
  end
63
63
  end
64
-
65
- module CSS::Test
66
- extend TestBase
67
-
68
- def self.extension
69
- 'css'
64
+
65
+ module CSS
66
+ module Test
67
+ extend TestBase
68
+
69
+ def self.extension
70
+ 'css'
71
+ end
70
72
  end
71
73
  end
72
74
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paste
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Crichton
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-12 00:00:00 -05:00
18
+ date: 2010-08-17 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -35,7 +35,7 @@ dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  type: :runtime
37
37
  prerelease: false
38
- name: paste
38
+ name: closure-compiler
39
39
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
@@ -49,8 +49,22 @@ dependencies:
49
49
  - !ruby/object:Gem::Dependency
50
50
  type: :runtime
51
51
  prerelease: false
52
- name: activesupport
52
+ name: paste
53
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ type: :runtime
65
+ prerelease: false
66
+ name: activesupport
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
54
68
  none: false
55
69
  requirements:
56
70
  - - ">="
@@ -62,12 +76,12 @@ dependencies:
62
76
  - 0
63
77
  - beta4
64
78
  version: 3.0.0.beta4
65
- requirement: *id003
79
+ requirement: *id004
66
80
  - !ruby/object:Gem::Dependency
67
81
  type: :development
68
82
  prerelease: false
69
83
  name: jeweler
70
- version_requirements: &id004 !ruby/object:Gem::Requirement
84
+ version_requirements: &id005 !ruby/object:Gem::Requirement
71
85
  none: false
72
86
  requirements:
73
87
  - - ">="
@@ -76,12 +90,12 @@ dependencies:
76
90
  segments:
77
91
  - 0
78
92
  version: "0"
79
- requirement: *id004
93
+ requirement: *id005
80
94
  - !ruby/object:Gem::Dependency
81
95
  type: :development
82
96
  prerelease: false
83
97
  name: rake
84
- version_requirements: &id005 !ruby/object:Gem::Requirement
98
+ version_requirements: &id006 !ruby/object:Gem::Requirement
85
99
  none: false
86
100
  requirements:
87
101
  - - ">="
@@ -90,12 +104,12 @@ dependencies:
90
104
  segments:
91
105
  - 0
92
106
  version: "0"
93
- requirement: *id005
107
+ requirement: *id006
94
108
  - !ruby/object:Gem::Dependency
95
109
  type: :development
96
110
  prerelease: false
97
111
  name: rcov
98
- version_requirements: &id006 !ruby/object:Gem::Requirement
112
+ version_requirements: &id007 !ruby/object:Gem::Requirement
99
113
  none: false
100
114
  requirements:
101
115
  - - ">="
@@ -104,12 +118,12 @@ dependencies:
104
118
  segments:
105
119
  - 0
106
120
  version: "0"
107
- requirement: *id006
121
+ requirement: *id007
108
122
  - !ruby/object:Gem::Dependency
109
123
  type: :development
110
124
  prerelease: false
111
125
  name: rspec
112
- version_requirements: &id007 !ruby/object:Gem::Requirement
126
+ version_requirements: &id008 !ruby/object:Gem::Requirement
113
127
  none: false
114
128
  requirements:
115
129
  - - ">="
@@ -122,7 +136,7 @@ dependencies:
122
136
  - beta
123
137
  - 19
124
138
  version: 2.0.0.beta.19
125
- requirement: *id007
139
+ requirement: *id008
126
140
  description: Asset Management for Rails
127
141
  email:
128
142
  - alex@alexcrichton.com