roger_sprockets 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 +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +16 -0
- data/lib/roger_sprockets.rb +9 -0
- data/lib/roger_sprockets/middleware.rb +52 -0
- data/lib/roger_sprockets/processor.rb +87 -0
- data/lib/roger_sprockets/version.rb +3 -0
- data/roger_sprockets.gemspec +27 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 81dc7b700c386c8d44b4e2d1df4c4598d391999f
|
4
|
+
data.tar.gz: 3bcc14b7001dd6556cee052fc31668250cee05e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 220909d093dad038dd9d11f521e46841f8326c288042c790738b34aa8edbe0fb543c12ccbca54b0e4f2fd25086652b53546cc1e5d435856784c63c0f0e3e7be7
|
7
|
+
data.tar.gz: 3a21d9c1f419b99ebed587ac0a835441a2aa5aa4a472f5e042945ae857ade7f16ed8fbb6fb0987af1c8c3b453d83c1d6e610158b587fda1225efeb7412ce4190
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Edwin van der Graaf
|
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,85 @@
|
|
1
|
+
# RogerSprockets
|
2
|
+
|
3
|
+
Add sprockets to your roger project.
|
4
|
+
|
5
|
+
> Sprockets is a Ruby library for compiling and serving web assets. It
|
6
|
+
> features declarative dependency management for JavaScript and CSS assets, as
|
7
|
+
> well as a powerful preprocessor pipeline that allows you to write assets in
|
8
|
+
> languages like CoffeeScript, Sass and SCSS.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem "roger_sprockets"
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Add the following lines to your Mockupfile
|
23
|
+
|
24
|
+
For serving with sprockets
|
25
|
+
|
26
|
+
```
|
27
|
+
mockup.serve do |s|
|
28
|
+
s.use(RogerSprockets::Middleware)
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
For making a release
|
33
|
+
```
|
34
|
+
mockup.release do |r|
|
35
|
+
r.use(RogerSprockets::Processors)
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
### Registering additional engines
|
40
|
+
|
41
|
+
```
|
42
|
+
require 'sprockets'
|
43
|
+
require 'mustache/js'
|
44
|
+
require 'tilt/mustache_js_template'
|
45
|
+
|
46
|
+
sprockets = Sprockets::Environment.new()
|
47
|
+
sprockets.register_engine '.mustache', Tilt::MustacheJsTemplate
|
48
|
+
|
49
|
+
mockup.serve do |s|
|
50
|
+
s.use(RogerSprockets::Middleware, :sprockets_environment => sprockets)
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
## Options
|
55
|
+
|
56
|
+
__[:sprockets_environment]__,
|
57
|
+
Pass a custom sprockets environment, in which you can register an additional enginge or tweak sprockets more to your need. See [registering-additional-engines].
|
58
|
+
|
59
|
+
__[:load_paths]__,
|
60
|
+
Add additional loading paths.
|
61
|
+
_Defaults:_ ``` ["html/javascripts"] ```
|
62
|
+
|
63
|
+
|
64
|
+
### Processor
|
65
|
+
__[:build_files]__,
|
66
|
+
Define which files `roger_sprockets` should build.
|
67
|
+
_Defaults:_ ``` ["html/javascripts/site.js"] ```
|
68
|
+
|
69
|
+
__[:clean]__,
|
70
|
+
`roger_sprockets` can clean your dependencies after you made a build.
|
71
|
+
Pass `true` to let it remove all dependencies.
|
72
|
+
|
73
|
+
|
74
|
+
## TODO
|
75
|
+
|
76
|
+
* Add test coverage (especially on some edge cases)
|
77
|
+
* Add asset fingerprinting
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
1. Fork it ( https://github.com/[my-github-username]/roger_sprockets/fork )
|
82
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
83
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
85
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "rubocop/rake_task"
|
4
|
+
|
5
|
+
task default: [:test, :rubocop]
|
6
|
+
|
7
|
+
desc "Run rubocop"
|
8
|
+
task :rubocop do
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
end
|
11
|
+
|
12
|
+
Rake::TestTask.new do |t|
|
13
|
+
t.libs << "test"
|
14
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
15
|
+
t.verbose = true
|
16
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module RogerSprockets
|
2
|
+
class Middleware
|
3
|
+
def initialize(app, options = {})
|
4
|
+
@app = app
|
5
|
+
defaults = {
|
6
|
+
sprockets_environment: ::Sprockets::Environment.new,
|
7
|
+
load_paths: ["html/javascripts", "bower_components"]
|
8
|
+
}
|
9
|
+
|
10
|
+
# Use the resolver to translate urls
|
11
|
+
# to file paths
|
12
|
+
@resolver = Roger::Resolver.new(app.project.html_path)
|
13
|
+
|
14
|
+
@options = defaults.update(options)
|
15
|
+
@sprockets = @options[:sprockets_environment]
|
16
|
+
|
17
|
+
# Add load_paths to sprocket env
|
18
|
+
@options[:load_paths].each do |load_path|
|
19
|
+
@sprockets.append_path(app.project.path + load_path)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(env)
|
24
|
+
url = ::Rack::Utils.unescape(env["PATH_INFO"].to_s).sub(/^\//, "")
|
25
|
+
|
26
|
+
# Convert the url to an absolute path,
|
27
|
+
# which is used to retrieve the asset from sprockets
|
28
|
+
asset_path = resolve_url(url)
|
29
|
+
|
30
|
+
if url.length > 1 && file = @sprockets.find_asset(asset_path)
|
31
|
+
respond(file)
|
32
|
+
else
|
33
|
+
@app.call(env)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def resolve_url(url)
|
40
|
+
@resolver.url_to_path url, exact_match: true
|
41
|
+
end
|
42
|
+
|
43
|
+
def respond(file)
|
44
|
+
resp = ::Rack::Response.new do |res|
|
45
|
+
res.status = 200
|
46
|
+
res.headers["Content-Type"] = file.content_type
|
47
|
+
res.write file.to_s
|
48
|
+
end
|
49
|
+
resp.finish
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "roger/release"
|
2
|
+
require "fileutils"
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module RogerSprockets
|
6
|
+
class Processor < ::Roger::Release::Processors::Base
|
7
|
+
def initialize(options = {})
|
8
|
+
@options = {
|
9
|
+
sprockets_environment: ::Sprockets::Environment.new,
|
10
|
+
build_files: ["html/javascripts/site.js"],
|
11
|
+
load_paths: ["html/javascripts", "bower_components"],
|
12
|
+
clean: true
|
13
|
+
}.update(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @option options [Hash]
|
17
|
+
# :build_files
|
18
|
+
def call(release, options = {})
|
19
|
+
@release = release
|
20
|
+
|
21
|
+
@options.update(options)
|
22
|
+
@sprockets = @options[:sprockets_environment]
|
23
|
+
|
24
|
+
# Add load_paths to sprocket env
|
25
|
+
@options[:load_paths].each do |load_path|
|
26
|
+
@sprockets.append_path(release.project.path + load_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Build output based on files passed by options[:build_files]
|
30
|
+
@options[:build_files].each do |filename|
|
31
|
+
build_file(filename)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Remove included dependencies
|
35
|
+
@options[:build_files].each do |filename|
|
36
|
+
clean_files(filename)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def build_file(filename)
|
43
|
+
asset = get_sprockets_file(filename)
|
44
|
+
|
45
|
+
build_file = source_file_in_build_path(filename)
|
46
|
+
|
47
|
+
# Write file to FS
|
48
|
+
@release.log self, "Building #{build_file}"
|
49
|
+
File.open(build_file, "w+") { |f| f.write(asset.to_s) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def clean_files(filename)
|
53
|
+
asset = get_sprockets_file(filename)
|
54
|
+
asset.dependencies.each do |dep|
|
55
|
+
dep_build_path = source_file_in_build_path(dep.filename)
|
56
|
+
|
57
|
+
# Check if file is contained in build_path
|
58
|
+
if dep_build_path.to_s.match(@release.config[:build_path].to_s)
|
59
|
+
@release.debug self, "Cleaning #{dep_build_path}"
|
60
|
+
FileUtils.rm_rf dep_build_path
|
61
|
+
else
|
62
|
+
@release.debug self, "Not cleaning: #{dep_build_path}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def source_file_in_build_path(filepath)
|
68
|
+
build_path = @release.config[:build_path]
|
69
|
+
source_path = @release.source_path
|
70
|
+
project_path = @release.project.path
|
71
|
+
|
72
|
+
# Create a absolute_path to the given file, in a string
|
73
|
+
# to gsub, the source_path with the build_path
|
74
|
+
absolute_filepath = (project_path.realpath + filepath)
|
75
|
+
|
76
|
+
# Does nothing when its outside
|
77
|
+
absolute_filepath.sub(source_path.to_s, build_path.to_s)
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_sprockets_file(filename)
|
81
|
+
asset_file = Pathname.new(filename).realpath
|
82
|
+
@sprockets.find_asset(asset_file)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
::Roger::Release::Processors.register(:sprockets, RogerSprockets::Processor)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "roger_sprockets/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "roger_sprockets"
|
8
|
+
spec.version = RogerSprockets::VERSION
|
9
|
+
spec.authors = ["Edwin van der Graaf"]
|
10
|
+
spec.email = ["edwin@digitpaint.nl"]
|
11
|
+
spec.summary = "Add sprockets to your roger project"
|
12
|
+
spec.homepage = "https://github.com/digitpaint/roger_sprockets"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "sprockets"
|
21
|
+
spec.add_dependency "sprockets-es6"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "test-unit", [">= 0"]
|
26
|
+
spec.add_development_dependency "rubocop", ["~> 0"]
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: roger_sprockets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edwin van der Graaf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sprockets
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sprockets-es6
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: test-unit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- edwin@digitpaint.nl
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/roger_sprockets.rb
|
110
|
+
- lib/roger_sprockets/middleware.rb
|
111
|
+
- lib/roger_sprockets/processor.rb
|
112
|
+
- lib/roger_sprockets/version.rb
|
113
|
+
- roger_sprockets.gemspec
|
114
|
+
homepage: https://github.com/digitpaint/roger_sprockets
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.0.14
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Add sprockets to your roger project
|
138
|
+
test_files: []
|