pakunok 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +56 -43
- data/HISTORY.md +7 -0
- data/README.md +1 -1
- data/lib/generators/pakunok/install/intall_generator.rb +7 -0
- data/lib/generators/templates/pakunok.rb +41 -0
- data/lib/pakunok.rb +11 -8
- data/lib/pakunok/engine.rb +12 -0
- data/lib/pakunok/helpers/assets_helper.rb +31 -0
- data/lib/pakunok/pakunok.rb +130 -0
- data/lib/pakunok/railtie.rb +9 -0
- data/lib/pakunok/renderers/script_renderer.rb +36 -0
- data/lib/pakunok/version.rb +1 -1
- data/pakunok.gemspec +2 -2
- data/spec/dummy/app/views/layouts/application.html.erb +4 -2
- data/spec/dummy/app/views/pages/index.html.erb +0 -1
- data/spec/dummy/config/application.rb +10 -9
- data/spec/dummy/config/boot.rb +3 -7
- data/spec/dummy/config/environments/development.rb +3 -0
- data/spec/dummy/config/environments/production.rb +11 -2
- data/spec/dummy/config/environments/test.rb +3 -0
- data/spec/dummy/config/initializers/pakunok.rb +6 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +5 -3
- data/spec/{haml_js_template_spec.rb → pakunok/haml_js_template_spec.rb} +0 -0
- data/spec/pakunok/pakunok_spec.rb +82 -0
- data/spec/pakunok/renderers_spec.rb +68 -0
- data/spec/spec_helper.rb +2 -0
- metadata +25 -15
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,89 +1,97 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pakunok (0.0.
|
4
|
+
pakunok (0.0.3)
|
5
5
|
execjs
|
6
|
-
rails (>= 3.1.0
|
7
|
-
sprockets (>= 2.0.0
|
6
|
+
rails (>= 3.1.0)
|
7
|
+
sprockets (>= 2.0.0)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: http://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actionmailer (3.1.0
|
13
|
-
actionpack (= 3.1.0
|
12
|
+
actionmailer (3.1.0)
|
13
|
+
actionpack (= 3.1.0)
|
14
14
|
mail (~> 2.3.0)
|
15
|
-
actionpack (3.1.0
|
16
|
-
activemodel (= 3.1.0
|
17
|
-
activesupport (= 3.1.0
|
15
|
+
actionpack (3.1.0)
|
16
|
+
activemodel (= 3.1.0)
|
17
|
+
activesupport (= 3.1.0)
|
18
18
|
builder (~> 3.0.0)
|
19
19
|
erubis (~> 2.7.0)
|
20
20
|
i18n (~> 0.6)
|
21
|
-
rack (~> 1.3.
|
22
|
-
rack-cache (~> 1.0.
|
23
|
-
rack-mount (~> 0.8.
|
24
|
-
rack-test (~> 0.6.
|
25
|
-
sprockets (~> 2.0.0
|
26
|
-
activemodel (3.1.0
|
27
|
-
activesupport (= 3.1.0
|
28
|
-
bcrypt-ruby (~>
|
21
|
+
rack (~> 1.3.2)
|
22
|
+
rack-cache (~> 1.0.3)
|
23
|
+
rack-mount (~> 0.8.2)
|
24
|
+
rack-test (~> 0.6.1)
|
25
|
+
sprockets (~> 2.0.0)
|
26
|
+
activemodel (3.1.0)
|
27
|
+
activesupport (= 3.1.0)
|
28
|
+
bcrypt-ruby (~> 3.0.0)
|
29
29
|
builder (~> 3.0.0)
|
30
30
|
i18n (~> 0.6)
|
31
|
-
activerecord (3.1.0
|
32
|
-
activemodel (= 3.1.0
|
33
|
-
activesupport (= 3.1.0
|
34
|
-
arel (~> 2.1
|
31
|
+
activerecord (3.1.0)
|
32
|
+
activemodel (= 3.1.0)
|
33
|
+
activesupport (= 3.1.0)
|
34
|
+
arel (~> 2.2.1)
|
35
35
|
tzinfo (~> 0.3.29)
|
36
|
-
activeresource (3.1.0
|
37
|
-
activemodel (= 3.1.0
|
38
|
-
activesupport (= 3.1.0
|
39
|
-
activesupport (3.1.0
|
36
|
+
activeresource (3.1.0)
|
37
|
+
activemodel (= 3.1.0)
|
38
|
+
activesupport (= 3.1.0)
|
39
|
+
activesupport (3.1.0)
|
40
40
|
multi_json (~> 1.0)
|
41
|
-
arel (2.1
|
42
|
-
bcrypt-ruby (
|
41
|
+
arel (2.2.1)
|
42
|
+
bcrypt-ruby (3.0.0)
|
43
43
|
builder (3.0.0)
|
44
|
+
coderay (0.9.8)
|
44
45
|
coffee-script (2.2.0)
|
45
46
|
coffee-script-source
|
46
47
|
execjs
|
47
48
|
coffee-script-source (1.1.2)
|
48
|
-
diff-lcs (1.1.
|
49
|
+
diff-lcs (1.1.3)
|
49
50
|
erubis (2.7.0)
|
50
51
|
execjs (1.2.4)
|
51
52
|
multi_json (~> 1.0)
|
52
|
-
hike (1.2.
|
53
|
+
hike (1.2.1)
|
53
54
|
i18n (0.6.0)
|
54
55
|
mail (2.3.0)
|
55
56
|
i18n (>= 0.4.0)
|
56
57
|
mime-types (~> 1.16)
|
57
58
|
treetop (~> 1.4.8)
|
59
|
+
method_source (0.6.0)
|
60
|
+
ruby_parser (>= 2.0.5)
|
58
61
|
mime-types (1.16)
|
59
62
|
multi_json (1.0.3)
|
60
63
|
polyglot (0.3.2)
|
64
|
+
pry (0.9.3)
|
65
|
+
coderay (>= 0.9.8)
|
66
|
+
method_source (>= 0.6.0)
|
67
|
+
ruby_parser (>= 2.0.5)
|
68
|
+
slop (~> 1.9.0)
|
61
69
|
rack (1.3.2)
|
62
|
-
rack-cache (1.0.
|
70
|
+
rack-cache (1.0.3)
|
63
71
|
rack (>= 0.4)
|
64
|
-
rack-mount (0.8.
|
72
|
+
rack-mount (0.8.3)
|
65
73
|
rack (>= 1.0.0)
|
66
74
|
rack-ssl (1.3.2)
|
67
75
|
rack
|
68
76
|
rack-test (0.6.1)
|
69
77
|
rack (>= 1.0)
|
70
|
-
rails (3.1.0
|
71
|
-
actionmailer (= 3.1.0
|
72
|
-
actionpack (= 3.1.0
|
73
|
-
activerecord (= 3.1.0
|
74
|
-
activeresource (= 3.1.0
|
75
|
-
activesupport (= 3.1.0
|
78
|
+
rails (3.1.0)
|
79
|
+
actionmailer (= 3.1.0)
|
80
|
+
actionpack (= 3.1.0)
|
81
|
+
activerecord (= 3.1.0)
|
82
|
+
activeresource (= 3.1.0)
|
83
|
+
activesupport (= 3.1.0)
|
76
84
|
bundler (~> 1.0)
|
77
|
-
railties (= 3.1.0
|
78
|
-
railties (3.1.0
|
79
|
-
actionpack (= 3.1.0
|
80
|
-
activesupport (= 3.1.0
|
85
|
+
railties (= 3.1.0)
|
86
|
+
railties (3.1.0)
|
87
|
+
actionpack (= 3.1.0)
|
88
|
+
activesupport (= 3.1.0)
|
81
89
|
rack-ssl (~> 1.3.2)
|
82
90
|
rake (>= 0.8.7)
|
83
91
|
rdoc (~> 3.4)
|
84
92
|
thor (~> 0.14.6)
|
85
93
|
rake (0.9.2)
|
86
|
-
rdoc (3.9.
|
94
|
+
rdoc (3.9.4)
|
87
95
|
rspec (2.6.0)
|
88
96
|
rspec-core (~> 2.6.0)
|
89
97
|
rspec-expectations (~> 2.6.0)
|
@@ -92,12 +100,16 @@ GEM
|
|
92
100
|
rspec-expectations (2.6.0)
|
93
101
|
diff-lcs (~> 1.1.2)
|
94
102
|
rspec-mocks (2.6.0)
|
95
|
-
|
103
|
+
ruby_parser (2.2.0)
|
104
|
+
sexp_processor (~> 3.0)
|
105
|
+
sexp_processor (3.0.6)
|
106
|
+
slop (1.9.1)
|
107
|
+
sprockets (2.0.0)
|
96
108
|
hike (~> 1.2)
|
97
109
|
rack (~> 1.0)
|
98
110
|
tilt (!= 1.3.0, ~> 1.1)
|
99
111
|
thor (0.14.6)
|
100
|
-
tilt (1.3.
|
112
|
+
tilt (1.3.3)
|
101
113
|
treetop (1.4.10)
|
102
114
|
polyglot
|
103
115
|
polyglot (>= 0.3.1)
|
@@ -109,4 +121,5 @@ PLATFORMS
|
|
109
121
|
DEPENDENCIES
|
110
122
|
coffee-script
|
111
123
|
pakunok!
|
124
|
+
pry
|
112
125
|
rspec
|
data/HISTORY.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 0.0.3 - in progress
|
2
|
+
|
3
|
+
* Single include for a set of assets (asset 'common' should be included before any other that requires it).
|
4
|
+
* Reference JS using labjs, headjs, requirejs or regular script tag. Sync ot async.
|
5
|
+
* Provide a way of serving assets from CDN instead of local.
|
6
|
+
* Automatically provide set of assets that should be precomiled for the rails app.
|
7
|
+
|
1
8
|
# 0.0.2 - 19 August 2011
|
2
9
|
|
3
10
|
* Added haml-js as a new asset
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
_Pakunok_ contains a set of prepackaged assets that you can easily include into your Rails 3.1 application (using assets pipeline).
|
4
4
|
|
5
|
-
You can see all the included [assets](assets.md). (reference those prefixed with `pakunok/`):
|
5
|
+
You can see all the included [assets](pakunok/blob/master/assets.md). (reference those prefixed with `pakunok/`):
|
6
6
|
|
7
7
|
Tested on MRI Ruby 1.9.2.
|
8
8
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'pakunok'
|
2
|
+
|
3
|
+
Pakunok::Pakunok.current.configure do
|
4
|
+
# You can choose how to include the assets into the page.
|
5
|
+
# The <script> tag is used by default.
|
6
|
+
# But can be changed to use JavaScript loader API, such as LABjs
|
7
|
+
javascript_loader(:script) # one of [:script, :labjs]
|
8
|
+
|
9
|
+
## Write asset dependecies here.
|
10
|
+
## For example:
|
11
|
+
# asset('jquery.js') .replace_with :cdn => 'ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'
|
12
|
+
# asset('enhance.js') .needs('jquery.js').as_async
|
13
|
+
# asset('application.js') .needs('jquery.js')
|
14
|
+
# asset('posts.js') .needs('application.js')
|
15
|
+
# asset('blog.js') .needs('application.js')
|
16
|
+
# asset('home.js') .needs('jquery.js', 'analytics.js').embed
|
17
|
+
#
|
18
|
+
## or if you just want to set the dependencies, you can use:
|
19
|
+
# add_dependencies {
|
20
|
+
# 'enhance.js' => 'jquery.js',
|
21
|
+
# 'application.js' => 'jquery.js',
|
22
|
+
# 'posts.js' => 'application.js',
|
23
|
+
# 'blog.js' => 'application.js',
|
24
|
+
# 'home.js' => 'jquery.js'
|
25
|
+
# 'home.js' => 'analytics.js'
|
26
|
+
# }
|
27
|
+
## then you can modify the assets that are already defined in such a way:
|
28
|
+
# asset('enhance.js').as_async
|
29
|
+
# asset('home.js').embed
|
30
|
+
|
31
|
+
## The options for an asset are:
|
32
|
+
##
|
33
|
+
## .replace_with(:cdn => 'url with or without protocol')
|
34
|
+
## Will replace the asset with the given url in production environment.
|
35
|
+
## If the url include the protocol (https:// or http://) that it always be used.
|
36
|
+
## Otherwise the same protocol as request is implied.
|
37
|
+
##
|
38
|
+
## .as_async - will try to reference the script asynchronously. That means it can't rely on order of loading.
|
39
|
+
##
|
40
|
+
## .embed - embeds the asset directly into the page. Good for small assets to save on number of HTTP requests.
|
41
|
+
end
|
data/lib/pakunok.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
require 'pakunok/railtie' if defined?(::Rails)
|
2
|
+
require 'pakunok/engine' if defined?(::Rails)
|
3
|
+
|
1
4
|
module Pakunok
|
2
|
-
|
3
|
-
|
4
|
-
next unless app.config.assets.enabled
|
5
|
+
extend ActiveSupport::Autoload
|
6
|
+
autoload :Pakunok, 'pakunok/pakunok'
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
module AssetRenderers
|
9
|
+
autoload :ScriptRenderer, 'pakunok/renderers/script_renderer'
|
10
|
+
end
|
11
|
+
|
12
|
+
module Helpers
|
13
|
+
autoload :AssetsHelper, 'pakunok/helpers/assets_helper'
|
11
14
|
end
|
12
15
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Pakunok
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
initializer "pakunok.configure_rails_initialization" do |app|
|
4
|
+
next unless app.config.assets.enabled
|
5
|
+
|
6
|
+
require 'sprockets'
|
7
|
+
require 'sprockets/engines'
|
8
|
+
require 'pakunok/haml_js_template'
|
9
|
+
app.assets.register_engine '.hamljs', ::Pakunok::HamlJsTemplate
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Pakunok
|
2
|
+
module Helpers
|
3
|
+
module AssetsHelper
|
4
|
+
|
5
|
+
def pakunok_assets
|
6
|
+
::Pakunok::Pakunok.current
|
7
|
+
end
|
8
|
+
|
9
|
+
def include_javascripts(path=nil)
|
10
|
+
include_pakunok_assets :javascript, path
|
11
|
+
end
|
12
|
+
|
13
|
+
def include_stylesheets(path=nil)
|
14
|
+
include_pakunok_assets :stylesheet, path
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def include_pakunok_assets(asset_type, path=nil)
|
19
|
+
p = pakunok_assets
|
20
|
+
path = path || (
|
21
|
+
request.params[:controller] + {:javascript => '.js', :stylesheet => '.css'}[asset_type]
|
22
|
+
).to_s
|
23
|
+
|
24
|
+
@pakunok_context ||= ::Pakunok::HttpContext.new(request)
|
25
|
+
renderer = p.renderer_for(p.render_types.fetch asset_type)
|
26
|
+
renderer.render(@pakunok_context, path).html_safe
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
|
2
|
+
module Pakunok
|
3
|
+
class Pakunok
|
4
|
+
attr_accessor :render_types
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@render_types = {:javascript => :script, :stylesheet => :link}
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.current(opts=nil)
|
11
|
+
@current = nil if opts && opts[:clear]
|
12
|
+
@current ||= Pakunok.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure(&block)
|
16
|
+
self.instance_eval &block
|
17
|
+
end
|
18
|
+
|
19
|
+
def asset(path)
|
20
|
+
@managed ||= Hash.new
|
21
|
+
asset = @managed[path]
|
22
|
+
return asset if asset
|
23
|
+
asset = @managed[path] = ManagedAsset.new(self, path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_dependencies(pairs)
|
27
|
+
pairs.each_pair do |path, dependent|
|
28
|
+
asset(path).needs(dependent)
|
29
|
+
end
|
30
|
+
return self
|
31
|
+
end
|
32
|
+
|
33
|
+
def renderer_for(name)
|
34
|
+
@renderers ||= Hash.new
|
35
|
+
renderer = @renderers[name]
|
36
|
+
unless renderer
|
37
|
+
renderer = ::Pakunok::AssetRenderers.const_get(name.to_s.capitalize + 'Renderer').new(self)
|
38
|
+
@renderers[name] = renderer
|
39
|
+
end
|
40
|
+
return renderer
|
41
|
+
end
|
42
|
+
|
43
|
+
def assets
|
44
|
+
@managed
|
45
|
+
end
|
46
|
+
|
47
|
+
def all_paths
|
48
|
+
assets.keys
|
49
|
+
end
|
50
|
+
|
51
|
+
def javascript_loader(renderer_type)
|
52
|
+
@render_types[:javascript] = renderer_type
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class HttpContext
|
57
|
+
attr_accessor :request
|
58
|
+
include Sprockets::Helpers::RailsHelper
|
59
|
+
|
60
|
+
def initialize(request)
|
61
|
+
# https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/helpers/rails_helper.rb
|
62
|
+
@request = request
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class ManagedAsset
|
67
|
+
attr_accessor :path, :cdn, :async, :embedded, :dependencies
|
68
|
+
|
69
|
+
def initialize(manager, path)
|
70
|
+
@manager, @path = manager, path
|
71
|
+
@async = false
|
72
|
+
@embedded = false
|
73
|
+
@dependencies = []
|
74
|
+
end
|
75
|
+
|
76
|
+
def needs(*deps)
|
77
|
+
deps.map {|path| @manager.asset(path) }.each do |asset|
|
78
|
+
@dependencies.push asset
|
79
|
+
end
|
80
|
+
return self
|
81
|
+
end
|
82
|
+
|
83
|
+
def embed
|
84
|
+
@embedded = true
|
85
|
+
return self
|
86
|
+
end
|
87
|
+
|
88
|
+
def replace_with(options)
|
89
|
+
@cdn = options[:cdn]
|
90
|
+
return self
|
91
|
+
end
|
92
|
+
|
93
|
+
def as_async
|
94
|
+
@async = true
|
95
|
+
return self
|
96
|
+
end
|
97
|
+
|
98
|
+
def async?; @async end
|
99
|
+
def embedded?; @embedded end
|
100
|
+
|
101
|
+
|
102
|
+
def url(context)
|
103
|
+
cdn ? cdn_url(context) : asset_url(context)
|
104
|
+
end
|
105
|
+
|
106
|
+
def cdn_url(context)
|
107
|
+
if cdn.match /^https?:\/\//i
|
108
|
+
cdn
|
109
|
+
else
|
110
|
+
context.request.protocol + cdn
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def asset_url(context)
|
115
|
+
context.asset_path path
|
116
|
+
end
|
117
|
+
|
118
|
+
def depends_on
|
119
|
+
full_dependencies.map {|asset| asset.path }
|
120
|
+
end
|
121
|
+
|
122
|
+
def full_dependencies(visit_map = {})
|
123
|
+
return [] if visit_map[self]
|
124
|
+
visit_map[self] = true
|
125
|
+
@dependencies.reverse.map do |asset|
|
126
|
+
asset.full_dependencies(visit_map) + [asset]
|
127
|
+
end.flatten - [self]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Pakunok
|
2
|
+
module AssetRenderers
|
3
|
+
|
4
|
+
class ScriptRenderer
|
5
|
+
def initialize(pakunok)
|
6
|
+
@pakunok = pakunok
|
7
|
+
end
|
8
|
+
|
9
|
+
def render(context, path)
|
10
|
+
asset = @pakunok.asset(path)
|
11
|
+
parts = asset.full_dependencies.map do |dep|
|
12
|
+
render_asset(context, dep)
|
13
|
+
end + [render_asset(context, asset)]
|
14
|
+
parts.join(separator)
|
15
|
+
end
|
16
|
+
|
17
|
+
def separator
|
18
|
+
"\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
def render_asset(context, asset)
|
22
|
+
resource = context.asset_paths.asset_environment[asset.path]
|
23
|
+
raise "Asset #{asset.path} is not available in rails. Check the pakunok configuration, you could misspell something." unless resource
|
24
|
+
async_attr = asset.async? ? " async='async'" : ''
|
25
|
+
if asset.embedded?
|
26
|
+
"<script type='text/javascript'#{async_attr}>\n" +
|
27
|
+
resource.to_s +
|
28
|
+
"\n</script>"
|
29
|
+
else
|
30
|
+
"<script type='text/javascript' src='#{asset.url(context)}'#{async_attr}></script>"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/pakunok/version.rb
CHANGED
data/pakunok.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.rubyforge_project = "pakunok"
|
15
15
|
|
16
|
-
s.add_dependency 'rails', '>= 3.1.0
|
17
|
-
s.add_dependency 'sprockets', '>= 2.0.0
|
16
|
+
s.add_dependency 'rails', '>= 3.1.0'
|
17
|
+
s.add_dependency 'sprockets', '>= 2.0.0'
|
18
18
|
s.add_dependency 'execjs'
|
19
19
|
s.add_development_dependency 'rspec'
|
20
20
|
|
@@ -2,13 +2,15 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>Dummy</title>
|
5
|
-
<%= stylesheet_link_tag "application" %>
|
6
|
-
<%= javascript_include_tag "application" %>
|
5
|
+
<!-- <%= stylesheet_link_tag "application" %> -->
|
6
|
+
<!-- <%= javascript_include_tag "application" %> -->
|
7
7
|
<%= csrf_meta_tags %>
|
8
8
|
</head>
|
9
9
|
<body>
|
10
10
|
|
11
11
|
<%= yield %>
|
12
12
|
|
13
|
+
<%= include_javascripts %>
|
14
|
+
|
13
15
|
</body>
|
14
16
|
</html>
|
@@ -1,14 +1,13 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
|
-
|
4
|
-
require "action_controller/railtie"
|
5
|
-
require "action_mailer/railtie"
|
6
|
-
require "active_resource/railtie"
|
7
|
-
require "rails/test_unit/railtie"
|
8
|
-
require 'sprockets/railtie'
|
3
|
+
require 'rails/all'
|
9
4
|
|
10
|
-
Bundler
|
11
|
-
|
5
|
+
if defined?(Bundler)
|
6
|
+
# If you precompile assets before deploying to production, use this line
|
7
|
+
Bundler.require *Rails.groups(:assets => %w(development test))
|
8
|
+
# If you want your assets lazily compiled in production, use this line
|
9
|
+
# Bundler.require(:default, :assets, Rails.env)
|
10
|
+
end
|
12
11
|
|
13
12
|
module Dummy
|
14
13
|
class Application < Rails::Application
|
@@ -42,6 +41,8 @@ module Dummy
|
|
42
41
|
|
43
42
|
# Enable the asset pipeline
|
44
43
|
config.assets.enabled = true
|
44
|
+
|
45
|
+
# Version of your assets, change this if you want to expire all your assets
|
46
|
+
config.assets.version = '1.0'
|
45
47
|
end
|
46
48
|
end
|
47
|
-
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
require 'bundler'
|
7
|
-
Bundler.setup
|
8
|
-
end
|
3
|
+
# Set up gems listed in the Gemfile.
|
4
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
9
5
|
|
10
|
-
|
6
|
+
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
@@ -14,9 +14,18 @@ Dummy::Application.configure do
|
|
14
14
|
# Compress JavaScripts and CSS
|
15
15
|
config.assets.compress = true
|
16
16
|
|
17
|
+
# Don't fallback to assets pipeline if a precompiled asset is missed
|
18
|
+
config.assets.compile = false
|
19
|
+
|
20
|
+
# Generate digests for assets URLs
|
21
|
+
config.assets.digest = true
|
22
|
+
|
23
|
+
# Defaults to Rails.root.join("public/assets")
|
24
|
+
# config.assets.manifest = YOUR_PATH
|
25
|
+
|
17
26
|
# Specifies the header that your server uses for sending files
|
18
|
-
#
|
19
|
-
config.action_dispatch.x_sendfile_header =
|
27
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
28
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
20
29
|
|
21
30
|
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
22
31
|
# config.force_ssl = true
|
@@ -36,4 +36,7 @@ Dummy::Application.configure do
|
|
36
36
|
|
37
37
|
# Print deprecation notices to the stderr
|
38
38
|
config.active_support.deprecation = :stderr
|
39
|
+
|
40
|
+
# Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
|
41
|
+
config.assets.allow_debugging = true
|
39
42
|
end
|
@@ -4,9 +4,11 @@
|
|
4
4
|
# is enabled by default.
|
5
5
|
|
6
6
|
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
-
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json]
|
9
|
+
end
|
8
10
|
|
9
11
|
# Disable root element in JSON by default.
|
10
|
-
|
11
|
-
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
self.include_root_in_json = false
|
12
14
|
end
|
File without changes
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pakunok'
|
3
|
+
|
4
|
+
describe Pakunok::Pakunok do
|
5
|
+
|
6
|
+
subject { Pakunok::Pakunok.new }
|
7
|
+
let(:request) { mock(:request) }
|
8
|
+
let(:context) { Pakunok::HttpContext.new(request) }
|
9
|
+
|
10
|
+
it 'should have default renderer for javascript' do
|
11
|
+
subject.render_types.should == {:javascript => :script, :stylesheet => :link}
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'adding asset to configuration' do
|
15
|
+
it 'should include dependent assets' do
|
16
|
+
subject.asset('a.js').needs 'b', 'c'
|
17
|
+
subject.assets.length.should == 3
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'with CDN' do
|
21
|
+
subject.asset('a.js').replace_with :cdn => 'google.com/a.js'
|
22
|
+
subject.asset('a.js').cdn.should == 'google.com/a.js'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'as async' do
|
26
|
+
asset = subject.asset('analytics.js').as_async
|
27
|
+
asset.async.should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'dependency' do
|
31
|
+
it 'with dependency' do
|
32
|
+
subject.asset('b.js').needs('a.js').depends_on.should include 'a.js'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'with more complex dependency' do
|
36
|
+
subject.add_dependencies '2'=>'1', '3'=>'2', '5'=>'4', '6' => '2', '6' => '3'
|
37
|
+
|
38
|
+
subject.asset('2').depends_on.should == ['1']
|
39
|
+
subject.asset('3').depends_on.should == ['1', '2']
|
40
|
+
subject.asset('5').depends_on.should == ['4']
|
41
|
+
subject.asset('6').depends_on.should == ['1', '2', '3']
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'with circular dependency' do
|
45
|
+
subject.asset('a').needs('c')
|
46
|
+
subject.asset('b').needs('a')
|
47
|
+
subject.asset('c').needs('a')
|
48
|
+
|
49
|
+
subject.asset('a').depends_on.should == ['c']
|
50
|
+
subject.asset('b').depends_on.should == ['c', 'a']
|
51
|
+
subject.asset('c').depends_on.should == ['a']
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'URL generation' do
|
58
|
+
|
59
|
+
before do
|
60
|
+
request.stub(:protocol).and_return 'http://'
|
61
|
+
subject.asset('b.js').needs('a.js')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'uses asset path with no CDN' do
|
65
|
+
context.should_receive(:asset_path).with('a.js')
|
66
|
+
subject.asset('a.js').url(context)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'with CDN and no protocol' do
|
70
|
+
request.stub(:protocol).and_return 'https://'
|
71
|
+
subject.asset('a.js').replace_with :cdn => 'google.com/a.js'
|
72
|
+
subject.asset('a.js').url(context).should == 'https://google.com/a.js'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'with CDN and protocol' do
|
76
|
+
subject.asset('a.js').replace_with :cdn => 'https://google.com/a.js'
|
77
|
+
subject.asset('a.js').url(context).should == 'https://google.com/a.js'
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pakunok'
|
3
|
+
|
4
|
+
describe Pakunok::Pakunok do
|
5
|
+
subject { Pakunok::Pakunok.new }
|
6
|
+
let(:request) { mock(:request) }
|
7
|
+
let(:context) { Pakunok::HttpContext.new(request) }
|
8
|
+
before do
|
9
|
+
context.stub(:asset_path) { |path| path }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should raise if renderer doesnt exist' do
|
13
|
+
lambda { subject.renderer_for(:non_existing) }.should raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return existing renderer' do
|
17
|
+
subject.renderer_for(:script).should_not be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'renderers' do
|
21
|
+
before do
|
22
|
+
subject.asset('a').as_async
|
23
|
+
subject.asset('b').needs 'a'
|
24
|
+
subject.asset('c').needs 'b'
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'script' do
|
28
|
+
before do
|
29
|
+
emu = double(:fake_sprockets_asset)
|
30
|
+
emu.stub(:to_s).and_return "I am inline!"
|
31
|
+
context.stub_chain(:asset_paths, :asset_environment, :[]) { |path| emu }
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:renderer) { ::Pakunok::AssetRenderers::ScriptRenderer.new(subject) }
|
35
|
+
|
36
|
+
def result(path='c')
|
37
|
+
renderer.render(context, path)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should apply async' do
|
41
|
+
result.should include "async='async'"
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should render script tags' do
|
45
|
+
result.should include "<script type='text/javascript' src='a'"
|
46
|
+
result.should include "<script type='text/javascript' src='b'>"
|
47
|
+
result.should include "<script type='text/javascript' src='c'>"
|
48
|
+
result.should include "</script>"
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should embed small script' do
|
52
|
+
|
53
|
+
subject.asset('emu').needs('a').embed()
|
54
|
+
result('emu').should include "I am inline!"
|
55
|
+
result('emu').should include "<script"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'labjs' do
|
60
|
+
it 'should apply async'
|
61
|
+
it 'should render script tag'
|
62
|
+
it 'should embed small script'
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pakunok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,34 +9,34 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-09-03 00:00:00.000000000 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
|
-
requirement: &
|
17
|
+
requirement: &12564440 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 3.1.0
|
22
|
+
version: 3.1.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *12564440
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: sprockets
|
28
|
-
requirement: &
|
28
|
+
requirement: &12563840 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.0.0
|
33
|
+
version: 2.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *12563840
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: execjs
|
39
|
-
requirement: &
|
39
|
+
requirement: &12563440 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *12563440
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &12562960 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *12562960
|
59
59
|
description: Pakunok has a set of prepackaged assets that you can easily include into
|
60
60
|
your Rails 3.1 application (using assets pipeline).
|
61
61
|
email:
|
@@ -72,8 +72,15 @@ files:
|
|
72
72
|
- README.md
|
73
73
|
- Rakefile
|
74
74
|
- assets.md
|
75
|
+
- lib/generators/pakunok/install/intall_generator.rb
|
76
|
+
- lib/generators/templates/pakunok.rb
|
75
77
|
- lib/pakunok.rb
|
78
|
+
- lib/pakunok/engine.rb
|
76
79
|
- lib/pakunok/haml_js_template.rb
|
80
|
+
- lib/pakunok/helpers/assets_helper.rb
|
81
|
+
- lib/pakunok/pakunok.rb
|
82
|
+
- lib/pakunok/railtie.rb
|
83
|
+
- lib/pakunok/renderers/script_renderer.rb
|
77
84
|
- lib/pakunok/version.rb
|
78
85
|
- lib/tasks/pakunok_tasks.rake
|
79
86
|
- pakunok.gemspec
|
@@ -107,6 +114,7 @@ files:
|
|
107
114
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
108
115
|
- spec/dummy/config/initializers/inflections.rb
|
109
116
|
- spec/dummy/config/initializers/mime_types.rb
|
117
|
+
- spec/dummy/config/initializers/pakunok.rb
|
110
118
|
- spec/dummy/config/initializers/secret_token.rb
|
111
119
|
- spec/dummy/config/initializers/session_store.rb
|
112
120
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
@@ -120,7 +128,9 @@ files:
|
|
120
128
|
- spec/dummy/public/favicon.ico
|
121
129
|
- spec/dummy/script/rails
|
122
130
|
- spec/fixtures/name.js.haml-js
|
123
|
-
- spec/haml_js_template_spec.rb
|
131
|
+
- spec/pakunok/haml_js_template_spec.rb
|
132
|
+
- spec/pakunok/pakunok_spec.rb
|
133
|
+
- spec/pakunok/renderers_spec.rb
|
124
134
|
- spec/spec_helper.rb
|
125
135
|
- spec/support/global.rb
|
126
136
|
- spec/support/matchers.rb
|
@@ -297,7 +307,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
297
307
|
version: '0'
|
298
308
|
segments:
|
299
309
|
- 0
|
300
|
-
hash:
|
310
|
+
hash: 3095464147754073608
|
301
311
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
302
312
|
none: false
|
303
313
|
requirements:
|
@@ -306,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
306
316
|
version: '0'
|
307
317
|
segments:
|
308
318
|
- 0
|
309
|
-
hash:
|
319
|
+
hash: 3095464147754073608
|
310
320
|
requirements: []
|
311
321
|
rubyforge_project: pakunok
|
312
322
|
rubygems_version: 1.6.2
|