assetsio-rails 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Martin Rehfeld
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,3 +1,30 @@
1
1
  # Assets.io Rails 3.1 Helper
2
2
 
3
- Use Assets.io to deliver your Javascript and CSS assets from the Amazon Cloudfront CDN.
3
+ Use Assets.io to deliver your Javascript and CSS assets from the
4
+ Amazon Cloudfront CDN.
5
+
6
+ ## Installation
7
+
8
+ Add `asssetsio-rails` to your Gemfile:
9
+
10
+ gem 'assetsio-rails'
11
+
12
+ Create an initializer, i.e. `config/initializers/assetsio.rb`:
13
+
14
+ require 'assetsio-rails'
15
+ AssetsIO.account = '<your-account-id>'
16
+
17
+ ## Usage
18
+
19
+ `assetsio-rails` hooks into the Rails 3.1 asset pipeline and will automatically
20
+ deliver Javascript & CSS assets included with `javascript_include_tag` and
21
+ `stylesheet_link_tag` via Assets.io and Amazon's Cloudfront CDN when run in the
22
+ `production` environment.
23
+
24
+ ## References
25
+
26
+ For more information about Assets.io visit <http://www.assets.io>
27
+
28
+ ## License
29
+
30
+ The `assetsio-rails` Gem is released under the MIT license.
data/Rakefile CHANGED
@@ -1,10 +1,16 @@
1
1
  require 'bundler'
2
- require 'bundler/setup'
3
- require 'bundler/gem_tasks'
2
+ Bundler.setup
3
+ Bundler::GemHelper.install_tasks
4
4
 
5
5
  require 'rdoc/task'
6
+ require 'rspec'
6
7
  require 'rspec/core/rake_task'
7
8
 
9
+ desc "Run all examples"
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.rspec_opts = %w[--color]
12
+ end
13
+
8
14
  task :default => :spec
9
15
 
10
16
  desc 'Generate documentation'
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'assetsio-rails/version'
2
+ $:.unshift File.expand_path('../lib', __FILE__)
3
+ require 'assetsio/rails/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'assetsio-rails'
@@ -9,17 +9,22 @@ Gem::Specification.new do |s|
9
9
  s.homepage = 'https://github.com/assets-io/assetsio-rails'
10
10
  s.description = 'Use Assets.io to deliver your Javascript and CSS assets from the Amazon Cloudfront CDN.'
11
11
  s.authors = ['Martin Rehfeld']
12
- s.version = AssetsIO::VERSION
12
+ s.version = AssetsIO::Rails::VERSION
13
13
  s.platform = Gem::Platform::RUBY
14
14
 
15
- s.add_dependency 'addressable'
15
+ s.rubygems_version = '1.3.7'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_path = 'lib'
21
+ s.extra_rdoc_files = ['README.md']
22
+ s.rdoc_options = ['--charset=UTF-8']
23
+
24
+ s.add_dependency 'assetsio', '0.0.2'
25
+ s.add_dependency 'railties', '>=3.1.0.rc4'
16
26
 
17
27
  s.add_development_dependency 'rdoc', '>=2.4.2'
18
28
  s.add_development_dependency 'rspec', '>=2.0'
19
29
  s.add_development_dependency 'rake'
20
-
21
- s.files = `git ls-files`.split("\n")
22
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
- s.require_paths = ['lib']
25
30
  end
@@ -1,2 +1,13 @@
1
- require 'assetsio-rails/helpers'
2
- require 'assetsio-rails/railtie' if defined?(Rails)
1
+ require 'assetsio'
2
+
3
+ module AssetsIO
4
+ module Rails
5
+
6
+ class Railtie < ::Rails::Railtie
7
+ config.to_prepare do
8
+ require 'assetsio/rails/sprockets'
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ begin
2
+ module Sprockets
3
+ module Helpers
4
+ module RailsHelper
5
+
6
+ def javascript_include_tag_with_assetsio(*sources)
7
+ if Rails.env.production?
8
+ options = sources.extract_options!
9
+ asset_sources = sources.map { |source| asset_path(source, 'js') }
10
+ javascript_include_tag_without_assetsio(AssetsIO.asset_url(asset_paths.controller.request, 'js', *asset_sources), options)
11
+ else
12
+ javascript_include_tag_without_assetsio(*sources)
13
+ end
14
+ end
15
+ alias_method_chain :javascript_include_tag, :assetsio
16
+
17
+ def stylesheet_link_tag_with_assetsio(*sources)
18
+ if Rails.env.production?
19
+ options = sources.extract_options!
20
+ asset_sources = sources.map { |source| asset_path(source, 'css') }
21
+ stylesheet_link_tag_without_assetsio(AssetsIO.asset_url(asset_paths.controller.request, 'css', *asset_sources), options)
22
+ else
23
+ stylesheet_link_tag_without_assetsio(*sources)
24
+ end
25
+ end
26
+ alias_method_chain :stylesheet_link_tag, :assetsio
27
+
28
+ end
29
+ end
30
+ end
31
+
32
+ rescue NameError => e
33
+ raise "assetsio-rails initialization failed: #{e}"
34
+ end
@@ -0,0 +1,7 @@
1
+ module AssetsIO
2
+ module Rails
3
+
4
+ VERSION = '0.0.3'
5
+
6
+ end
7
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+ require 'sprockets'
3
+ require 'assetsio/rails/sprockets'
4
+
5
+ describe 'SprocketsHelper' do
6
+
7
+ let(:account) { 'assetsio-account' }
8
+ let(:sources) { 'http://example.org/asset' }
9
+ let(:options) { {} }
10
+ let(:request) { stub('request', :url => 'http://example.org/') }
11
+ let(:application) { stub('application', :assets => Sprockets::Environment.new) }
12
+ let(:config) { stub('config', :perform_caching => false, :relative_url_root => nil, :asset_host => nil) }
13
+ let(:controller) { stub('controller', :request => request, :config => config) }
14
+
15
+ subject {
16
+ c = Struct.new(:config, :controller)
17
+ c.send(:include, ::Sprockets::Helpers::RailsHelper)
18
+ c.new(config, controller)
19
+ }
20
+
21
+ before( :each ) do
22
+ Rails.stub(:application => application)
23
+ AssetsIO.account = account
24
+ end
25
+
26
+ describe '#javascript_include_tag(*sources)' do
27
+ describe 'method chain' do
28
+ it 'should define #javascript_include_tag_with_assetsio' do
29
+ subject.should respond_to(:javascript_include_tag_with_assetsio)
30
+ end
31
+
32
+ it 'should define #javascript_include_tag_without_assetsio' do
33
+ subject.should respond_to(:javascript_include_tag_without_assetsio)
34
+ end
35
+ end
36
+
37
+ context 'in Rails production env' do
38
+ before( :each ) do
39
+ Rails.env.stub(:production? => true)
40
+ end
41
+
42
+ it 'should modify the sources with AssetsIO.asset_url' do
43
+ AssetsIO.should_receive(:asset_url).with(request, 'js', 'http://example.org/asset').and_return('http://assets.io/id.js')
44
+ subject.should_receive(:javascript_include_tag_without_assetsio).with('http://assets.io/id.js', options)
45
+ subject.javascript_include_tag(sources, options)
46
+ end
47
+
48
+ context 'with options' do
49
+ let(:options) { {:recursive => true} }
50
+
51
+ it 'should pass given options unaltered' do
52
+ subject.should_receive(:javascript_include_tag_without_assetsio).with(anything(), options)
53
+ subject.javascript_include_tag(sources, options)
54
+ end
55
+ end
56
+ end
57
+
58
+ context 'in other Rails envs' do
59
+ before( :each ) do
60
+ Rails.env.stub(:production? => false)
61
+ end
62
+
63
+ it 'should pass the sources unaltered' do
64
+ subject.should_receive(:javascript_include_tag_without_assetsio).with(sources)
65
+ subject.javascript_include_tag(sources)
66
+ end
67
+ end
68
+ end
69
+
70
+ describe '#stylesheet_link_tag(*sources)' do
71
+ describe 'method chain' do
72
+ it 'should define #stylesheet_link_tag_with_assetsio' do
73
+ subject.should respond_to(:stylesheet_link_tag_with_assetsio)
74
+ end
75
+
76
+ it 'should define #stylesheet_link_tag_without_assetsio' do
77
+ subject.should respond_to(:stylesheet_link_tag_without_assetsio)
78
+ end
79
+ end
80
+
81
+ context 'in Rails production env' do
82
+ before( :each ) do
83
+ Rails.env.stub(:production? => true)
84
+ end
85
+
86
+ it 'should modify the sources with AssetsIO.asset_url' do
87
+ AssetsIO.should_receive(:asset_url).with(request, 'css', 'http://example.org/asset').and_return('http://assets.io/id.css')
88
+ subject.should_receive(:stylesheet_link_tag_without_assetsio).with('http://assets.io/id.css', options)
89
+ subject.stylesheet_link_tag(sources, options)
90
+ end
91
+
92
+ context 'with options' do
93
+ let(:options) { {:recursive => true} }
94
+
95
+ it 'should pass given options unaltered' do
96
+ subject.should_receive(:stylesheet_link_tag_without_assetsio).with(anything(), options)
97
+ subject.stylesheet_link_tag(sources, options)
98
+ end
99
+ end
100
+ end
101
+
102
+ context 'in other Rails envs' do
103
+ before( :each ) do
104
+ Rails.env.stub(:production? => false)
105
+ end
106
+
107
+ it 'should pass the sources unaltered' do
108
+ subject.should_receive(:stylesheet_link_tag_without_assetsio).with(sources)
109
+ subject.stylesheet_link_tag(sources)
110
+ end
111
+ end
112
+ end
113
+
114
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails'
2
+ require 'active_support/core_ext/object/to_json'
3
+ require 'action_view/helpers/capture_helper'
4
+ require 'sprockets/helpers/rails_helper'
5
+ require 'assetsio'
6
+
7
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
+
9
+ RSpec.configure do |c|
10
+ # room for custom config options
11
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: assetsio-rails
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Martin Rehfeld
@@ -10,23 +10,34 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-06 00:00:00 +02:00
13
+ date: 2011-06-13 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: addressable
17
+ name: assetsio
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - ">="
21
+ - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
23
+ version: 0.0.2
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: rdoc
28
+ name: railties
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 3.1.0.rc4
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rdoc
40
+ requirement: &id003 !ruby/object:Gem::Requirement
30
41
  none: false
31
42
  requirements:
32
43
  - - ">="
@@ -34,10 +45,10 @@ dependencies:
34
45
  version: 2.4.2
35
46
  type: :development
36
47
  prerelease: false
37
- version_requirements: *id002
48
+ version_requirements: *id003
38
49
  - !ruby/object:Gem::Dependency
39
50
  name: rspec
40
- requirement: &id003 !ruby/object:Gem::Requirement
51
+ requirement: &id004 !ruby/object:Gem::Requirement
41
52
  none: false
42
53
  requirements:
43
54
  - - ">="
@@ -45,10 +56,10 @@ dependencies:
45
56
  version: "2.0"
46
57
  type: :development
47
58
  prerelease: false
48
- version_requirements: *id003
59
+ version_requirements: *id004
49
60
  - !ruby/object:Gem::Dependency
50
61
  name: rake
51
- requirement: &id004 !ruby/object:Gem::Requirement
62
+ requirement: &id005 !ruby/object:Gem::Requirement
52
63
  none: false
53
64
  requirements:
54
65
  - - ">="
@@ -56,35 +67,36 @@ dependencies:
56
67
  version: "0"
57
68
  type: :development
58
69
  prerelease: false
59
- version_requirements: *id004
70
+ version_requirements: *id005
60
71
  description: Use Assets.io to deliver your Javascript and CSS assets from the Amazon Cloudfront CDN.
61
72
  email: martin.rehfeld@assets.io
62
73
  executables: []
63
74
 
64
75
  extensions: []
65
76
 
66
- extra_rdoc_files: []
67
-
77
+ extra_rdoc_files:
78
+ - README.md
68
79
  files:
69
80
  - .gitignore
81
+ - .rspec
70
82
  - .rvmrc
71
83
  - Gemfile
84
+ - MIT-LICENSE
72
85
  - README.md
73
86
  - Rakefile
74
87
  - assetsio-rails.gemspec
75
88
  - lib/assetsio-rails.rb
76
- - lib/assetsio-rails/helpers.rb
77
- - lib/assetsio-rails/railtie.rb
78
- - lib/assetsio-rails/sprockets.rb
79
- - lib/assetsio-rails/version.rb
80
- - rails/init.rb
89
+ - lib/assetsio/rails/sprockets.rb
90
+ - lib/assetsio/rails/version.rb
91
+ - spec/assetsio/rails/sprockets_spec.rb
92
+ - spec/spec_helper.rb
81
93
  has_rdoc: true
82
94
  homepage: https://github.com/assets-io/assetsio-rails
83
95
  licenses: []
84
96
 
85
97
  post_install_message:
86
- rdoc_options: []
87
-
98
+ rdoc_options:
99
+ - --charset=UTF-8
88
100
  require_paths:
89
101
  - lib
90
102
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -92,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
104
  requirements:
93
105
  - - ">="
94
106
  - !ruby/object:Gem::Version
95
- hash: -4394763084675672952
107
+ hash: -2855542715019590920
96
108
  segments:
97
109
  - 0
98
110
  version: "0"
@@ -101,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
113
  requirements:
102
114
  - - ">="
103
115
  - !ruby/object:Gem::Version
104
- hash: -4394763084675672952
116
+ hash: -2855542715019590920
105
117
  segments:
106
118
  - 0
107
119
  version: "0"
@@ -112,5 +124,6 @@ rubygems_version: 1.6.2
112
124
  signing_key:
113
125
  specification_version: 3
114
126
  summary: Assets.io helper for Rails 3.1
115
- test_files: []
116
-
127
+ test_files:
128
+ - spec/assetsio/rails/sprockets_spec.rb
129
+ - spec/spec_helper.rb
@@ -1,25 +0,0 @@
1
- require 'addressable/uri'
2
- require 'base64'
3
-
4
- module AssetsIO
5
-
6
- class << self
7
- attr_accessor :account, :origin
8
-
9
- def asset_url(request, source, type)
10
- source_url = Addressable::URI.parse(request.url) + source
11
- asset_spec = {
12
- :a => account,
13
- :r => 'b6',
14
- :h => 'localhost', # TODO: remove once whitelisting refers to sources
15
- :s => [ source_url.to_s ],
16
- :v => 0,
17
- :w => 0
18
- }
19
-
20
- origin_server = origin || "//#{account}.cloudfront.net"
21
- "#{origin_server}/#{Base64.urlsafe_encode64(asset_spec.to_json)}.#{type}"
22
- end
23
- end
24
-
25
- end
@@ -1,9 +0,0 @@
1
- module AssetsIO
2
-
3
- class Railtie < ::Rails::Railtie
4
- config.to_prepare do
5
- require 'assetsio-rails/sprockets'
6
- end
7
- end
8
-
9
- end
@@ -1,32 +0,0 @@
1
- begin
2
- if ActionView::Helpers.const_defined?(:SprocketsHelper)
3
-
4
- module ::ActionView::Helpers::SprocketsHelper
5
-
6
- def sprockets_javascript_include_tag_with_assetsio(source, options = {})
7
- if Rails.env.production?
8
- sprockets_javascript_include_tag_without_assetsio(AssetsIO.asset_url(sprockets_asset_paths.controller.request, asset_path(source, 'js'), 'js'), options)
9
- else
10
- sprockets_javascript_include_tag_without_assetsio(source, options)
11
- end
12
- end
13
- alias_method_chain :sprockets_javascript_include_tag, :assetsio
14
-
15
- def sprockets_stylesheet_link_tag_with_assetsio(source, options = {})
16
- if Rails.env.production?
17
- sprockets_stylesheet_link_tag_without_assetsio(AssetsIO.asset_url(sprockets_asset_paths.controller.request, asset_path(source, 'css'), 'css'), options)
18
- else
19
- sprockets_stylesheet_link_tag_without_assetsio(source, options)
20
- end
21
- end
22
- alias_method_chain :sprockets_stylesheet_link_tag, :assetsio
23
-
24
- end
25
-
26
- else
27
- raise NameError
28
- end
29
-
30
- rescue NameError
31
- raise "assetsio-rails initialization failed: ActionView::Helpers::SprocketsHelper is not defined!"
32
- end
@@ -1,5 +0,0 @@
1
- module AssetsIO
2
-
3
- VERSION = '0.0.1'
4
-
5
- end
@@ -1,2 +0,0 @@
1
- # this is for Rails only
2
- require File.dirname(__FILE__) + '/../lib/assetsio-rails'