jammit-sinatra 0.6.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/LICENSE +22 -0
- data/README.md +35 -0
- data/jammit-sinatra.gemspec +23 -0
- data/lib/jammit/middleware.rb +114 -0
- data/lib/jammit/sinatra.rb +35 -0
- data/lib/jammit-sinatra.rb +1 -0
- metadata +77 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2011 Jacques Crocker
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Jammit Sinatra
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
Jammit-Sinatra is a jammit wrapper that allows Jammit to work properly in Sinatra/Padrino web apps.
|
6
|
+
|
7
|
+
It includes middleware and fixed up view helpers (`include_javascripts` and `include_stylesheets`).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
To install jammit-sinatra, just use:
|
12
|
+
|
13
|
+
gem install jammit-sinatra
|
14
|
+
|
15
|
+
If you are using bundler, add it to your project's `Gemfile`:
|
16
|
+
|
17
|
+
gem 'jammit-sinatra'
|
18
|
+
|
19
|
+
|
20
|
+
## With Sinatra
|
21
|
+
|
22
|
+
In your app code, you'll need to register Jammit:
|
23
|
+
|
24
|
+
register Jammit
|
25
|
+
|
26
|
+
You'll also need to load the jammit configuration file. So in your configure block, run:
|
27
|
+
|
28
|
+
::RAILS_ENV = "development" # this is needed to work around a Jammit limitation
|
29
|
+
Jammit.load_configuration("/path/to/config/assets.yml")
|
30
|
+
|
31
|
+
In order to use the `include_javascripts` and `include_stylesheets` you'll need to have working implemetnations of javascript_include_tag and stylesheets_include_tag. You can easily pull these helpers into your existing Sinatra app from Padrino. See instructions [here](http://www.padrinorb.com/guides/standalone-usage-in-sinatra).
|
32
|
+
|
33
|
+
## With Padrino
|
34
|
+
|
35
|
+
padrino-gen plugin jammit
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'jammit-sinatra'
|
3
|
+
s.version = '0.6.0.1'
|
4
|
+
|
5
|
+
s.homepage = "http://documentcloud.github.com/jammit/"
|
6
|
+
s.summary = "Industrial Strength Asset Packaging for Sinatra/Padrino"
|
7
|
+
s.description = <<-EOS
|
8
|
+
Jammit is an industrial strength asset packaging library for Sinatra/Padrino,
|
9
|
+
providing both the CSS and JavaScript concatenation and compression that
|
10
|
+
you'd expect, as well as YUI Compressor and Closure Compiler compatibility,
|
11
|
+
ahead-of-time gzipping, built-in JavaScript template support, and optional
|
12
|
+
Data-URI / MHTML image embedding.
|
13
|
+
EOS
|
14
|
+
|
15
|
+
s.authors = ['Jacques Crocker']
|
16
|
+
s.email = 'railsjedi@gmail.com'
|
17
|
+
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.add_dependency 'jammit', '>= 0.6.0'
|
21
|
+
|
22
|
+
s.files = Dir['lib/**/*', 'jammit-sinatra.gemspec', 'LICENSE', 'README.md']
|
23
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Jammit
|
2
|
+
|
3
|
+
# Rack Middle that allows Jammit to integrate with any Rack compatible web
|
4
|
+
# framework. It takes responsibility for /assets, and dynamically packages
|
5
|
+
# any missing or uncached asset packages.
|
6
|
+
|
7
|
+
class Middleware
|
8
|
+
|
9
|
+
VALID_FORMATS = [:css, :js]
|
10
|
+
|
11
|
+
SUFFIX_STRIPPER = /-(datauri|mhtml)\Z/
|
12
|
+
|
13
|
+
NOT_FOUND_PATH = "#{PUBLIC_ROOT}/404.html"
|
14
|
+
|
15
|
+
def initialize(app)
|
16
|
+
@app = app
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
dup._call(env)
|
21
|
+
end
|
22
|
+
|
23
|
+
def _call(env)
|
24
|
+
if matches = %r(^/#{Jammit.package_path}/(.*)\.(.*)).match(env['PATH_INFO'])
|
25
|
+
package(matches[1].to_s, matches[2] || "none")
|
26
|
+
else
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# The "package" action receives all requests for asset packages that haven't
|
34
|
+
# yet been cached. The package will be built, cached, and gzipped.
|
35
|
+
def package(package, extension)
|
36
|
+
parse_request(package, extension)
|
37
|
+
template_ext = Jammit.template_extension.to_sym
|
38
|
+
result = []
|
39
|
+
|
40
|
+
headers = {
|
41
|
+
'Cache-Control' => "public, max-age=#{(60*60*24*365.25*10).to_i}",
|
42
|
+
'Expires' => (Time.now + 60*60*24*365.25*10).httpdate
|
43
|
+
}
|
44
|
+
|
45
|
+
case @extension
|
46
|
+
when :js
|
47
|
+
@contents = Jammit.packager.pack_javascripts(@package)
|
48
|
+
@contents = @contents.to_js if @contents.respond_to?(:to_js)
|
49
|
+
result = [
|
50
|
+
200,
|
51
|
+
headers.merge({
|
52
|
+
'Content-Type' => Rack::Mime.mime_type(".js")
|
53
|
+
}),
|
54
|
+
[@contents]
|
55
|
+
]
|
56
|
+
when template_ext
|
57
|
+
@contents = Jammit.packager.pack_templates(@package)
|
58
|
+
@contents = @contents.to_js if @contents.respond_to?(:to_js)
|
59
|
+
[
|
60
|
+
200,
|
61
|
+
headers.merge({
|
62
|
+
'Content-Type' => Rack::Mime.mime_type(".js")
|
63
|
+
}),
|
64
|
+
[@contents]
|
65
|
+
]
|
66
|
+
when :css
|
67
|
+
[
|
68
|
+
200,
|
69
|
+
headers.merge({
|
70
|
+
'Content-Type' => Rack::Mime.mime_type(".css")
|
71
|
+
}),
|
72
|
+
[generate_stylesheets]
|
73
|
+
]
|
74
|
+
end
|
75
|
+
rescue Jammit::PackageNotFound
|
76
|
+
[404, {'Content-Type' => 'text/plain'}, ['Not found']]
|
77
|
+
end
|
78
|
+
|
79
|
+
# Generate the complete, timestamped, MHTML url -- if we're rendering a
|
80
|
+
# dynamic MHTML package, we'll need to put one URL in the response, and a
|
81
|
+
# different one into the cached package.
|
82
|
+
def prefix_url(path)
|
83
|
+
host = request.port == 80 ? request.host : request.host_with_port
|
84
|
+
"#{request.protocol}#{host}#{path}"
|
85
|
+
end
|
86
|
+
|
87
|
+
# If we're generating MHTML/CSS, return a stylesheet with the absolute
|
88
|
+
# request URL to the client, and cache a version with the timestamped cache
|
89
|
+
# URL swapped in.
|
90
|
+
def generate_stylesheets
|
91
|
+
return @contents = Jammit.packager.pack_stylesheets(@package, @variant) unless @variant == :mhtml
|
92
|
+
@mtime = Time.now
|
93
|
+
request_url = prefix_url(request.fullpath)
|
94
|
+
cached_url = prefix_url(Jammit.asset_url(@package, @extension, @variant, @mtime))
|
95
|
+
css = Jammit.packager.pack_stylesheets(@package, @variant, request_url)
|
96
|
+
# @contents = css.gsub(request_url, cached_url) if perform_caching
|
97
|
+
css
|
98
|
+
end
|
99
|
+
|
100
|
+
# Extracts the package name, extension (:css, :js), and variant (:datauri,
|
101
|
+
# :mhtml) from the incoming URL.
|
102
|
+
def parse_request(pack, extension)
|
103
|
+
@extension = extension.to_sym
|
104
|
+
raise PackageNotFound unless (VALID_FORMATS + [Jammit.template_extension.to_sym]).include?(@extension)
|
105
|
+
if Jammit.embed_assets
|
106
|
+
suffix_match = pack.match(SUFFIX_STRIPPER)
|
107
|
+
@variant = Jammit.embed_assets && suffix_match && suffix_match[1].to_sym
|
108
|
+
pack.sub!(SUFFIX_STRIPPER, '')
|
109
|
+
end
|
110
|
+
@package = pack.to_sym
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'jammit'
|
2
|
+
require 'jammit/middleware'
|
3
|
+
|
4
|
+
# allows use to include jammit/helper without exploding
|
5
|
+
module ActionView
|
6
|
+
class Base
|
7
|
+
end
|
8
|
+
end
|
9
|
+
require 'jammit/helper'
|
10
|
+
|
11
|
+
module Jammit::HelperOverrides
|
12
|
+
def javascript_include_tag(*sources)
|
13
|
+
super(*sources.flatten)
|
14
|
+
end
|
15
|
+
|
16
|
+
def stylesheet_link_tag(*sources)
|
17
|
+
super(*sources.flatten)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# provides hook so you can run
|
22
|
+
# register Jammit in your
|
23
|
+
module Jammit
|
24
|
+
def self.registered(app)
|
25
|
+
app.helpers Jammit::Helper
|
26
|
+
app.helpers Jammit::HelperOverrides
|
27
|
+
|
28
|
+
app.use Jammit::Middleware
|
29
|
+
|
30
|
+
# reload assets after every request (on development only)
|
31
|
+
if app.development?
|
32
|
+
app.before { Jammit.reload! }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'jammit/sinatra'
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jammit-sinatra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.6.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jacques Crocker
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-10 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: jammit
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.6.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
description: " Jammit is an industrial strength asset packaging library for Sinatra/Padrino,\n providing both the CSS and JavaScript concatenation and compression that\n you'd expect, as well as YUI Compressor and Closure Compiler compatibility,\n ahead-of-time gzipping, built-in JavaScript template support, and optional\n Data-URI / MHTML image embedding.\n"
|
28
|
+
email: railsjedi@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- lib/jammit/middleware.rb
|
37
|
+
- lib/jammit/sinatra.rb
|
38
|
+
- lib/jammit-sinatra.rb
|
39
|
+
- jammit-sinatra.gemspec
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://documentcloud.github.com/jammit/
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: -3190729303344462550
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: -3190729303344462550
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.6.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Industrial Strength Asset Packaging for Sinatra/Padrino
|
76
|
+
test_files: []
|
77
|
+
|