fallback_assets 0.0.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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YmEyOGFhM2ZmN2I5NjM2NGVlYjhmYTFhNTg2YmM1NzhmMzEzMzQ4MA==
5
+ data.tar.gz: !binary |-
6
+ MDY2NWJmMzJlYTJkMjc2NmUyNzA1MDQ2ZTVjNzQ3N2Q5NDM2ZTRlYg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWY0ZTAyODQ5ODFkODgwNjkzNTgxYWM4NDA0YzM4NjY5Mjg0OGQ0OTk2NDJj
10
+ MzAxN2EyMjEzYTJjNjMzZTViMWIyOGY5MGVhNmZlOGZmYmMyYjg4N2U2MWQ1
11
+ OTUwOWY1ZjM4YzI3MDIwMTM0OTkyNmRjNzA4NjQ1YWNlMDE5YzE=
12
+ data.tar.gz: !binary |-
13
+ NmE1YmEzZDIxMTY5MDgwYTcwM2ExYzYxYzIxZDdkNGE2NWUyYWE2ZmNmMDZm
14
+ MGQ2ODE0ODlhMjEwNGJjMGI3ODk4NzQyNGE1MWI5YWUwYjlhNzQ1MDJiMDZm
15
+ MTIyMzRlMjZjMjdhMWI5MmE1ODRjYWE5NjNhMTdhNTIxMTY4OGM=
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format d
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fallback_assets (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rspec (2.14.1)
11
+ rspec-core (~> 2.14.0)
12
+ rspec-expectations (~> 2.14.0)
13
+ rspec-mocks (~> 2.14.0)
14
+ rspec-core (2.14.7)
15
+ rspec-expectations (2.14.4)
16
+ diff-lcs (>= 1.1.3, < 2.0)
17
+ rspec-mocks (2.14.4)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.3)
24
+ fallback_assets!
25
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 djalmaaraujo
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,41 @@
1
+ # Fallback Asset Gem
2
+ Create fallbacks to your assets. Helpful to work with development and cdn assets.
3
+
4
+ ## Installation
5
+ In your Gemfile:
6
+ ```ruby
7
+ gem 'fallback_assets'
8
+ ```
9
+
10
+ ## Features
11
+ * Add assets (javascripts / stylesheets) to your codebase with fallback to local files
12
+ * Great to use with CDN assets (first idea)
13
+ * The local asset will be used if the CDN is not available
14
+ * Easy to config
15
+
16
+ ## How to use
17
+
18
+ ### Single use
19
+ ```haml
20
+ = fallback_javascript :underscore
21
+ = fallback_stylesheet :normalize
22
+ ```
23
+
24
+ ### Configuration
25
+ Create a file config/fallback_assets.yml under your rails app.
26
+
27
+ ```yaml
28
+ fallbacks:
29
+ stylesheets:
30
+ normalize:
31
+ production: //cdn/normalize.min.css
32
+ development: normalize.css
33
+
34
+ javascripts:
35
+ jquery:
36
+ production: //cdn/jquery.min.js
37
+ development: jquery.js
38
+ ```
39
+
40
+ ## Copyright
41
+ Copyright © 2014 Djalma Araújo. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 'fallback_assets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fallback_assets"
8
+ spec.version = FallbackAssets::VERSION
9
+ spec.authors = ["djalmaaraujo"]
10
+ spec.email = ["djalma.araujo@gmail.com"]
11
+ spec.description = %q{Easy to use helper to work with your assets}
12
+ spec.summary = %q{Create fallbacks to your assets. Helpful to work with development and cdn assets.}
13
+ spec.homepage = "https://github.com/djalmaaraujo/fallback_assets"
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 'rspec'
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'fallback_assets'
2
+
3
+ module FallbackAssets
4
+ module Helper
5
+ def fallback_stylesheet(name)
6
+ asset = FallbackAssets::load_stylesheet(name)
7
+
8
+ FallbackAssets::HtmlAsset.new(asset).create_link
9
+ end
10
+
11
+ def fallback_javascript(name)
12
+ asset = FallbackAssets::load_javascript(name)
13
+
14
+ FallbackAssets::HtmlAsset.new(asset).create_script
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require "fallback_assets"
2
+
3
+ module FallbackAssets
4
+ class HtmlAsset
5
+ def initialize(asset)
6
+ @asset = asset
7
+ end
8
+
9
+ def create_script
10
+ "<script src=\"#{@asset}\"></script>"
11
+ end
12
+
13
+ def create_link
14
+ "<link rel=\"stylesheet\" href=\"#{@asset}\" />"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ require 'fallback_assets'
2
+ require 'fallback_assets/helper'
3
+
4
+ module FallbackAssets
5
+ class FallbackAssetsRailtie < Rails::Railtie
6
+ ActiveSupport.on_load(:action_view) do
7
+ include FallbackAssets::Helper
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module FallbackAssets
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'yaml'
2
+ require "fallback_assets/version"
3
+ require "fallback_assets/html_asset"
4
+ require "fallback_assets/railtie"
5
+
6
+ module FallbackAssets
7
+ def self.load(type, name)
8
+ return false unless available_assets.include?(type)
9
+ return false unless type.is_a?(Symbol)
10
+ return false unless name.is_a?(Symbol)
11
+
12
+ asset = {type: type.to_s, name: name.to_s}
13
+ asset_from_environment(asset) || asset_from_environment(asset, "development")
14
+ end
15
+
16
+ def self.asset_from_environment(asset, env = false)
17
+ config = settings
18
+ env = environment || "development"
19
+
20
+ return false unless config["fallbacks"][asset[:type]]
21
+ return false unless config["fallbacks"][asset[:type]][asset[:name]]
22
+ return false unless config["fallbacks"][asset[:type]][asset[:name]][env]
23
+
24
+ config["fallbacks"][asset[:type]][asset[:name]][env]
25
+ end
26
+
27
+ def self.settings
28
+ YAML.load_file("#{Rails.root}/config/fallback_assets.yml")
29
+ end
30
+
31
+ def self.environment
32
+ ENV['RAILS_ENV']
33
+ end
34
+
35
+ def self.available_assets
36
+ [:javascripts, :stylesheets]
37
+ end
38
+
39
+ def self.load_javascript(name)
40
+ load(:javascripts, name)
41
+ end
42
+
43
+ def self.load_stylesheet(name)
44
+ load(:stylesheets, name)
45
+ end
46
+ end
@@ -0,0 +1,10 @@
1
+ fallbacks:
2
+ stylesheets:
3
+ normalize:
4
+ production: //cdn/normalize.min.css
5
+ development: normalize.css
6
+
7
+ javascripts:
8
+ jquery:
9
+ production: //cdn/jquery.min.js
10
+ development: jquery.js
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+ describe FallbackAssets do
5
+ specify { FallbackAssets.should be_a(Module) }
6
+
7
+ let(:settings) { YAML.load_file("spec/fixtures/config/fallback_assets.yml") }
8
+
9
+ before(:each) do
10
+ stub_const "Rails", double(root: "spec/fixtures")
11
+ stub_const "ENV", {"RAILS_ENV" => "development"}
12
+ end
13
+
14
+ describe "Configuration File" do
15
+ before do
16
+ YAML.stub(:load_file).with("#{Rails.root}/config/fallback_assets.yml").and_return(settings)
17
+ end
18
+
19
+ it "loads the configuration file into settings" do
20
+ expect(FallbackAssets.settings).to equal settings
21
+ end
22
+
23
+ end
24
+
25
+ describe "Asset loader" do
26
+
27
+ describe "#load" do
28
+
29
+ it "loads an asset with different types" do
30
+ expect(FallbackAssets.load(:javascripts, :jquery)).to eq "jquery.js"
31
+ expect(FallbackAssets.load(:stylesheets, :normalize)).to eq "normalize.css"
32
+ end
33
+
34
+ it 'loads an asset from a different environment' do
35
+ stub_const "ENV", {"RAILS_ENV" => "production"}
36
+ expect(FallbackAssets.load(:javascripts, :jquery)).to eq "//cdn/jquery.min.js"
37
+ end
38
+
39
+ it 'loads an asset from development if environment is crazy' do
40
+ stub_const "RAILS_ENV", "crazyenv"
41
+ expect(FallbackAssets.load(:javascripts, :jquery)).to eq "jquery.js"
42
+ end
43
+
44
+ it 'returns false for a non-symbol type or name' do
45
+ expect(FallbackAssets.load(false, false)).to be_false
46
+ expect(FallbackAssets.load(:javascripts, false)).to be_false
47
+ expect(FallbackAssets.load(false, :jquery)).to be_false
48
+ end
49
+
50
+ it 'returns false for a non valid asset type' do
51
+ expect(FallbackAssets.load(:javascripts, :pretty)).to be_false
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ describe "#load_javascript" do
59
+ it "returns an javascript asset for default environment" do
60
+ expect(FallbackAssets.load_javascript(:jquery)).to eq "jquery.js"
61
+ end
62
+
63
+ it "returns an javascript asset for production environment" do
64
+ stub_const "ENV", {"RAILS_ENV" => "production"}
65
+ expect(FallbackAssets.load_javascript(:jquery)).to eq "//cdn/jquery.min.js"
66
+ end
67
+
68
+ it "returns false when trying to load a existing stylesheet in config file" do
69
+ expect(FallbackAssets.load_javascript(:normalize)).to be_false
70
+ end
71
+
72
+ end
73
+
74
+ describe "#load_stylesheet" do
75
+ it "returns an stylesheet asset for default environment" do
76
+ expect(FallbackAssets.load_stylesheet(:normalize)).to eq "normalize.css"
77
+ end
78
+
79
+ it "returns an stylesheet asset for production environment" do
80
+ stub_const "ENV", {"RAILS_ENV" => "production"}
81
+ expect(FallbackAssets.load_stylesheet(:normalize)).to eq "//cdn/normalize.min.css"
82
+ end
83
+
84
+ it "returns false when trying to load a existing javascript in config file" do
85
+ expect(FallbackAssets.load_stylesheet(:jquery)).to be_false
86
+ end
87
+
88
+ end
89
+
90
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ require 'fallback_assets/helper'
4
+
5
+ describe FallbackAssets::Helper do
6
+ let(:settings) { YAML.load_file("spec/fixtures/config/fallback_assets.yml") }
7
+
8
+ before(:each) do
9
+ stub_const "Rails", double(root: "spec/fixtures")
10
+ stub_const "ENV", {"RAILS_ENV" => "development"}
11
+ end
12
+
13
+ include FallbackAssets::Helper
14
+
15
+ describe "#fallback_stylesheet" do
16
+
17
+ it "returns an stylesheet link tag" do
18
+ expect(fallback_stylesheet(:normalize)).to eq "<link rel=\"stylesheet\" href=\"normalize.css\" />"
19
+ end
20
+
21
+ end
22
+
23
+ describe "#fallback_javascript" do
24
+
25
+ it "returns an script tag" do
26
+ expect(fallback_javascript(:jquery)).to eq "<script src=\"jquery.js\"></script>"
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'fallback_assets/html_asset'
3
+
4
+ describe FallbackAssets::HtmlAsset do
5
+ describe "#create_tag" do
6
+ it "returns a javascript tag for an loaded javascript asset" do
7
+ expect(FallbackAssets::HtmlAsset.new("jquery.js").create_script).to eq "<script src=\"jquery.js\"></script>"
8
+ end
9
+
10
+ it "returns a link tag for an loaded stylesheet asset" do
11
+ expect(FallbackAssets::HtmlAsset.new("normalize.css").create_link).to eq "<link rel=\"stylesheet\" href=\"normalize.css\" />"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'fallback_assets'
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fallback_assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - djalmaaraujo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-03 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: rspec
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: Easy to use helper to work with your assets
42
+ email:
43
+ - djalma.araujo@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rspec
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - fallback_assets.gemspec
56
+ - lib/fallback_assets.rb
57
+ - lib/fallback_assets/helper.rb
58
+ - lib/fallback_assets/html_asset.rb
59
+ - lib/fallback_assets/railtie.rb
60
+ - lib/fallback_assets/version.rb
61
+ - spec/fixtures/config/fallback_assets.yml
62
+ - spec/lib/fallback_assets/fallback_assets_spec.rb
63
+ - spec/lib/fallback_assets/helper_spec.rb
64
+ - spec/lib/fallback_assets/html_asset_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: https://github.com/djalmaaraujo/fallback_assets
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.1.11
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Create fallbacks to your assets. Helpful to work with development and cdn
90
+ assets.
91
+ test_files:
92
+ - spec/fixtures/config/fallback_assets.yml
93
+ - spec/lib/fallback_assets/fallback_assets_spec.rb
94
+ - spec/lib/fallback_assets/helper_spec.rb
95
+ - spec/lib/fallback_assets/html_asset_spec.rb
96
+ - spec/spec_helper.rb