forked from darkhelmet/sinatra-bundles
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Upgrade vendored sinatra to 1.0.a and include rack 1.1.0
Don't shrink variables when javascript file includes 'eval(' to prevent breaking eval calls
- Loading branch information
1 parent
ac86c9a
commit febdfbb
Showing
182 changed files
with
12,537 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Sinatra | ||
module Bundles | ||
# The base class for a bundle of files. | ||
# The developer user sinatra-bundles should | ||
# never have to deal with this directly | ||
class Bundle | ||
def initialize(app, files) | ||
@app = app | ||
@files = files | ||
end | ||
|
||
# Since we pass Bundles back as the body, | ||
# this follows Rack standards and supports an each method | ||
# to yield parts of the body, in our case, the files. | ||
def each | ||
@files.each do |f| | ||
content = File.read(path(f)) | ||
content = compress(content) if @app.compress_bundles | ||
# Include a new line to prevent weirdness at file boundaries | ||
yield("#{content}\n") | ||
end | ||
end | ||
|
||
private | ||
|
||
# The timestamp of the bundle, which is the newest file in the bundle. | ||
# | ||
# @return [Integer] The timestamp of the bundle | ||
def stamp | ||
@files.map do |f| | ||
File.mtime(path(f)) | ||
end.sort.first.to_i | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Sinatra | ||
module Bundles | ||
# View helpers | ||
module Helpers | ||
# Emit a script tag for a javascript bundle | ||
# | ||
# @param [Symbol,String] bundle The bundle name | ||
# @return [String] HTML script tag | ||
def javascript_bundle_include_tag(bundle) | ||
options.javascript_bundles[bundle].to_html(bundle) | ||
end | ||
|
||
# Emit a script tag for a stylesheet bundle | ||
# | ||
# @param [Symbol,String] bundle The bundle name | ||
# @return [String] HTML link tag | ||
def stylesheet_bundle_link_tag(bundle) | ||
options.stylesheet_bundles[bundle].to_html(bundle) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'sinatra/bundles/bundle' | ||
require 'packr' | ||
|
||
module Sinatra | ||
module Bundles | ||
# Bundle for javascripts | ||
class JavascriptBundle < Bundle | ||
# Generate the HTML tag for the script file | ||
# | ||
# @param [String] name The name of a bundle | ||
# @return [String] The HTML that can be inserted into the doc | ||
def to_html(name) | ||
"<script type='text/javascript' src='/javascripts/bundles/#{name}.js#{@app.stamp_bundles ? "?#{stamp}" : ''}'></script>" | ||
end | ||
|
||
protected | ||
|
||
# Compress Javascript | ||
# | ||
# @param [String] js The Javascript to compress | ||
# @return [String] Compressed Javascript | ||
def compress(js) | ||
# Don't shrink variables if the file includes a call to `eval` | ||
Packr.pack(js, :shrink_vars => !js.include?('eval(')) | ||
end | ||
|
||
# Get the path of the file on disk | ||
# | ||
# @param [String] filename The name of sheet, | ||
# assumed to be in the public directory, under 'javascripts' | ||
# @return [String] The full path to the file | ||
def path(filename) | ||
File.join(@app.public, 'javascripts', "#{filename}.js") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'sinatra/bundles/bundle' | ||
require 'rainpress' | ||
|
||
module Sinatra | ||
module Bundles | ||
# Bundle for stylesheets | ||
class StylesheetBundle < Bundle | ||
# Generate the HTML tag for the stylesheet | ||
# | ||
# @param [String] name The name of a bundle | ||
# @return [String] The HTML that can be inserted into the doc | ||
def to_html(name) | ||
"<link type='text/css' href='/stylesheets/bundles/#{name}.css#{@app.stamp_bundles ? "?#{stamp}" : ''}' rel='stylesheet' media='screen' />" | ||
end | ||
|
||
protected | ||
|
||
# Compress CSS | ||
# | ||
# @param [String] css The CSS to compress | ||
# @return [String] Compressed CSS | ||
def compress(css) | ||
Rainpress.compress(css) | ||
end | ||
|
||
# Get the path of the file on disk | ||
# | ||
# @param [String] filename The name of sheet, | ||
# assumed to be in the public directory, under 'stylesheets' | ||
# @return [String] The full path to the file | ||
def path(filename) | ||
File.join(@app.public, 'stylesheets', "#{filename}.css") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
gem 'sinatra', '>= 0.10.1' | ||
gem 'sinatra', '>= 1.0.a' | ||
require 'sinatra/base' | ||
require 'sinatra/bundles' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function something(name) { | ||
eval('alert(name);'); | ||
} | ||
|
||
something('bob'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/Users/darkhelmet/local/ree/bin/ruby | ||
# | ||
# This file was generated by RubyGems. | ||
# | ||
# The application 'rack' is installed as part of a gem, and | ||
# this file is here to facilitate running it. | ||
# | ||
|
||
require 'rubygems' | ||
|
||
version = ">= 0" | ||
|
||
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then | ||
version = $1 | ||
ARGV.shift | ||
end | ||
|
||
gem 'rack', version | ||
load Gem.bin_path('rack', 'rackup', version) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Copyright (c) 2007, 2008, 2009, 2010 Christian Neukirchen <purl.org/net/chneukirchen> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to | ||
deal in the Software without restriction, including without limitation the | ||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
sell copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
= Known issues with Rack and Web servers | ||
|
||
* Lighttpd sets wrong SCRIPT_NAME and PATH_INFO if you mount your | ||
FastCGI app at "/". This can be fixed by using this middleware: | ||
|
||
class LighttpdScriptNameFix | ||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
env["PATH_INFO"] = env["SCRIPT_NAME"].to_s + env["PATH_INFO"].to_s | ||
env["SCRIPT_NAME"] = "" | ||
@app.call(env) | ||
end | ||
end | ||
|
||
Of course, use this only when your app runs at "/". | ||
|
||
Since lighttpd 1.4.23, you also can use the "fix-root-scriptname" flag | ||
in fastcgi.server. |
Empty file.
Oops, something went wrong.