paste 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +20 -36
- data/lib/paste/cache.rb +33 -0
- data/lib/paste/compress.rb +71 -0
- data/lib/paste/erb_renderer.rb +53 -0
- data/lib/paste/glue.rb +46 -3
- data/lib/paste/parser/sprockets.rb +42 -36
- data/lib/paste/rails/helper.rb +27 -16
- data/lib/paste/rails/railtie.rb +7 -7
- data/lib/paste/rails/updater.rb +2 -0
- data/lib/paste/rails.rb +3 -3
- data/lib/paste/resolver.rb +5 -4
- data/lib/paste/tasks/paste.rake +1 -6
- data/lib/paste/version.rb +1 -1
- data/lib/paste.rb +10 -29
- data/spec/paste/cache_spec.rb +41 -0
- data/spec/paste/{js/config_spec.rb → config_spec.rb} +12 -12
- data/spec/paste/erb_spec.rb +88 -0
- data/spec/paste/glue_spec.rb +56 -0
- data/spec/paste/provides_spec.rb +18 -0
- data/spec/paste/rails/helper_spec.rb +45 -26
- data/spec/spec_helper.rb +4 -4
- data/spec/support/helpers.rb +35 -49
- metadata +21 -43
- data/lib/paste/capistrano.rb +0 -32
- data/lib/paste/css/base.rb +0 -6
- data/lib/paste/js/base.rb +0 -26
- data/lib/paste/js/cache.rb +0 -111
- data/lib/paste/js/chain.rb +0 -55
- data/lib/paste/js/compress.rb +0 -46
- data/lib/paste/js/erb_renderer.rb +0 -55
- data/lib/paste/js/unify.rb +0 -38
- data/spec/paste/css/provides_spec.rb +0 -29
- data/spec/paste/js/cache_spec.rb +0 -47
- data/spec/paste/js/chain_spec.rb +0 -133
- data/spec/paste/js/compress_spec.rb +0 -43
- data/spec/paste/js/erb_spec.rb +0 -106
- data/spec/paste/js/unify_spec.rb +0 -90
data/README.rdoc
CHANGED
@@ -13,14 +13,14 @@ Put all of your javascript files in <tt>app/javascripts</tt>. You can even make
|
|
13
13
|
|
14
14
|
Now in your views, whenever you need javascript, just call
|
15
15
|
<% javascript 'some/javascript/file' %>
|
16
|
-
<%
|
17
|
-
or
|
16
|
+
<% stylesheet 'some/css/file' %>
|
17
|
+
or
|
18
18
|
<% javascript 'foo/bar', 'foo', 'baz' %>
|
19
|
-
|
19
|
+
|
20
20
|
And then in your layout file,
|
21
21
|
|
22
|
-
<%=
|
23
|
-
<%=
|
22
|
+
<%= javascript_tags %>
|
23
|
+
<%= stylesheet_tags %>
|
24
24
|
|
25
25
|
And that's it!
|
26
26
|
|
@@ -28,15 +28,7 @@ I would recommend you add <tt>public/javascripts/*</tt> to the ignore list of yo
|
|
28
28
|
|
29
29
|
== Behaviour
|
30
30
|
|
31
|
-
Paste uses +stylesheet_link_tag+ with a <tt>:cache</tt> option set to a hash of the included
|
32
|
-
|
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).
|
35
|
-
|
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.
|
37
|
-
|
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.
|
31
|
+
Paste uses +stylesheet_link_tag+ and +javascript_include_tag+ with a <tt>:cache</tt> option set to a hash of the included files. Normally this means that in production all files are concatenated together.
|
40
32
|
|
41
33
|
== Example
|
42
34
|
|
@@ -46,7 +38,7 @@ Assume that <tt>app/javascripts/jquery.js</tt> exists and we have these files:
|
|
46
38
|
|
47
39
|
//= require <jquery>
|
48
40
|
//= require <foo/bar>
|
49
|
-
|
41
|
+
|
50
42
|
$(function() {
|
51
43
|
$('#foo').fadeIn().html($['BAR_VALUE']);
|
52
44
|
});
|
@@ -58,10 +50,10 @@ Assume that <tt>app/javascripts/jquery.js</tt> exists and we have these files:
|
|
58
50
|
$['BAR_VALUE'] = <%= Bar::BAR_VALUE %>;
|
59
51
|
|
60
52
|
==== app/views/foo/index.html.erb
|
61
|
-
|
53
|
+
|
62
54
|
<% javascript 'foo' %>
|
63
|
-
<%
|
64
|
-
|
55
|
+
<% stylesheet 'foo' %>
|
56
|
+
|
65
57
|
<div id='bar'>
|
66
58
|
And the bar value for today is: <div id='foo'></div>
|
67
59
|
</div>
|
@@ -71,31 +63,23 @@ For this example, whenever +foo/index.html.erb+ is rendered, the stylesheet +pub
|
|
71
63
|
== Configuration
|
72
64
|
|
73
65
|
The following are recognized options:
|
74
|
-
|
66
|
+
|
75
67
|
# These options are read by both Paste::JS and Paste::CSS
|
76
|
-
Paste
|
68
|
+
Paste.configure do |config|
|
77
69
|
config.root # the root directory (defaults to Rails.root or the pwd)
|
78
70
|
|
79
71
|
config.tmp_path # a temporary directory to use. Can be relative to the root
|
80
72
|
# or it can be an absolute path. Default: 'tmp/paste-cache'
|
81
|
-
end
|
82
73
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
74
|
+
config.js_destination # relative or absolute path of where to put
|
75
|
+
# javascripts. Default: 'public/javascripts'
|
76
|
+
|
77
|
+
config.js_load_path # The load path for javascripts. This is where to find
|
78
|
+
# the source files. Default: ['app/javascripts']
|
79
|
+
|
90
80
|
config.erb_path # relative or absolute path of where to generate the
|
91
81
|
# 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
|
-
|
82
|
+
|
99
83
|
config.parser # The parser class to use when determining dependencies
|
100
84
|
# of javascripts. Default: Paste::Parser::Sprockets
|
101
85
|
end
|
@@ -110,4 +94,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
110
94
|
|
111
95
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
112
96
|
|
113
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
97
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/paste/cache.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'active_support/core_ext/module/synchronization'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Paste
|
5
|
+
module Cache
|
6
|
+
|
7
|
+
def rebuild
|
8
|
+
find_sources
|
9
|
+
|
10
|
+
@sources.reject!{ |_, parser| !File.exists? parser.file }
|
11
|
+
|
12
|
+
@sources.values.each &:copy_if_needed
|
13
|
+
end
|
14
|
+
|
15
|
+
def parser source
|
16
|
+
find_sources if @sources.nil?
|
17
|
+
@sources[find(source)]
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def find_sources
|
23
|
+
@sources ||= {}
|
24
|
+
|
25
|
+
load_path.each do |path|
|
26
|
+
Dir[path + '/**/*.js'].each do |file|
|
27
|
+
@sources[file] ||= config.parser.new(self, file.gsub(path + '/', ''))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'closure-compiler'
|
2
|
+
require 'active_support/core_ext/hash/except'
|
3
|
+
|
4
|
+
module Paste
|
5
|
+
module Compress
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
# alias_method_chain :rebuild!, :compression
|
10
|
+
end
|
11
|
+
|
12
|
+
def rebuild_with_compression! options = {}
|
13
|
+
rebuild_without_compression!
|
14
|
+
|
15
|
+
results.keys.each do |result|
|
16
|
+
compress result, options
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def compress result, options = {}
|
21
|
+
case options[:compress]
|
22
|
+
when 'google'
|
23
|
+
google_compress result, options.except(:compress)
|
24
|
+
when nil, false
|
25
|
+
# Compression not asked for
|
26
|
+
else
|
27
|
+
raise "Unknown compression technique: #{options[:compress]}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def has_java?
|
34
|
+
system 'java &> /dev/null'
|
35
|
+
end
|
36
|
+
|
37
|
+
def google_compress *args
|
38
|
+
has_java? ? google_compress_with_java(*args) :
|
39
|
+
google_compress_without_java(*args)
|
40
|
+
end
|
41
|
+
|
42
|
+
def google_compress_with_java result, options = {}
|
43
|
+
file, output = destination(result), ''
|
44
|
+
handle = File.open(file, 'a+')
|
45
|
+
File.open(file, 'r') do |f|
|
46
|
+
output = Closure::Compiler.new(options).compile f
|
47
|
+
end
|
48
|
+
|
49
|
+
File.open(file, 'w+') { |f| f << output.chomp }
|
50
|
+
end
|
51
|
+
|
52
|
+
def google_compress_without_java result, options = {}
|
53
|
+
file = destination result
|
54
|
+
uri = URI.parse('http://closure-compiler.appspot.com/compile')
|
55
|
+
req = Net::HTTP.post_form(uri,
|
56
|
+
:js_code => File.read(file),
|
57
|
+
:compilation_level => options[:compilation_level] ||
|
58
|
+
'SIMPLE_OPTIMIZATIONS',
|
59
|
+
:output_format => 'text',
|
60
|
+
:output_info => 'compiled_code'
|
61
|
+
)
|
62
|
+
|
63
|
+
if req.is_a? Net::HTTPSuccess
|
64
|
+
File.open(file, 'w') { |f| f << req.body.chomp }
|
65
|
+
else
|
66
|
+
raise "Google couldn't compile #{result}!"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Paste
|
4
|
+
module ERBRenderer
|
5
|
+
|
6
|
+
def render_all_erb
|
7
|
+
erb_sources.each { |s| render_erb s }
|
8
|
+
end
|
9
|
+
|
10
|
+
def render_erb source
|
11
|
+
to_generate = erb_path source.sub(/\.erb$/, '')
|
12
|
+
source = find source
|
13
|
+
|
14
|
+
if !File.exists?(to_generate) ||
|
15
|
+
File.mtime(source) > File.mtime(to_generate)
|
16
|
+
|
17
|
+
FileUtils.mkdir_p File.dirname(to_generate)
|
18
|
+
contents = PasteERBHelper.new(File.read(source)).result
|
19
|
+
File.open(to_generate, 'w') { |f| f << contents }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def erb_sources
|
26
|
+
sources = load_path.map do |path|
|
27
|
+
Dir[path + '/**/*.js.erb'].map do |erb|
|
28
|
+
erb.gsub(path + '/', '')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
sources.flatten
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# This needs to be outside of the module because we don't want to
|
38
|
+
# force templates to always do ::Rails
|
39
|
+
class PasteERBHelper < ERB
|
40
|
+
include ActionView::Helpers if defined?(ActionView::Helpers)
|
41
|
+
|
42
|
+
def config
|
43
|
+
Rails.application.config.action_controller if defined?(Rails)
|
44
|
+
end
|
45
|
+
|
46
|
+
def result *args
|
47
|
+
super binding
|
48
|
+
end
|
49
|
+
|
50
|
+
def controller
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
end
|
data/lib/paste/glue.rb
CHANGED
@@ -6,7 +6,50 @@ module Paste
|
|
6
6
|
|
7
7
|
include ActiveSupport::Configurable
|
8
8
|
include Resolver
|
9
|
-
include
|
10
|
-
|
9
|
+
include ERBRenderer
|
10
|
+
include Cache
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
config.js_load_path << erb_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def paste *sources
|
17
|
+
js_dependencies = []
|
18
|
+
css_dependencies = []
|
19
|
+
|
20
|
+
sources.each do |source|
|
21
|
+
in_order_traversal parser(source), js_dependencies, css_dependencies
|
22
|
+
end
|
23
|
+
|
24
|
+
{
|
25
|
+
:javascripts => js_dependencies,
|
26
|
+
:stylesheets => css_dependencies
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def in_order_traversal parser, js_deps, css_deps, current_path = []
|
33
|
+
return if js_deps.include? parser.source
|
34
|
+
|
35
|
+
if current_path.include? parser.source
|
36
|
+
raise "Circular dependency at #{parser.source}"
|
37
|
+
end
|
38
|
+
|
39
|
+
current_path.push parser.source
|
40
|
+
|
41
|
+
parser.js_dependencies.each do |dependency|
|
42
|
+
in_order_traversal parser(dependency), js_deps, css_deps, current_path
|
43
|
+
end
|
44
|
+
|
45
|
+
js_deps.push current_path.pop
|
46
|
+
|
47
|
+
parser.css_dependencies.each do |css_dep|
|
48
|
+
css_deps.push css_dep
|
49
|
+
end
|
50
|
+
|
51
|
+
css_deps.uniq!
|
52
|
+
end
|
53
|
+
|
11
54
|
end
|
12
|
-
end
|
55
|
+
end
|
@@ -4,37 +4,54 @@ module Paste
|
|
4
4
|
module Parser
|
5
5
|
class Sprockets
|
6
6
|
|
7
|
-
attr_reader :glue, :
|
7
|
+
attr_reader :glue, :source, :file
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
|
14
|
-
reset!
|
9
|
+
def initialize glue, source
|
10
|
+
@glue = glue
|
11
|
+
@source = source
|
12
|
+
@file = glue.find source
|
13
|
+
reset_if_needed
|
15
14
|
end
|
16
15
|
|
17
16
|
def js_dependencies
|
18
|
-
|
17
|
+
reset_if_needed
|
19
18
|
@js_dependencies
|
20
19
|
end
|
21
20
|
|
22
21
|
def css_dependencies
|
23
|
-
|
22
|
+
reset_if_needed
|
24
23
|
@css_dependencies
|
25
24
|
end
|
26
25
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
def copy_if_needed
|
27
|
+
dest = glue.destination(source)
|
28
|
+
|
29
|
+
if !File.exists?(dest) || File.mtime(dest) != File.mtime(@file)
|
30
|
+
FileUtils.mkdir_p File.dirname(dest)
|
31
|
+
FileUtils.cp @file, dest
|
32
|
+
File.utime File.mtime(@file), File.mtime(@file), dest
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def reset_if_needed
|
37
|
+
if @js_dependencies.nil? || @css_dependencies.nil? ||
|
38
|
+
@last_updated.nil? || @last_updated < File.mtime(@file)
|
39
|
+
|
40
|
+
begin
|
41
|
+
@last_updated = Time.now
|
42
|
+
|
43
|
+
@secretary = ::Sprockets::Secretary.new(
|
44
|
+
:root => glue.root,
|
45
|
+
:expand_paths => false,
|
46
|
+
:load_path => glue.load_path,
|
47
|
+
:source_files => [@file]
|
48
|
+
)
|
49
|
+
|
50
|
+
generate_dependencies
|
51
|
+
rescue ::Sprockets::LoadError => e
|
52
|
+
raise ResolveError.new(e.message)
|
53
|
+
end
|
54
|
+
end
|
38
55
|
end
|
39
56
|
|
40
57
|
protected
|
@@ -47,31 +64,20 @@ module Paste
|
|
47
64
|
def generate_dependencies
|
48
65
|
@js_dependencies = []
|
49
66
|
@css_dependencies = []
|
50
|
-
sources.each { |source| in_order_traversal source }
|
51
|
-
end
|
52
|
-
|
53
|
-
def in_order_traversal source, current_path = []
|
54
|
-
return if @js_dependencies.include? source
|
55
|
-
raise "Circular dependency at #{source}" if current_path.include? source
|
56
67
|
|
57
|
-
|
68
|
+
source_file = ::Sprockets::SourceFile.new environment,
|
69
|
+
::Sprockets::Pathname.new(environment, @file)
|
58
70
|
|
59
|
-
source_file = ::Sprockets::SourceFile.new environment,
|
60
|
-
::Sprockets::Pathname.new(environment, glue.find(source))
|
61
|
-
css_deps = []
|
62
71
|
source_file.source_lines.each do |line|
|
63
72
|
if line.require?
|
64
|
-
|
73
|
+
@js_dependencies << line.require[/^.(.*).$/, 1]
|
65
74
|
elsif line.css_require?
|
66
|
-
|
75
|
+
@css_dependencies << line.css_require
|
67
76
|
end
|
68
77
|
end
|
69
|
-
|
70
|
-
@js_dependencies.push current_path.pop
|
71
|
-
@css_dependencies = @css_dependencies | css_deps
|
72
78
|
end
|
73
79
|
|
74
|
-
end
|
80
|
+
end
|
75
81
|
end
|
76
82
|
end
|
77
83
|
|
data/lib/paste/rails/helper.rb
CHANGED
@@ -3,26 +3,22 @@ require 'digest/sha1'
|
|
3
3
|
module Paste
|
4
4
|
module Rails
|
5
5
|
module Helper
|
6
|
-
def paste_js_tags *javascripts
|
7
|
-
include_javascripts *javascripts
|
8
6
|
|
9
|
-
|
7
|
+
def javascript_tags *javascripts
|
8
|
+
include_javascripts *javascripts
|
10
9
|
|
11
10
|
results = Paste::Rails.glue.paste *@javascripts
|
12
11
|
|
13
|
-
javascript_include_tag(
|
12
|
+
javascript_include_tag *add_cache_argument(results[:javascripts])
|
14
13
|
end
|
15
14
|
|
16
|
-
def
|
17
|
-
|
15
|
+
def stylesheet_tags *other_css
|
16
|
+
include_stylesheets *other_css
|
18
17
|
|
19
18
|
results = Paste::Rails.glue.paste *(@javascripts ||= [])
|
20
|
-
all_css = (results[:
|
19
|
+
all_css = (results[:stylesheets] + @css).uniq
|
21
20
|
|
22
|
-
|
23
|
-
all_css << {:cache => cache} unless Paste::CSS.config.no_cache
|
24
|
-
|
25
|
-
stylesheet_link_tag *all_css
|
21
|
+
stylesheet_link_tag *add_cache_argument(all_css)
|
26
22
|
end
|
27
23
|
|
28
24
|
def include_javascripts *javascripts
|
@@ -35,20 +31,35 @@ module Paste
|
|
35
31
|
@javascripts
|
36
32
|
end
|
37
33
|
|
38
|
-
def
|
34
|
+
def include_stylesheets *css
|
39
35
|
@css ||= []
|
40
36
|
@css += css.flatten
|
41
37
|
@css.uniq!
|
42
38
|
end
|
43
39
|
|
44
|
-
def
|
40
|
+
def included_stylesheets
|
45
41
|
@css
|
46
42
|
end
|
47
43
|
|
48
44
|
alias :include_javascript :include_javascripts
|
49
45
|
alias :javascript :include_javascripts
|
50
|
-
|
51
|
-
|
46
|
+
alias :javascripts :include_javascripts
|
47
|
+
|
48
|
+
alias :stylesheet :include_stylesheets
|
49
|
+
alias :stylesheets :include_stylesheets
|
50
|
+
alias :include_stylesheet :include_stylesheets
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def add_cache_argument sources
|
55
|
+
if Paste.config.no_cache
|
56
|
+
sources
|
57
|
+
else
|
58
|
+
cache = Digest::SHA1.hexdigest(sources.sort.join)[0..12]
|
59
|
+
sources + [{:cache => cache}]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
52
63
|
end
|
53
64
|
end
|
54
|
-
end
|
65
|
+
end
|
data/lib/paste/rails/railtie.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
module Paste
|
2
2
|
module Rails
|
3
3
|
class Railtie < ::Rails::Railtie
|
4
|
-
|
4
|
+
|
5
5
|
initializer 'paste_initializer' do
|
6
|
-
Paste
|
6
|
+
Paste.config.root = ::Rails.root
|
7
7
|
ActionView::Base.send :include, Helper
|
8
|
+
Paste::Rails.glue = Paste::Glue.new
|
8
9
|
|
9
10
|
if ::Rails.env.development?
|
10
|
-
Paste::Rails.glue = Paste::JS::Chain.new
|
11
11
|
config.app_middleware.use Paste::Rails::Updater
|
12
12
|
else
|
13
|
-
Paste::Rails.glue = Paste::JS::Unify.new
|
14
13
|
config.to_prepare do
|
15
14
|
Paste::Rails.glue.render_all_erb
|
15
|
+
Paste::Rails.glue.rebuild
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
if Paste
|
20
|
-
Paste
|
19
|
+
if Paste.config.serve_assets
|
20
|
+
Paste.config.js_destination = 'tmp/javascripts'
|
21
21
|
|
22
22
|
# We want this serving to be at the very front
|
23
23
|
config.app_middleware.insert_before Rack::Runtime,
|
24
24
|
::Rack::Static,
|
25
25
|
:urls => ['/javascripts'],
|
26
|
-
:root => File.dirname(Paste
|
26
|
+
:root => File.dirname(Paste.config.js_destination)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
data/lib/paste/rails/updater.rb
CHANGED
data/lib/paste/rails.rb
CHANGED
@@ -3,11 +3,11 @@ module Paste
|
|
3
3
|
autoload :Helper, 'paste/rails/helper'
|
4
4
|
autoload :Railtie, 'paste/rails/railtie'
|
5
5
|
autoload :Updater, 'paste/rails/updater'
|
6
|
-
|
6
|
+
|
7
7
|
class << self
|
8
8
|
attr_accessor_with_default :glue do
|
9
|
-
Paste::
|
9
|
+
Paste::Glue.new
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
data/lib/paste/resolver.rb
CHANGED
@@ -13,20 +13,21 @@ module Paste
|
|
13
13
|
end
|
14
14
|
|
15
15
|
[:destination, :root, :erb_path, :tmp_path].each do |attribute|
|
16
|
+
config_attribute = attribute == :destination ? :js_destination : attribute
|
16
17
|
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
17
18
|
def #{attribute} relative = ''
|
18
19
|
if relative.blank?
|
19
|
-
resolve config.#{
|
20
|
+
resolve config.#{config_attribute}
|
20
21
|
else
|
21
|
-
File.join resolve(config.#{
|
22
|
+
File.join resolve(config.#{config_attribute}), relative
|
22
23
|
end
|
23
24
|
end
|
24
25
|
RUBY
|
25
26
|
end
|
26
27
|
|
27
28
|
def load_path
|
28
|
-
config.
|
29
|
-
end
|
29
|
+
config.js_load_path.map { |p| resolve p }
|
30
|
+
end
|
30
31
|
|
31
32
|
def find source
|
32
33
|
source += '.js' unless source.end_with?('.js') || source.end_with?('.erb')
|
data/lib/paste/tasks/paste.rake
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
namespace :paste do
|
2
2
|
desc 'Rebuild all cached javascripts'
|
3
3
|
task :rebuild => :environment do
|
4
|
-
Paste::Rails.glue.rebuild
|
5
|
-
end
|
6
|
-
|
7
|
-
desc 'Compress all cached javascripts'
|
8
|
-
task :compress => :environment do
|
9
|
-
Paste::Rails.glue.rebuild! :compress => 'google'
|
4
|
+
Paste::Rails.glue.rebuild
|
10
5
|
end
|
11
6
|
end
|
data/lib/paste/version.rb
CHANGED
data/lib/paste.rb
CHANGED
@@ -5,31 +5,17 @@ require 'active_support/core_ext/module/attr_accessor_with_default'
|
|
5
5
|
require 'active_support/core_ext/module/delegation'
|
6
6
|
|
7
7
|
module Paste
|
8
|
+
autoload :Cache, 'paste/cache'
|
9
|
+
autoload :Compress, 'paste/compress'
|
10
|
+
autoload :ERBRenderer, 'paste/erb_renderer'
|
8
11
|
autoload :Glue, 'paste/glue'
|
9
12
|
autoload :NeedsUpdate, 'paste/needs_update'
|
10
13
|
autoload :Rails, 'paste/rails'
|
11
14
|
autoload :Resolver, 'paste/resolver'
|
12
15
|
autoload :VERSION, 'paste/version'
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
autoload :Cache, 'paste/js/cache'
|
17
|
-
autoload :Chain, 'paste/js/chain'
|
18
|
-
autoload :Compress, 'paste/js/compress'
|
19
|
-
autoload :ERBRenderer, 'paste/js/erb_renderer'
|
20
|
-
autoload :Unify, 'paste/js/unify'
|
21
|
-
|
22
|
-
class << self
|
23
|
-
delegate :configure, :config, :to => Base
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
module CSS
|
28
|
-
autoload :Base, 'paste/css/base'
|
29
|
-
|
30
|
-
class << self
|
31
|
-
delegate :configure, :config, :to => Base
|
32
|
-
end
|
17
|
+
class << self
|
18
|
+
delegate :configure, :config, :to => Glue
|
33
19
|
end
|
34
20
|
|
35
21
|
module Parser
|
@@ -37,22 +23,17 @@ module Paste
|
|
37
23
|
end
|
38
24
|
end
|
39
25
|
|
40
|
-
Paste
|
26
|
+
Paste.configure do |config|
|
41
27
|
config.root = Dir.pwd
|
42
28
|
config.tmp_path = 'tmp/paste-cache'
|
43
|
-
end
|
44
29
|
|
45
|
-
|
46
|
-
config.
|
47
|
-
config.load_path = ['app/javascripts']
|
30
|
+
config.js_destination = 'public/javascripts'
|
31
|
+
config.js_load_path = ['app/javascripts']
|
48
32
|
config.erb_path = 'tmp/paste-cache/erb'
|
49
|
-
config.cache_file = 'sprockets.yml'
|
50
33
|
config.parser = Paste::Parser::Sprockets
|
51
|
-
end
|
52
34
|
|
53
|
-
|
54
|
-
config.
|
55
|
-
config.load_path = ['app/stylesheets']
|
35
|
+
config.css_destination = 'public/stylesheets'
|
36
|
+
config.css_load_path = ['app/stylesheets']
|
56
37
|
end
|
57
38
|
|
58
39
|
require 'paste/rails/railtie' if defined?(Rails)
|