cdn_tags 0.1.1 → 0.2.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/lib/cdn_tags/configuration.rb +13 -2
- data/lib/cdn_tags/helpers.rb +4 -4
- data/lib/cdn_tags/version.rb +1 -1
- data/lib/cdn_tags.rb +1 -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: 7882463fd9f4b646d015a8c558bdecb8bd2ca188
|
4
|
+
data.tar.gz: 3c840551c8eaec7d476e88e58ad16170afbd03dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b95d17ef764ecc8428fd3d4d7aba035e7fce3f473a1f1b5acb4b4e61b42d150f2fa9e0e389a295abe8eebd60876f4de3169dc24eacc78c7387cb7ad5e6ddd940
|
7
|
+
data.tar.gz: 4c3423b373f0c1b554dd77ab8bf6e5a7498f9580e77cd46f2a3a6e168954e8762f5eefef5e017c3a4c21de0497b77589ed777be2adac6daca7b15e05a2b30629
|
@@ -2,12 +2,23 @@ require 'rails'
|
|
2
2
|
|
3
3
|
module CdnTags
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :scripts_urls, :stylesheets_urls, :environment
|
6
|
+
attr_accessor :raise_on_missing, :add_to_precompile
|
6
7
|
|
7
8
|
def initialize
|
8
|
-
self.
|
9
|
+
self.scripts_urls = {}
|
10
|
+
self.stylesheets_urls = {}
|
9
11
|
self.environment = Rails.env
|
10
12
|
self.raise_on_missing = false
|
13
|
+
self.add_to_precompile = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_rails_precompile!
|
17
|
+
return unless self.add_to_precompile
|
18
|
+
scripts_precompile = self.scripts_urls.keys.map { |s| File.extname(s) == '' ? "#{s}.js" : s }
|
19
|
+
stylesheets_precompile = self.stylesheets_urls.keys.map { |s| File.extname(s) == '' ? "#{s}.css" : s }
|
20
|
+
added_precompile = scripts_precompile + stylesheets_precompile
|
21
|
+
Rails.application.config.assets.precompile += added_precompile
|
11
22
|
end
|
12
23
|
end
|
13
24
|
end
|
data/lib/cdn_tags/helpers.rb
CHANGED
@@ -4,22 +4,22 @@ module CdnTags
|
|
4
4
|
module Helpers
|
5
5
|
def javascript_cdn_include_tag(*sources)
|
6
6
|
options = sources.extract_options!
|
7
|
-
mapped_sources = CdnTags.map_sources(sources)
|
7
|
+
mapped_sources = CdnTags.map_sources(sources, :scripts_urls)
|
8
8
|
javascript_include_tag *mapped_sources, options
|
9
9
|
end
|
10
10
|
|
11
11
|
def stylesheet_cdn_link_tag(*sources)
|
12
12
|
options = sources.extract_options!
|
13
|
-
mapped_sources = CdnTags.map_sources(sources)
|
13
|
+
mapped_sources = CdnTags.map_sources(sources, :stylesheets_urls)
|
14
14
|
stylesheet_link_tag *mapped_sources, options
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.map_sources(sources)
|
18
|
+
def self.map_sources(sources, config_key)
|
19
19
|
config = CdnTags.configuration
|
20
20
|
return sources unless config.environment.to_sym == :production
|
21
21
|
sources.map do |s|
|
22
|
-
src = config.
|
22
|
+
src = config.send(config_key)[s]
|
23
23
|
if src.nil?
|
24
24
|
raise CdnTags::Error.new(config), "#{s} is not defined. Check CdnTags configuration." if config.raise_on_missing
|
25
25
|
s
|
data/lib/cdn_tags/version.rb
CHANGED
data/lib/cdn_tags.rb
CHANGED