use gem/rip versions of deps instead of vendoring

This commit is contained in:
tdreyno 2009-09-24 16:35:03 -07:00
parent ed26918b10
commit 0476d8c00e
67 changed files with 30 additions and 2888 deletions

View file

@ -16,8 +16,12 @@ begin
gem.add_dependency("yui-compressor")
gem.add_dependency("sprockets")
gem.add_dependency("sinatra")
gem.add_dependency("foca-sinatra-content-for")
gem.add_dependency("brynary-rack-test")
gem.add_dependency("markaby")
gem.add_dependency("sbfaulkner-sinatra-markaby")
gem.add_dependency("maruku")
gem.add_dependency("wbzyl-sinatra-maruku")
gem.add_dependency("haml", ">=2.1.0")
gem.add_dependency("chriseppstein-compass")
end

View file

@ -4,8 +4,8 @@
require 'templater'
MIDDLEMAN_BUILDER = true
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
require File.join(File.dirname(__FILE__), '..', 'lib', 'vendor', 'rack-test', 'lib', 'rack', 'test')
require 'middleman'
require 'rack-test'
module Generators
extend Templater::Manifold

View file

@ -4,3 +4,7 @@ git://github.com/sstephenson/sprockets.git
git://github.com/sinatra/sinatra.git
git://github.com/nex3/haml.git
git://github.com/chriseppstein/compass.git
git://github.com/foca/sinatra-content-for.git
git://github.com/brynary/rack-test.git
git://github.com/sbfaulkner/sinatra-markaby.git
git://github.com/wbzyl/sinatra-maruku.git

View file

@ -2,14 +2,14 @@ require 'haml'
require 'compass' #must be loaded before sinatra
require 'sinatra/base'
# Sprockets ruby 1.9 hack
require 'sprockets'
require File.join(File.dirname(__FILE__), 'middleman', 'sprockets_ext')
# Sprockets ruby 1.9 hack
require 'middleman/sprockets+ruby19'
require "yui/compressor"
# Include content_for support
require File.join(File.dirname(__FILE__), '..', 'lib', 'vendor', 'sinatra-content-for', 'lib', 'sinatra', 'content_for')
require 'sinatra-content-for'
class Middleman < Sinatra::Base
set :app_file, __FILE__

View file

@ -1,4 +1,4 @@
# Include markaby support
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'vendor', 'sinatra-markaby', 'lib', 'sinatra', 'markaby')
require 'sinatra-markaby'
Middleman.helpers Sinatra::Markaby
Middleman.supported_formats << "mab"

View file

@ -1,4 +1,4 @@
# Include maruku support
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'vendor', 'sinatra-maruku', 'lib', 'sinatra', 'maruku')
require 'sinatra-maruku'
Middleman.helpers Sinatra::Maruku
Middleman.supported_formats << "maruku"

View file

@ -1,29 +0,0 @@
module Sprockets
class SourceFile
def source_lines
@lines ||= begin
lines = []
comments = []
File.open(pathname.absolute_location, 'rb') do |file|
file.each do |line|
lines << line = SourceLine.new(self, line, file.lineno)
if line.begins_pdoc_comment? || comments.any?
comments << line
end
if line.ends_multiline_comment?
if line.ends_pdoc_comment?
comments.each { |l| l.comment! }
end
comments.clear
end
end
end
lines
end
end
end
end

View file

@ -1,64 +0,0 @@
== Git
* Minor enhancements
* Support initializing a Rack::Test::Session with an app in addition to
a Rack::MockSession
* Allow CONTENT_TYPE to be specified in the env and not overwritten when
sending a POST or PUT
== 0.4.0 / 2009-06-25
* Minor enhancements
* Expose hook for building Rack::MockSessions for frameworks that need
to configure them before use
* Support passing in arrays of raw cookies in addition to a newline
separated string
* Support after_request callbacks in MockSession for things like running
background jobs
* Allow multiple named sessions using with_session
* Initialize Rack::Test::Sessions with Rack::MockSessions instead of apps.
This change should help integration with other Ruby web frameworks
(like Merb).
* Support sending bodies for PUT requests (Larry Diehl)
== 0.3.0 / 2009-05-17
* Major enhancements
* Ruby 1.9 compatible (Simon Rozet, Michael Fellinger)
* Minor enhancements
* Add CookieJar#[] and CookieJar#[]= methods
* Make the default host configurable
* Use Rack::Lint and fix errors (Simon Rozet)
* Extract Rack::MockSession from Rack::Test::Session to handle tracking
the last request and response and the cookie jar
* Add #set_cookie and #clear_cookies methods
* Rename #authorize to #basic_authorize (#authorize remains as an alias)
(Simon Rozet)
== 0.2.0 / 2009-04-26
Because #last_response is now a MockResponse instead of a Rack::Response,
#last_response.body now returns a string instead of an array.
* Major enhancements
* Support multipart requests via the UploadedFile class (thanks, Rails)
* Minor enhancements
* Updated for Rack 1.0
* Don't require rubygems (See http://gist.github.com/54177)
* Support HTTP Digest authentication with the #digest_authorize method
* #last_response returns a MockResponse instead of a Response
(Michael Fellinger)
== 0.1.0 / 2009-03-02
* 1 major enhancement
* Birthday!

View file

@ -1,19 +0,0 @@
Copyright (c) 2008-2009 Bryan Helmkamp, Engine Yard Inc.
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 OR COPYRIGHT HOLDERS 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.

View file

@ -1,57 +0,0 @@
= Rack::Test
- http://gitrdoc.com/brynary/rack-test
- http://github.com/brynary/rack-test
== Description
Rack::Test is a small, simple testing API for Rack apps. It can be used on its
own or as a reusable starting point for Web frameworks and testing libraries
to build on. Most of its initial functionality is an extraction of Merb 1.0's
request helpers feature.
== Features
* Maintains a cookie jar across requests
* Easily follow redirects when desired
* Set request headers to be used by all subsequent requests
* Small footprint. Approximately 200 LOC
== Example
require "rack/test"
class HomepageTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
MyApp.new
end
def test_redirect_logged_in_users_to_dashboard
authorize "bryan", "secret"
get "/"
follow_redirect!
assert_equal "http://example.org/redirected", last_request.url
assert last_response.ok?
end
end
== Install
To install the latest release as a gem:
sudo gem install rack-test
== Authors
- Maintained by {Bryan Helmkamp}[mailto:bryan@brynary.com]
- Contributions from Simon Rozet and Pat Nakajima
- Much of the original code was extracted from Merb 1.0's request helper
== License
Copyright (c) 2008-2009 Bryan Helmkamp, Engine Yard Inc.
See MIT-LICENSE.txt in this directory.

View file

@ -1,62 +0,0 @@
require "rubygems"
require "rake/rdoctask"
require "rake/gempackagetask"
require "rake/clean"
require "spec/rake/spectask"
require File.expand_path("./lib/rack/test")
Spec::Rake::SpecTask.new do |t|
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
end
desc "Run all specs in spec directory with RCov"
Spec::Rake::SpecTask.new(:rcov) do |t|
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
t.rcov = true
t.rcov_opts = lambda do
IO.readlines(File.dirname(__FILE__) + "/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
end
end
desc "Run the specs"
task :default => :spec
spec = Gem::Specification.new do |s|
s.name = "rack-test"
s.version = Rack::Test::VERSION
s.author = "Bryan Helmkamp"
s.email = "bryan" + "@" + "brynary.com"
s.homepage = "http://github.com/brynary/rack-test"
s.summary = "Simple testing API built on Rack"
s.description = s.summary
s.files = %w[History.txt Rakefile README.rdoc] + Dir["lib/**/*"]
# rdoc
s.has_rdoc = true
s.extra_rdoc_files = %w(README.rdoc MIT-LICENSE.txt)
end
Rake::GemPackageTask.new(spec) do |package|
package.gem_spec = spec
end
desc "Delete generated RDoc"
task :clobber_docs do
FileUtils.rm_rf("doc")
end
desc "Generate RDoc"
task :docs => :clobber_docs do
system "hanna --title 'Rack::Test #{Rack::Test::VERSION} API Documentation'"
end
desc 'Install the package as a gem.'
task :install => [:clean, :package] do
gem = Dir['pkg/*.gem'].first
sh "sudo gem install --no-rdoc --no-ri --local #{gem}"
end
desc 'Removes trailing whitespace'
task :whitespace do
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
end

View file

@ -1,57 +0,0 @@
module Rack
class MockSession
attr_writer :cookie_jar
attr_reader :last_response
attr_reader :default_host
def initialize(app, default_host = Rack::Test::DEFAULT_HOST)
@app = app
@after_request = []
@default_host = default_host
end
def after_request(&block)
@after_request << block
end
def clear_cookies
@cookie_jar = Rack::Test::CookieJar.new([], @default_host)
end
def set_cookie(cookie, uri = nil)
cookie_jar.merge(cookie, uri)
end
def request(uri, env)
env["HTTP_COOKIE"] ||= cookie_jar.for(uri)
@last_request = Rack::Request.new(env)
status, headers, body = @app.call(@last_request.env)
@last_response = MockResponse.new(status, headers, body, env["rack.errors"].flush)
cookie_jar.merge(last_response.headers["Set-Cookie"], uri)
@after_request.each { |hook| hook.call }
@last_response
end
# Return the last request issued in the session. Raises an error if no
# requests have been sent yet.
def last_request
raise Rack::Test::Error.new("No request yet. Request a page first.") unless @last_request
@last_request
end
# Return the last response received in the session. Raises an error if
# no requests have been sent yet.
def last_response
raise Rack::Test::Error.new("No response yet. Request a page first.") unless @last_response
@last_response
end
def cookie_jar
@cookie_jar ||= Rack::Test::CookieJar.new([], @default_host)
end
end
end

View file

@ -1,246 +0,0 @@
unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__) + "/.."))
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/.."))
end
require "uri"
require "rack"
require "rack/mock_session"
require "rack/test/cookie_jar"
require "rack/test/mock_digest_request"
require "rack/test/utils"
require "rack/test/methods"
require "rack/test/uploaded_file"
module Rack
module Test
VERSION = "0.4.0"
DEFAULT_HOST = "example.org"
MULTIPART_BOUNDARY = "----------XnJLe9ZIbbGUYtzPQJ16u1"
# The common base class for exceptions raised by Rack::Test
class Error < StandardError; end
class Session
extend Forwardable
include Rack::Test::Utils
def_delegators :@rack_mock_session, :clear_cookies, :set_cookie, :last_response, :last_request
# Initialize a new session for the given Rack app
def initialize(mock_session)
@headers = {}
if mock_session.is_a?(MockSession)
@rack_mock_session = mock_session
else
@rack_mock_session = MockSession.new(mock_session)
end
@default_host = @rack_mock_session.default_host
end
# Issue a GET request for the given URI with the given params and Rack
# environment. Stores the issues request object in #last_request and
# the app's response in #last_response. Yield #last_response to a block
# if given.
#
# Example:
# get "/"
def get(uri, params = {}, env = {}, &block)
env = env_for(uri, env.merge(:method => "GET", :params => params))
process_request(uri, env, &block)
end
# Issue a POST request for the given URI. See #get
#
# Example:
# post "/signup", "name" => "Bryan"
def post(uri, params = {}, env = {}, &block)
env = env_for(uri, env.merge(:method => "POST", :params => params))
process_request(uri, env, &block)
end
# Issue a PUT request for the given URI. See #get
#
# Example:
# put "/"
def put(uri, params = {}, env = {}, &block)
env = env_for(uri, env.merge(:method => "PUT", :params => params))
process_request(uri, env, &block)
end
# Issue a DELETE request for the given URI. See #get
#
# Example:
# delete "/"
def delete(uri, params = {}, env = {}, &block)
env = env_for(uri, env.merge(:method => "DELETE", :params => params))
process_request(uri, env, &block)
end
# Issue a HEAD request for the given URI. See #get
#
# Example:
# head "/"
def head(uri, params = {}, env = {}, &block)
env = env_for(uri, env.merge(:method => "HEAD", :params => params))
process_request(uri, env, &block)
end
# Issue a request to the Rack app for the given URI and optional Rack
# environment. Stores the issues request object in #last_request and
# the app's response in #last_response. Yield #last_response to a block
# if given.
#
# Example:
# request "/"
def request(uri, env = {}, &block)
env = env_for(uri, env)
process_request(uri, env, &block)
end
# Set a header to be included on all subsequent requests through the
# session. Use a value of nil to remove a previously configured header.
#
# Example:
# header "User-Agent", "Firefox"
def header(name, value)
if value.nil?
@headers.delete(name)
else
@headers[name] = value
end
end
# Set the username and password for HTTP Basic authorization, to be
# included in subsequent requests in the HTTP_AUTHORIZATION header.
#
# Example:
# basic_authorize "bryan", "secret"
def basic_authorize(username, password)
encoded_login = ["#{username}:#{password}"].pack("m*")
header('HTTP_AUTHORIZATION', "Basic #{encoded_login}")
end
alias_method :authorize, :basic_authorize
def digest_authorize(username, password)
@digest_username = username
@digest_password = password
end
# Rack::Test will not follow any redirects automatically. This method
# will follow the redirect returned in the last response. If the last
# response was not a redirect, an error will be raised.
def follow_redirect!
unless last_response.redirect?
raise Error.new("Last response was not a redirect. Cannot follow_redirect!")
end
get(last_response["Location"])
end
private
def env_for(path, env)
uri = URI.parse(path)
uri.host ||= @default_host
env = default_env.merge(env)
env.update("HTTPS" => "on") if URI::HTTPS === uri
env["X-Requested-With"] = "XMLHttpRequest" if env[:xhr]
if (env[:method] == "POST" || env["REQUEST_METHOD"] == "POST" ||
env[:method] == "PUT" || env["REQUEST_METHOD"] == "PUT") && !env.has_key?(:input)
env["CONTENT_TYPE"] ||= "application/x-www-form-urlencoded"
multipart = (Hash === env[:params]) &&
env[:params].any? { |_, v| UploadedFile === v }
if multipart
env[:input] = multipart_body(env.delete(:params))
env["CONTENT_LENGTH"] ||= env[:input].length.to_s
env["CONTENT_TYPE"] = "multipart/form-data; boundary=#{MULTIPART_BOUNDARY}"
else
env[:input] = params_to_string(env.delete(:params))
end
end
params = env[:params] || {}
params.update(parse_query(uri.query))
uri.query = requestify(params)
if env.has_key?(:cookie)
set_cookie(env.delete(:cookie), uri)
end
Rack::MockRequest.env_for(uri.to_s, env)
end
def process_request(uri, env)
uri = URI.parse(uri)
uri.host ||= @default_host
@rack_mock_session.request(uri, env)
if retry_with_digest_auth?(env)
auth_env = env.merge({
"HTTP_AUTHORIZATION" => digest_auth_header,
"rack-test.digest_auth_retry" => true
})
auth_env.delete('rack.request')
process_request(uri.path, auth_env)
else
yield last_response if block_given?
last_response
end
end
def digest_auth_header
challenge = last_response["WWW-Authenticate"].split(" ", 2).last
params = Rack::Auth::Digest::Params.parse(challenge)
params.merge!({
"username" => @digest_username,
"nc" => "00000001",
"cnonce" => "nonsensenonce",
"uri" => last_request.path_info,
"method" => last_request.env["REQUEST_METHOD"],
})
params["response"] = MockDigestRequest.new(params).response(@digest_password)
"Digest #{params}"
end
def retry_with_digest_auth?(env)
last_response.status == 401 &&
digest_auth_configured? &&
!env["rack-test.digest_auth_retry"]
end
def digest_auth_configured?
@digest_username
end
def default_env
{ "rack.test" => true, "REMOTE_ADDR" => "127.0.0.1" }.merge(@headers)
end
def params_to_string(params)
case params
when Hash then requestify(params)
when nil then ""
else params
end
end
end
end
end

View file

@ -1,169 +0,0 @@
require "uri"
module Rack
module Test
class Cookie
include Rack::Utils
# :api: private
attr_reader :name, :value
# :api: private
def initialize(raw, uri = nil, default_host = DEFAULT_HOST)
@default_host = default_host
uri ||= default_uri
# separate the name / value pair from the cookie options
@name_value_raw, options = raw.split(/[;,] */n, 2)
@name, @value = parse_query(@name_value_raw, ';').to_a.first
@options = parse_query(options, ';')
@options["domain"] ||= (uri.host || default_host)
@options["path"] ||= uri.path.sub(/\/[^\/]*\Z/, "")
end
def replaces?(other)
[name.downcase, domain, path] == [other.name.downcase, other.domain, other.path]
end
# :api: private
def raw
@name_value_raw
end
# :api: private
def empty?
@value.nil? || @value.empty?
end
# :api: private
def domain
@options["domain"]
end
def secure?
@options.has_key?("secure")
end
# :api: private
def path
@options["path"].strip || "/"
end
# :api: private
def expires
Time.parse(@options["expires"]) if @options["expires"]
end
# :api: private
def expired?
expires && expires < Time.now
end
# :api: private
def valid?(uri)
uri ||= default_uri
if uri.host.nil?
uri.host = @default_host
end
(!secure? || (secure? && uri.scheme == "https")) &&
uri.host =~ Regexp.new("#{Regexp.escape(domain)}$", Regexp::IGNORECASE) &&
uri.path =~ Regexp.new("^#{Regexp.escape(path)}")
end
# :api: private
def matches?(uri)
! expired? && valid?(uri)
end
# :api: private
def <=>(other)
# Orders the cookies from least specific to most
[name, path, domain.reverse] <=> [other.name, other.path, other.domain.reverse]
end
protected
def default_uri
URI.parse("//" + @default_host + "/")
end
end
class CookieJar
# :api: private
def initialize(cookies = [], default_host = DEFAULT_HOST)
@default_host = default_host
@cookies = cookies
@cookies.sort!
end
def [](name)
cookies = hash_for(nil)
# TODO: Should be case insensitive
cookies[name] && cookies[name].value
end
def []=(name, value)
# TODO: needs proper escaping
merge("#{name}=#{value}")
end
def merge(raw_cookies, uri = nil)
return unless raw_cookies
Array(raw_cookies).join("\n").split("\n").each do |raw_cookie|
cookie = Cookie.new(raw_cookie, uri, @default_host)
self << cookie if cookie.valid?(uri)
end
end
def <<(new_cookie)
@cookies.reject! do |existing_cookie|
new_cookie.replaces?(existing_cookie)
end
@cookies << new_cookie
@cookies.sort!
end
# :api: private
def for(uri)
hash_for(uri).values.map { |c| c.raw }.join(';')
end
def to_hash
cookies = {}
hash_for(nil).each do |name, cookie|
cookies[name] = cookie.value
end
return cookies
end
protected
def hash_for(uri = nil)
cookies = {}
# The cookies are sorted by most specific first. So, we loop through
# all the cookies in order and add it to a hash by cookie name if
# the cookie can be sent to the current URI. It's added to the hash
# so that when we are done, the cookies will be unique by name and
# we'll have grabbed the most specific to the URI.
@cookies.each do |cookie|
cookies[cookie.name] = cookie if cookie.matches?(uri)
end
return cookies
end
end
end
end

View file

@ -1,73 +0,0 @@
require "forwardable"
module Rack
module Test
module Methods
extend Forwardable
def rack_mock_session(name = :default)
return build_rack_mock_session unless name
@_rack_mock_sessions ||= {}
@_rack_mock_sessions[name] ||= build_rack_mock_session
end
def build_rack_mock_session
Rack::MockSession.new(app)
end
def rack_test_session(name = :default)
return build_rack_test_session(name) unless name
@_rack_test_sessions ||= {}
@_rack_test_sessions[name] ||= build_rack_test_session(name)
end
def build_rack_test_session(name)
Rack::Test::Session.new(rack_mock_session(name))
end
def current_session
rack_test_session(_current_session_names.last)
end
def with_session(name)
_current_session_names.push(name)
yield rack_test_session(name)
_current_session_names.pop
end
def _current_session_names
@_current_session_names ||= [:default]
end
METHODS = [
:request,
# HTTP verbs
:get,
:post,
:put,
:delete,
:head,
# Redirects
:follow_redirect!,
# Header-related features
:header,
:set_cookie,
:clear_cookies,
:authorize,
:basic_authorize,
:digest_authorize,
# Expose the last request and response
:last_response,
:last_request
]
def_delegators :current_session, *METHODS
end
end
end

View file

@ -1,27 +0,0 @@
module Rack
module Test
class MockDigestRequest
def initialize(params)
@params = params
end
def method_missing(sym)
if @params.has_key? k = sym.to_s
return @params[k]
end
super
end
def method
@params['method']
end
def response(password)
Rack::Auth::Digest::MD5.new(nil).send :digest, self, password
end
end
end
end

View file

@ -1,36 +0,0 @@
require "tempfile"
module Rack
module Test
class UploadedFile
# The filename, *not* including the path, of the "uploaded" file
attr_reader :original_filename
# The content type of the "uploaded" file
attr_accessor :content_type
def initialize(path, content_type = "text/plain", binary = false)
raise "#{path} file does not exist" unless ::File.exist?(path)
@content_type = content_type
@original_filename = ::File.basename(path)
@tempfile = Tempfile.new(@original_filename)
@tempfile.set_encoding(Encoding::BINARY) if @tempfile.respond_to?(:set_encoding)
@tempfile.binmode if binary
FileUtils.copy_file(path, @tempfile.path)
end
def path
@tempfile.path
end
alias_method :local_path, :path
def method_missing(method_name, *args, &block) #:nodoc:
@tempfile.__send__(method_name, *args, &block)
end
end
end
end

View file

@ -1,75 +0,0 @@
module Rack
module Test
module Utils
include Rack::Utils
def requestify(value, prefix = nil)
case value
when Array
value.map do |v|
requestify(v, "#{prefix}[]")
end.join("&")
when Hash
value.map do |k, v|
requestify(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k))
end.join("&")
else
"#{prefix}=#{escape(value)}"
end
end
module_function :requestify
def multipart_requestify(params, first=true)
p = Hash.new
params.each do |key, value|
k = first ? key.to_s : "[#{key}]"
if Hash === value
multipart_requestify(value, false).each do |subkey, subvalue|
p[k + subkey] = subvalue
end
else
p[k] = value
end
end
return p
end
module_function :multipart_requestify
def multipart_body(params)
multipart_requestify(params).map do |key, value|
if value.respond_to?(:original_filename)
::File.open(value.path, "rb") do |f|
f.set_encoding(Encoding::BINARY) if f.respond_to?(:set_encoding)
<<-EOF
--#{MULTIPART_BOUNDARY}\r
Content-Disposition: form-data; name="#{key}"; filename="#{escape(value.original_filename)}"\r
Content-Type: #{value.content_type}\r
Content-Length: #{::File.stat(value.path).size}\r
\r
#{f.read}\r
EOF
end
else
<<-EOF
--#{MULTIPART_BOUNDARY}\r
Content-Disposition: form-data; name="#{key}"\r
\r
#{value}\r
EOF
end
end.join("")+"--#{MULTIPART_BOUNDARY}--\r"
end
module_function :multipart_body
end
end
end

View file

@ -1,3 +0,0 @@
require "fake_app"
run Rack::Test::FakeApp

View file

@ -1,109 +0,0 @@
require "sinatra/base"
module Rack
module Test
class FakeApp < Sinatra::Default
head "/" do
"meh"
end
get "/" do
"Hello, GET: #{params.inspect}"
end
get "/redirect" do
redirect "/redirected"
end
get "/redirected" do
"You've been redirected"
end
get "/void" do
[200, {}, ""]
end
get "/cookies/show" do
request.cookies.inspect
end
get "/COOKIES/show" do
request.cookies.inspect
end
get "/not-cookies/show" do
request.cookies.inspect
end
get "/cookies/set-secure" do
raise if params["value"].nil?
response.set_cookie("secure-cookie", :value => params["value"], :secure => true)
"Set"
end
get "/cookies/set-simple" do
raise if params["value"].nil?
response.set_cookie "simple", params["value"]
"Set"
end
get "/cookies/delete" do
response.delete_cookie "value"
end
get "/cookies/count" do
old_value = request.cookies["count"].to_i || 0
new_value = (old_value + 1).to_s
response.set_cookie("count", :value => new_value)
new_value
end
get "/cookies/set" do
raise if params["value"].nil?
response.set_cookie("value", {
:value => params["value"],
:path => "/cookies",
:expires => Time.now + 10
})
"Set"
end
get "/cookies/domain" do
old_value = request.cookies["count"].to_i || 0
new_value = (old_value + 1).to_s
response.set_cookie("count", :value => new_value, :domain => "localhost.com")
new_value
end
get "/cookies/set-uppercase" do
raise if params["value"].nil?
response.set_cookie("VALUE", {
:value => params["value"],
:path => "/cookies",
:expires => Time.now + 10
})
"Set"
end
post "/" do
"Hello, POST: #{params.inspect}"
end
put "/" do
"Hello, PUT: #{params.inspect}"
end
delete "/" do
"Hello, DELETE: #{params.inspect}"
end
end
end
end

View file

@ -1 +0,0 @@
bar

View file

@ -1,176 +0,0 @@
require File.dirname(__FILE__) + "/../../spec_helper"
describe Rack::Test::Session do
def have_body(string)
simple_matcher "have body #{string.inspect}" do |response|
response.body.should == string
end
end
context "cookies" do
it "keeps a cookie jar" do
get "/cookies/show"
last_request.cookies.should == {}
get "/cookies/set", "value" => "1"
get "/cookies/show"
last_request.cookies.should == { "value" => "1" }
end
it "doesn't send expired cookies" do
get "/cookies/set", "value" => "1"
now = Time.now
Time.stub!(:now => now + 60)
get "/cookies/show"
last_request.cookies.should == {}
end
it "doesn't send cookies with the wrong domain" do
get "http://www.example.com/cookies/set", "value" => "1"
get "http://www.other.example/cookies/show"
last_request.cookies.should == {}
end
it "doesn't send cookies with the wrong path" do
get "/cookies/set", "value" => "1"
get "/not-cookies/show"
last_request.cookies.should == {}
end
it "persists cookies across requests that don't return any cookie headers" do
get "/cookies/set", "value" => "1"
get "/void"
get "/cookies/show"
last_request.cookies.should == { "value" => "1" }
end
it "deletes cookies" do
get "/cookies/set", "value" => "1"
get "/cookies/delete"
get "/cookies/show"
last_request.cookies.should == { }
end
xit "respects cookie domains when no domain is explicitly set" do
request("http://example.org/cookies/count").should have_body("1")
request("http://www.example.org/cookies/count").should have_body("1")
request("http://example.org/cookies/count").should have_body("2")
request("http://www.example.org/cookies/count").should have_body("2")
end
it "treats domains case insensitively" do
get "http://example.com/cookies/set", "value" => "1"
get "http://EXAMPLE.COM/cookies/show"
last_request.cookies.should == { "value" => "1" }
end
it "treats paths case sensitively" do
get "/cookies/set", "value" => "1"
get "/COOKIES/show"
last_request.cookies.should == {}
end
it "prefers more specific cookies" do
get "http://example.com/cookies/set", "value" => "domain"
get "http://sub.example.com/cookies/set", "value" => "sub"
get "http://sub.example.com/cookies/show"
last_request.cookies.should == { "value" => "sub" }
get "http://example.com/cookies/show"
last_request.cookies.should == { "value" => "domain" }
end
it "treats cookie names case insensitively" do
get "/cookies/set", "value" => "lowercase"
get "/cookies/set-uppercase", "value" => "UPPERCASE"
get "/cookies/show"
last_request.cookies.should == { "VALUE" => "UPPERCASE" }
end
it "defaults the domain to the request domain" do
get "http://example.com/cookies/set-simple", "value" => "cookie"
get "http://example.com/cookies/show"
last_request.cookies.should == { "simple" => "cookie" }
get "http://other.example/cookies/show"
last_request.cookies.should == {}
end
it "defaults the domain to the request path up to the last slash" do
get "/cookies/set-simple", "value" => "1"
get "/not-cookies/show"
last_request.cookies.should == {}
end
it "supports secure cookies" do
get "https://example.com/cookies/set-secure", "value" => "set"
get "http://example.com/cookies/show"
last_request.cookies.should == {}
get "https://example.com/cookies/show"
last_request.cookies.should == { "secure-cookie" => "set" }
end
it "keeps separate cookie jars for different domains" do
get "http://example.com/cookies/set", "value" => "example"
get "http://example.com/cookies/show"
last_request.cookies.should == { "value" => "example" }
get "http://other.example/cookies/set", "value" => "other"
get "http://other.example/cookies/show"
last_request.cookies.should == { "value" => "other" }
get "http://example.com/cookies/show"
last_request.cookies.should == { "value" => "example" }
end
it "allows cookies to be cleared" do
get "/cookies/set", "value" => "1"
clear_cookies
get "/cookies/show"
last_request.cookies.should == {}
end
it "allow cookies to be set" do
set_cookie "value=10"
get "/cookies/show"
last_request.cookies.should == { "value" => "10" }
end
it "allows an array of cookies to be set" do
set_cookie ["value=10", "foo=bar"]
get "/cookies/show"
last_request.cookies.should == { "value" => "10", "foo" => "bar" }
end
it "supports multiple sessions" do
with_session(:first) do
get "/cookies/set", "value" => "1"
get "/cookies/show"
last_request.cookies.should == { "value" => "1" }
end
with_session(:second) do
get "/cookies/show"
last_request.cookies.should == { }
end
end
it "uses :default as the default session name" do
get "/cookies/set", "value" => "1"
get "/cookies/show"
last_request.cookies.should == { "value" => "1" }
with_session(:default) do
get "/cookies/show"
last_request.cookies.should == { "value" => "1" }
end
end
it "accepts explicitly provided cookies" do
request "/cookies/show", :cookie => "value=1"
last_request.cookies.should == { "value" => "1" }
end
end
end

View file

@ -1,48 +0,0 @@
require File.dirname(__FILE__) + "/../../spec_helper"
describe Rack::Test::Session do
context "HTTP Digest authentication" do
def app
app = Rack::Auth::Digest::MD5.new(Rack::Test::FakeApp.new) do |username|
{ 'alice' => 'correct-password' }[username]
end
app.realm = 'WallysWorld'
app.opaque = 'this-should-be-secret'
app
end
def be_challenge
simple_matcher "a HTTP Digest challenge response" do |response|
response.status == 401 &&
response['WWW-Authenticate'] =~ /^Digest / &&
response.body.empty?
end
end
it 'incorrectly authenticates GETs' do
digest_authorize 'foo', 'bar'
get '/'
last_response.should be_challenge
end
it "correctly authenticates GETs" do
digest_authorize "alice", "correct-password"
response = get "/"
response.should be_ok
end
it "correctly authenticates POSTs" do
digest_authorize "alice", "correct-password"
response = post "/"
response.should be_ok
end
it "returns a re-challenge if authenticating incorrectly" do
digest_authorize "alice", "incorrect-password"
response = get "/"
response.should be_challenge
end
end
end

View file

@ -1,85 +0,0 @@
require File.dirname(__FILE__) + "/../../spec_helper"
describe Rack::Test::Session do
def test_file_path
File.dirname(__FILE__) + "/../../fixtures/foo.txt"
end
def uploaded_file
Rack::Test::UploadedFile.new(test_file_path)
end
context "uploading a file" do
it "sends the multipart/form-data content type" do
post "/", "photo" => uploaded_file
last_request.env["CONTENT_TYPE"].should include("multipart/form-data;")
end
it "sends regular params" do
post "/", "photo" => uploaded_file, "foo" => "bar"
last_request.POST["foo"].should == "bar"
end
it "sends nested params" do
post "/", "photo" => uploaded_file, "foo" => {"bar" => "baz"}
last_request.POST["foo"]["bar"].should == "baz"
end
it "sends multiple nested params" do
post "/", "photo" => uploaded_file, "foo" => {"bar" => {"baz" => "bop"}}
last_request.POST["foo"]["bar"]["baz"].should == "bop"
end
xit "sends params with arrays" do
post "/", "photo" => uploaded_file, "foo" => ["1", "2"]
last_request.POST["foo[]"].should == ["1", "2"]
end
it "sends params with encoding sensitive values" do
post "/", "photo" => uploaded_file, "foo" => "bar? baz"
last_request.POST["foo"].should == "bar? baz"
end
it "sends params with parens in names" do
post "/", "photo" => uploaded_file, "foo(1i)" => "bar"
last_request.POST["foo(1i)"].should == "bar"
end
it "sends params with encoding sensitive names" do
post "/", "photo" => uploaded_file, "foo bar" => "baz"
last_request.POST["foo bar"].should == "baz"
end
it "sends files with the filename" do
post "/", "photo" => uploaded_file
last_request.POST["photo"][:filename].should == "foo.txt"
end
it "sends files with the text/plain MIME type by default" do
post "/", "photo" => uploaded_file
last_request.POST["photo"][:type].should == "text/plain"
end
it "sends files with the right name" do
post "/", "photo" => uploaded_file
last_request.POST["photo"][:name].should == "photo"
end
it "allows overriding the content type" do
post "/", "photo" => Rack::Test::UploadedFile.new(test_file_path, "image/jpeg")
last_request.POST["photo"][:type].should == "image/jpeg"
end
it "sends files with a Content-Length in the header" do
post "/", "photo" => uploaded_file
last_request.POST["photo"][:head].should include("Content-Length: 4")
end
it "sends files as Tempfiles" do
post "/", "photo" => uploaded_file
last_request.POST["photo"][:tempfile].should be_a(::Tempfile)
end
end
end

View file

@ -1,44 +0,0 @@
require File.dirname(__FILE__) + "/../../spec_helper"
describe Rack::Test::Utils do
include Rack::Test::Utils
describe "requestify" do
it "converts empty strings to =" do
requestify("").should == "="
end
it "converts nil to =" do
requestify(nil).should == "="
end
it "converts hashes" do
requestify(:a => 1).should == "a=1"
end
it "converts hashes with multiple keys" do
hash = { :a => 1, :b => 2 }
["a=1&b=2", "b=2&a=1"].should include(requestify(hash))
end
it "converts arrays with one element" do
requestify(:a => [1]).should == "a[]=1"
end
it "converts arrays with multiple elements" do
requestify(:a => [1, 2]).should == "a[]=1&a[]=2"
end
it "converts nested hashes" do
requestify(:a => { :b => 1 }).should == "a[b]=1"
end
it "converts arrays nested in a hash" do
requestify(:a => { :b => [1, 2] }).should == "a[b][]=1&a[b][]=2"
end
it "converts arrays of hashes" do
requestify(:a => [{ :b => 2}, { :c => 3}]).should == "a[][b]=2&a[][c]=3"
end
end
end

View file

@ -1,363 +0,0 @@
require File.dirname(__FILE__) + "/../spec_helper"
describe Rack::Test::Session do
describe "initialization" do
it "supports being initialized with a Rack::MockSession app" do
session = Rack::Test::Session.new(Rack::MockSession.new(app))
session.request("/").should be_ok
end
it "supports being initialized with an app" do
session = Rack::Test::Session.new(app)
session.request("/").should be_ok
end
end
describe "#request" do
it "requests the URI using GET by default" do
request "/"
last_request.should be_get
last_response.should be_ok
end
it "returns a response" do
request("/").should be_ok
end
it "uses the provided env" do
request "/", "X-Foo" => "bar"
last_request.env["X-Foo"].should == "bar"
end
it "defaults to GET" do
request "/"
last_request.env["REQUEST_METHOD"].should == "GET"
end
it "defaults the REMOTE_ADDR to 127.0.0.1" do
request "/"
last_request.env["REMOTE_ADDR"].should == "127.0.0.1"
end
it "sets rack.test to true in the env" do
request "/"
last_request.env["rack.test"].should == true
end
it "defaults to port 80" do
request "/"
last_request.env["SERVER_PORT"].should == "80"
end
it "defaults to example.org" do
request "/"
last_request.env["SERVER_NAME"].should == "example.org"
end
it "yields the response to a given block" do
request "/" do |response|
response.should be_ok
end
end
it "supports sending :params" do
request "/", :params => { "foo" => "bar" }
last_request.GET["foo"].should == "bar"
end
it "doesn't follow redirects by default" do
request "/redirect"
last_response.should be_redirect
last_response.body.should be_empty
end
context "when input is given" do
it "should send the input" do
request "/", :method => "POST", :input => "foo"
last_request.env["rack.input"].read.should == "foo"
end
it "should not send a multipart request" do
request "/", :method => "POST", :input => "foo"
last_request.env["CONTENT_TYPE"].should_not == "application/x-www-form-urlencoded"
end
end
context "for a POST specified with :method" do
it "uses application/x-www-form-urlencoded as the CONTENT_TYPE" do
request "/", :method => "POST"
last_request.env["CONTENT_TYPE"].should == "application/x-www-form-urlencoded"
end
end
context "for a POST specified with REQUEST_METHOD" do
it "uses application/x-www-form-urlencoded as the CONTENT_TYPE" do
request "/", "REQUEST_METHOD" => "POST"
last_request.env["CONTENT_TYPE"].should == "application/x-www-form-urlencoded"
end
end
context "when CONTENT_TYPE is specified in the env" do
it "does not overwrite the CONTENT_TYPE" do
request "/", "CONTENT_TYPE" => "application/xml"
last_request.env["CONTENT_TYPE"].should == "application/xml"
end
end
context "when the URL is https://" do
it "sets SERVER_PORT to 443" do
get "https://example.org/"
last_request.env["SERVER_PORT"].should == "443"
end
it "sets HTTPS to on" do
get "https://example.org/"
last_request.env["HTTPS"].should == "on"
end
end
context "for a XHR" do
it "sends XMLHttpRequest for the X-Requested-With header" do
request "/", :xhr => true
last_request.env["X-Requested-With"].should == "XMLHttpRequest"
end
end
end
describe "#header" do
it "sets a header to be sent with requests" do
header "User-Agent", "Firefox"
request "/"
last_request.env["User-Agent"].should == "Firefox"
end
it "persists across multiple requests" do
header "User-Agent", "Firefox"
request "/"
request "/"
last_request.env["User-Agent"].should == "Firefox"
end
it "overwrites previously set headers" do
header "User-Agent", "Firefox"
header "User-Agent", "Safari"
request "/"
last_request.env["User-Agent"].should == "Safari"
end
it "can be used to clear a header" do
header "User-Agent", "Firefox"
header "User-Agent", nil
request "/"
last_request.env.should_not have_key("User-Agent")
end
it "is overridden by headers sent during the request" do
header "User-Agent", "Firefox"
request "/", "User-Agent" => "Safari"
last_request.env["User-Agent"].should == "Safari"
end
end
describe "#authorize" do
it "sets the HTTP_AUTHORIZATION header" do
authorize "bryan", "secret"
request "/"
last_request.env["HTTP_AUTHORIZATION"].should == "Basic YnJ5YW46c2VjcmV0\n"
end
it "includes the header for subsequent requests" do
basic_authorize "bryan", "secret"
request "/"
request "/"
last_request.env["HTTP_AUTHORIZATION"].should == "Basic YnJ5YW46c2VjcmV0\n"
end
end
describe "follow_redirect!" do
it "follows redirects" do
get "/redirect"
follow_redirect!
last_response.should_not be_redirect
last_response.body.should == "You've been redirected"
end
it "does not include params when following the redirect" do
get "/redirect", { "foo" => "bar" }
follow_redirect!
last_request.GET.should == {}
end
it "raises an error if the last_response is not set" do
lambda {
follow_redirect!
}.should raise_error(Rack::Test::Error)
end
it "raises an error if the last_response is not a redirect" do
get "/"
lambda {
follow_redirect!
}.should raise_error(Rack::Test::Error)
end
end
describe "#last_request" do
it "returns the most recent request" do
request "/"
last_request.env["PATH_INFO"].should == "/"
end
it "raises an error if no requests have been issued" do
lambda {
last_request
}.should raise_error(Rack::Test::Error)
end
end
describe "#last_response" do
it "returns the most recent response" do
request "/"
last_response["Content-Type"].should == "text/html"
end
it "raises an error if no requests have been issued" do
lambda {
last_response
}.should raise_error
end
end
describe "after_request" do
it "runs callbacks after each request" do
ran = false
rack_mock_session.after_request do
ran = true
end
get "/"
ran.should == true
end
it "runs multiple callbacks" do
count = 0
2.times do
rack_mock_session.after_request do
count += 1
end
end
get "/"
count.should == 2
end
end
describe "#get" do
it_should_behave_like "any #verb methods"
def verb
"get"
end
it "uses the provided params hash" do
get "/", :foo => "bar"
last_request.GET.should == { "foo" => "bar" }
end
it "sends params with parens in names" do
get "/", "foo(1i)" => "bar"
last_request.GET["foo(1i)"].should == "bar"
end
it "supports params with encoding sensitive names" do
get "/", "foo bar" => "baz"
last_request.GET["foo bar"].should == "baz"
end
it "supports params with nested encoding sensitive names" do
get "/", "boo" => {"foo bar" => "baz"}
last_request.GET.should == {"boo" => {"foo bar" => "baz"}}
end
it "accepts params in the path" do
get "/?foo=bar"
last_request.GET.should == { "foo" => "bar" }
end
end
describe "#head" do
it_should_behave_like "any #verb methods"
def verb
"head"
end
end
describe "#post" do
it_should_behave_like "any #verb methods"
def verb
"post"
end
it "uses the provided params hash" do
post "/", :foo => "bar"
last_request.POST.should == { "foo" => "bar" }
end
it "supports params with encoding sensitive names" do
post "/", "foo bar" => "baz"
last_request.POST["foo bar"].should == "baz"
end
it "uses application/x-www-form-urlencoded as the CONTENT_TYPE" do
post "/"
last_request.env["CONTENT_TYPE"].should == "application/x-www-form-urlencoded"
end
it "accepts a body" do
post "/", "Lobsterlicious!"
last_request.body.read.should == "Lobsterlicious!"
end
context "when CONTENT_TYPE is specified in the env" do
it "does not overwrite the CONTENT_TYPE" do
post "/", {}, { "CONTENT_TYPE" => "application/xml" }
last_request.env["CONTENT_TYPE"].should == "application/xml"
end
end
end
describe "#put" do
it_should_behave_like "any #verb methods"
def verb
"put"
end
it "accepts a body" do
put "/", "Lobsterlicious!"
last_request.body.read.should == "Lobsterlicious!"
end
end
describe "#delete" do
it_should_behave_like "any #verb methods"
def verb
"delete"
end
end
end

View file

@ -1 +0,0 @@
-x gems,spec

View file

@ -1 +0,0 @@
--color

View file

@ -1,48 +0,0 @@
require "rubygems"
require "spec"
gem "rack", "~> 1.0.0"
require File.expand_path(File.dirname(__FILE__) + "/../lib/rack/test")
require File.dirname(__FILE__) + "/fixtures/fake_app"
Spec::Runner.configure do |config|
config.include Rack::Test::Methods
def app
Rack::Lint.new(Rack::Test::FakeApp.new)
end
end
describe "any #verb methods", :shared => true do
it "requests the URL using VERB" do
send(verb, "/")
last_request.env["REQUEST_METHOD"].should == verb.upcase
last_response.should be_ok
end
it "uses the provided env" do
send(verb, "/", {}, { "User-Agent" => "Rack::Test" })
last_request.env["User-Agent"].should == "Rack::Test"
end
it "yields the response to a given block" do
yielded = false
send(verb, "/") do |response|
response.should be_ok
yielded = true
end
yielded.should be_true
end
context "for a XHR" do
it "sends XMLHttpRequest for the X-Requested-With header" do
send(verb, "/", {}, { :xhr => true })
last_request.env["X-Requested-With"].should == "XMLHttpRequest"
end
end
end

View file

@ -1,22 +0,0 @@
(The MIT License)
Copyright (c) 2008-2009 Nicolas Sanguinetti, entp.com
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 OR COPYRIGHT HOLDERS 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.

View file

@ -1,49 +0,0 @@
= ContentFor
Small extension for the Sinatra[http://sinatrarb.com] web framework
that allows you to use the following helpers in your views:
<% content_for :some_key do %>
<chunk of="html">...</chunk>
<% end %>
<% yield_content :some_key %>
This allows you to capture blocks inside views to be rendered later
in this request. For example, to populate different parts of your
layout from your view.
When using this with the Haml rendering engine, you should do the
following:
- content_for :some_key do
%chunk{ :of => "html" } ...
= yield_content :some_key
<b>Note</b> that with ERB <tt>yield_content</tt> is called <b>without</b>
an '=' block (<tt><%= %></tt>), but with Haml it uses <tt>= yield_content</tt>.
Using an '=' block in ERB will output the content twice for each block,
so if you have problems with that, make sure to check for this.
== Usage
If you're writing "classic" style apps, then requring
<tt>sinatra/content_for</tt> should be enough. If you're writing
"classy" apps, then you also need to call
<tt>helpers Sinatra::ContentFor</tt> in your app definition.
== And how is this useful?
For example, some of your views might need a few javascript tags and
stylesheets, but you don't want to force this files in all your pages.
Then you can put <tt><% yield_content :scripts_and_styles %></tt> on
your layout, inside the <head> tag, and each view can call
<tt>content_for</tt> setting the appropriate set of tags that should
be added to the layout.
== Credits
Code by foca[http://github.com/foca], inspired on the Ruby on Rails
helpers with the same name. Haml support by mattly[http://github.com/mattly].

View file

@ -1,33 +0,0 @@
require "rake/testtask"
begin
require "hanna/rdoctask"
rescue LoadError
require "rake/rdoctask"
end
begin
require "metric_fu"
rescue LoadError
end
begin
require "mg"
MG.new("sinatra-content-for.gemspec")
rescue LoadError
end
desc "Default: run all tests"
task :default => :test
desc "Run library tests"
Rake::TestTask.new do |t|
t.test_files = FileList['test/**/*_test.rb']
end
Rake::RDocTask.new do |rd|
rd.main = "README"
rd.title = "Documentation for ContentFor"
rd.rdoc_files.include("README.rdoc", "LICENSE", "lib/**/*.rb")
rd.rdoc_dir = "doc"
end

View file

@ -1,58 +0,0 @@
module Sinatra
module ContentFor
# Capture a block of content to be rendered later. For example:
#
# <% content_for :head do %>
# <script type="text/javascript" src="/foo.js"></script>
# <% end %>
#
# You can call +content_for+ multiple times with the same key
# (in the example +:head+), and when you render the blocks for
# that key all of them will be rendered, in the same order you
# captured them.
#
# Your blocks can also receive values, which are passed to them
# by <tt>yield_content</tt>
def content_for(key, &block)
content_blocks[key.to_sym] << block
end
# Render the captured blocks for a given key. For example:
#
# <head>
# <title>Example</title>
# <% yield_content :head %>
# </head>
#
# Would render everything you declared with <tt>content_for
# :head</tt> before closing the <tt><head></tt> tag.
#
# You can also pass values to the content blocks by passing them
# as arguments after the key:
#
# <% yield_content :head, 1, 2 %>
#
# Would pass <tt>1</tt> and <tt>2</tt> to all the blocks registered
# for <tt>:head</tt>.
#
# *NOTICE* that you call this without an <tt>=</tt> sign. IE,
# in a <tt><% %></tt> block, and not in a <tt><%= %></tt> block.
def yield_content(key, *args)
content_blocks[key.to_sym].map do |content|
if respond_to?(:block_is_haml?) && block_is_haml?(content)
capture_haml(*args, &content)
else
content.call(*args)
end
end.join
end
private
def content_blocks
@content_blocks ||= Hash.new {|h,k| h[k] = [] }
end
end
helpers ContentFor
end

View file

@ -1,34 +0,0 @@
Gem::Specification.new do |s|
s.name = "sinatra-content-for"
s.version = "0.2"
s.date = "2009-05-09"
s.description = "Small Sinatra extension to add a content_for helper similar to Rails'"
s.summary = "Small Sinatra extension to add a content_for helper similar to Rails'"
s.homepage = "http://sinatrarb.com"
s.authors = ["Nicolás Sanguinetti"]
s.email = "contacto@nicolassanguinetti.info"
s.require_paths = ["lib"]
s.rubyforge_project = "sinatra-ditties"
s.has_rdoc = true
s.rubygems_version = "1.3.1"
s.add_dependency "sinatra"
if s.respond_to?(:add_development_dependency)
s.add_development_dependency "contest"
s.add_development_dependency "sr-mg"
s.add_development_dependency "redgreen"
end
s.files = %w[
.gitignore
LICENSE
README.rdoc
sinatra-content-for.gemspec
lib/sinatra/content_for.rb
test/content_for_test.rb
]
end

View file

@ -1,156 +0,0 @@
ENV['RACK_ENV'] = 'test'
begin
require 'rack'
rescue LoadError
require 'rubygems'
require 'rack'
end
require 'contest'
require 'sinatra/test'
require 'haml'
begin
require 'redgreen'
rescue LoadError
end
require File.dirname(__FILE__) + '/../lib/sinatra/content_for'
Sinatra::Base.set :environment, :test
module Sinatra
class Base
set :environment, :test
helpers ContentFor
end
end
class Test::Unit::TestCase
include Sinatra::Test
class << self
alias_method :it, :test
end
def mock_app(base=Sinatra::Base, &block)
@app = Sinatra.new(base, &block)
end
end
class ContentForTest < Test::Unit::TestCase
context 'using erb' do
def erb_app(view)
mock_app {
layout { '<% yield_content :foo %>' }
get('/') { erb view }
}
end
it 'renders blocks declared with the same key you use when rendering' do
erb_app '<% content_for :foo do %>foo<% end %>'
get '/'
assert ok?
assert_equal 'foo', body
end
it 'does not render a block with a different key' do
erb_app '<% content_for :bar do %>bar<% end %>'
get '/'
assert ok?
assert_equal '', body
end
it 'renders multiple blocks with the same key' do
erb_app <<-erb_snippet
<% content_for :foo do %>foo<% end %>
<% content_for :foo do %>bar<% end %>
<% content_for :baz do %>WON'T RENDER ME<% end %>
<% content_for :foo do %>baz<% end %>
erb_snippet
get '/'
assert ok?
assert_equal 'foobarbaz', body
end
it 'passes values to the blocks' do
mock_app {
layout { '<% yield_content :foo, 1, 2 %>' }
get('/') { erb '<% content_for :foo do |a, b| %><i><%= a %></i> <%= b %><% end %>' }
}
get '/'
assert ok?
assert_equal '<i>1</i> 2', body
end
end
context 'with haml' do
def haml_app(view)
mock_app {
layout { '= yield_content :foo' }
get('/') { haml view }
}
end
it 'renders blocks declared with the same key you use when rendering' do
haml_app <<-haml_end
- content_for :foo do
foo
haml_end
get '/'
assert ok?
assert_equal "foo\n", body
end
it 'does not render a block with a different key' do
haml_app <<-haml_end
- content_for :bar do
bar
haml_end
get '/'
assert ok?
assert_equal "\n", body
end
it 'renders multiple blocks with the same key' do
haml_app <<-haml_end
- content_for :foo do
foo
- content_for :foo do
bar
- content_for :baz do
WON'T RENDER ME
- content_for :foo do
baz
haml_end
get '/'
assert ok?
assert_equal "foo\nbar\nbaz\n", body
end
it 'passes values to the blocks' do
mock_app {
layout { '= yield_content :foo, 1, 2' }
get('/') {
haml <<-haml_end
- content_for :foo do |a, b|
%i= a
=b
haml_end
}
}
get '/'
assert ok?
assert_equal "<i>1</i>\n2\n", body
end
end
end

View file

@ -1,7 +0,0 @@
= 0.9.2.2
* layout support is tested
= 0.9.2.1
* use Rack::Test instead of Sinatra::Test

View file

@ -1,20 +0,0 @@
Copyright (c) 2009 unwwwired.net
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 OR COPYRIGHT HOLDERS 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.

View file

@ -1,33 +0,0 @@
= sinatra-markaby
sinatra-markaby is an extension for sinatra to enable rendering of html files
using markaby templates.
== Installation
sudo gem install sbfaulkner-sinatra-markaby -s http://gems.github.com
== Example
require 'rubygems'
require 'sinatra'
require 'sinatra/markaby'
get '/' do
markaby :template
end
__END__
@@ template
mab.html do
head { title "Hello world" }
body do
p "Hello world!!!!!"
end
end
== Legal
Author:: S. Brent Faulkner <brentf@unwwwired.net>
License:: Copyright (c) 2009 unwwwired.net, released under the MIT license

View file

@ -1,45 +0,0 @@
require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |s|
s.name = "sinatra-markaby"
s.summary = %Q{Sinatra plugin to enable markaby (.mab) template rendering.}
s.email = "brentf@unwwwired.net"
s.homepage = "http://github.com/sbfaulkner/sinatra-markaby"
s.description = "Sinatra plugin to enable markaby (.mab) template rendering."
s.authors = ["S. Brent Faulkner"]
s.add_dependency "markaby"
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'sinatra-markaby'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib' << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |t|
t.libs << 'test'
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end
rescue LoadError
puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
end
task :default => :test

View file

@ -1,3 +0,0 @@
= TODO
* refactor render/views in sinatra

View file

@ -1,4 +0,0 @@
---
:major: 0
:minor: 9
:patch: 2.2

View file

@ -1,31 +0,0 @@
require 'sinatra/base'
require 'markaby'
module Sinatra
module Markaby
# Generate html file using Markaby.
# Takes the name of a template to render as a Symbol and returns a String with the rendered output.
#
# Options for markaby may be specified in Sinatra using set :markaby, { ... }
# TODO: the options aren't actually used yet
def mab(template=nil, options={}, locals = {}, &block)
options, template = template, nil if template.is_a?(Hash)
template = lambda { block } if template.nil?
render :mab, template, options, locals
end
protected
def render_mab(template, data, options, locals, &block)
filename = options.delete(:filename) || '<MARKABY>'
line = options.delete(:line) || 1
mab = ::Markaby::Builder.new(locals)
if data.respond_to?(:to_str)
eval(data.to_str, binding, filename, line)
elsif data.kind_of?(Proc)
data.call(mab)
end
end
end
helpers Markaby
end

View file

@ -1,49 +0,0 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{sinatra-markaby}
s.version = "0.9.2.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["S. Brent Faulkner"]
s.date = %q{2009-04-29}
s.description = %q{Sinatra plugin to enable markaby (.mab) template rendering.}
s.email = %q{brentf@unwwwired.net}
s.extra_rdoc_files = [
"LICENSE",
"README.rdoc"
]
s.files = [
"LICENSE",
"README.rdoc",
"Rakefile",
"VERSION.yml",
"lib/sinatra/markaby.rb",
"test/sinatra_markaby_test.rb",
"test/test_helper.rb",
"test/views/hello.mab"
]
s.has_rdoc = true
s.homepage = %q{http://github.com/sbfaulkner/sinatra-markaby}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.1}
s.summary = %q{Sinatra plugin to enable markaby (.mab) template rendering.}
s.test_files = [
"test/sinatra_markaby_test.rb",
"test/test_helper.rb"
]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<markaby>, [">= 0"])
else
s.add_dependency(%q<markaby>, [">= 0"])
end
else
s.add_dependency(%q<markaby>, [">= 0"])
end
end

View file

@ -1,72 +0,0 @@
require File.dirname(__FILE__) + '/test_helper'
class SinatraMarkabyTest < Test::Unit::TestCase
def markaby_app(&block)
mock_app {
use_in_file_templates!
helpers Sinatra::Markaby
set :views, File.dirname(__FILE__) + '/views'
get '/', &block
}
get '/'
end
def test_renders_inline_strings
markaby_app { markaby 'mab.p "Hello shrimp!"' }
assert last_response.ok?
assert_equal '<p>Hello shrimp!</p>', last_response.body
end
def test_renders_inline_blocks
markaby_app {
@name = 'Frank & Mary'
markaby do |mab|
mab.p "Hello #{@name}!"
end
}
assert last_response.ok?
assert_equal '<p>Hello Frank &amp; Mary!</p>', last_response.body
end
def test_renders_markaby_files_in_views_path
markaby_app {
@name = 'World'
markaby :hello
}
assert last_response.ok?
assert_equal '<p>Hello, World!</p>', last_response.body
end
def test_renders_in_file_template
markaby_app {
@name = 'Joe'
markaby :in_file
}
assert last_response.ok?
assert_equal '<p>Hey Joe</p>', last_response.body
end
def test_renders_with_layout
markaby_app {
@name = 'with Layout'
markaby :hello, :layout => :html
}
assert last_response.ok?
assert_equal '<html><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"/><title>Hello</title></head><body><p>Hello, with Layout!</p></body></html>', last_response.body
end
def test_raises_error_if_template_not_found
mock_app {
helpers Sinatra::Markaby
set :environment, :test
set :raise_errors, true
get('/') { markaby :no_such_template }
}
assert_raises(Errno::ENOENT) { get('/') }
end
end
__END__
@@ in_file
mab.p "Hey #{@name}"

View file

@ -1,19 +0,0 @@
require 'rubygems'
require 'test/unit'
require 'rack/test'
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'sinatra/markaby'
class Test::Unit::TestCase
include Rack::Test::Methods
attr_reader :app
# Sets up a Sinatra::Base subclass defined with the block
# given. Used in setup or individual spec methods to establish
# the application.
def mock_app(base=Sinatra::Base, &block)
@app = Sinatra.new(base, &block)
end
end

View file

@ -1 +0,0 @@
mab.p "Hello, #{@name}!"

View file

@ -1,4 +0,0 @@
mab.html do
head { title "Hello" }
body { yield }
end

View file

@ -1,22 +0,0 @@
(The MIT License)
Copyright (c) 2008 Wlodek Bzyl
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 OR COPYRIGHT HOLDERS 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.

View file

@ -1,85 +0,0 @@
# Sinatra Maruku Extension
The *sinatra-maruku* extension provides `maruku` helper method
for rendering Maruku templates.
To install it, run:
sudo gem install wbzyl-sinatra-maruku -s http://gems.github.com
To test it, create a simple Sinatra application:
# app.rb
require 'rubygems'
require 'sinatra'
gem 'wbzyl-sinatra-maruku'
require 'sinatra/maruku'
get "/" do
maruku "# Hello Maruku"
end
and run it with:
ruby app.rb
The result could be seen at *http://localhost:4567*.
Another example could be find in the *examples* directory.
Run it with:
rackup -p 4567 config.ru
and visit *http://localhost:4567* to contemplate the sheer
beauty of rendered text written in Maruku notation.
## Two links to Maruku related material
* [Maruku features](http://maruku.rubyforge.org/maruku.html)
* [Literate Maruku](http://www.slideshare.net/schmidt/literate-maruku)
## Template Languages (*update to The Sinatra Book*)
### Maruku Templates
This helper method:
get '/' do
maruku :index
end
renders template *./views/index.maruku*.
If a layout named *layout.maruku* exists, it will be used each time
a template is rendered.
You can disable layouts by passing `:layout => false`
to *maruku* helper. For example
get '/' do
maruku :index, :layout => false
end
You can set a different layout from the default one with:
get '/' do
maruku :index, :layout => :application
end
This renders *./views/index.maruku* template
within *./views/application.maruku* layout.
## Sample layout for Maruku templates
CSS: /stylesheets/application.css /stylesheets/print.css
Lang: pl
Title: Hello Maruku
LaTeX preamble: preamble.tex
# Hello Maruku {.header}
<%= yield %>

View file

@ -1,34 +0,0 @@
require 'rake'
require 'rake/testtask'
require "rake/clean"
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "sinatra-maruku"
gem.summary = "An extension providing Maruku templates for Sinatra applications."
gem.email = "matwb@univ.gda.pl"
gem.homepage = "http://github.com/wbzyl/sinatra-maruku"
gem.description = gem.description
gem.authors = ["Wlodek Bzyl"]
gem.add_runtime_dependency 'sinatra', '>=0.10.1'
gem.add_runtime_dependency 'maruku', '>=0.6.0'
gem.add_development_dependency 'rack', '>=1.0.0'
gem.add_development_dependency 'rack-test', '>=0.3.0'
# gem is a Gem::Specification
# refer to http://www.rubygems.org/read/chapter/20 for additional settings
end
rescue LoadError
puts "Jeweler not available."
puts "Install it with:"
puts " sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
Rake::TestTask.new(:test) do |t|
t.libs << 'lib' << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end

View file

@ -1,4 +0,0 @@
---
:major: 0
:minor: 10
:patch: 1

View file

@ -1,8 +0,0 @@
require 'rubygems'
require 'sinatra'
require 'sinatra/maruku'
get "/" do
#maruku :hello, :layout => false
maruku :index
end

View file

@ -1,4 +0,0 @@
# run it: rackup config.ru -p 4567
require 'app'
run Sinatra::Application

View file

@ -1,15 +0,0 @@
require 'rubygems'
require 'sinatra/base'
require 'sinatra/maruku'
require 'rack'
class MApp < Sinatra::Base
helpers Sinatra::Maruku
get '/' do
maruku "## hello form modular app"
end
end
Rack::Handler::Thin.run MApp.new, :Port => 4567

View file

@ -1,23 +0,0 @@
html {
margin: 0;
padding: 0;
background-color: #B5052E;
line-height: 1.6;
}
body {
margin: 1em auto 1em auto;
padding: 1em 2em 2em 1em;
width: 760px;
border: 1px solid black;
background-color: #E8DDCB;
}
pre {
padding: 0.5em 0 0.5em 2em;
background-color: #D7D3C1;
}
h1, h2, h3 {
color: #B5052E;
}

View file

@ -1,32 +0,0 @@
Maruku features
===============
Maruku allows you to write in an easy-to-read-and-write syntax, like this:
> [This document in Markdown][this_md]
Then it can be translated to HTML:
> [This document in HTML][this_html]
or LaTeX, which is then converted to PDF:
> [This document in PDF][this_pdf]
Maruku implements:
* the original [Markdown syntax][markdown_html]
([HTML][markdown_html] or [PDF][markdown_pdf]), translated by Maruku).
* all the improvements in PHP Markdown Extra.
* a new [meta-data syntax][meta_data_proposal]
[markdown_html]: http://maruku.rubyforge.org/markdown_syntax.html
[markdown_pdf]: http://maruku.rubyforge.org/markdown_syntax.pdf
[this_md]: http://maruku.rubyforge.org/maruku.md
[this_html]: http://maruku.rubyforge.org/maruku.html
[this_pdf]: http://maruku.rubyforge.org/maruku.pdf
[Andrea Censi]: http://www.dis.uniroma1.it/~acensi/
[meta_data_proposal]: http://maruku.rubyforge.org/proposal.html

View file

@ -1,9 +0,0 @@
CSS: /stylesheets/application.css /stylesheets/print.css
Javascript: /javascriprs/application.js
Lang: pl
Title: Hello Maruku
LaTeX preamble: preamble.tex
# Hello Maruku {.header}
<%= yield %>

View file

@ -1,25 +0,0 @@
require 'maruku'
require 'sinatra/base'
module Sinatra
module Maruku
def maruku(template, options={}, locals={})
render :maruku, template, options, locals
end
private
def render_maruku(template, data, options, locals, &block)
maruku_src = render_erb(template, data, options, locals, &block)
instance = ::Maruku.new(maruku_src, options)
if block_given?
# render layout
instance.to_html_document
else
# render template
instance.to_html
end
end
end
helpers Maruku
end

View file

@ -1,70 +0,0 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{sinatra-maruku}
s.version = "0.10.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Wlodek Bzyl"]
s.date = %q{2009-07-26}
s.description = %q{}
s.email = %q{matwb@univ.gda.pl}
s.extra_rdoc_files = [
"LICENSE",
"README.markdown"
]
s.files = [
".gitignore",
"LICENSE",
"README.markdown",
"Rakefile",
"VERSION.yml",
"examples/app.rb",
"examples/config.ru",
"examples/mapp.rb",
"examples/public/javascripts/application.js",
"examples/public/stylesheets/application.css",
"examples/public/stylesheets/print.css",
"examples/views/index.maruku",
"examples/views/layout.maruku",
"lib/sinatra/maruku.rb",
"sinatra-maruku.gemspec",
"test/sinatra_maruku_test.rb",
"test/test_helper.rb",
"test/views/hello.maruku",
"test/views/layout2.maruku"
]
s.homepage = %q{http://github.com/wbzyl/sinatra-maruku}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
s.summary = %q{An extension providing Maruku templates for Sinatra applications.}
s.test_files = [
"test/test_helper.rb",
"test/sinatra_maruku_test.rb",
"examples/mapp.rb",
"examples/app.rb"
]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<sinatra>, [">= 0.10.1"])
s.add_runtime_dependency(%q<maruku>, [">= 0.6.0"])
s.add_development_dependency(%q<rack>, [">= 1.0.0"])
s.add_development_dependency(%q<rack-test>, [">= 0.3.0"])
else
s.add_dependency(%q<sinatra>, [">= 0.10.1"])
s.add_dependency(%q<maruku>, [">= 0.6.0"])
s.add_dependency(%q<rack>, [">= 1.0.0"])
s.add_dependency(%q<rack-test>, [">= 0.3.0"])
end
else
s.add_dependency(%q<sinatra>, [">= 0.10.1"])
s.add_dependency(%q<maruku>, [">= 0.6.0"])
s.add_dependency(%q<rack>, [">= 1.0.0"])
s.add_dependency(%q<rack-test>, [">= 0.3.0"])
end
end

View file

@ -1,91 +0,0 @@
require File.dirname(__FILE__) + '/test_helper'
class SinatraMarukuTest < Test::Unit::TestCase
include Rack::Test::Methods
def maruku_app(&block)
mock_app {
set :views, File.dirname(__FILE__) + '/views'
helpers Sinatra::Maruku
set :show_exceptions, false
get '/', &block
}
get '/'
end
def test_renders_inline_strings
maruku_app { maruku 'hello world' }
assert last_response.ok?
assert_equal "<p>hello world</p>", last_response.body
end
def test_renders_inline_erb_string
maruku_app { maruku '<%= 1 + 1 %>' }
assert last_response.ok?
assert_equal "<p>2</p>", last_response.body
end
def test_renders_files_in_views_path
maruku_app { maruku :hello }
assert last_response.ok?
assert_equal "<h1 id='hello_world'>hello world</h1>", last_response.body
end
def test_takes_locals_option
maruku_app {
locals = {:foo => 'Bar'}
maruku "<%= foo %>", :locals => locals
}
assert last_response.ok?
assert_equal "<p>Bar</p>", last_response.body
end
def test_renders_with_inline_layouts
maruku_app {
maruku 'Sparta', :layout => 'THIS. IS. <%= yield.upcase %>'
}
assert last_response.ok?
assert_equal "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC\n \"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN\"\n \"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd\">\n<html xmlns:svg='http://www.w3.org/2000/svg' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>\n<head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title></title></head>\n<body>\n<p>THIS. IS. <P>SPARTA</P></p>\n</body></html>", last_response.body
end
def test_renders_with_file_layouts
maruku_app {
maruku 'hello world', :layout => :layout2
}
assert last_response.ok?
assert_equal "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC\n \"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN\"\n \"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd\">\n<html xmlns:svg='http://www.w3.org/2000/svg' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>\n<head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title></title></head>\n<body>\n<p>erb layout <p>hello world</p></p>\n</body></html>", last_response.body
end
def test_renders_erb_with_blocks
mock_app {
set :views, File.dirname(__FILE__) + '/views'
helpers Sinatra::Maruku
def container
yield
end
def is
"THIS. IS. SPARTA!"
end
get '/' do
maruku '<% container do %> <%= is %> <% end %>'
end
}
get '/'
assert last_response.ok?
assert_equal "<p>THIS. IS. SPARTA!</p>", last_response.body
end
def test_raises_error_if_template_not_found
mock_app {
set :views, File.dirname(__FILE__) + '/views'
helpers Sinatra::Maruku
set :show_exceptions, false
get('/') { maruku :no_such_template }
}
assert_raise(Errno::ENOENT) { get('/') }
end
end

View file

@ -1,21 +0,0 @@
require 'rubygems'
require 'test/unit'
require 'rack/test'
path = File.expand_path("../lib" + File.dirname(__FILE__))
$:.unshift(path) unless $:.include?(path)
require 'sinatra/maruku'
class Test::Unit::TestCase
include Rack::Test::Methods
attr_reader :app
# Sets up a Sinatra::Base subclass defined with the block
# given. Used in setup or individual spec methods to establish
# the application.
def mock_app(base=Sinatra::Base, &block)
@app = Sinatra.new(base, &block)
end
end

View file

@ -1 +0,0 @@
# hello world

View file

@ -1,2 +0,0 @@
erb layout
<%= yield %>

View file

@ -26,6 +26,7 @@ Gem::Specification.new do |s|
"bin/mm-build",
"bin/mm-init",
"bin/mm-server",
"deps.rip",
"lib/middleman.rb",
"lib/middleman/helpers.rb",
"lib/middleman/markaby.rb",
@ -74,8 +75,12 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<yui-compressor>, [">= 0"])
s.add_runtime_dependency(%q<sprockets>, [">= 0"])
s.add_runtime_dependency(%q<sinatra>, [">= 0"])
s.add_runtime_dependency(%q<foca-sinatra-content-for>, [">= 0"])
s.add_runtime_dependency(%q<brynary-rack-test>, [">= 0"])
s.add_runtime_dependency(%q<markaby>, [">= 0"])
s.add_runtime_dependency(%q<sbfaulkner-sinatra-markaby>, [">= 0"])
s.add_runtime_dependency(%q<maruku>, [">= 0"])
s.add_runtime_dependency(%q<wbzyl-sinatra-maruku>, [">= 0"])
s.add_runtime_dependency(%q<haml>, [">= 2.1.0"])
s.add_runtime_dependency(%q<chriseppstein-compass>, [">= 0"])
else
@ -83,8 +88,12 @@ Gem::Specification.new do |s|
s.add_dependency(%q<yui-compressor>, [">= 0"])
s.add_dependency(%q<sprockets>, [">= 0"])
s.add_dependency(%q<sinatra>, [">= 0"])
s.add_dependency(%q<foca-sinatra-content-for>, [">= 0"])
s.add_dependency(%q<brynary-rack-test>, [">= 0"])
s.add_dependency(%q<markaby>, [">= 0"])
s.add_dependency(%q<sbfaulkner-sinatra-markaby>, [">= 0"])
s.add_dependency(%q<maruku>, [">= 0"])
s.add_dependency(%q<wbzyl-sinatra-maruku>, [">= 0"])
s.add_dependency(%q<haml>, [">= 2.1.0"])
s.add_dependency(%q<chriseppstein-compass>, [">= 0"])
end
@ -93,8 +102,12 @@ Gem::Specification.new do |s|
s.add_dependency(%q<yui-compressor>, [">= 0"])
s.add_dependency(%q<sprockets>, [">= 0"])
s.add_dependency(%q<sinatra>, [">= 0"])
s.add_dependency(%q<foca-sinatra-content-for>, [">= 0"])
s.add_dependency(%q<brynary-rack-test>, [">= 0"])
s.add_dependency(%q<markaby>, [">= 0"])
s.add_dependency(%q<sbfaulkner-sinatra-markaby>, [">= 0"])
s.add_dependency(%q<maruku>, [">= 0"])
s.add_dependency(%q<wbzyl-sinatra-maruku>, [">= 0"])
s.add_dependency(%q<haml>, [">= 2.1.0"])
s.add_dependency(%q<chriseppstein-compass>, [">= 0"])
end

View file

@ -44,7 +44,7 @@ describe "Builder" do
it "should build sass files" do
File.exists?("#{@root_dir}/build/stylesheets/site.css").should be_true
File.read("#{@root_dir}/build/stylesheets/site.css").should include("html, body, div, span, applet, object, iframe")
File.read("#{@root_dir}/build/stylesheets/site.css").should include("html,body,div,span,applet,object,iframe")
end
it "should build static css files" do