rails-controller-assets 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9452403711cb6d8ffc66a15db1210f8f5bc525b3
|
4
|
+
data.tar.gz: 058f82160f7779f2da7aa3d053354268b7380be3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ed72890133d880c171b8f81ea0b2647423559ceafa77925cbbe6cdf2bc25252ddfd286270749e5e882ad82481408cc74a326c6018fbe2db3c20646651699dcf
|
7
|
+
data.tar.gz: 2a482402421fc1ae9d17dab7aa516cbc1cbc159f3b6075b9cb8c5c1e302d5d7df3ad49594d2314a1a12ea24f51bdd1b8b517bc145922aa38a7b7afdf5aa5548c
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# RailsControllerAssets
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/pusewicz/rails-controller-assets.png?branch=master)](https://travis-ci.org/pusewicz/rails-controller-assets)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/pusewicz/rails-controller-assets.png)](https://codeclimate.com/github/pusewicz/rails-controller-assets)
|
5
|
+
|
3
6
|
This gems allows to automatically precompile bundles of assets per controller or controller/action pair.
|
4
7
|
|
5
8
|
It's great when you want to keep action or controller specific CSS/JavaScript in a separate file.
|
@@ -33,3 +36,7 @@ The gem will look for bundle files that match:
|
|
33
36
|
|
34
37
|
* `{controller_name}.{js|css}`
|
35
38
|
* `{controller_name}_{action_name}.{js|css}`
|
39
|
+
|
40
|
+
|
41
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/pusewicz/rails-controller-assets/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
42
|
+
|
@@ -1,71 +1,73 @@
|
|
1
|
-
module RailsControllerAssets
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module RailsControllerAssets
|
2
|
+
module ControllerAssetsHelper
|
3
|
+
def controller_stylesheets
|
4
|
+
styles = []
|
5
|
+
styles << controller_stylesheet if controller_stylesheet?
|
6
|
+
styles << controller_and_action_stylesheet if controller_and_action_stylesheet?
|
7
|
+
styles
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def controller_and_action
|
11
|
+
[controller_path, action_name].join('_')
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def controller_stylesheet?
|
15
|
+
controller_asset?(:css)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def controller_and_action_stylesheet?
|
19
|
+
controller_and_action_asset?(:css)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def controller_javascripts
|
23
|
+
scripts = []
|
24
|
+
scripts << controller_javascript if controller_javascript?
|
25
|
+
scripts << controller_and_action_javascript if controller_and_action_javascript?
|
26
|
+
scripts
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def controller_javascript?
|
30
|
+
controller_asset?(:js)
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def controller_and_action_javascript?
|
34
|
+
controller_and_action_asset?(:js)
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def controller_asset?(type)
|
38
|
+
Rails.application.assets.find_asset(controller_asset(type))
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
def controller_and_action_asset?(type)
|
42
|
+
Rails.application.assets.find_asset(controller_and_action_asset(type))
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def controller_asset(type)
|
46
|
+
"#{controller_path}.#{type}"
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def controller_and_action_asset(type)
|
50
|
+
"#{controller_and_action}.#{type}"
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
def controller_javascript
|
54
|
+
controller_asset(:js)
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
def controller_and_action_javascript
|
58
|
+
controller_and_action_asset(:js)
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
def controller_stylesheet
|
62
|
+
controller_asset(:css)
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
def controller_and_action_stylesheet
|
66
|
+
controller_and_action_asset(:css)
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
69
|
+
def skip_controller_stylesheet!
|
70
|
+
stylesheet_bundles.delete(controller_stylesheet)
|
71
|
+
end
|
70
72
|
end
|
71
73
|
end
|
@@ -1,63 +1,65 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module RailsControllerAssets
|
2
|
+
class Precompiler
|
3
|
+
def call(asset, filename)
|
4
|
+
return false unless filename =~ /\/app\/assets/
|
5
|
+
if include?(asset)
|
6
|
+
puts "Including #{asset}"
|
7
|
+
true
|
8
|
+
else
|
9
|
+
false
|
10
|
+
end
|
9
11
|
end
|
10
|
-
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def arity
|
14
|
+
2
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
+
protected
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def controller_paths
|
20
|
+
@controller_paths ||= find_controller_paths
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def controller_actions
|
24
|
+
@controller_actions ||= find_controller_actions
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def include?(asset)
|
28
|
+
return false unless asset =~ /\.(css|js)\z/
|
29
|
+
return false if partial?(asset)
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
controller_asset?(asset) || action_asset?(asset)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def partial?(asset)
|
35
|
+
asset.split('/').last.start_with?('_')
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
def controller_asset?(asset)
|
39
|
+
controller_paths.any? { |path| asset.include?(path) }
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
def action_asset?(asset)
|
43
|
+
controller_actions.any? { |action| asset.include?(action) }
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
def controllers
|
47
|
+
@eager_load ||= Rails.application.eager_load!
|
48
|
+
@controllers ||= ::ActionController::Base.descendants
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
def find_controller_actions
|
52
|
+
controllers.map do |controller|
|
53
|
+
controller.action_methods.map do |action|
|
54
|
+
"#{controller.controller_path}_#{action}"
|
55
|
+
end
|
56
|
+
end.flatten
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def find_controller_paths
|
60
|
+
controllers.map do |controller|
|
61
|
+
controller.controller_path
|
62
|
+
end
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-controller-assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Usewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|