sprockets_helper_rails3 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rvmrc ADDED
@@ -0,0 +1,3 @@
1
+ rvm 1.9.2
2
+ rvm gemset use sprockets_helper --create
3
+
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ gem "sprockets", "~> 2.0"
14
+ gem 'rspec'
15
+ gem 'rspec-rails'
16
+ gem "actionpack", "~> 3.0.10"
17
+ gem "rails", "~> 3.0.10"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,111 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.10)
6
+ actionpack (= 3.0.10)
7
+ mail (~> 2.2.19)
8
+ actionpack (3.0.10)
9
+ activemodel (= 3.0.10)
10
+ activesupport (= 3.0.10)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.5.0)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.14)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.10)
19
+ activesupport (= 3.0.10)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.10)
23
+ activemodel (= 3.0.10)
24
+ activesupport (= 3.0.10)
25
+ arel (~> 2.0.10)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.10)
28
+ activemodel (= 3.0.10)
29
+ activesupport (= 3.0.10)
30
+ activesupport (3.0.10)
31
+ arel (2.0.10)
32
+ builder (2.1.2)
33
+ diff-lcs (1.1.3)
34
+ erubis (2.6.6)
35
+ abstract (>= 1.0.0)
36
+ git (1.2.5)
37
+ hike (1.2.1)
38
+ i18n (0.5.0)
39
+ jeweler (1.6.4)
40
+ bundler (~> 1.0)
41
+ git (>= 1.2.5)
42
+ rake
43
+ json (1.6.1)
44
+ mail (2.2.19)
45
+ activesupport (>= 2.3.6)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.17.2)
50
+ polyglot (0.3.2)
51
+ rack (1.2.4)
52
+ rack-mount (0.6.14)
53
+ rack (>= 1.0.0)
54
+ rack-test (0.5.7)
55
+ rack (>= 1.0)
56
+ rails (3.0.10)
57
+ actionmailer (= 3.0.10)
58
+ actionpack (= 3.0.10)
59
+ activerecord (= 3.0.10)
60
+ activeresource (= 3.0.10)
61
+ activesupport (= 3.0.10)
62
+ bundler (~> 1.0)
63
+ railties (= 3.0.10)
64
+ railties (3.0.10)
65
+ actionpack (= 3.0.10)
66
+ activesupport (= 3.0.10)
67
+ rake (>= 0.8.7)
68
+ rdoc (~> 3.4)
69
+ thor (~> 0.14.4)
70
+ rake (0.9.2.2)
71
+ rcov (0.9.11)
72
+ rdoc (3.11)
73
+ json (~> 1.4)
74
+ rspec (2.6.0)
75
+ rspec-core (~> 2.6.0)
76
+ rspec-expectations (~> 2.6.0)
77
+ rspec-mocks (~> 2.6.0)
78
+ rspec-core (2.6.4)
79
+ rspec-expectations (2.6.0)
80
+ diff-lcs (~> 1.1.2)
81
+ rspec-mocks (2.6.0)
82
+ rspec-rails (2.6.1)
83
+ actionpack (~> 3.0)
84
+ activesupport (~> 3.0)
85
+ railties (~> 3.0)
86
+ rspec (~> 2.6.0)
87
+ shoulda (2.11.3)
88
+ sprockets (2.0.3)
89
+ hike (~> 1.2)
90
+ rack (~> 1.0)
91
+ tilt (~> 1.1, != 1.3.0)
92
+ thor (0.14.6)
93
+ tilt (1.3.3)
94
+ treetop (1.4.10)
95
+ polyglot
96
+ polyglot (>= 0.3.1)
97
+ tzinfo (0.3.30)
98
+
99
+ PLATFORMS
100
+ ruby
101
+
102
+ DEPENDENCIES
103
+ actionpack (~> 3.0.10)
104
+ bundler (~> 1.0.0)
105
+ jeweler (~> 1.6.4)
106
+ rails (~> 3.0.10)
107
+ rcov
108
+ rspec
109
+ rspec-rails
110
+ shoulda
111
+ sprockets (~> 2.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ilya Katz
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.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = sprockets_helper
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to sprockets_helper
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Ilya Katz. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "sprockets_helper_rails3"
18
+ gem.homepage = "http://github.com/ilyakatz/sprockets_helper_rails3"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Sprockets helper for rails3.0}
21
+ gem.description = %Q{A helper gem that attaches fingerprint for static assets (js/css) using sprockets in rails 3.0}
22
+ gem.email = "ilyakatz@gmail.com"
23
+ gem.authors = ["Ilya Katz"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test' << 'spec'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "sprockets_helper #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,43 @@
1
+ require 'action_view'
2
+ require 'sprockets'
3
+
4
+ module ActionView
5
+ module Helpers
6
+
7
+ module AssetTagHelper
8
+ def javascript_include_tag_with_sprockets(*sources)
9
+ sprocketized_sources = sources.map do |source|
10
+ source = source.gsub(/^\/assets\//, "")
11
+ source = source.gsub(/\.js$/, "")
12
+ if source.kind_of? String and !Assets[source].nil?
13
+ digest = Assets[source].digest
14
+ "/assets/#{source}.js?#{digest}"
15
+ else
16
+ source
17
+ end
18
+ end
19
+ javascript_include_tag_without_sprockets(*sprocketized_sources)
20
+ end
21
+
22
+ alias_method_chain :javascript_include_tag, :sprockets
23
+
24
+ private
25
+
26
+ def path_to_stylesheet_with_sprockets(source)
27
+ source = source.gsub(/^\/assets\//, "")
28
+ source = source.gsub(/\.css$/, "")
29
+ source = if source.kind_of? String and Assets["#{source}.css"].present?
30
+ digest = Assets["#{source}.css"].digest
31
+ "/assets/#{source}.css?#{digest}"
32
+ else
33
+ source
34
+ end
35
+ path_to_stylesheet_without_sprockets(source)
36
+ end
37
+
38
+ alias_method_chain :path_to_stylesheet, :sprockets
39
+
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1 @@
1
+ require 'sprockets_helper/initializers/sprockets_helper'
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+ require 'action_view'
3
+ require 'sprockets'
4
+
5
+ include ActionView::Helpers::AssetTagHelper
6
+
7
+ puts Rails.root
8
+ Assets = Sprockets::Environment.new("#{Rails.root}/test/rails_app") do |env|
9
+ assets = ["javascripts", "stylesheets"]
10
+ paths = ["app/assets/"].map { |path|
11
+ assets.map do |folder|
12
+ "#{path}#{folder}"
13
+ end
14
+ }.flatten
15
+
16
+ paths.each do |path|
17
+ env.append_path path
18
+ end
19
+ end
20
+
21
+ describe ActionView::Helpers::AssetTagHelper do
22
+
23
+ describe "validate javascript sprockets helper" do
24
+
25
+ it "use sprockets if name doesn't contain assets but sprockets manages the file" do
26
+ fingerprint = Assets["application"].digest
27
+ javascript_include_tag("application").should == %Q[<script src="/assets/application.js?#{fingerprint}" type="text/javascript"></script>]
28
+ end
29
+
30
+ it "use sprockets if name contain assets but sprockets manages the file" do
31
+ fingerprint = Assets["application"].digest
32
+ javascript_include_tag("/assets/application").should == %Q[<script src="/assets/application.js?#{fingerprint}" type="text/javascript"></script>]
33
+ end
34
+
35
+ it "should not use assets path if file is not managed by sprockets" do
36
+ javascript_include_tag("asdfasdf").should == %Q[<script src="/javascripts/asdfasdf.js" type="text/javascript"></script>]
37
+ end
38
+
39
+ it "make sure can handle names with extension js" do
40
+ fingerprint = Assets["application"].digest
41
+ javascript_include_tag("/assets/application.js").should == %Q[<script src="/assets/application.js?#{fingerprint}" type="text/javascript"></script>]
42
+
43
+ javascript_include_tag("asdfasdf.js").should == %Q[<script src="/javascripts/asdfasdf.js" type="text/javascript"></script>]
44
+ end
45
+
46
+ end
47
+
48
+ describe "css helper" do
49
+
50
+ it "should correctly show plain ol' css file" do
51
+ stylesheet_link_tag("ie.css", :media=>:all).should include("/stylesheets/ie.css")
52
+ end
53
+
54
+ it "should render sprockets css" do
55
+ fingerprint = Assets["application.css"].digest
56
+ stylesheet_link_tag("application.css").should == "<link href=\"/assets/application.css?#{fingerprint}\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
57
+ end
58
+
59
+ it "should verify that can pass in extra arguments" do
60
+ fingerprint = Assets["application.css"].digest
61
+ stylesheet_link_tag("application.css", :media=>:all).should == "<link href=\"/assets/application.css?#{fingerprint}\" media=\"all\" rel=\"stylesheet\" type=\"text/css\" />"
62
+ end
63
+
64
+ it "should be resilient to /assets directory" do
65
+ fingerprint = Assets["application.css"].digest
66
+ stylesheet_link_tag("/assets/application.css", :media=>:all).should == "<link href=\"/assets/application.css?#{fingerprint}\" media=\"all\" rel=\"stylesheet\" type=\"text/css\" />"
67
+ end
68
+
69
+ it "should be resilient to missing extention directory" do
70
+ fingerprint = Assets["application.css"].digest
71
+ stylesheet_link_tag("application", :media=>:all).should == "<link href=\"/assets/application.css?#{fingerprint}\" media=\"all\" rel=\"stylesheet\" type=\"text/css\" />"
72
+ end
73
+
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+
3
+ #Bundler.require(:default, "development")
4
+
5
+
6
+ ENV["RAILS_ENV"] ||= 'test'
7
+ require File.expand_path("../../test/rails_app/config/environment", __FILE__)
8
+ require 'rspec/rails'
9
+ require './lib/initializers/sprockets_helper.rb'
10
+ RSpec.configure do |config|
11
+ # == Mock Framework
12
+ #
13
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
+ #
15
+ # config.mock_with :mocha
16
+ # config.mock_with :flexmock
17
+ # config.mock_with :rr
18
+ config.mock_with :rspec
19
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require "active_resource/railtie"
5
+ require "rails/test_unit/railtie"
6
+
7
+ # If you have a Gemfile, require the gems listed there, including any gems
8
+ # you've limited to :test, :development, or :production.
9
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
10
+
11
+ module RailsApp
12
+ class Application < Rails::Application
13
+ # Settings in config/environments/* take precedence over those specified here.
14
+ # Application configuration should go into files in config/initializers
15
+ # -- all .rb files in that directory are automatically loaded.
16
+
17
+ # Custom directories with classes and modules you want to be autoloadable.
18
+ # config.autoload_paths += %W(#{config.root}/extras)
19
+
20
+ # Only load the plugins named here, in the order given (default is alphabetical).
21
+ # :all can be used as a placeholder for all plugins not explicitly named.
22
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
23
+
24
+ # Activate observers that should always be running.
25
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
26
+
27
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
28
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
29
+ # config.time_zone = 'Central Time (US & Canada)'
30
+
31
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
32
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
33
+ # config.i18n.default_locale = :de
34
+
35
+ # JavaScript files you want as :defaults (application.js is always included).
36
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
37
+
38
+ # Configure the default encoding used in templates for Ruby 1.9.
39
+ config.encoding = "utf-8"
40
+
41
+ # Configure sensitive parameters which will be filtered from the log file.
42
+ config.filter_parameters += [:password]
43
+ end
44
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ RailsApp::Application.initialize!
@@ -0,0 +1,58 @@
1
+ RailsApp::Application.routes.draw do
2
+ # The priority is based upon order of creation:
3
+ # first created -> highest priority.
4
+
5
+ # Sample of regular route:
6
+ # match 'products/:id' => 'catalog#view'
7
+ # Keep in mind you can assign values other than :controller and :action
8
+
9
+ # Sample of named route:
10
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
+ # This route can be invoked with purchase_url(:id => product.id)
12
+
13
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
14
+ # resources :products
15
+
16
+ # Sample resource route with options:
17
+ # resources :products do
18
+ # member do
19
+ # get 'short'
20
+ # post 'toggle'
21
+ # end
22
+ #
23
+ # collection do
24
+ # get 'sold'
25
+ # end
26
+ # end
27
+
28
+ # Sample resource route with sub-resources:
29
+ # resources :products do
30
+ # resources :comments, :sales
31
+ # resource :seller
32
+ # end
33
+
34
+ # Sample resource route with more complex sub-resources
35
+ # resources :products do
36
+ # resources :comments
37
+ # resources :sales do
38
+ # get 'recent', :on => :collection
39
+ # end
40
+ # end
41
+
42
+ # Sample resource route within a namespace:
43
+ # namespace :admin do
44
+ # # Directs /admin/products/* to Admin::ProductsController
45
+ # # (app/controllers/admin/products_controller.rb)
46
+ # resources :products
47
+ # end
48
+
49
+ # You can have the root of your site routed with "root"
50
+ # just remember to delete public/index.html.
51
+ # root :to => "welcome#index"
52
+
53
+ # See how all your routes lay out with "rake routes"
54
+
55
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
56
+ # Note: This route will make all actions in every controller accessible via GET requests.
57
+ # match ':controller(/:action(/:id(.:format)))'
58
+ end
@@ -0,0 +1,2 @@
1
+ // Place your application-specific JavaScript functions and classes here
2
+ // This file is automatically included by javascript_include_tag :defaults