cdn_tags 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbf4ad61b09272ead59aa0b4d7b71aefbae87a6d
4
- data.tar.gz: a3ce877867f60e631293000fb46983db3da948f9
3
+ metadata.gz: 73a78cc8439f3f719dbf7513947fa607821f6154
4
+ data.tar.gz: 9b2b85b79bcef5fbc000db6c13e7fd81790b7dfd
5
5
  SHA512:
6
- metadata.gz: 0e8d322896d9ccc9234824be49d28a6e0b377929083dcb1e0273d0bfcd324fdcd006e9e7a844d4d0936bac162fbb796044b747c72ae9288730ad1e0be10e32f2
7
- data.tar.gz: 0749e24c0d8fc96505762dd782553480ed34d80b229630473f103604e03b254cbd7d4efca8f62291a242c8f2f5ef1e2fc1e56777ba88c32234667aa9fc928089
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 scripts to `Rails.application.config.assets` or not.
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/claude-tech/cdn-tags-rails
94
- [travis-img]: https://travis-ci.org/claude-tech/cdn-tags-rails.svg?branch=master
95
- [coveralls-link]: https://coveralls.io/r/claude-tech/cdn-tags-rails?branch=master
96
- [coveralls-img]: https://img.shields.io/coveralls/claude-tech/cdn-tags-rails.svg
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
- self.update_rails_precompile!
19
- self.fix_cdn_environments_keys!
19
+ update_rails_precompile!
20
+ fix_keys!
21
+ set_should_raise!
20
22
  end
21
23
 
22
- def fix_cdn_environments_keys!
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]
@@ -17,15 +17,19 @@ module CdnTags
17
17
 
18
18
  def self.map_sources(sources, config_key)
19
19
  config = CdnTags.configuration
20
- return sources unless config.cdn_environments.include? config.environment.to_sym
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.raise_on_missing
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
@@ -1,3 +1,3 @@
1
1
  module CdnTags
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -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.1
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-26 00:00:00.000000000 Z
11
+ date: 2014-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec