cdn_bacon 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e1e3092e25f97e0ce03ef025e84f8f50ca2beb6
4
+ data.tar.gz: b9e11c358fa65f135ac1f08a73e2c21889b5dc8b
5
+ SHA512:
6
+ metadata.gz: 69bb94451e4e2234b9cc731f61c3863bb5ec278da889cc257194add61389553af8d869e89ea5fa8b6b351ba3e6953af075c8cc6f4efd05ffaf1e32d9b97f458a
7
+ data.tar.gz: 6002987355a597994aa80bb6695b5d2d86c88e26fa70d12ebd4ba9e6a3877829d0ba3bcb3f04d8d7f0675865be0c0e5e7dbeb001603c1049e6925f18d605e1bc
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cdn_bacon.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Bart Jedrocha
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # CdnBacon
2
+
3
+ Provides two view helpers for loading Javascript and CSS libraries from a CDN into your Rails application.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cdn_bacon'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ Define a configuration file under `config/cdn_assets.yml`
18
+
19
+ ````yaml
20
+ # set to true if you only want local(fallback) versions loaded in dev
21
+ only_fallbacks_in_dev: false
22
+
23
+ javascripts:
24
+ jquery:
25
+ cdn: "//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js"
26
+ fallback: "jquery-2.0.0"
27
+ fallback_test: "window.jQuery"
28
+
29
+ jquery_ui:
30
+ cdn: "//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"
31
+ fallback: "jquery-ui-1.10.3"
32
+ fallback_test: "window.jQuery.ui"
33
+
34
+ modernizr:
35
+ cdn: "//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"
36
+ fallback: "modernizr-2.6.2"
37
+ fallback_test: "window.Modernizr"
38
+
39
+ underscore:
40
+ cdn: "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"
41
+ fallback: "underscore-1.4.4"
42
+ fallback_test: "window._"
43
+
44
+ stylesheets:
45
+ jquery_ui:
46
+ cdn: "//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/css/base/jquery-ui.css"
47
+ fallback: "jquery-ui-1.10.3"
48
+
49
+ font_awesome:
50
+ cdn: "//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"
51
+ fallback: "font-awesome-4.0.3"
52
+ ````
53
+
54
+ You can then do the following in your layouts
55
+
56
+ ````erb
57
+ <%= javascript_cdn_include_tag :jquery, :underscore %>
58
+ <%= stylesheet_cdn_link_tag :font_awesome %>
59
+ ````
60
+
61
+ which will generate the following
62
+
63
+ ````html
64
+ <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js" type="text/javascript"></script>
65
+ <script type="text/javascript">
66
+ //<![CDATA[
67
+ window.jQuery || document.write(unescape('%3Cscript src="/javascripts/libraries/jquery-2.0.0.js?1371735212" type="text/javascript">%3C/script>'))
68
+ //]]>
69
+ </script>
70
+ <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js" type="text/javascript"></script>
71
+ <script type="text/javascript">
72
+ //<![CDATA[
73
+ window._ || document.write(unescape('%3Cscript src="/javascripts/libraries/underscore-1.4.4.js?1371735212" type="text/javascript">%3C/script>'))
74
+ //]]>
75
+ </script>
76
+ <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" media="screen" rel="stylesheet" type="text/css">
77
+ ````
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create new Pull Request
86
+
87
+ ## License
88
+ Copyright (c) 2013 Bart Jedrocha, released under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/cdn_bacon.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cdn_bacon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cdn_bacon"
8
+ spec.version = CdnBacon::VERSION
9
+ spec.authors = ["Bart Jedrocha"]
10
+ spec.email = ["bart.jedrocha@gmail.com"]
11
+ spec.description = %q{Rails helpers for loading Javascript and CSS from a CDN and falling back to local where available}
12
+ spec.summary = %q{Rails helpers for loading JS and CSS from various CDNs}
13
+ spec.homepage = "http://github.com/bjedrocha/cdn_bacon"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/lib/cdn_bacon.rb ADDED
@@ -0,0 +1,45 @@
1
+ require "cdn_bacon/version"
2
+ require "cdn_bacon/action_view_extensions"
3
+ require "cdn_bacon/railtie" if defined? Rails
4
+
5
+ module CdnBacon
6
+ APP_ROOT = File.expand_path((defined?(Rails) && !Rails.root.blank?) ? Rails.root : ENV['RAILS_ROOT'] || ".")
7
+ DEFAULT_CONFIG_PATH = File.join(APP_ROOT, 'config', 'cdn_assets.yml')
8
+
9
+ class MissingConfiguration < NameError; end
10
+
11
+ class << self
12
+ attr_reader :configuration, :only_fallbacks_in_dev, :rails_env
13
+ end
14
+
15
+ @configuration = {}
16
+
17
+ # Load the configuration from the specified @config_path@
18
+ def self.load_configuration(config_path)
19
+ exists = config_path && File.exists?(config_path)
20
+ raise MissingConfiguration, "could not find the \"#{config_path}\" configuration file" unless exists
21
+
22
+ conf = YAML.load(ERB.new(File.read(config_path)).result)
23
+ @rails_env = (defined?(Rails) ? ::Rails.env : ENV['RAILS_ENV'] || "development")
24
+
25
+ @configuration = symbolize_keys(conf)
26
+ @only_fallbacks_in_dev = conf[:only_fallbacks_in_dev] || false
27
+ symbolize_keys(conf[:javascripts]) if conf[:javascripts]
28
+ symbolize_keys(conf[:stylesheets]) if conf[:stylehseets]
29
+ self
30
+ end
31
+
32
+ private
33
+
34
+ # Clone of active_support's symbolize_keys.
35
+ # Converts a hash's keys to all symbols.
36
+ def self.symbolize_keys(hash)
37
+ hash.keys.each do |key|
38
+ val = hash.delete(key)
39
+ hash[(key.to_sym rescue key)] = val.is_a?(Hash) ? symbolize_keys(val) : val
40
+ end
41
+ hash
42
+ end
43
+ end
44
+
45
+ CdnBacon.load_configuration(CdnBacon::DEFAULT_CONFIG_PATH) if defined? Rails
@@ -0,0 +1,49 @@
1
+ module CdnBacon
2
+ module ActionViewExtensions
3
+ def javascript_cdn_include_tag(*sources)
4
+ js = CdnBacon.configuration[:javascripts] || {}
5
+ tags = []
6
+
7
+ if CdnBacon.rails_env == 'development' && CdnBacon.only_fallbacks_in_dev
8
+ sources.each do |source|
9
+ if js.has_key?(source) && js[source].has_key?(:fallback)
10
+ tags << javascript_include_tag(js[source][:fallback])
11
+ end
12
+ end
13
+ else
14
+ sources.each do |source|
15
+ if js.has_key?(source) && js[source].has_key?(:cdn)
16
+ tags << javascript_include_tag(js[source][:cdn])
17
+
18
+ if js[source].has_key?(:fallback) && js[source].has_key?(:fallback_test)
19
+ tags << javascript_tag("#{js[source][:fallback_test]} || document.write(unescape('#{javascript_include_tag(js[source][:fallback]).gsub('<', '%3C')}'))")
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ tags.join("\n").html_safe
26
+ end
27
+
28
+ def stylesheet_cdn_link_tag(*sources)
29
+ css = CdnBacon.configuration[:stylesheets] || {}
30
+ links = []
31
+
32
+ if CdnBacon.rails_env == 'development' && CdnBacon.only_fallbacks_in_dev
33
+ sources.each do |source|
34
+ if css.has_key?(source) && css[source].has_key?(:fallback)
35
+ links << stylesheet_link_tag(css[source][:fallback])
36
+ end
37
+ end
38
+ else
39
+ sources.each do |source|
40
+ if css.has_key?(source) && css[source].has_key?(:cdn)
41
+ links << stylesheet_link_tag(css[source][:cdn])
42
+ end
43
+ end
44
+ end
45
+
46
+ links.join("\n").html_safe
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,9 @@
1
+ module CdnBacon
2
+ class Railtie < Rails::Railtie
3
+ initializer 'cdn_bacon.action_view' do
4
+ ActiveSupport.on_load(:action_view) do
5
+ include CdnBacon::ActionViewExtensions
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module CdnBacon
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cdn_bacon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bart Jedrocha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Rails helpers for loading Javascript and CSS from a CDN and falling back
42
+ to local where available
43
+ email:
44
+ - bart.jedrocha@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - CHANGELOG.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - cdn_bacon.gemspec
56
+ - lib/cdn_bacon.rb
57
+ - lib/cdn_bacon/action_view_extensions.rb
58
+ - lib/cdn_bacon/railtie.rb
59
+ - lib/cdn_bacon/version.rb
60
+ homepage: http://github.com/bjedrocha/cdn_bacon
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.1.10
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Rails helpers for loading JS and CSS from various CDNs
84
+ test_files: []