sinatra-assetpack-flexible-compression 0.0.1
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/.gitignore +4 -0
- data/Gemfile +2 -0
- data/HISTORY.md +131 -0
- data/README.md +664 -0
- data/Rakefile +31 -0
- data/docsrc/style.css +32 -0
- data/examples/basic/.gitignore +1 -0
- data/examples/basic/Rakefile +7 -0
- data/examples/basic/app.rb +39 -0
- data/examples/basic/app/css/test.sass +11 -0
- data/examples/basic/app/images/icon.png +0 -0
- data/examples/basic/app/js/app.js +4 -0
- data/examples/basic/app/js/vendor/jquery.js +2 -0
- data/examples/basic/app/js/vendor/jquery.plugin.js +2 -0
- data/examples/basic/app/js/vendor/underscore.js +2 -0
- data/examples/basic/views/index.erb +26 -0
- data/examples/classic/app.rb +24 -0
- data/examples/classic/css/screen.scss +1 -0
- data/examples/compass/.gitignore +1 -0
- data/examples/compass/Rakefile +7 -0
- data/examples/compass/app.rb +45 -0
- data/examples/compass/app/css/main.scss +64 -0
- data/examples/compass/app/images/icon-scfd8d7d404.png +0 -0
- data/examples/compass/app/images/icon/mail.png +0 -0
- data/examples/compass/app/images/icon/refresh.png +0 -0
- data/examples/compass/app/images/junk/mail.png +0 -0
- data/examples/compass/app/images/junk/refresh.png +0 -0
- data/examples/compass/app/js/app.js +3 -0
- data/examples/compass/app/js/vendor/jquery.js +2 -0
- data/examples/compass/app/js/vendor/jquery.plugin.js +2 -0
- data/examples/compass/app/js/vendor/underscore.js +2 -0
- data/examples/compass/config.ru +3 -0
- data/examples/compass/views/index.erb +15 -0
- data/lib/sinatra/assetpack.rb +61 -0
- data/lib/sinatra/assetpack/buster_helpers.rb +36 -0
- data/lib/sinatra/assetpack/class_methods.rb +82 -0
- data/lib/sinatra/assetpack/compressor.rb +54 -0
- data/lib/sinatra/assetpack/configurator.rb +21 -0
- data/lib/sinatra/assetpack/css.rb +36 -0
- data/lib/sinatra/assetpack/engine.rb +20 -0
- data/lib/sinatra/assetpack/engines/closure.rb +19 -0
- data/lib/sinatra/assetpack/engines/jsmin.rb +10 -0
- data/lib/sinatra/assetpack/engines/sass.rb +11 -0
- data/lib/sinatra/assetpack/engines/simple.rb +11 -0
- data/lib/sinatra/assetpack/engines/sqwish.rb +21 -0
- data/lib/sinatra/assetpack/engines/uglify.rb +12 -0
- data/lib/sinatra/assetpack/engines/yui.rb +22 -0
- data/lib/sinatra/assetpack/hasharray.rb +66 -0
- data/lib/sinatra/assetpack/helpers.rb +61 -0
- data/lib/sinatra/assetpack/html_helpers.rb +17 -0
- data/lib/sinatra/assetpack/image.rb +59 -0
- data/lib/sinatra/assetpack/options.rb +326 -0
- data/lib/sinatra/assetpack/package.rb +116 -0
- data/lib/sinatra/assetpack/rake.rb +29 -0
- data/lib/sinatra/assetpack/version.rb +7 -0
- data/test/app/.gitignore +1 -0
- data/test/app/Rakefile +7 -0
- data/test/app/app.rb +62 -0
- data/test/app/app/css/behavior.htc +1 -0
- data/test/app/app/css/js2c.css +494 -0
- data/test/app/app/css/screen.sass +9 -0
- data/test/app/app/css/sqwishable.css +7 -0
- data/test/app/app/css/style.css +3 -0
- data/test/app/app/css/stylus.styl +3 -0
- data/test/app/app/css_stylus/stylus.styl +3 -0
- data/test/app/app/images/background.jpg +1 -0
- data/test/app/app/images/email.png +0 -0
- data/test/app/app/js/_ignoreme.js +1 -0
- data/test/app/app/js/hello.js +1 -0
- data/test/app/app/js/hi.coffee +2 -0
- data/test/app/app/js/ugly.js +7 -0
- data/test/app/app/js_glob/a/b/c1/hello.js +1 -0
- data/test/app/app/js_glob/a/b/c2/hi.js +1 -0
- data/test/app/app/js_glob/a/b/c2/hola.js +1 -0
- data/test/app/app/views/index.haml +1 -0
- data/test/arity_test.rb +26 -0
- data/test/build_test.rb +31 -0
- data/test/cache_test.rb +9 -0
- data/test/compressed_test.rb +30 -0
- data/test/glob_test.rb +42 -0
- data/test/helpers_test.rb +30 -0
- data/test/ignore_test.rb +30 -0
- data/test/img_test.rb +31 -0
- data/test/local_file_test.rb +21 -0
- data/test/mime_type_test.rb +33 -0
- data/test/non_existent_test.rb +45 -0
- data/test/options_test.rb +21 -0
- data/test/order_test.rb +20 -0
- data/test/preproc_test.rb +28 -0
- data/test/redundant_test.rb +11 -0
- data/test/simplecss_test.rb +16 -0
- data/test/sqwish_test.rb +31 -0
- data/test/stylus_test.rb +23 -0
- data/test/template_cache_test.rb +29 -0
- data/test/test_helper.rb +46 -0
- data/test/tilt_test.rb +11 -0
- data/test/uglifier_test.rb +23 -0
- data/test/unit_test.rb +109 -0
- data/test/yui_test.rb +22 -0
- metadata +276 -0
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
desc "Invokes the test suite in multiple RVM environments"
|
2
|
+
task :'test!' do
|
3
|
+
# Override this by adding RVM_TEST_ENVS=".." in .rvmrc
|
4
|
+
envs = ENV['RVM_TEST_ENVS'] || '1.9.2@sinatra,1.8.7@sinatra'
|
5
|
+
puts "* Testing in the following RVM environments: #{envs.gsub(',', ', ')}"
|
6
|
+
system "rvm #{envs} rake test" or abort
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Runs tests"
|
10
|
+
task :test do
|
11
|
+
Dir['test/*_test.rb'].each { |f| load f }
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :test
|
15
|
+
|
16
|
+
gh = "rstacruz/sinatra-assetpack"
|
17
|
+
namespace :doc do
|
18
|
+
# http://github.com/rstacruz/reacco
|
19
|
+
desc "Builds the documentation into doc/"
|
20
|
+
task :build do
|
21
|
+
system "reacco -a --github #{gh} --css docsrc/style.css"
|
22
|
+
end
|
23
|
+
|
24
|
+
# http://github.com/rstacruz/git-update-ghpages
|
25
|
+
desc "Posts documentation to GitHub pages"
|
26
|
+
task :deploy => :build do
|
27
|
+
system "git update-ghpages #{gh} -i doc/"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
task :doc => :'doc:build'
|
data/docsrc/style.css
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
section.features {
|
2
|
+
background: #f6f6ff;
|
3
|
+
overflow: hidden; }
|
4
|
+
|
5
|
+
h2 {
|
6
|
+
font-size: 26pt; }
|
7
|
+
|
8
|
+
section.features h2 {
|
9
|
+
font-size: 32pt; }
|
10
|
+
|
11
|
+
section.features ul {
|
12
|
+
max-width: none;
|
13
|
+
margin-left: 0;
|
14
|
+
padding-left: 0;
|
15
|
+
width: 100%; }
|
16
|
+
|
17
|
+
section.features li {
|
18
|
+
list-style-type: none;
|
19
|
+
width: 420px;
|
20
|
+
float: left; margin-right: 40px; }
|
21
|
+
|
22
|
+
section.features li:nth-child(odd) {
|
23
|
+
clear: both; }
|
24
|
+
|
25
|
+
section.features li>p>strong {
|
26
|
+
font-family: shanti, sans-serif;
|
27
|
+
font-weight: normal;
|
28
|
+
font-size: 1.2em;
|
29
|
+
text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.1);
|
30
|
+
display: block;
|
31
|
+
margin-bottom: 5px;
|
32
|
+
color: #88a; }
|
@@ -0,0 +1 @@
|
|
1
|
+
public
|
@@ -0,0 +1,39 @@
|
|
1
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'sinatra/assetpack'
|
5
|
+
|
6
|
+
class App < Sinatra::Base
|
7
|
+
set :root, File.dirname(__FILE__)
|
8
|
+
register Sinatra::AssetPack
|
9
|
+
|
10
|
+
assets do
|
11
|
+
#js_compression :closure
|
12
|
+
js_compression :uglify
|
13
|
+
|
14
|
+
js :main, '/js/main.js', [
|
15
|
+
'/js/vendor/*.js',
|
16
|
+
'/js/app.js'
|
17
|
+
]
|
18
|
+
|
19
|
+
css :main, [
|
20
|
+
'/css/*.css'
|
21
|
+
]
|
22
|
+
|
23
|
+
# The second parameter here is optional (see above).
|
24
|
+
# It will default to '/css/#{name}.css'.
|
25
|
+
css :more, '/css/more.css', [
|
26
|
+
'/css/more/*.css'
|
27
|
+
]
|
28
|
+
|
29
|
+
prebuild true
|
30
|
+
end
|
31
|
+
|
32
|
+
get '/' do
|
33
|
+
erb :index
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if __FILE__ == $0
|
38
|
+
App.run!
|
39
|
+
end
|
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8" />
|
5
|
+
<title></title>
|
6
|
+
|
7
|
+
<!-- These should include all the JS files defined in the app. -->
|
8
|
+
<%= js :main %>
|
9
|
+
<%= css :main %>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<h1>Hello!</h1>
|
13
|
+
<h4>View the source of this file to see the JS files as they were included.</h4>
|
14
|
+
|
15
|
+
<h3>Image test:</h3>
|
16
|
+
|
17
|
+
<!-- This should have width and height. -->
|
18
|
+
<%= img '/images/icon.png' %>
|
19
|
+
|
20
|
+
<h3>Image embedding test:</h3>
|
21
|
+
<div id="image_embedding_test">
|
22
|
+
<!-- This should have a CSS background that uses a data: URI. -->
|
23
|
+
<!-- Inspect that <div> to see. -->
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'sinatra'
|
4
|
+
require 'sinatra/assetpack'
|
5
|
+
|
6
|
+
assets do
|
7
|
+
# By default, Sinatra::AssetPack looks at ./app/css/, ./app/js/ and
|
8
|
+
# ./app/images. Let's change this to look at ./css.
|
9
|
+
serve '/css', from: 'css'
|
10
|
+
|
11
|
+
css :main, [
|
12
|
+
'/css/*.css'
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
get "/" do
|
17
|
+
css :main
|
18
|
+
end
|
19
|
+
|
20
|
+
__END__
|
21
|
+
|
22
|
+
@@ index
|
23
|
+
<%= css :main %>
|
24
|
+
<h1>Hello!</h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
body { color: red }
|
@@ -0,0 +1 @@
|
|
1
|
+
public
|
@@ -0,0 +1,45 @@
|
|
1
|
+
$:.unshift File.expand_path('../../../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'sinatra/assetpack'
|
5
|
+
require 'compass'
|
6
|
+
require 'sinatra/support'
|
7
|
+
|
8
|
+
Encoding.default_external = 'utf-8' if defined?(::Encoding)
|
9
|
+
|
10
|
+
class App < Sinatra::Base
|
11
|
+
disable :show_exceptions
|
12
|
+
enable :raise_exceptions
|
13
|
+
|
14
|
+
set :root, File.dirname(__FILE__)
|
15
|
+
|
16
|
+
# This is a convenient way of setting up Compass in a Sinatra
|
17
|
+
# project without mucking around with load paths and such.
|
18
|
+
register Sinatra::CompassSupport
|
19
|
+
|
20
|
+
# ### Compass sprite configuration
|
21
|
+
# Skip this section if you don't need sprite images.
|
22
|
+
#
|
23
|
+
# Configure Compass so it knows where to look for sprites. This tells
|
24
|
+
# Compass to look for images in `app/images`, dump sprite images in the same
|
25
|
+
# folder, and link to it with HTTP images path.
|
26
|
+
#
|
27
|
+
c = Compass.configuration
|
28
|
+
c.project_path = root
|
29
|
+
c.images_dir = "app/images"
|
30
|
+
c.http_images_path = "/images"
|
31
|
+
|
32
|
+
# Asset Pack.
|
33
|
+
register Sinatra::AssetPack
|
34
|
+
assets do
|
35
|
+
css :main, ['/css/*.css']
|
36
|
+
end
|
37
|
+
|
38
|
+
get '/' do
|
39
|
+
erb :index
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if __FILE__ == $0
|
44
|
+
App.run!
|
45
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
@import 'compass/css3';
|
2
|
+
@import 'compass/reset';
|
3
|
+
|
4
|
+
html, body {
|
5
|
+
font-family: sans-serif;
|
6
|
+
font-size: 11pt;
|
7
|
+
line-height: 1.5; }
|
8
|
+
|
9
|
+
body {
|
10
|
+
background: #c2c2cf; }
|
11
|
+
|
12
|
+
#all {
|
13
|
+
background: white;
|
14
|
+
color: #333;
|
15
|
+
padding: 10px;
|
16
|
+
width: 500px;
|
17
|
+
margin: 50px auto; }
|
18
|
+
|
19
|
+
// ### Optional sprite config
|
20
|
+
// You may put any of these before the `all-icon-sprites` line.
|
21
|
+
// These are completely optional.
|
22
|
+
|
23
|
+
// #### Sprite sets: (/icon/*.png)
|
24
|
+
$icon-spacing: 0; // How much blank space (in pixels) to put
|
25
|
+
$icon-dimensions: false; // Sets width/height in the classes
|
26
|
+
$icon-repeat: no-repeat;
|
27
|
+
$icon-position: 0;
|
28
|
+
|
29
|
+
// #### Individual images: (/icon/mail.png)
|
30
|
+
$icon-mail-spacing: 0;
|
31
|
+
$icon-mail-repeat: no-repeat;
|
32
|
+
$icon-mail-position: 0px;
|
33
|
+
|
34
|
+
// ### Sprite setup
|
35
|
+
// For "mail.png" and "refresh.png", this creates classes for .icon-mail and
|
36
|
+
// .icon-refresh that you can @extend from.
|
37
|
+
//
|
38
|
+
// See: http://compass-style.org/help/tutorials/configuration-reference/
|
39
|
+
//
|
40
|
+
@import "icon/*.png";
|
41
|
+
@include all-icon-sprites;
|
42
|
+
|
43
|
+
.image1, .image2 {
|
44
|
+
width: 16px; height: 16px;
|
45
|
+
display: inline-block; }
|
46
|
+
|
47
|
+
.image1 {
|
48
|
+
@extend .icon-mail; }
|
49
|
+
|
50
|
+
.image2 {
|
51
|
+
@extend .icon-refresh; }
|
52
|
+
|
53
|
+
// ### Advanced control
|
54
|
+
// The sprite map is available as $icon-sprites. You can then use
|
55
|
+
// `sprite()` on it.
|
56
|
+
|
57
|
+
.image3 {
|
58
|
+
background: sprite($icon-sprites, refresh); }
|
59
|
+
//background: url(...) 0 -16px;
|
60
|
+
|
61
|
+
.image3-with-offset {
|
62
|
+
background: sprite($icon-sprites, refresh, -2px, -9px); }
|
63
|
+
//background: url(...) -2px -19px;
|
64
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8" />
|
5
|
+
<title></title>
|
6
|
+
<%= css :main %>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<div id="all">
|
10
|
+
<h1>Here are some sprites:</h1>
|
11
|
+
<span class='image1'></span>
|
12
|
+
<span class='image2'></span>
|
13
|
+
</div>
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
module AssetPack
|
5
|
+
def self.registered(app)
|
6
|
+
app.helpers Helpers
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns a list of formats that can be served.
|
10
|
+
# Anything not in this list will be rejected.
|
11
|
+
def self.supported_formats
|
12
|
+
@supported_formats ||= %w(css js png jpg gif svg otf eot ttf woff htc)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a map of what MIME format each Tilt type returns.
|
16
|
+
def self.tilt_formats
|
17
|
+
@formats ||= begin
|
18
|
+
hash = Hash.new
|
19
|
+
Tilt.mappings.each do |format, (engine, _)|
|
20
|
+
case engine.default_mime_type
|
21
|
+
when 'text/css' then hash[format] = 'css'
|
22
|
+
when 'application/javascript' then hash[format] = 'js'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
hash
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the inverse of tilt_formats.
|
31
|
+
def self.tilt_formats_reverse
|
32
|
+
re = Hash.new { |h, k| h[k] = Array.new }
|
33
|
+
formats.each { |tilt, out| re[out] << tilt }
|
34
|
+
out
|
35
|
+
end
|
36
|
+
|
37
|
+
PREFIX = File.dirname(__FILE__)
|
38
|
+
|
39
|
+
autoload :ClassMethods, "#{PREFIX}/assetpack/class_methods"
|
40
|
+
autoload :Options, "#{PREFIX}/assetpack/options"
|
41
|
+
autoload :Helpers, "#{PREFIX}/assetpack/helpers"
|
42
|
+
autoload :HtmlHelpers, "#{PREFIX}/assetpack/html_helpers"
|
43
|
+
autoload :BusterHelpers, "#{PREFIX}/assetpack/buster_helpers"
|
44
|
+
autoload :Engine, "#{PREFIX}/assetpack/engine"
|
45
|
+
autoload :Package, "#{PREFIX}/assetpack/package"
|
46
|
+
autoload :Compressor, "#{PREFIX}/assetpack/compressor"
|
47
|
+
autoload :Image, "#{PREFIX}/assetpack/image"
|
48
|
+
autoload :Css, "#{PREFIX}/assetpack/css"
|
49
|
+
autoload :Configurator, "#{PREFIX}/assetpack/configurator"
|
50
|
+
autoload :HashArray, "#{PREFIX}/assetpack/hasharray"
|
51
|
+
|
52
|
+
include ClassMethods
|
53
|
+
|
54
|
+
Error = Class.new(StandardError)
|
55
|
+
|
56
|
+
require "#{PREFIX}/assetpack/version"
|
57
|
+
end
|
58
|
+
|
59
|
+
# Autoload in Sinatra classic mode
|
60
|
+
register AssetPack
|
61
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Sinatra
|
2
|
+
module AssetPack
|
3
|
+
module BusterHelpers
|
4
|
+
extend self
|
5
|
+
# Returns the cache buster suffix for given file(s).
|
6
|
+
# This implementation somewhat obfuscates the mtime to not reveal deployment dates.
|
7
|
+
def cache_buster_hash(*files)
|
8
|
+
i = mtime_for(files)
|
9
|
+
(i * 4567).to_s.reverse[0...6] if i
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns the maximum mtime for a given list of files.
|
13
|
+
# It will return nil if none of them are found.
|
14
|
+
def mtime_for(files)
|
15
|
+
files.map { |f| File.mtime(f).to_i if f.is_a?(String) && File.file?(f) }.compact.max
|
16
|
+
end
|
17
|
+
|
18
|
+
# Adds a cache buster for the given path.
|
19
|
+
#
|
20
|
+
# The 2nd parameter (and beyond) are the files to take mtime from.
|
21
|
+
# If the files are not found, the paths will be left as they are.
|
22
|
+
#
|
23
|
+
# add_cache_buster('/images/email.png', '/var/www/x/public/images/email.png')
|
24
|
+
#
|
25
|
+
def add_cache_buster(path, *files)
|
26
|
+
hash = cache_buster_hash *files
|
27
|
+
|
28
|
+
if hash
|
29
|
+
path.gsub(/(\.[^.]+)$/) { |ext| ".#{hash}#{ext}" }
|
30
|
+
else
|
31
|
+
path
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|