cdn_tags 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -7
- data/lib/cdn_tags/configuration.rb +16 -4
- data/lib/cdn_tags/helpers.rb +7 -3
- data/lib/cdn_tags/version.rb +1 -1
- data/lib/generators/cdn_tags/install/templates/cdn_tags.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73a78cc8439f3f719dbf7513947fa607821f6154
|
4
|
+
data.tar.gz: 9b2b85b79bcef5fbc000db6c13e7fd81790b7dfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 972d450fab00f6a2a523cd72239f4678b88ea1c9baf39547f804eb2edbe10938c94241bbed1a2b7593d729d103f71ebd1840f1440c795403b12ad16fc9c32683
|
7
|
+
data.tar.gz: c93f9f83af1403ca4ce30fd90f23097652a21273a6f513d01ee4055176303e6ce80eeb14bb2ccea04a32f03988ada004e434a19c2c0de148390fbc36bfe9fda4
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# CdnTags [![Build Status][travis-img]][travis-link] [![Coverage Status][coveralls-img]][coveralls-link] [![Gem Version][gem-img]][gem-link]
|
1
|
+
# CdnTags [![Build Status][travis-img]][travis-link] [![Coverage Status][coveralls-img]][coveralls-link] [![Code Climate][code-climate-img]][code-climate-link] [![Gem Version][gem-img]][gem-link]
|
2
2
|
|
3
3
|
|
4
4
|
Using a CDN in development is kind of painful when the
|
@@ -52,8 +52,8 @@ This will automatically add the files to `Rails.application.config.assets.precom
|
|
52
52
|
|
53
53
|
* `scripts_urls` (`Hash`, default: `{}`): The scripts that should be served from a CDN.
|
54
54
|
* `stylesheets_urls` (`Hash`, default: `{}`): The stylesheets that should be served from a CDN.
|
55
|
-
* `add_to_precompile` (`true`|`false`, default: `true`): Automatically add
|
56
|
-
* `raise_on_missing` (`true`|`false`, default: `false`): Raise an exception or not if the asset used with CDN helper is not defined in `scripts_urls` or `stylesheets_urls`.
|
55
|
+
* `add_to_precompile` (`true`|`false`, default: `true`): Automatically add assets to `Rails.application.config.assets` or not.
|
56
|
+
* `raise_on_missing` (`true`|`false`|`Array`, default: `false`): Raise an exception or not if the asset used with CDN helper is not defined in `scripts_urls` or `stylesheets_urls`. If an array is given, an exception will be set if the current environment is in this array.
|
57
57
|
* `cdn_environments` (`Array`, default: `[:production]`): The environments in which CDN should be used instead of normal asset.
|
58
58
|
|
59
59
|
## Usage
|
@@ -90,9 +90,11 @@ This will result in the following HTML output.
|
|
90
90
|
```
|
91
91
|
|
92
92
|
|
93
|
-
[travis-link]: https://travis-ci.org/
|
94
|
-
[travis-img]: https://travis-ci.org/
|
95
|
-
[coveralls-link]: https://coveralls.io/r/
|
96
|
-
[coveralls-img]: https://img.shields.io/coveralls/
|
93
|
+
[travis-link]: https://travis-ci.org/claudetech/cdn-tags-rails
|
94
|
+
[travis-img]: https://travis-ci.org/claudetech/cdn-tags-rails.svg?branch=master
|
95
|
+
[coveralls-link]: https://coveralls.io/r/claudetech/cdn-tags-rails?branch=master
|
96
|
+
[coveralls-img]: https://img.shields.io/coveralls/claudetech/cdn-tags-rails.svg
|
97
97
|
[gem-link]: http://badge.fury.io/rb/cdn_tags
|
98
98
|
[gem-img]: https://badge.fury.io/rb/cdn_tags.svg
|
99
|
+
[code-climate-img]: https://codeclimate.com/github/claudetech/cdn-tags-rails.png
|
100
|
+
[code-climate-link]: https://codeclimate.com/github/claudetech/cdn-tags-rails
|
@@ -4,6 +4,7 @@ module CdnTags
|
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :scripts_urls, :stylesheets_urls, :environment
|
6
6
|
attr_accessor :raise_on_missing, :add_to_precompile, :cdn_environments
|
7
|
+
attr_reader :should_raise
|
7
8
|
|
8
9
|
def initialize
|
9
10
|
self.scripts_urls = {}
|
@@ -15,12 +16,24 @@ module CdnTags
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def post_configure_hooks
|
18
|
-
|
19
|
-
|
19
|
+
update_rails_precompile!
|
20
|
+
fix_keys!
|
21
|
+
set_should_raise!
|
20
22
|
end
|
21
23
|
|
22
|
-
|
24
|
+
private
|
25
|
+
def set_should_raise!
|
26
|
+
if self.raise_on_missing == !!self.raise_on_missing
|
27
|
+
@should_raise = self.raise_on_missing
|
28
|
+
else
|
29
|
+
self.raise_on_missing.map! { |s| s.to_sym }
|
30
|
+
@should_raise = self.raise_on_missing.include? self.environment
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def fix_keys!
|
23
35
|
self.cdn_environments.map! { |s| s.to_sym }
|
36
|
+
self.environment = self.environment.to_sym
|
24
37
|
end
|
25
38
|
|
26
39
|
def update_rails_precompile!
|
@@ -31,7 +44,6 @@ module CdnTags
|
|
31
44
|
Rails.application.config.assets.precompile += added_precompile
|
32
45
|
end
|
33
46
|
|
34
|
-
private
|
35
47
|
def should_append_extension(filename)
|
36
48
|
extname = File.extname(filename)
|
37
49
|
extname.empty? or /[0-9]+/.match extname[1..-1]
|
data/lib/cdn_tags/helpers.rb
CHANGED
@@ -17,15 +17,19 @@ module CdnTags
|
|
17
17
|
|
18
18
|
def self.map_sources(sources, config_key)
|
19
19
|
config = CdnTags.configuration
|
20
|
-
|
20
|
+
do_replace = config.cdn_environments.include? config.environment.to_sym
|
21
|
+
return sources unless do_replace || config.should_raise
|
21
22
|
sources.map do |s|
|
22
23
|
src = config.send(config_key)[s]
|
23
24
|
if src.nil?
|
24
|
-
raise CdnTags::Error.new(config), "#{s} is not defined. Check CdnTags configuration." if config.
|
25
|
+
raise CdnTags::Error.new(config), "#{s} is not defined. Check CdnTags configuration." if config.should_raise
|
25
26
|
s
|
26
27
|
else
|
27
|
-
src
|
28
|
+
do_replace ? src : s
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
32
|
+
|
33
|
+
def maybe_raise(src, config_key)
|
34
|
+
end
|
31
35
|
end
|
data/lib/cdn_tags/version.rb
CHANGED
@@ -10,7 +10,10 @@ CdnTags.configure do |c|
|
|
10
10
|
}
|
11
11
|
|
12
12
|
# Set to true to raise an exception if the demanded
|
13
|
-
# asset is not defined above
|
13
|
+
# asset is not defined above. The following values are possible.
|
14
|
+
# true: will always raise when not found
|
15
|
+
# false: will never raise
|
16
|
+
# Array: will raise if the current environment is in this array
|
14
17
|
# c.raise_on_missing = false
|
15
18
|
|
16
19
|
# Set to false to avoid adding the above assets
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdn_tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Perez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|