cdn_tags 0.2.1 → 0.2.2
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/LICENSE +20 -0
- data/README.md +53 -0
- data/lib/cdn_tags/version.rb +1 -1
- data/lib/generators/initializer_geenrator.rb +7 -0
- data/lib/generators/templates/cdn_tags.rb +19 -0
- data/specs/cdn_tags_spec.rb +118 -0
- data/specs/spec_helper.rb +15 -0
- metadata +11 -18
- data/lib/tasks/cdn_tags_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f16dcecb7ea4d331c0a0ccad04f682f83b5e1908
|
4
|
+
data.tar.gz: dfede84d60cd1dd5e689661de92c9b940bb8d9dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f87e288f2dbff52e0206d276a12616aeef19112985367755e43a8b93f4d6a77abc43c593be41c1070dfe63250f2a0668200904e12dd8f05157fadf2ab564351
|
7
|
+
data.tar.gz: 9b9f020514e4864235662dc973b16996b2744590f87a7dd76f4820c3cb1229a73341a8a2f8ef453880c7cbc1e8c334c0ba8053351c86de3341de81ce81389fa6
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 Claude Tech
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# CdnTags
|
2
|
+
|
3
|
+
Using a CDN in development is kind of painful when the
|
4
|
+
network is unstable, however in production common libraries
|
5
|
+
should generally be served via a CDN.
|
6
|
+
This gem helps to automatize this process.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add
|
11
|
+
|
12
|
+
```
|
13
|
+
gem 'cdn_tags'
|
14
|
+
```
|
15
|
+
|
16
|
+
to your Gemfile.
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
Create config/initializers/cdn_tags.rb and configure your assets.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
CdnTags.configure do |c|
|
24
|
+
c.scripts_urls = {
|
25
|
+
'/path/to/jquery' => '//code.jquery.com/jquery-2.1.1.min.js',
|
26
|
+
}
|
27
|
+
c.stylesheets_urls = {
|
28
|
+
'/path/to/bootstrap' => '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
This will automatically add the files to `Rails.application.config.assets.precompile`. If you want to disable this behavior, you can set
|
34
|
+
`add_to_precompile` to `false` in the configuration.
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
Just replace `javascript_include_tag` and `stylesheet_link_tag`
|
39
|
+
by `javascript_cdn_include_tag` and `stylesheet_cdn_link_tag`.
|
40
|
+
|
41
|
+
For example,
|
42
|
+
|
43
|
+
```erb
|
44
|
+
<%= javascript_include_tag '/path/to/jquery' %>
|
45
|
+
<%= stylesheet_link_tag '/path/to/bootstrap' %>
|
46
|
+
```
|
47
|
+
|
48
|
+
becomes
|
49
|
+
|
50
|
+
```erb
|
51
|
+
<%= javascript_cdn_include_tag '/path/to/jquery' %>
|
52
|
+
<%= stylesheet_cdn_link_tag '/path/to/bootstrap' %>
|
53
|
+
```
|
data/lib/cdn_tags/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
CdnTags.configure do |c|
|
2
|
+
# Add scripts using CDN here
|
3
|
+
c.scripts_urls = {
|
4
|
+
# 'jquery-1.9.1' => 'http://code.jquery.com/jquery-1.9.1.js'
|
5
|
+
}
|
6
|
+
|
7
|
+
# Add stylesheets using CDN here
|
8
|
+
c.stylesheets_urls = {
|
9
|
+
# 'bootstrap' => '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'
|
10
|
+
}
|
11
|
+
|
12
|
+
# Set to true to raise an exception if the demanded
|
13
|
+
# asset is not defined above
|
14
|
+
# c.raise_on_missing = false
|
15
|
+
|
16
|
+
# Set to false to avoid adding the above assets
|
17
|
+
# to Rails.config.assets.precompile automatically
|
18
|
+
# c.add_to_precompile = true
|
19
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
require 'cdn_tags'
|
3
|
+
|
4
|
+
def script_src(html)
|
5
|
+
doc = Nokogiri::HTML(html)
|
6
|
+
doc.xpath('//script')[0].attr('src')
|
7
|
+
end
|
8
|
+
|
9
|
+
def link_href(html)
|
10
|
+
doc = Nokogiri::HTML(html)
|
11
|
+
doc.xpath('//link')[0].attr('href')
|
12
|
+
end
|
13
|
+
|
14
|
+
describe CdnTags do
|
15
|
+
describe CdnTags::Configuration do
|
16
|
+
it 'should have default values' do
|
17
|
+
expect(CdnTags.configuration.stylesheets_urls).to eq({})
|
18
|
+
expect(CdnTags.configuration.scripts_urls).to eq({})
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should bet settable' do
|
22
|
+
CdnTags.configure do |c|
|
23
|
+
c.scripts_urls["foo"] = "bar"
|
24
|
+
end
|
25
|
+
expect(CdnTags.configuration.scripts_urls["foo"]).to eq("bar")
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should update Rails assets precompile' do
|
29
|
+
expect(Rails.application.config.assets.precompile).not_to include('jquery-1.9.1.js')
|
30
|
+
expect(Rails.application.config.assets.precompile).not_to include('bootstrap.css')
|
31
|
+
CdnTags.configure do |c|
|
32
|
+
c.scripts_urls["jquery-1.9.1"] = "foobar"
|
33
|
+
c.stylesheets_urls["bootstrap"] = "foobar"
|
34
|
+
end
|
35
|
+
expect(Rails.application.config.assets.precompile).to include('jquery-1.9.1.js')
|
36
|
+
expect(Rails.application.config.assets.precompile).to include('bootstrap.css')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should not update Rails assets precompile if disabled' do
|
40
|
+
expect(Rails.application.config.assets.precompile).not_to include('angular.js')
|
41
|
+
CdnTags.configure do |c|
|
42
|
+
c.scripts_urls["angular"] = "foobar"
|
43
|
+
c.add_to_precompile = false
|
44
|
+
end
|
45
|
+
expect(Rails.application.config.assets.precompile).not_to include('angular.js')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe CdnTags::Helpers do
|
50
|
+
view = ActionView::Base.new
|
51
|
+
subject { view }
|
52
|
+
|
53
|
+
before(:each) do
|
54
|
+
CdnTags.configure do |c|
|
55
|
+
c.scripts_urls = {
|
56
|
+
'jquery' => '//code.jquery.com/jquery-2.1.1.min.js',
|
57
|
+
}
|
58
|
+
c.stylesheets_urls = {
|
59
|
+
'bootstrap' => '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'
|
60
|
+
}
|
61
|
+
c.raise_on_missing = false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
tests = [
|
66
|
+
{
|
67
|
+
method: 'javascript_cdn_include_tag',
|
68
|
+
path_helper: 'javascript_path',
|
69
|
+
extracter: 'script_src',
|
70
|
+
asset: 'jquery',
|
71
|
+
config_key: 'scripts_urls'
|
72
|
+
},
|
73
|
+
{
|
74
|
+
method: 'stylesheet_cdn_link_tag',
|
75
|
+
path_helper: 'stylesheet_path',
|
76
|
+
extracter: 'link_href',
|
77
|
+
asset: 'bootstrap',
|
78
|
+
config_key: 'stylesheets_urls'
|
79
|
+
}
|
80
|
+
]
|
81
|
+
|
82
|
+
tests.each do |t|
|
83
|
+
it { should respond_to(t[:method]) }
|
84
|
+
|
85
|
+
describe "##{t[:method]}" do
|
86
|
+
it 'should not replace sources in development and test envs' do
|
87
|
+
CdnTags.configuration.environment = "development"
|
88
|
+
tag = view.send(t[:method], "foo")
|
89
|
+
expected = view.send(t[:path_helper], "foo")
|
90
|
+
expect(send(t[:extracter], tag)).to eq(expected)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should replace sources in production' do
|
94
|
+
CdnTags.configuration.environment = "production"
|
95
|
+
tag = view.send(t[:method], t[:asset])
|
96
|
+
urls = CdnTags.configuration.send(t[:config_key])
|
97
|
+
expected = urls[t[:asset]]
|
98
|
+
expect(send(t[:extracter], tag)).to eq(expected)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should ignore unconfigured sources' do
|
102
|
+
CdnTags.configuration.environment = "production"
|
103
|
+
tag = view.send(t[:method], "foo")
|
104
|
+
expected = view.send(t[:path_helper], "foo")
|
105
|
+
expect(send(t[:extracter], tag)).to eq(expected)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should raise error when configured' do
|
109
|
+
CdnTags.configure do |c|
|
110
|
+
c.raise_on_missing = true
|
111
|
+
end
|
112
|
+
CdnTags.configuration.environment = "production"
|
113
|
+
expect { view.send(t[:method], "foo") }.to raise_error(CdnTags::Error)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.color = true
|
7
|
+
config.formatter = 'documentation'
|
8
|
+
end
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
11
|
+
|
12
|
+
class DummyApp < Rails::Application
|
13
|
+
end
|
14
|
+
|
15
|
+
Rails.application = DummyApp.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdn_tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Perez
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: jazz_hands
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.5'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.5'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rails
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,14 +59,19 @@ executables: []
|
|
73
59
|
extensions: []
|
74
60
|
extra_rdoc_files: []
|
75
61
|
files:
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
76
64
|
- Rakefile
|
77
65
|
- lib/cdn_tags.rb
|
78
66
|
- lib/cdn_tags/configuration.rb
|
79
67
|
- lib/cdn_tags/error.rb
|
80
68
|
- lib/cdn_tags/helpers.rb
|
81
69
|
- lib/cdn_tags/version.rb
|
82
|
-
- lib/
|
83
|
-
|
70
|
+
- lib/generators/initializer_geenrator.rb
|
71
|
+
- lib/generators/templates/cdn_tags.rb
|
72
|
+
- specs/cdn_tags_spec.rb
|
73
|
+
- specs/spec_helper.rb
|
74
|
+
homepage: https://github.com/claude-tech/cdn-tags-rails
|
84
75
|
licenses:
|
85
76
|
- MIT
|
86
77
|
metadata: {}
|
@@ -104,5 +95,7 @@ rubygems_version: 2.2.0
|
|
104
95
|
signing_key:
|
105
96
|
specification_version: 4
|
106
97
|
summary: Helpers to use CDN scripts in Rails production.
|
107
|
-
test_files:
|
98
|
+
test_files:
|
99
|
+
- specs/cdn_tags_spec.rb
|
100
|
+
- specs/spec_helper.rb
|
108
101
|
has_rdoc:
|