sinatra-minify 0.2.0 → 0.2.2
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.
- data/LICENSE +20 -0
- data/README.md +33 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/sinatra/minify/compressor.rb +13 -1
- data/lib/sinatra/minify/config.rb +5 -1
- data/lib/sinatra/minify/package.rb +4 -8
- data/lib/sinatra/minify.rb +3 -0
- data/sinatra-minify.gemspec +7 -4
- data/test/fixtures/exampleapp/config/assets-glob_error.yml +3 -0
- data/test/helper.rb +0 -1
- data/test/test_minify.rb +13 -0
- metadata +9 -4
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Rico Sta. Cruz, Cyril David and Sinefunc, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -13,13 +13,14 @@ Add these to your app's main file:
|
|
13
13
|
register Sinatra::Minify
|
14
14
|
end
|
15
15
|
|
16
|
-
Add this to your `Rakefile`:
|
16
|
+
Add this to your app's `Rakefile`:
|
17
17
|
|
18
18
|
load 'vendor/sinatra-minify/lib/tasks.rake'
|
19
19
|
|
20
20
|
Now add your JS/CSS packages in `config/assets.yml` (relative to your app's root path).
|
21
21
|
The files are are assumed to be in `public/js` and `public/css` by default.
|
22
22
|
|
23
|
+
# config/assets.yml
|
23
24
|
js:
|
24
25
|
base:
|
25
26
|
- jquery-1.4.2.js
|
@@ -34,6 +35,7 @@ The files are are assumed to be in `public/js` and `public/css` by default.
|
|
34
35
|
|
35
36
|
Now add the helpers to your templates:
|
36
37
|
|
38
|
+
# views/layout.erb (for example)
|
37
39
|
...
|
38
40
|
<%= css_assets 'base' %>
|
39
41
|
<%= css_assets 'homepage' %>
|
@@ -116,3 +118,33 @@ Ignore minified files in source control
|
|
116
118
|
It'd be good practice to add `*.min.{css,js}` to your `.gitignore` file (or similar,
|
117
119
|
for those not using Git).
|
118
120
|
|
121
|
+
Using sinatra-minify with Less / Sass
|
122
|
+
-------------------------------------
|
123
|
+
|
124
|
+
Let's say you have some routes like
|
125
|
+
|
126
|
+
get '/css/:file.css' do
|
127
|
+
# some code here that opens the less file
|
128
|
+
end
|
129
|
+
|
130
|
+
In order to properly minify this, the application must be running when
|
131
|
+
you do `rake minify:build`. By default, we assume you have your app running in
|
132
|
+
`http://localhost:4567`, but you can easily override this by doing:
|
133
|
+
|
134
|
+
# First let's run your application. Let's say it's a rack app:
|
135
|
+
rackup config.ru
|
136
|
+
|
137
|
+
# Now specify the URL via:
|
138
|
+
MINIFY_SITE_URL=http://localhost:9292 rake minify:build
|
139
|
+
|
140
|
+
|
141
|
+
Authors
|
142
|
+
=======
|
143
|
+
|
144
|
+
Sinatra-minify is co-authored by Rico Sta. Cruz and Cyril David of Sinefunc, Inc.
|
145
|
+
See more of our work on [www.sinefunc.com](http://www.sinefunc.com)!
|
146
|
+
|
147
|
+
Copyright
|
148
|
+
---------
|
149
|
+
|
150
|
+
(c) 2010 Rico Sta. Cruz, Cyril David and Sinefunc, Inc. See the LICENSE file for more details.
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |s|
|
7
7
|
s.name = "sinatra-minify"
|
8
|
-
s.authors = ["
|
8
|
+
s.authors = ["Rico Sta. Cruz", "Cyril David", "Sinefunc, Inc."]
|
9
9
|
s.email = "info@sinefunc.com"
|
10
10
|
s.summary = "CSS/JS compressor for Sinatra"
|
11
11
|
s.homepage = "http://www.github.com/sinefunc/sinatra-minify"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'open-uri'
|
3
|
+
|
1
4
|
module Sinatra
|
2
5
|
module Minify
|
3
6
|
class Compressor
|
@@ -8,12 +11,14 @@ module Sinatra
|
|
8
11
|
@file = file
|
9
12
|
@package = package
|
10
13
|
@command = :"minify_#{@type}"
|
14
|
+
@host = ENV["MINIFY_SITE_URL"] || "http://localhost:4567"
|
11
15
|
|
12
16
|
raise ArgumentError if not ['js', 'css'].include?(type)
|
13
17
|
end
|
14
18
|
|
15
19
|
# Rebuilds the minified .min.* files.
|
16
20
|
def build
|
21
|
+
FileUtils.mkdir_p(File.dirname(file))
|
17
22
|
File.open(file, 'w') { |f| f.write minify(concatenated) }
|
18
23
|
file
|
19
24
|
end
|
@@ -26,7 +31,14 @@ module Sinatra
|
|
26
31
|
private
|
27
32
|
# TODO: decouple this further?
|
28
33
|
def concatenated
|
29
|
-
package.files.map { |f|
|
34
|
+
package.files.map { |f|
|
35
|
+
if File.exist?(f)
|
36
|
+
File.read(f)
|
37
|
+
else
|
38
|
+
path = f.split('public').last
|
39
|
+
open("#{ @host }#{ path}").read
|
40
|
+
end
|
41
|
+
}.join("\n").strip
|
30
42
|
end
|
31
43
|
|
32
44
|
def minify(src)
|
@@ -26,8 +26,12 @@ module Sinatra
|
|
26
26
|
File.join(File.dirname(@settings.app_file), *args)
|
27
27
|
end
|
28
28
|
|
29
|
+
def config_file
|
30
|
+
@settings.minify_config
|
31
|
+
end
|
32
|
+
|
29
33
|
def sets
|
30
|
-
YAML.load_file(root_path(
|
34
|
+
YAML.load_file(root_path(config_file))[@type]
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Sinatra
|
2
2
|
module Minify
|
3
3
|
class Package
|
4
|
-
GlobNoMatchError = Class.new(StandardError)
|
5
|
-
|
6
4
|
attr :type, :set, :compressor, :filename
|
7
5
|
|
8
6
|
class << self
|
@@ -47,7 +45,7 @@ module Sinatra
|
|
47
45
|
def initialize(type, set, app_class = ::Main)
|
48
46
|
@type = type.to_s
|
49
47
|
@app_class = app_class
|
50
|
-
@set = set
|
48
|
+
@set = set.to_s
|
51
49
|
@config = Config.new(@type, app_class)
|
52
50
|
@filename = "#{set}.min.#{type}"
|
53
51
|
@compressor = Compressor.new(@type, public_dir(@filename), self)
|
@@ -57,9 +55,7 @@ module Sinatra
|
|
57
55
|
def html
|
58
56
|
if @app_class.minify?
|
59
57
|
file = public_dir(filename)
|
60
|
-
|
61
|
-
mtime = File.mtime(file).to_i
|
62
|
-
|
58
|
+
mtime = File.exists?(file) ? File.mtime(file).to_i : ''
|
63
59
|
asset_include_tag public_url(filename), mtime
|
64
60
|
else
|
65
61
|
enumerate_all_assets
|
@@ -95,9 +91,9 @@ module Sinatra
|
|
95
91
|
def asset_include_tag(path, mtime)
|
96
92
|
case type
|
97
93
|
when 'js'
|
98
|
-
"<script src='#{
|
94
|
+
"<script src='#{path}?#{mtime}' type='text/javascript'></script>"
|
99
95
|
when 'css'
|
100
|
-
"<link rel='stylesheet' href='#{
|
96
|
+
"<link rel='stylesheet' href='#{path}?#{mtime}' media='all' />"
|
101
97
|
else
|
102
98
|
raise ArgumentError, "only js/css are supported"
|
103
99
|
end
|
data/lib/sinatra/minify.rb
CHANGED
@@ -15,12 +15,15 @@ module Sinatra
|
|
15
15
|
autoload :Compressor, 'sinatra/minify/compressor'
|
16
16
|
autoload :Helpers, 'sinatra/minify/helpers'
|
17
17
|
|
18
|
+
GlobNoMatchError = Class.new(StandardError)
|
19
|
+
|
18
20
|
def self.registered( app )
|
19
21
|
app.helpers Helpers
|
20
22
|
app.set :js_url, '/js' # => http://site.com/js
|
21
23
|
app.set :js_path, '/public/js' # => ~/myproject/public/js
|
22
24
|
app.set :css_url, '/css'
|
23
25
|
app.set :css_path, '/public/css'
|
26
|
+
app.set :minify_config, 'config/assets.yml'
|
24
27
|
app.disable :force_minify
|
25
28
|
end
|
26
29
|
|
data/sinatra-minify.gemspec
CHANGED
@@ -5,19 +5,21 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-minify}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["
|
12
|
-
s.date = %q{2010-
|
11
|
+
s.authors = ["Rico Sta. Cruz", "Cyril David", "Sinefunc, Inc."]
|
12
|
+
s.date = %q{2010-05-22}
|
13
13
|
s.description = %q{sinatra-minify is an extension for Sinatra to compress assets.}
|
14
14
|
s.email = %q{info@sinefunc.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
|
-
"
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
17
18
|
]
|
18
19
|
s.files = [
|
19
20
|
".gitignore",
|
20
21
|
".rvmrc",
|
22
|
+
"LICENSE",
|
21
23
|
"README.md",
|
22
24
|
"Rakefile",
|
23
25
|
"VERSION",
|
@@ -30,6 +32,7 @@ Gem::Specification.new do |s|
|
|
30
32
|
"sinatra-minify.gemspec",
|
31
33
|
"test/fixtures/control/style-default-compressed.css",
|
32
34
|
"test/fixtures/exampleapp/app.rb",
|
35
|
+
"test/fixtures/exampleapp/config/assets-glob_error.yml",
|
33
36
|
"test/fixtures/exampleapp/config/assets.yml",
|
34
37
|
"test/fixtures/exampleapp/public/css/style-default.css",
|
35
38
|
"test/fixtures/exampleapp/public/js/script-1.js",
|
data/test/helper.rb
CHANGED
data/test/test_minify.rb
CHANGED
@@ -92,4 +92,17 @@ class TestMinify < Test::Unit::TestCase
|
|
92
92
|
assert_equal 9, unknown.index('aoeu=456;')
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
describe "second config file" do
|
97
|
+
def setup
|
98
|
+
app.set :minify_config, 'config/assets-glob_error.yml'
|
99
|
+
end
|
100
|
+
|
101
|
+
should "throw an error on an invalid glob" do
|
102
|
+
package = Sinatra::Minify::Package.new(:js, 'base', app)
|
103
|
+
assert_raise Sinatra::Minify::GlobNoMatchError do
|
104
|
+
package.html
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
95
108
|
end
|
metadata
CHANGED
@@ -5,16 +5,18 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
|
-
-
|
12
|
+
- Rico Sta. Cruz
|
13
|
+
- Cyril David
|
14
|
+
- Sinefunc, Inc.
|
13
15
|
autorequire:
|
14
16
|
bindir: bin
|
15
17
|
cert_chain: []
|
16
18
|
|
17
|
-
date: 2010-
|
19
|
+
date: 2010-05-22 00:00:00 +08:00
|
18
20
|
default_executable:
|
19
21
|
dependencies:
|
20
22
|
- !ruby/object:Gem::Dependency
|
@@ -36,10 +38,12 @@ executables: []
|
|
36
38
|
extensions: []
|
37
39
|
|
38
40
|
extra_rdoc_files:
|
41
|
+
- LICENSE
|
39
42
|
- README.md
|
40
43
|
files:
|
41
44
|
- .gitignore
|
42
45
|
- .rvmrc
|
46
|
+
- LICENSE
|
43
47
|
- README.md
|
44
48
|
- Rakefile
|
45
49
|
- VERSION
|
@@ -52,6 +56,7 @@ files:
|
|
52
56
|
- sinatra-minify.gemspec
|
53
57
|
- test/fixtures/control/style-default-compressed.css
|
54
58
|
- test/fixtures/exampleapp/app.rb
|
59
|
+
- test/fixtures/exampleapp/config/assets-glob_error.yml
|
55
60
|
- test/fixtures/exampleapp/config/assets.yml
|
56
61
|
- test/fixtures/exampleapp/public/css/style-default.css
|
57
62
|
- test/fixtures/exampleapp/public/js/script-1.js
|