padrino-sprockets 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/padrino/sprockets-version.rb +1 -1
- data/lib/padrino/sprockets.rb +71 -15
- metadata +5 -5
data/lib/padrino/sprockets.rb
CHANGED
@@ -1,43 +1,99 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require "sprockets
|
2
|
+
require "sprockets"
|
3
|
+
require "tilt"
|
4
|
+
|
5
|
+
module Sprockets
|
6
|
+
class JSMinifier < Tilt::Template
|
7
|
+
def prepare
|
8
|
+
end
|
9
|
+
|
10
|
+
def evaluate(context, locals, &block)
|
11
|
+
JSMin.minify(data)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
3
16
|
module Padrino
|
4
17
|
module Sprockets
|
5
|
-
class << self
|
6
|
-
def registered(app)
|
7
|
-
app.helpers Helpers
|
8
|
-
end
|
9
|
-
end
|
10
18
|
module Helpers
|
11
19
|
module ClassMethods
|
12
20
|
def sprockets(options={})
|
13
21
|
url = options[:url] || 'assets'
|
14
22
|
_root = options[:root] || root
|
23
|
+
paths = options[:paths] || []
|
15
24
|
set :sprockets_url, url
|
16
|
-
|
25
|
+
options[:root] = _root
|
26
|
+
options[:url] = url
|
27
|
+
options[:paths] = paths
|
28
|
+
use Padrino::Sprockets::App, options
|
17
29
|
end
|
18
30
|
end
|
31
|
+
|
32
|
+
module AssetTagHelpers
|
33
|
+
# Change the folders to /assets/
|
34
|
+
def asset_folder_name(kind)
|
35
|
+
case kind
|
36
|
+
when :css then 'assets'
|
37
|
+
when :js then 'assets'
|
38
|
+
else kind.to_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end # AssetTagHelpers
|
42
|
+
|
19
43
|
def self.included(base)
|
20
|
-
base.
|
44
|
+
base.send(:include, AssetTagHelpers)
|
45
|
+
base.extend ClassMethods
|
21
46
|
end
|
22
47
|
end #Helpers
|
48
|
+
|
23
49
|
class App
|
50
|
+
attr_reader :environment
|
51
|
+
|
24
52
|
def initialize(app, options={})
|
25
53
|
@app = app
|
26
54
|
@root = options[:root]
|
27
55
|
url = options[:url] || 'assets'
|
28
56
|
@matcher = /^\/#{url}\/*/
|
29
|
-
|
30
|
-
|
57
|
+
setup_environment(options[:minify], options[:paths] || [])
|
58
|
+
end
|
59
|
+
|
60
|
+
def setup_environment(minify=false, extra_paths=[])
|
61
|
+
@environment = ::Sprockets::Environment.new(@root)
|
31
62
|
@environment.append_path 'assets/javascripts'
|
32
63
|
@environment.append_path 'assets/stylesheets'
|
33
64
|
@environment.append_path 'assets/images'
|
65
|
+
|
66
|
+
if minify
|
67
|
+
if defined?(YUI)
|
68
|
+
@environment.css_compressor = YUI::CssCompressor.new
|
69
|
+
else
|
70
|
+
puts "Add yui-compressor to your Gemfile to enable css compression"
|
71
|
+
end
|
72
|
+
if defined?(JSMin)
|
73
|
+
@environment.register_postprocessor "application/javascript", ::Sprockets::JSMinifier
|
74
|
+
else
|
75
|
+
puts "Add jsmin to your Gemfile to enable minification"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
extra_paths.each do |sprocket_path|
|
80
|
+
@environment.append_path sprocket_path
|
81
|
+
end
|
34
82
|
end
|
83
|
+
|
35
84
|
def call(env)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
85
|
+
if @matcher =~ env["PATH_INFO"]
|
86
|
+
env['PATH_INFO'].sub!(@matcher,'')
|
87
|
+
@environment.call(env)
|
88
|
+
else
|
89
|
+
@app.call(env)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class << self
|
95
|
+
def registered(app)
|
96
|
+
app.helpers Padrino::Sprockets::Helpers
|
41
97
|
end
|
42
98
|
end
|
43
99
|
end #Sprockets
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-sprockets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sprockets
|
16
|
-
requirement: &
|
16
|
+
requirement: &70143262763320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70143262763320
|
25
25
|
description: Padrino with Sprockets
|
26
26
|
email:
|
27
27
|
- nightsailer@gmail.com
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
53
|
rubyforge_project:
|
54
|
-
rubygems_version: 1.8.
|
54
|
+
rubygems_version: 1.8.16
|
55
55
|
signing_key:
|
56
56
|
specification_version: 3
|
57
57
|
summary: Padrino with Sprockets
|