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 +1 -0
- data/Gemfile.lock +4 -1
- data/README.rdoc +80 -67
- data/VERSION +1 -1
- data/lib/paste/css/base.rb +1 -4
- data/lib/paste/js/compress.rb +9 -15
- data/paste.gemspec +5 -2
- data/spec/paste/js/compress_spec.rb +2 -1
- data/spec/spec_helper.rb +0 -3
- data/spec/support/helpers.rb +8 -6
- metadata +30 -16
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
paste (0.1.
|
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
|
-
|
2
|
-
=================
|
1
|
+
= Paste
|
3
2
|
|
4
|
-
This gem
|
3
|
+
This gem simplifies dependencies between javascript and easily allows requiring of javascript.
|
5
4
|
|
6
|
-
|
5
|
+
== Installing
|
7
6
|
|
8
|
-
In your Gemfile:
|
7
|
+
In your Gemfile: <tt>gem 'paste'</tt>
|
9
8
|
|
10
|
-
Then,
|
9
|
+
Then, <tt>bundle install</tt>
|
11
10
|
|
12
|
-
|
13
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
22
|
+
<%= paste_js_tags %>
|
23
|
+
<%= paste_css_tags %>
|
28
24
|
|
29
|
-
And that's it!
|
25
|
+
And that's it!
|
30
26
|
|
31
|
-
I would recommend you add
|
27
|
+
I would recommend you add <tt>public/javascripts/*</tt> to the ignore list of your VCS.
|
32
28
|
|
33
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
41
|
+
== Example
|
49
42
|
|
50
|
-
|
43
|
+
Assume that <tt>app/javascripts/jquery.js</tt> exists and we have these files:
|
51
44
|
|
52
|
-
|
53
|
-
|
45
|
+
==== app/javascripts/foo.js
|
46
|
+
|
47
|
+
//= require <jquery>
|
48
|
+
//= require <foo/bar>
|
54
49
|
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
$(function() {
|
51
|
+
$('#foo').fadeIn().html($['BAR_VALUE']);
|
52
|
+
});
|
58
53
|
|
59
|
-
|
54
|
+
==== app/javascripts/foo/bar.js.erb
|
60
55
|
|
61
|
-
|
56
|
+
//= require <jquery>
|
62
57
|
|
63
|
-
|
58
|
+
$['BAR_VALUE'] = <%= Bar::BAR_VALUE %>;
|
64
59
|
|
65
|
-
|
60
|
+
==== app/views/foo/index.html.erb
|
66
61
|
|
67
|
-
|
62
|
+
<% javascript 'foo' %>
|
63
|
+
<% css 'foo' %>
|
68
64
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
+
0.2.0
|
data/lib/paste/css/base.rb
CHANGED
data/lib/paste/js/compress.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
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
|
35
|
-
|
36
|
-
|
37
|
-
|
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.
|
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
|
+
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',
|
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
data/spec/support/helpers.rb
CHANGED
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
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-
|
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:
|
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:
|
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: *
|
79
|
+
requirement: *id004
|
66
80
|
- !ruby/object:Gem::Dependency
|
67
81
|
type: :development
|
68
82
|
prerelease: false
|
69
83
|
name: jeweler
|
70
|
-
version_requirements: &
|
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: *
|
93
|
+
requirement: *id005
|
80
94
|
- !ruby/object:Gem::Dependency
|
81
95
|
type: :development
|
82
96
|
prerelease: false
|
83
97
|
name: rake
|
84
|
-
version_requirements: &
|
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: *
|
107
|
+
requirement: *id006
|
94
108
|
- !ruby/object:Gem::Dependency
|
95
109
|
type: :development
|
96
110
|
prerelease: false
|
97
111
|
name: rcov
|
98
|
-
version_requirements: &
|
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: *
|
121
|
+
requirement: *id007
|
108
122
|
- !ruby/object:Gem::Dependency
|
109
123
|
type: :development
|
110
124
|
prerelease: false
|
111
125
|
name: rspec
|
112
|
-
version_requirements: &
|
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: *
|
139
|
+
requirement: *id008
|
126
140
|
description: Asset Management for Rails
|
127
141
|
email:
|
128
142
|
- alex@alexcrichton.com
|