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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +16 -0
- data/Gemfile +8 -1
- data/LICENSE +19 -19
- data/README.md +3 -3
- data/Rakefile +22 -0
- data/gemfiles/3.2.gemfile +5 -0
- data/gemfiles/4.1.gemfile +5 -0
- data/gemfiles/4.2.gemfile +5 -0
- data/lib/rails_serve_static_assets/railtie.rb +5 -1
- data/lib/rails_serve_static_assets/version.rb +1 -1
- data/rails_serve_static_assets.gemspec +5 -1
- data/test/integration/static_file_service_test.rb +23 -0
- data/test/rails_app/Rakefile +7 -0
- data/test/rails_app/app/assets/images/schneems.png +0 -0
- data/test/rails_app/app/assets/javascripts/application.js +1 -0
- data/test/rails_app/app/assets/javascripts/foo.js +1 -0
- data/test/rails_app/app/assets/stylesheets/application.css +13 -0
- data/test/rails_app/app/assets/stylesheets/foo.css +1 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/authenticated_controller.rb +12 -0
- data/test/rails_app/app/controllers/pages_controller.rb +7 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/helpers/authenticated_helper.rb +2 -0
- data/test/rails_app/app/views/authenticated/index.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +14 -0
- data/test/rails_app/app/views/pages/index.html.erb +1 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +49 -0
- data/test/rails_app/config/boot.rb +10 -0
- data/test/rails_app/config/database.yml +22 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +25 -0
- data/test/rails_app/config/environments/production.rb +26 -0
- data/test/rails_app/config/environments/test.rb +2 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/inflections.rb +10 -0
- data/test/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/locales/devise.en.yml +59 -0
- data/test/rails_app/config/locales/en.yml +9 -0
- data/test/rails_app/config/locales/es.yml +10 -0
- data/test/rails_app/config/routes.rb +62 -0
- data/test/rails_app/db/test.sqlite3 +0 -0
- data/test/rails_app/log/development.log +3060 -0
- data/test/rails_app/log/production.log +8453 -0
- data/test/rails_app/log/test.log +316579 -0
- data/test/rails_app/perf.rake +4 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/assets/application-5f55f638b632759d9c9113417c3ac6bd.css +15 -0
- data/test/rails_app/public/assets/application-5f55f638b632759d9c9113417c3ac6bd.css.gz +0 -0
- data/test/rails_app/public/assets/application-89f8f774b6fb6783dfccc79d4103f256.js +2 -0
- data/test/rails_app/public/assets/application-89f8f774b6fb6783dfccc79d4103f256.js.gz +0 -0
- data/test/rails_app/public/assets/manifest-7bf37a2cd54094ac4d4308b706454b81.json +1 -0
- data/test/rails_app/public/assets/schneems-cb0905b917bde936182e153558f54a5f.png +0 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +6 -0
- data/test/test_helper.rb +52 -0
- metadata +154 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b57356cb57b226f6f31ef6780186dd0fee37cf2
|
4
|
+
data.tar.gz: 978c074bd92a0d42ee9b288c42b43b9f8231a64c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99c780d2f36b1a807114cfc2e40cbf6638c06eeac7cad8e138ea9cf385b455c8e6c8aa3cac546fd5300d3e7d309d45d7d246a5748084bf70a070a101ab19d294
|
7
|
+
data.tar.gz: 7d259374be229858394159e4577acbad000e2bb0e9d1b28423ee0d2ff949d241e158718f49b5f6d97bb790b27514596f49912c625079cf8e091c347e797350b6
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
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
|
-
|
2
|
-
All rights reserved.
|
1
|
+
The MIT License (MIT)
|
3
2
|
|
4
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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 `
|
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
|
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
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module RailsServeStaticAssets
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
config.before_initialize do
|
4
|
-
|
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
|
@@ -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 = '
|
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
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
// require_tree
|
@@ -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 @@
|
|
1
|
+
sup
|
@@ -0,0 +1 @@
|
|
1
|
+
ohai
|
@@ -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,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,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
|