cdn_tags 0.3.2 → 0.4.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 +4 -4
- data/README.md +22 -2
- data/lib/cdn_tags.rb +1 -1
- data/lib/cdn_tags/configuration.rb +11 -1
- data/lib/cdn_tags/helpers.rb +1 -1
- data/lib/cdn_tags/version.rb +1 -1
- data/lib/generators/cdn_tags/install/templates/cdn_tags.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67f7daf2bf064f0a887c3b481cc30a20d8dc7fa9
|
4
|
+
data.tar.gz: cffa665ffa5e7020168ca31b53435fec4a164559
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e56816a2739f7a11642400e432eea2bbf10925e877cecf0808e61edf60697c2249ddb106055fda3756056924b19139683be7c76aa689f8f534d8b95946651d0
|
7
|
+
data.tar.gz: 9a83451dda24f3ca1b72953f793ac3299378af29404b8a0ce99e09058da3f048b476e4e55907188dc01ee07e3de7da9daa2491020b61c8151d1256dbc859ae8c
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# CdnTags
|
1
|
+
# CdnTags [![Build Status][travis-img]][travis-link] [![Coverage Status][coveralls-img]][coveralls-link]
|
2
|
+
|
2
3
|
|
3
4
|
Using a CDN in development is kind of painful when the
|
4
5
|
network is unstable, however in production common libraries
|
@@ -13,7 +14,12 @@ Add
|
|
13
14
|
gem 'cdn_tags'
|
14
15
|
```
|
15
16
|
|
16
|
-
to your Gemfile
|
17
|
+
to your Gemfile and run
|
18
|
+
|
19
|
+
```
|
20
|
+
bundle install
|
21
|
+
```
|
22
|
+
|
17
23
|
|
18
24
|
## Configuration
|
19
25
|
|
@@ -40,6 +46,14 @@ end
|
|
40
46
|
This will automatically add the files to `Rails.application.config.assets.precompile`. If you want to disable this behavior, you can set
|
41
47
|
`add_to_precompile` to `false` in the configuration.
|
42
48
|
|
49
|
+
### Configuration items
|
50
|
+
|
51
|
+
* `scripts_urls` (`Hash`, default: `{}`): The scripts that should be served from a CDN.
|
52
|
+
* `stylesheets_urls` (`Hash`, default: `{}`): The stylesheets that should be served from a CDN.
|
53
|
+
* `add_to_precompile` (`true`|`false`, default: `true`): Automatically add scripts to `Rails.application.config.assets` or not.
|
54
|
+
* `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
|
+
* `cdn_environments` (`Array`, default: `[:production]`): The environments in which CDN should be used instead of normal asset.
|
56
|
+
|
43
57
|
## Usage
|
44
58
|
|
45
59
|
Just replace `javascript_include_tag` and `stylesheet_link_tag`
|
@@ -72,3 +86,9 @@ This will result in the following HTML output.
|
|
72
86
|
```html
|
73
87
|
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
|
74
88
|
```
|
89
|
+
|
90
|
+
|
91
|
+
[travis-link]: https://travis-ci.org/claude-tech/cdn-tags-rails
|
92
|
+
[travis-img]: https://travis-ci.org/claude-tech/cdn-tags-rails.svg?branch=master
|
93
|
+
[coveralls-link]: https://coveralls.io/r/claude-tech/cdn-tags-rails?branch=master
|
94
|
+
[coveralls-img]: https://img.shields.io/coveralls/claude-tech/cdn-tags-rails.svg
|
data/lib/cdn_tags.rb
CHANGED
@@ -3,7 +3,7 @@ require 'rails'
|
|
3
3
|
module CdnTags
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :scripts_urls, :stylesheets_urls, :environment
|
6
|
-
attr_accessor :raise_on_missing, :add_to_precompile
|
6
|
+
attr_accessor :raise_on_missing, :add_to_precompile, :cdn_environments
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
self.scripts_urls = {}
|
@@ -11,6 +11,16 @@ module CdnTags
|
|
11
11
|
self.environment = Rails.env
|
12
12
|
self.raise_on_missing = false
|
13
13
|
self.add_to_precompile = true
|
14
|
+
self.cdn_environments = [:production]
|
15
|
+
end
|
16
|
+
|
17
|
+
def post_configure_hooks
|
18
|
+
self.update_rails_precompile!
|
19
|
+
self.fix_cdn_environments_keys!
|
20
|
+
end
|
21
|
+
|
22
|
+
def fix_cdn_environments_keys!
|
23
|
+
self.cdn_environments.map! { |s| s.to_sym }
|
14
24
|
end
|
15
25
|
|
16
26
|
def update_rails_precompile!
|
data/lib/cdn_tags/helpers.rb
CHANGED
@@ -17,7 +17,7 @@ module CdnTags
|
|
17
17
|
|
18
18
|
def self.map_sources(sources, config_key)
|
19
19
|
config = CdnTags.configuration
|
20
|
-
return sources unless config.environment.to_sym
|
20
|
+
return sources unless config.cdn_environments.include? config.environment.to_sym
|
21
21
|
sources.map do |s|
|
22
22
|
src = config.send(config_key)[s]
|
23
23
|
if src.nil?
|
data/lib/cdn_tags/version.rb
CHANGED
@@ -16,4 +16,9 @@ CdnTags.configure do |c|
|
|
16
16
|
# Set to false to avoid adding the above assets
|
17
17
|
# to Rails.config.assets.precompile automatically
|
18
18
|
# c.add_to_precompile = true
|
19
|
+
|
20
|
+
|
21
|
+
# Modify this array to set in which environments
|
22
|
+
# should CDN be used
|
23
|
+
# c.cdn_environments = [:production]
|
19
24
|
end
|