sinatra-asset-snack 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +9 -9
- data/.travis.yml +6 -0
- data/Gemfile.lock +16 -16
- data/README.md +20 -0
- data/lib/sinatra/asset_snack.rb +8 -4
- data/lib/sinatra/asset_snack/asset_snack.rb +10 -13
- data/lib/sinatra/asset_snack/compilers/asset_compiler.rb +2 -2
- data/lib/sinatra/asset_snack/compilers/sass_compiler.rb +2 -7
- data/lib/sinatra/asset_snack/precompile.rb +21 -0
- data/lib/sinatra/asset_snack/rake.rb +17 -0
- data/lib/sinatra/asset_snack/version.rb +1 -1
- data/sinatra-asset-snack.gemspec +1 -0
- data/test/asset_snack_test.rb +5 -1
- data/test/compilers/coffee_script_compiler_test.rb +2 -3
- data/test/precompile_test.rb +28 -0
- data/test/test_helper.rb +2 -1
- metadata +21 -4
- data/travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTI0NGUxZDJmYTlkODE1MzBkZTc3MmFjNTEyMzU3ODkxZDlkY2EwZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
M2M2NzhlMzA5ODc3MGQ3YzAzMGViMzlkMDcxYWVmZmExYjQwNzBiMQ==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTJhYmU2ZDk2MTQ2YTVkNGJkNzI0ZGY3YTMwNzMzMWRlYjExMWZiNGM3YjIz
|
10
|
+
NzEwMGM2MGI4Y2FmN2NhZGVlZjdiNmM1ZThkMTRlOWIxZDc2ZjdiYmY3Mzc1
|
11
|
+
OGU2ZDU3MjRhZmRjYmIwZjc5MDRjYTBiMTI4ZTAyYjNhNWJiZTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWM5ZTNiYWNmNmUyYWM4NzRiZWRiODBkYjA1NzFkYzYxNWU2NzUxYzZmNjZi
|
14
|
+
NTllYzNkMzkxZmVlMTMxZDMxMDVmOWMyYThhOTE3YTgzMzY2MDMzOTYyYjEw
|
15
|
+
Yjc4MGYzOWZmZjhmZmY2MThkMjdlMmYwNGVhM2FjM2NiNGJjOTE=
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,50 +1,50 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sinatra-asset-snack (0.1.
|
4
|
+
sinatra-asset-snack (0.1.5)
|
5
5
|
coffee-script
|
6
6
|
mime-types
|
7
7
|
sass
|
8
8
|
sinatra
|
9
|
+
yajl-ruby
|
9
10
|
|
10
11
|
GEM
|
11
12
|
remote: https://rubygems.org/
|
12
13
|
specs:
|
13
14
|
ansi (1.4.3)
|
14
|
-
builder (3.2.
|
15
|
+
builder (3.2.2)
|
15
16
|
coffee-script (2.2.0)
|
16
17
|
coffee-script-source
|
17
18
|
execjs
|
18
|
-
coffee-script-source (1.
|
19
|
-
execjs (1.
|
20
|
-
|
21
|
-
hashie (2.0.3)
|
19
|
+
coffee-script-source (1.7.0)
|
20
|
+
execjs (2.1.0)
|
21
|
+
hashie (2.0.5)
|
22
22
|
metaclass (0.0.1)
|
23
|
-
mime-types (
|
24
|
-
minitest (4.7.
|
25
|
-
minitest-reporters (0.14.
|
23
|
+
mime-types (2.3)
|
24
|
+
minitest (4.7.4)
|
25
|
+
minitest-reporters (0.14.20)
|
26
26
|
ansi
|
27
27
|
builder
|
28
28
|
minitest (>= 2.12, < 5.0)
|
29
29
|
powerbar
|
30
|
-
mocha (0.
|
30
|
+
mocha (0.14.0)
|
31
31
|
metaclass (~> 0.0.1)
|
32
|
-
multi_json (1.7.2)
|
33
32
|
powerbar (1.0.11)
|
34
33
|
ansi (~> 1.4.0)
|
35
34
|
hashie (>= 1.1.0)
|
36
35
|
rack (1.5.2)
|
37
|
-
rack-protection (1.5.
|
36
|
+
rack-protection (1.5.3)
|
38
37
|
rack
|
39
38
|
rack-test (0.6.2)
|
40
39
|
rack (>= 1.0)
|
41
40
|
rake (10.0.4)
|
42
|
-
sass (3.
|
43
|
-
sinatra (1.4.
|
44
|
-
rack (~> 1.
|
41
|
+
sass (3.3.8)
|
42
|
+
sinatra (1.4.5)
|
43
|
+
rack (~> 1.4)
|
45
44
|
rack-protection (~> 1.4)
|
46
45
|
tilt (~> 1.3, >= 1.3.4)
|
47
|
-
tilt (1.
|
46
|
+
tilt (1.4.1)
|
47
|
+
yajl-ruby (1.2.0)
|
48
48
|
|
49
49
|
PLATFORMS
|
50
50
|
ruby
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/benkitzelman/sinatra-asset-snack)
|
4
4
|
[](http://badge.fury.io/rb/sinatra-asset-snack)
|
5
|
+
[](https://coderwall.com/benkitzelman)
|
5
6
|
|
6
7
|
A lean asset compiler for Sinatra developed specifically for Coffeescript and SASS.
|
7
8
|
It stitches all assets for a route into a single file, no uglification, no minification (configure your server to use Gzip),
|
@@ -59,3 +60,22 @@ See each compiler's repo for the list of configuration options
|
|
59
60
|
[coffee-script](http://github.com/josh/ruby-coffee-script)
|
60
61
|
|
61
62
|
[sass](http://sass-lang.com/)
|
63
|
+
|
64
|
+
## Precompile
|
65
|
+
|
66
|
+
To precompile your assets, you must set a constant `APP_FILE` to the
|
67
|
+
source file which defines your Sinatra app.
|
68
|
+
|
69
|
+
### Rakefile
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
APP_FILE = "lib/app/app.rb"
|
73
|
+
require 'sinatra/asset_snack/rake'
|
74
|
+
```
|
75
|
+
|
76
|
+
This defines the rake task `assetsnack:build` which will precompile your
|
77
|
+
assets.
|
78
|
+
|
79
|
+
|
80
|
+
[](https://bitdeli.com/free "Bitdeli Badge")
|
81
|
+
|
data/lib/sinatra/asset_snack.rb
CHANGED
@@ -2,9 +2,13 @@ require 'mime/types'
|
|
2
2
|
require 'sass'
|
3
3
|
require 'coffee-script'
|
4
4
|
|
5
|
-
|
5
|
+
require 'sinatra/asset_snack/compilers/asset_compiler'
|
6
6
|
|
7
|
-
require
|
7
|
+
require 'sinatra/asset_snack/version'
|
8
|
+
require 'sinatra/asset_snack/helpers'
|
9
|
+
require 'sinatra/asset_snack/extensions'
|
10
|
+
require 'sinatra/asset_snack/configuration'
|
11
|
+
require 'sinatra/asset_snack/asset_snack'
|
8
12
|
|
9
|
-
|
10
|
-
|
13
|
+
require 'sinatra/asset_snack/compilers/coffee_script_compiler'
|
14
|
+
require 'sinatra/asset_snack/compilers/sass_compiler'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Sinatra
|
2
2
|
module AssetSnack
|
3
3
|
class << self
|
4
|
-
attr_reader :compilers, :configuration
|
4
|
+
attr_reader :compilers, :configuration, :app
|
5
5
|
|
6
6
|
def registered(app, &block)
|
7
7
|
@configuration = Configuration.new
|
8
|
+
@app = app # Used in precompile step
|
8
9
|
|
9
10
|
app.extend ClassMethods
|
10
11
|
app.send(:include, InstanceMethods)
|
@@ -13,14 +14,12 @@ module Sinatra
|
|
13
14
|
|
14
15
|
def register_compiler(compiler, handled_extensions)
|
15
16
|
@compilers ||= {}
|
16
|
-
handled_extensions.each
|
17
|
-
@compilers[ext.downcase.to_sym] = compiler
|
18
|
-
end
|
17
|
+
handled_extensions.each { |ext| @compilers[ext.downcase.to_sym] = compiler }
|
19
18
|
end
|
20
19
|
|
21
20
|
def compiler_for(file_path)
|
22
21
|
ext = (File.extname(file_path) || '.').downcase[1..-1]
|
23
|
-
@compilers[ext.to_sym]
|
22
|
+
@compilers[ext.to_sym] || Compilers::AssetCompiler
|
24
23
|
end
|
25
24
|
|
26
25
|
def assets
|
@@ -44,13 +43,9 @@ module Sinatra
|
|
44
43
|
expand(paths).reduce({body: '', mime_type: 'text/plain'}) do |content, path|
|
45
44
|
next unless File.exists?(path)
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
else
|
51
|
-
compiled = File.read path
|
52
|
-
content_type = MIME::Types.type_for(path).first.to_s
|
53
|
-
end
|
46
|
+
compiler = AssetSnack.compiler_for(path)
|
47
|
+
compiled = compiler.compile_file(path)
|
48
|
+
content_type = compiler.compiled_mime_type || MIME::Types.type_for(path).first.to_s
|
54
49
|
|
55
50
|
{
|
56
51
|
mime_type: content_type || content[:mime_type],
|
@@ -60,7 +55,9 @@ module Sinatra
|
|
60
55
|
end
|
61
56
|
|
62
57
|
def expand(paths)
|
63
|
-
paths.reduce([])
|
58
|
+
paths.reduce([]) do |file_list, path|
|
59
|
+
file_list += File.file?(path) ? [path] : Dir.glob(path)
|
60
|
+
end.uniq
|
64
61
|
end
|
65
62
|
end # InstanceMethods
|
66
63
|
end # AssetSnack
|
@@ -24,9 +24,9 @@ module Sinatra
|
|
24
24
|
|
25
25
|
def compile_file(file_path)
|
26
26
|
ext = ext_for file_path
|
27
|
-
return unless ext && handled_extensions.include?(ext.to_sym)
|
28
|
-
|
29
27
|
file_content = File.read file_path
|
28
|
+
|
29
|
+
return file_content unless ext && (handled_extensions || []).include?(ext.to_sym)
|
30
30
|
new.compile(file_content, file_path)
|
31
31
|
end
|
32
32
|
|
@@ -11,13 +11,8 @@ module Sinatra
|
|
11
11
|
|
12
12
|
def compile(sass_script, file_path = nil)
|
13
13
|
config = self.class.configuration
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
config.merge!(syntax: :scss)
|
18
|
-
end
|
19
|
-
|
20
|
-
Sass.compile(sass_script, config)
|
14
|
+
syntax = (file_path && ext_for(file_path) == 'sass') ? :sass : :scss
|
15
|
+
Sass.compile sass_script, config.merge(syntax: syntax)
|
21
16
|
end
|
22
17
|
end
|
23
18
|
end # Compilers
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
module AssetSnack
|
5
|
+
def self.precompile!(opts={})
|
6
|
+
snack = self
|
7
|
+
Module.new do
|
8
|
+
extend snack::InstanceMethods
|
9
|
+
snack.assets.each do |assets|
|
10
|
+
path = File.join(snack.app.public_dir, assets[:route])
|
11
|
+
FileUtils.mkdir_p File.dirname(path)
|
12
|
+
puts "compiling #{path}" if opts[:verbose]
|
13
|
+
File.open(path, 'w') do |file|
|
14
|
+
file.write compile(assets[:paths])[:body]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
unless defined?(APP_FILE)
|
2
|
+
$stderr.write "Error: Please set APP_FILE before setting up AssetSnack rake tasks.\n"
|
3
|
+
$stderr.write "Example:\n"
|
4
|
+
$stderr.write " APP_FILE = 'init.rb'\n"
|
5
|
+
$stderr.write " require 'sinatra/asset_snack/rake'\n"
|
6
|
+
$stderr.write "\n"
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :assetsnack do
|
11
|
+
desc "Build assets"
|
12
|
+
task :build do
|
13
|
+
require File.expand_path(APP_FILE, Dir.pwd)
|
14
|
+
require 'sinatra/asset_snack/precompile'
|
15
|
+
Sinatra::AssetSnack.precompile!(verbose:true)
|
16
|
+
end
|
17
|
+
end
|
data/sinatra-asset-snack.gemspec
CHANGED
data/test/asset_snack_test.rb
CHANGED
@@ -39,5 +39,9 @@ module Sinatra
|
|
39
39
|
Sinatra::AssetSnack.assets.must_include js_assets
|
40
40
|
Sinatra::AssetSnack.assets.must_include css_assets
|
41
41
|
end
|
42
|
+
|
43
|
+
it 'should be able to determine public directory' do
|
44
|
+
Sinatra::AssetSnack.app.public_dir.must_equal App.public_dir
|
45
|
+
end
|
42
46
|
end
|
43
|
-
end
|
47
|
+
end
|
@@ -10,7 +10,6 @@ module Sinatra
|
|
10
10
|
(function() {
|
11
11
|
(function() {
|
12
12
|
var x;
|
13
|
-
|
14
13
|
return x = "test";
|
15
14
|
});
|
16
15
|
|
@@ -18,7 +17,7 @@ module Sinatra
|
|
18
17
|
EOS
|
19
18
|
}
|
20
19
|
|
21
|
-
before
|
20
|
+
before do
|
22
21
|
Sinatra::AssetSnack.configuration.compilers[:coffee_script] = {}
|
23
22
|
end
|
24
23
|
|
@@ -43,4 +42,4 @@ module Sinatra
|
|
43
42
|
AssetSnack.compiler_for('test.coffee').must_equal AssetSnack::Compilers::CoffeeScriptCompiler
|
44
43
|
end
|
45
44
|
end
|
46
|
-
end
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require './test/test_helper'
|
2
|
+
require 'sinatra/asset_snack/precompile'
|
3
|
+
|
4
|
+
module Sinatra::AssetSnack
|
5
|
+
describe "Sinatra::AssetSnack.precompile!" do
|
6
|
+
let(:app) { App.new }
|
7
|
+
let(:public) { App.public_dir }
|
8
|
+
let(:paths) do
|
9
|
+
Sinatra::AssetSnack.assets.map do |i|
|
10
|
+
File.join(public, File.dirname(i[:route]))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
FileUtils.rm_r(public) if Dir.exists?(public)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "must write compiled files to the public directory" do
|
19
|
+
Sinatra::AssetSnack.precompile!
|
20
|
+
paths.wont_be_empty
|
21
|
+
paths.each {|dir| Dir.glob("#{dir}/*").wont_be_empty }
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
FileUtils.rm_r(public) if Dir.exists?(public)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
ENV['RACK_ENV'] = 'test'
|
2
|
-
require 'minitest/spec'
|
3
2
|
require 'minitest/autorun'
|
3
|
+
require 'minitest/spec'
|
4
4
|
require "minitest/reporters"
|
5
5
|
require "mocha/setup"
|
6
6
|
require 'rack/test'
|
@@ -15,3 +15,4 @@ class App < Sinatra::Base
|
|
15
15
|
asset_map '/javascript/application_js_only.js', ['test/fixtures/**/*.js']
|
16
16
|
asset_map '/stylesheets/application.css', ['test/fixtures/**/*.scss']
|
17
17
|
end
|
18
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-asset-snack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Kitzelman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yajl-ruby
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: minitest
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,6 +159,7 @@ extensions: []
|
|
145
159
|
extra_rdoc_files: []
|
146
160
|
files:
|
147
161
|
- .gitignore
|
162
|
+
- .travis.yml
|
148
163
|
- Gemfile
|
149
164
|
- Gemfile.lock
|
150
165
|
- LICENSE.txt
|
@@ -158,6 +173,8 @@ files:
|
|
158
173
|
- lib/sinatra/asset_snack/configuration.rb
|
159
174
|
- lib/sinatra/asset_snack/extensions.rb
|
160
175
|
- lib/sinatra/asset_snack/helpers.rb
|
176
|
+
- lib/sinatra/asset_snack/precompile.rb
|
177
|
+
- lib/sinatra/asset_snack/rake.rb
|
161
178
|
- lib/sinatra/asset_snack/version.rb
|
162
179
|
- sinatra-asset-snack.gemspec
|
163
180
|
- test/asset_snack_test.rb
|
@@ -170,8 +187,8 @@ files:
|
|
170
187
|
- test/fixtures/test.scss
|
171
188
|
- test/fixtures/test_two.coffee
|
172
189
|
- test/helpers_test.rb
|
190
|
+
- test/precompile_test.rb
|
173
191
|
- test/test_helper.rb
|
174
|
-
- travis.yml
|
175
192
|
homepage: http://github.com/benkitzelman/sinatra-asset-snack
|
176
193
|
licenses: []
|
177
194
|
metadata: {}
|
@@ -191,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
208
|
version: '0'
|
192
209
|
requirements: []
|
193
210
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.
|
211
|
+
rubygems_version: 2.2.2
|
195
212
|
signing_key:
|
196
213
|
specification_version: 4
|
197
214
|
summary: Real quick asset compilation of Coffeescript to Javascript and SASS to CSS
|