gulp-pipeline-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +2 -0
- data/gulp-pipeline-rails.gemspec +23 -0
- data/lib/gulp/pipeline/rails.rb +9 -0
- data/lib/gulp/pipeline/rails/all.rb +18 -0
- data/lib/gulp/pipeline/rails/assets.rb +93 -0
- data/lib/gulp/pipeline/rails/helper.rb +24 -0
- data/lib/gulp/pipeline/rails/patches.rb +21 -0
- data/lib/gulp/pipeline/rails/patches/metarequest_middlewares_headers.rb +15 -0
- data/lib/gulp/pipeline/rails/patches/route_wrapper.rb +20 -0
- data/lib/gulp/pipeline/rails/railtie.rb +78 -0
- data/lib/gulp/pipeline/rails/server.rb +135 -0
- data/lib/gulp/pipeline/rails/version.rb +7 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8209c637cdffae16d89f3835e0527391f7d27dfd
|
4
|
+
data.tar.gz: c8a24828ef21f8496dada1f1b3ac21e0e1bbc930
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f77ccc0980d0cb3df72cdae0beaf8843f4ad234b9b98a82baa8a7233d2a64f73ca61bc271a278e3a68da068bfddbcf531a0345f674a98f0b6c190c83f749a7d8
|
7
|
+
data.tar.gz: cf96500d1fb8010aab0ace5798335eed544130635ec25cdc4c94e58459afe53688435c5bb0c58e555b4388eb87131a13ce95f0382f6a94ec819a8dee01748862
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gulp-pipeline-rails
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Kevin Ross
|
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,73 @@
|
|
1
|
+
# gulp-pipeline-rails
|
2
|
+
|
3
|
+
Remove Sprockets from Rails and use [gulp-pipleline](https://github.com/alienfast/gulp-pipeline). Simpler, faster, and integrates very well with the rest of the assets community.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'gulp-pipeline-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install gulp-pipeline-rails
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
1. Remove sprockets from your `application.rb` and initialize Rails with `gulp-pipeline-rails`
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# require 'rails/all' <== DELETE this line
|
25
|
+
require 'gulp/pipeline/rails/all'
|
26
|
+
```
|
27
|
+
|
28
|
+
1. Remove unneeded gems such as:
|
29
|
+
- rails-jquery
|
30
|
+
- rails-sass
|
31
|
+
- uglifier
|
32
|
+
|
33
|
+
1. Remove unneeded `config.assets.*` configurations, simply leave `config.assets.debug` per environment.
|
34
|
+
|
35
|
+
1. Delete your old `public` and `tmp` folders.
|
36
|
+
|
37
|
+
1. Setup [gulp-pipleline](https://github.com/alienfast/gulp-pipeline) to generate your assets
|
38
|
+
|
39
|
+
2. Startup rails and you should be serving from your new asset pipeline!
|
40
|
+
|
41
|
+
## Goals
|
42
|
+
This gem is actually quite simple, and most of these goals are accomplished by the primary project [gulp-pipleline](https://github.com/alienfast/gulp-pipeline). Nonetheless, if you are coming from rails, this is what to expect:
|
43
|
+
|
44
|
+
### Simple
|
45
|
+
Ultimately this gem is simply serving static assets, we need nothing more complicated.
|
46
|
+
|
47
|
+
### Easy
|
48
|
+
With very few configurations it is easy to understand and hard to go wrong. The defaults should be good for almost everyone. The only common config is `config.assets.debug` based on the environment.
|
49
|
+
|
50
|
+
### Community Friendly
|
51
|
+
Make it easy to use community assets, namely `npm` packages
|
52
|
+
|
53
|
+
### Engine aware
|
54
|
+
[gulp-pipleline](https://github.com/alienfast/gulp-pipeline) and this gem should support engine configurations (at least yours). Beware, if the engines depend on sprockets, we do not have a goal of supporting them.
|
55
|
+
|
56
|
+
### Performance
|
57
|
+
There should be no performance penalty for using [gulp-pipleline](https://github.com/alienfast/gulp-pipeline) and this gem, in fact, it should be generally faster for development. Static file serving from external servers should be unaffected.
|
58
|
+
|
59
|
+
### Remove Sprockets
|
60
|
+
We don't want to match Sprockets in functionality, but remove it from rails and provide simple static asset serving. We want to remain something simpler, if you want something close to sprockets then I encourage you to engage there and help them make their project better.
|
61
|
+
|
62
|
+
|
63
|
+
## TODO
|
64
|
+
- Tests, primarily the `Gulp::Pipeline::Rails::Assets` class which contains asset resolution/path computation
|
65
|
+
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
1. Fork it ( https://github.com/[my-github-username]/gulp-pipeline-rails/fork )
|
70
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -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 'gulp/pipeline/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'gulp-pipeline-rails'
|
8
|
+
spec.version = Gulp::Pipeline::Rails::VERSION
|
9
|
+
spec.authors = ['Kevin Ross']
|
10
|
+
spec.email = ['kevin.ross@alienfast.com']
|
11
|
+
spec.summary = %q{Rails asset pipeline replacement using gulp-pipeline assets}
|
12
|
+
spec.description = %q{Remove sprockets and use gulp-pipeline. Simpler, faster, and integrates very well with the rest of the assets community.}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.6'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Use this file instead of `rails/all` in order to load the gulp pipeline instead of sprockets
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
%w(
|
6
|
+
active_record
|
7
|
+
action_controller
|
8
|
+
action_view
|
9
|
+
action_mailer
|
10
|
+
active_job
|
11
|
+
rails/test_unit
|
12
|
+
gulp/pipeline/rails
|
13
|
+
).each do |framework|
|
14
|
+
begin
|
15
|
+
require "#{framework}/railtie"
|
16
|
+
rescue LoadError
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Gulp
|
2
|
+
module Pipeline
|
3
|
+
module Rails
|
4
|
+
class Assets
|
5
|
+
class << self
|
6
|
+
|
7
|
+
# Computes asset path to public directory. We override this in the Helper to resolve
|
8
|
+
# either debug or digest assets.
|
9
|
+
#
|
10
|
+
# source: favicon.ico
|
11
|
+
# options: {type: :image}
|
12
|
+
def compute_asset_path(source, options = {})
|
13
|
+
dir = type_directory_map[options[:type]] || ''
|
14
|
+
|
15
|
+
# get the relative file path without a leading slash (empty dir join adds leading slash)
|
16
|
+
file = if dir.eql? '' then
|
17
|
+
source
|
18
|
+
else
|
19
|
+
File.join(dir, source)
|
20
|
+
end
|
21
|
+
if (debug)
|
22
|
+
path = File.join('/', base_path, file)
|
23
|
+
else
|
24
|
+
manifested = manifest[file]
|
25
|
+
raise "#{source} not found in the manifest. Perhaps you need to recreate it by running `gulp digest` or `gulp rev`" if manifested.nil?
|
26
|
+
path = File.join('/', base_path, manifested)
|
27
|
+
end
|
28
|
+
path
|
29
|
+
end
|
30
|
+
|
31
|
+
# Yield a digest path with respect to debug turned on or off
|
32
|
+
def base_path
|
33
|
+
if debug
|
34
|
+
"#{debug_prefix}/"
|
35
|
+
else
|
36
|
+
"#{digest_prefix}/"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def mount_path(prefix)
|
41
|
+
"/#{base_path}#{prefix}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def path_matches?(path)
|
45
|
+
(path =~ matches_regex) == 0
|
46
|
+
end
|
47
|
+
|
48
|
+
def path_starts_with?(path)
|
49
|
+
(path =~ starts_with_regex) == 0
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def manifest
|
55
|
+
return @_manifest unless @_manifest.nil?
|
56
|
+
|
57
|
+
# read manifest and cache it
|
58
|
+
path = ::Rails.application.root.join('public', digest_prefix, 'rev-manifest.json')
|
59
|
+
# if not debug, require manifest
|
60
|
+
raise "#{path} not found. Run `gulp digest` or `gulp rev`." unless File.exists?(path)
|
61
|
+
@_manifest = JSON.parse(File.read(path))
|
62
|
+
end
|
63
|
+
|
64
|
+
# lazy load/cache regex
|
65
|
+
def matches_regex
|
66
|
+
@_matches_regex ||= %r{\A/#{base_path}\z}
|
67
|
+
end
|
68
|
+
|
69
|
+
# lazy load/cache regex
|
70
|
+
def starts_with_regex
|
71
|
+
@_starts_with_regex ||= %r{\A/#{base_path}}
|
72
|
+
end
|
73
|
+
|
74
|
+
def type_directory_map
|
75
|
+
@_type_directory_map ||= ::Rails.application.config.assets.type_directory_map
|
76
|
+
end
|
77
|
+
|
78
|
+
def debug
|
79
|
+
@_debug ||= ::Rails.application.config.assets.debug
|
80
|
+
end
|
81
|
+
|
82
|
+
def digest_prefix
|
83
|
+
@_digest_prefix ||= ::Rails.application.config.assets.digest_prefix
|
84
|
+
end
|
85
|
+
|
86
|
+
def debug_prefix
|
87
|
+
@_debug_prefix ||= ::Rails.application.config.assets.debug_prefix
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Gulp
|
2
|
+
module Pipeline
|
3
|
+
module Rails
|
4
|
+
module Helper
|
5
|
+
# Maps asset types to public directory.
|
6
|
+
ASSET_PUBLIC_DIRECTORIES = {
|
7
|
+
audio: '/audios',
|
8
|
+
font: '/fonts',
|
9
|
+
image: '/images',
|
10
|
+
javascript: '/javascripts',
|
11
|
+
stylesheet: '/stylesheets',
|
12
|
+
video: '/videos'
|
13
|
+
}
|
14
|
+
|
15
|
+
# Computes asset path to public directory. Plugins and
|
16
|
+
# extensions can override this method to point to custom assets
|
17
|
+
# or generate digested paths or query strings.
|
18
|
+
def compute_asset_path(source, options = {})
|
19
|
+
Assets.compute_asset_path(source, options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'gulp/pipeline/rails/patches/route_wrapper'
|
2
|
+
|
3
|
+
module Gulp
|
4
|
+
module Pipeline
|
5
|
+
module Rails
|
6
|
+
|
7
|
+
# set our paths to be regarded as internal paths
|
8
|
+
ActionDispatch::Routing::RouteWrapper.class_eval do
|
9
|
+
prepend Patches::RouteWrapper
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
if defined?(MetaRequest::Middlewares::Headers)
|
14
|
+
require 'gulp/pipeline/rails/patches/metarequest_middlewares_headers'
|
15
|
+
MetaRequest::Middlewares::Headers.class_eval do
|
16
|
+
prepend Patches::MetaRequestMiddlewaresHeaders
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'gulp/pipeline/rails/assets'
|
2
|
+
|
3
|
+
module Gulp
|
4
|
+
module Pipeline
|
5
|
+
module Rails
|
6
|
+
module Patches
|
7
|
+
module MetaRequestMiddlewaresHeaders
|
8
|
+
def asset?(path)
|
9
|
+
@app_config.respond_to?(:assets) && Assets.path_starts_with?(path)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'gulp/pipeline/rails/assets'
|
2
|
+
|
3
|
+
module Gulp
|
4
|
+
module Pipeline
|
5
|
+
module Rails
|
6
|
+
module Patches
|
7
|
+
module RouteWrapper
|
8
|
+
|
9
|
+
def internal_assets_path?
|
10
|
+
Assets.path_matches? path
|
11
|
+
end
|
12
|
+
|
13
|
+
def internal?
|
14
|
+
super || internal_assets_path?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'rails/railtie'
|
3
|
+
require 'action_controller/railtie'
|
4
|
+
require 'active_support/core_ext/module/remove_method'
|
5
|
+
require 'set'
|
6
|
+
|
7
|
+
require 'gulp/pipeline/rails/server'
|
8
|
+
require 'gulp/pipeline/rails/assets'
|
9
|
+
require 'gulp/pipeline/rails/helper'
|
10
|
+
|
11
|
+
module Rails
|
12
|
+
class Application
|
13
|
+
# Hack: We need to remove Rails' built in config.assets so we can do our own thing.
|
14
|
+
class Configuration
|
15
|
+
remove_possible_method :assets
|
16
|
+
end
|
17
|
+
|
18
|
+
# Undefine Rails' assets method before redefining it, to avoid warnings.
|
19
|
+
remove_possible_method :assets
|
20
|
+
remove_possible_method :assets=
|
21
|
+
|
22
|
+
attr_accessor :assets
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Gulp
|
27
|
+
module Pipeline
|
28
|
+
module Rails
|
29
|
+
class Railtie < ::Rails::Railtie
|
30
|
+
|
31
|
+
config.assets = ActiveSupport::OrderedOptions.new
|
32
|
+
config.assets.debug = false
|
33
|
+
config.assets.digest_prefix = 'assets/digest'
|
34
|
+
config.assets.debug_prefix = 'assets/debug'
|
35
|
+
|
36
|
+
# Maps asset types to public directory. If unmapped, there will be nothing added to the path. This must match the physical layout of the public directory under #{config.assets.digest_prefix} and #{config.assets.debug_prefix}
|
37
|
+
config.assets.type_directory_map = {}
|
38
|
+
# config.assets.type_directory_map = {
|
39
|
+
# audio: 'audios',
|
40
|
+
# font: 'fonts',
|
41
|
+
# image: 'images',
|
42
|
+
# javascript: 'javascripts',
|
43
|
+
# stylesheet: 'stylesheets',
|
44
|
+
# video: 'videos'
|
45
|
+
# }
|
46
|
+
|
47
|
+
|
48
|
+
# We don't use this, but rails/engine.rb `append_assets_path` blows up without presenting this as a configurable option
|
49
|
+
config.assets.paths = []
|
50
|
+
|
51
|
+
# rake_tasks do |app|
|
52
|
+
# require 'gulp/pipeline/rails/task'
|
53
|
+
# Gulp::Pipeline::Rails::Task.new(app)
|
54
|
+
# end
|
55
|
+
|
56
|
+
config.after_initialize do |app|
|
57
|
+
config = app.config
|
58
|
+
|
59
|
+
app.assets = Server.new(app)
|
60
|
+
app.routes.prepend do
|
61
|
+
# for each asset path, add a route to our server - e.g. this may be /images or /digest/images depending on `config.assets.debug`. This means that these paths are stored and served as-is, enabling the greatest compatibility with external file serving.
|
62
|
+
prefixes = config.assets.type_directory_map.values || ['']
|
63
|
+
prefixes.each do |prefix|
|
64
|
+
mount app.assets => Assets.mount_path(prefix)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# now require our patches for the common items that are hard linked to '/assets'
|
69
|
+
require 'gulp/pipeline/rails/patches'
|
70
|
+
|
71
|
+
ActiveSupport.on_load(:action_view) do
|
72
|
+
include Gulp::Pipeline::Rails::Helper
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'rack/utils'
|
3
|
+
require 'gulp/pipeline/rails/assets'
|
4
|
+
|
5
|
+
module Gulp
|
6
|
+
module Pipeline
|
7
|
+
module Rails
|
8
|
+
# `Server` provides a Rack compatible `call` interface and url generation helpers.
|
9
|
+
class Server
|
10
|
+
|
11
|
+
def initialize(app, options = {})
|
12
|
+
config = app.config
|
13
|
+
|
14
|
+
@debug = config.assets.debug
|
15
|
+
@file_server = Rack::File.new(app.root.join('public', Assets.base_path).to_s)
|
16
|
+
@cache_duration = options[:duration] || 1
|
17
|
+
@duration_in_seconds = duration_in_seconds
|
18
|
+
@duration_in_words = duration_in_words
|
19
|
+
end
|
20
|
+
|
21
|
+
# A request for `"/assets/javascripts/foo/bar.js"` will search the public directory.
|
22
|
+
def call(env)
|
23
|
+
if env['REQUEST_METHOD'] != 'GET'
|
24
|
+
return method_not_allowed_response
|
25
|
+
end
|
26
|
+
|
27
|
+
msg = "Served asset #{env['PATH_INFO']} -"
|
28
|
+
|
29
|
+
# Extract the path from everything after the leading slash
|
30
|
+
path = Rack::Utils.unescape(env['PATH_INFO'].to_s.sub(/^\//, ''))
|
31
|
+
|
32
|
+
status, headers, body =
|
33
|
+
if forbidden_request?(path)
|
34
|
+
# URLs containing a `..` are rejected for security reasons.
|
35
|
+
forbidden_response
|
36
|
+
else
|
37
|
+
# # If not debug, enforce/require fingerprinted url. Do we really need this or just paranoia?
|
38
|
+
# if (!@debug)
|
39
|
+
# fingerprint = path_fingerprint(path)
|
40
|
+
# if (fingerprint.nil?)
|
41
|
+
# msg += ' not a manifested file'
|
42
|
+
# return not_found_response
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
|
46
|
+
# standard file serve
|
47
|
+
@file_server.call(env)
|
48
|
+
end
|
49
|
+
|
50
|
+
# log our status
|
51
|
+
case status
|
52
|
+
when :ok
|
53
|
+
logger.info "#{msg} 200 OK "
|
54
|
+
when :not_modified
|
55
|
+
logger.info "#{msg} 304 Not Modified "
|
56
|
+
when :not_found
|
57
|
+
logger.info "#{msg} 404 Not Found "
|
58
|
+
else
|
59
|
+
logger.info "#{msg} #{status} Unknown status message "
|
60
|
+
end
|
61
|
+
|
62
|
+
# add cache headers
|
63
|
+
headers['Cache-Control'] ="max-age=#{@duration_in_seconds}, public"
|
64
|
+
headers['Expires'] = @duration_in_words
|
65
|
+
|
66
|
+
# return results
|
67
|
+
[status, headers, body]
|
68
|
+
|
69
|
+
rescue Exception => e
|
70
|
+
logger.error "Error serving asset #{path}:"
|
71
|
+
logger.error "#{e.class.name}: #{e.message}"
|
72
|
+
raise
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
def forbidden_request?(path)
|
77
|
+
# Prevent access to files elsewhere on the file system
|
78
|
+
#
|
79
|
+
# http://example.org/assets/../../../etc/passwd
|
80
|
+
#
|
81
|
+
path.include?('..') || absolute_path?(path)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Public: Check if path is absolute or relative.
|
85
|
+
#
|
86
|
+
# path - String path.
|
87
|
+
#
|
88
|
+
# Returns true if path is absolute, otherwise false.
|
89
|
+
if File::ALT_SEPARATOR
|
90
|
+
require 'pathname'
|
91
|
+
|
92
|
+
# On Windows, ALT_SEPARATOR is \
|
93
|
+
# Delegate to Pathname since the logic gets complex.
|
94
|
+
def absolute_path?(path)
|
95
|
+
Pathname.new(path).absolute?
|
96
|
+
end
|
97
|
+
else
|
98
|
+
def absolute_path?(path)
|
99
|
+
path[0] == File::SEPARATOR
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Returns a 403 Forbidden response tuple
|
104
|
+
def forbidden_response
|
105
|
+
[403, {'Content-Type' => 'text/plain', 'Content-Length' => '9'}, ['Forbidden']]
|
106
|
+
end
|
107
|
+
|
108
|
+
# Returns a 404 Not Found response tuple
|
109
|
+
def not_found_response
|
110
|
+
[404, {'Content-Type' => 'text/plain', 'Content-Length' => '9', 'X-Cascade' => 'pass'}, ['Not found']]
|
111
|
+
end
|
112
|
+
|
113
|
+
def method_not_allowed_response
|
114
|
+
[405, {'Content-Type' => 'text/plain', 'Content-Length' => '18'}, ['Method Not Allowed']]
|
115
|
+
end
|
116
|
+
|
117
|
+
def logger
|
118
|
+
::Rails.logger
|
119
|
+
end
|
120
|
+
|
121
|
+
def duration_in_words
|
122
|
+
(Time.now + duration_in_seconds).strftime '%a, %d %b %Y %H:%M:%S GMT'
|
123
|
+
end
|
124
|
+
|
125
|
+
def duration_in_seconds
|
126
|
+
(60 * 60 * 24 * 365 * @cache_duration).to_i
|
127
|
+
end
|
128
|
+
|
129
|
+
# def path_fingerprint(path)
|
130
|
+
# path[/-([0-9a-f]{7,128})\.[^.]+\z/, 1]
|
131
|
+
# end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gulp-pipeline-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Ross
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-16 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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: Remove sprockets and use gulp-pipeline. Simpler, faster, and integrates
|
42
|
+
very well with the rest of the assets community.
|
43
|
+
email:
|
44
|
+
- kevin.ross@alienfast.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".ruby-gemset"
|
51
|
+
- ".ruby-version"
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- gulp-pipeline-rails.gemspec
|
57
|
+
- lib/gulp/pipeline/rails.rb
|
58
|
+
- lib/gulp/pipeline/rails/all.rb
|
59
|
+
- lib/gulp/pipeline/rails/assets.rb
|
60
|
+
- lib/gulp/pipeline/rails/helper.rb
|
61
|
+
- lib/gulp/pipeline/rails/patches.rb
|
62
|
+
- lib/gulp/pipeline/rails/patches/metarequest_middlewares_headers.rb
|
63
|
+
- lib/gulp/pipeline/rails/patches/route_wrapper.rb
|
64
|
+
- lib/gulp/pipeline/rails/railtie.rb
|
65
|
+
- lib/gulp/pipeline/rails/server.rb
|
66
|
+
- lib/gulp/pipeline/rails/version.rb
|
67
|
+
homepage: ''
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.4.8
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Rails asset pipeline replacement using gulp-pipeline assets
|
91
|
+
test_files: []
|