rails_serve_static_assets 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +16 -0
  4. data/Gemfile +8 -1
  5. data/LICENSE +19 -19
  6. data/README.md +3 -3
  7. data/Rakefile +22 -0
  8. data/gemfiles/3.2.gemfile +5 -0
  9. data/gemfiles/4.1.gemfile +5 -0
  10. data/gemfiles/4.2.gemfile +5 -0
  11. data/lib/rails_serve_static_assets/railtie.rb +5 -1
  12. data/lib/rails_serve_static_assets/version.rb +1 -1
  13. data/rails_serve_static_assets.gemspec +5 -1
  14. data/test/integration/static_file_service_test.rb +23 -0
  15. data/test/rails_app/Rakefile +7 -0
  16. data/test/rails_app/app/assets/images/schneems.png +0 -0
  17. data/test/rails_app/app/assets/javascripts/application.js +1 -0
  18. data/test/rails_app/app/assets/javascripts/foo.js +1 -0
  19. data/test/rails_app/app/assets/stylesheets/application.css +13 -0
  20. data/test/rails_app/app/assets/stylesheets/foo.css +1 -0
  21. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  22. data/test/rails_app/app/controllers/authenticated_controller.rb +12 -0
  23. data/test/rails_app/app/controllers/pages_controller.rb +7 -0
  24. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  25. data/test/rails_app/app/helpers/authenticated_helper.rb +2 -0
  26. data/test/rails_app/app/views/authenticated/index.html.erb +1 -0
  27. data/test/rails_app/app/views/layouts/application.html.erb +14 -0
  28. data/test/rails_app/app/views/pages/index.html.erb +1 -0
  29. data/test/rails_app/config.ru +4 -0
  30. data/test/rails_app/config/application.rb +49 -0
  31. data/test/rails_app/config/boot.rb +10 -0
  32. data/test/rails_app/config/database.yml +22 -0
  33. data/test/rails_app/config/environment.rb +5 -0
  34. data/test/rails_app/config/environments/development.rb +25 -0
  35. data/test/rails_app/config/environments/production.rb +26 -0
  36. data/test/rails_app/config/environments/test.rb +2 -0
  37. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  38. data/test/rails_app/config/initializers/inflections.rb +10 -0
  39. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  40. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  41. data/test/rails_app/config/initializers/session_store.rb +8 -0
  42. data/test/rails_app/config/locales/devise.en.yml +59 -0
  43. data/test/rails_app/config/locales/en.yml +9 -0
  44. data/test/rails_app/config/locales/es.yml +10 -0
  45. data/test/rails_app/config/routes.rb +62 -0
  46. data/test/rails_app/db/test.sqlite3 +0 -0
  47. data/test/rails_app/log/development.log +3060 -0
  48. data/test/rails_app/log/production.log +8453 -0
  49. data/test/rails_app/log/test.log +316579 -0
  50. data/test/rails_app/perf.rake +4 -0
  51. data/test/rails_app/public/404.html +26 -0
  52. data/test/rails_app/public/422.html +26 -0
  53. data/test/rails_app/public/500.html +26 -0
  54. data/test/rails_app/public/assets/application-5f55f638b632759d9c9113417c3ac6bd.css +15 -0
  55. data/test/rails_app/public/assets/application-5f55f638b632759d9c9113417c3ac6bd.css.gz +0 -0
  56. data/test/rails_app/public/assets/application-89f8f774b6fb6783dfccc79d4103f256.js +2 -0
  57. data/test/rails_app/public/assets/application-89f8f774b6fb6783dfccc79d4103f256.js.gz +0 -0
  58. data/test/rails_app/public/assets/manifest-7bf37a2cd54094ac4d4308b706454b81.json +1 -0
  59. data/test/rails_app/public/assets/schneems-cb0905b917bde936182e153558f54a5f.png +0 -0
  60. data/test/rails_app/public/favicon.ico +0 -0
  61. data/test/rails_app/script/rails +6 -0
  62. data/test/test_helper.rb +52 -0
  63. metadata +154 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4b9e2f685ac142d180ca674e23d1a3f1cbf73dd
4
- data.tar.gz: 99269b8768c5692012850dd727f085bf9df1de6a
3
+ metadata.gz: 0b57356cb57b226f6f31ef6780186dd0fee37cf2
4
+ data.tar.gz: 978c074bd92a0d42ee9b288c42b43b9f8231a64c
5
5
  SHA512:
6
- metadata.gz: 5a7b1e8a9a74fecdd138432b3b6cd26e0d8b4e8a90ce8c91e2178f088b0d76fefdc15e1cf295ee4af1a578fde629a5dd525f8116022e85fa324bdff84d12f203
7
- data.tar.gz: 9843941d471bf55ea7e5312958eb229c18d58eb2dbb5ce55526972007d927a761fae835f4e78c16a9bc95e077757fe14154bd7a4fa0a2ee782f27aa1f6b191b8
6
+ metadata.gz: 99c780d2f36b1a807114cfc2e40cbf6638c06eeac7cad8e138ea9cf385b455c8e6c8aa3cac546fd5300d3e7d309d45d7d246a5748084bf70a070a101ab19d294
7
+ data.tar.gz: 7d259374be229858394159e4577acbad000e2bb0e9d1b28423ee0d2ff949d241e158718f49b5f6d97bb790b27514596f49912c625079cf8e091c347e797350b6
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1
6
+ - ruby-head
7
+ - jruby-19mode
8
+
9
+ gemfile:
10
+ - gemfiles/3.2.gemfile
11
+ - gemfiles/4.1.gemfile
12
+ - gemfiles/4.2.gemfile
13
+
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: ruby-head
data/Gemfile CHANGED
@@ -1,4 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rails_serve_static_assets.gemspec
4
- gemspec
4
+ gemspec :path => File.expand_path("../.", __FILE__)
5
+
6
+ group :development, :test do
7
+ gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
8
+ gem "activerecord-jdbcsqlite3-adapter", '~> 1.3.13', :platform => :jruby
9
+ end
10
+
11
+ gem 'launchy'
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- Copyright (c) 2013, Heroku
2
- All rights reserved.
1
+ The MIT License (MIT)
3
2
 
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
6
- * Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
8
- * Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
3
+ Copyright (c) 2013,2014 Heroku
11
4
 
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
- DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
16
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -22,14 +22,14 @@ gem 'rails_serve_static_assets'
22
22
  Then run
23
23
 
24
24
  ```
25
- $ bundle install`
25
+ $ bundle install
26
26
  ```
27
27
 
28
- You also need the `rails_stdout_logging` gem. You can get both of them together by installing `rails_on_heroku` gem.
28
+ You also need the `rails_stdout_logging` gem. You can get both of them together by installing [`rails_12factor`](https://github.com/heroku/rails_12factor) gem.
29
29
 
30
30
  ## Rails 4 Serve Static Assets
31
31
 
32
- In the default Rails development environment assets are served through a middleware called [sprockets](https://github.com/sstephenson/sprockets). In production however most one off Rails deployments will put their ruby server behind reverse HTTP proxy server such as Nginx which can load balance their sites and can serve static files directly. When Nginx sees a request for an asset such as `/assets/rails.png` it will grab it from disk at `/public/assets/rails.png` and serve it. The Rails server will never even sees the request.
32
+ In the default Rails development environment assets are served through a middleware called [sprockets](https://github.com/sstephenson/sprockets). In production however most one off Rails deployments will put their ruby server behind reverse HTTP proxy server such as Nginx which can load balance their sites and can serve static files directly. When Nginx sees a request for an asset such as `/assets/rails.png` it will grab it from disk at `/public/assets/rails.png` and serve it. The Rails server will never even see the request.
33
33
 
34
34
  On a 12factor platform, Nginx is not required to run your application. Your app should be capable of handling requests directly, or through a [routing layer](https://devcenter.heroku.com/articles/http-routing) that may handles load balancing while you scale out horizontally. The caching behavior of Nginx is not needed if your application is serving static assets through an [edge caching CDN](https://en.wikipedia.org/wiki/Content_delivery_network).
35
35
 
data/Rakefile CHANGED
@@ -1,2 +1,24 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development, :test)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'rake/testtask'
16
+
17
+ Rake::TestTask.new(:test) do |t|
18
+ t.libs << 'lib'
19
+ t.libs << 'test'
20
+ t.pattern = 'test/**/*_test.rb'
21
+ t.verbose = false
22
+ end
23
+
24
+ task default: :test
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ eval Pathname.new(__FILE__).join("../../Gemfile").read
4
+
5
+ gem "rails", "~> 3.2.21"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ eval Pathname.new(__FILE__).join("../../Gemfile").read
4
+
5
+ gem "rails", "~> 4.1.8"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ eval Pathname.new(__FILE__).join("../../Gemfile").read
4
+
5
+ gem "rails", "~> 4.1.8"
@@ -1,7 +1,11 @@
1
1
  module RailsServeStaticAssets
2
2
  class Railtie < Rails::Railtie
3
3
  config.before_initialize do
4
- ::Rails.configuration.serve_static_assets = true
4
+ if Rails.version >= "4.2.0"
5
+ ::Rails.configuration.serve_static_files = true
6
+ else
7
+ ::Rails.configuration.serve_static_assets = true
8
+ end
5
9
  ::Rails.configuration.action_dispatch.x_sendfile_header = nil
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module RailsServeStaticAssets
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -14,5 +14,9 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "rails_serve_static_assets"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = RailsServeStaticAssets::VERSION
17
- gem.license = 'LICENSE'
17
+ gem.license = 'MIT'
18
+
19
+ gem.add_development_dependency "rails", [">= 3.1"]
20
+ gem.add_development_dependency "capybara", [">= 0"]
21
+ gem.add_development_dependency "sprockets", [">= 0"]
18
22
  end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class StaticFileServiceTest < ActiveSupport::IntegrationCase
4
+ test 'renders CSS' do
5
+ visit "/assets/application-5f55f638b632759d9c9113417c3ac6bd.css"
6
+ assert_equal 200, page.status_code
7
+ end
8
+
9
+ test 'renders JS' do
10
+ visit "/assets/application-89f8f774b6fb6783dfccc79d4103f256.js"
11
+ assert_equal 200, page.status_code
12
+ end
13
+
14
+ test 'renders images' do
15
+ visit "/assets/schneems-cb0905b917bde936182e153558f54a5f.png"
16
+ assert_equal 200, page.status_code
17
+ end
18
+
19
+ test 'does not render imaginary things' do
20
+ visit "/assets/does-not-exist.png"
21
+ refute_equal 200, page.status_code
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1 @@
1
+ var foo = 1;
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1 @@
1
+ .foo { background-color: red;}
@@ -0,0 +1,9 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ before_filter :pull_out_locale
4
+
5
+
6
+ def pull_out_locale
7
+ I18n.locale = params[:locale] if params[:locale].present?
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class AuthenticatedController < ApplicationController
2
+ if respond_to?(:before_filter)
3
+ class << self
4
+ alias :before_action :before_filter
5
+ end
6
+ end
7
+
8
+ before_action :authenticate_user!
9
+
10
+ def index
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ class PagesController < ApplicationController
2
+
3
+ def index
4
+ end
5
+
6
+ private
7
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module AuthenticatedHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%# stylesheet_link_tag :all %>
6
+ <%# javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,49 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require :default
10
+
11
+ require "rails_serve_static_assets"
12
+ require 'sprockets/railtie'
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ config.action_mailer.default_url_options = { host: 'localhost:3000' }
17
+
18
+ # Settings in config/environments/* take precedence over those specified here.
19
+ # Application configuration should go into files in config/initializers
20
+ # -- all .rb files in that directory are automatically loaded.
21
+
22
+ # Custom directories with classes and modules you want to be autoloadable.
23
+ # config.autoload_paths += %W(#{config.root}/extras)
24
+
25
+ # Only load the plugins named here, in the order given (default is alphabetical).
26
+ # :all can be used as a placeholder for all plugins not explicitly named.
27
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
28
+
29
+ # Activate observers that should always be running.
30
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
31
+
32
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
33
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
34
+ # config.time_zone = 'Central Time (US & Canada)'
35
+
36
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
37
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
38
+ # config.i18n.default_locale = :de
39
+
40
+ # JavaScript files you want as :defaults (application.js is always included).
41
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
42
+
43
+ # Configure the default encoding used in templates for Ruby 1.9.
44
+ config.encoding = "utf-8"
45
+
46
+ # Configure sensitive parameters which will be filtered from the log file.
47
+ config.filter_parameters += [:password]
48
+ end
49
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+
4
+ default: &default
5
+ adapter: sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ development:
10
+ <<: *default
11
+ database: db/development.sqlite3
12
+
13
+ # Warning: The database defined as "test" will be erased and
14
+ # re-generated from your development database when you run "rake".
15
+ # Do not set this db to the same as development or production.
16
+ test:
17
+ <<: *default
18
+ database: db/test.sqlite3
19
+
20
+ production:
21
+ <<: *default
22
+ database: db/production.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,25 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+ end
25
+
@@ -0,0 +1,26 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # Specifies the header that your server uses for sending files
13
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
+
15
+ config.assets.compress = true
16
+ config.assets.js_compressor = :uglifier
17
+
18
+ # Don't fallback to assets pipeline if a precompiled asset is missed
19
+ config.assets.compile = false
20
+ config.assets.digest = true
21
+
22
+ config.i18n.fallbacks = true
23
+
24
+ # Send deprecation notices to registered listeners
25
+ config.active_support.deprecation = :notify
26
+ end