ratpack 0.0.2 → 0.1.0
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/README.rdoc +3 -2
- data/lib/sinatra/ratpack.rb +78 -13
- data/test/ratpack_test.rb +64 -0
- data/test/sinatra_app.rb +49 -0
- metadata +29 -14
- data/.document +0 -5
- data/.gitignore +0 -21
- data/Rakefile +0 -53
- data/VERSION +0 -1
- data/ratpack.gemspec +0 -54
- data/test/helper.rb +0 -10
- data/test/test_ratpack.rb +0 -7
data/README.rdoc
CHANGED
@@ -23,8 +23,9 @@ See auto-generated documentation at {rdoc.info/projects/zeke/ratpack}[http://rdo
|
|
23
23
|
|
24
24
|
== Colophon
|
25
25
|
|
26
|
-
Thanks to the Sinatra page {Writing Extensions}[http://www.sinatrarb.com/extensions.html]
|
27
|
-
|
26
|
+
* Thanks to the Sinatra page on {Writing Extensions}[http://www.sinatrarb.com/extensions.html]
|
27
|
+
* The url_for method was snagged from {http://github.com/emk/sinatra-url-for/}[github.com/emk/sinatra-url-for]
|
28
|
+
* Gem built with {http://github.com/technicalpickles/jeweler/}[Jeweler]
|
28
29
|
|
29
30
|
== Copyright
|
30
31
|
|
data/lib/sinatra/ratpack.rb
CHANGED
@@ -5,47 +5,61 @@ module Sinatra
|
|
5
5
|
|
6
6
|
# Accepts a single filename or an array of filenames (with or without .js extension)
|
7
7
|
# Assumes javascripts are in public/javascripts
|
8
|
-
def
|
8
|
+
def javascript_include_tag(string_or_array, *args)
|
9
9
|
files = string_or_array.is_a?(Array) ? string_or_array : [string_or_array]
|
10
|
+
options = {
|
11
|
+
:charset => "utf-8",
|
12
|
+
:type => "text/javascript",
|
13
|
+
}.merge(args.extract_options!)
|
14
|
+
|
10
15
|
files.map do |file|
|
11
|
-
path = "
|
12
|
-
|
16
|
+
path = "#{ file.gsub(/\.js/i, "") }.js" # Append .js if needed
|
17
|
+
path = "/javascripts/#{path}" unless path.include? "://" # Add stylesheets directory to path if not a full URL
|
18
|
+
options[:src] = url_for(path)
|
19
|
+
content_tag(:script, "", options)
|
13
20
|
end.join("\n")
|
14
21
|
end
|
15
22
|
|
16
23
|
# Accepts a single filename or an array of filenames (with or without .css extension)
|
17
24
|
# Assumes stylesheets are in public/stylesheets
|
18
|
-
def stylesheet_link_tag(string_or_array)
|
25
|
+
def stylesheet_link_tag(string_or_array, *args)
|
19
26
|
files = string_or_array.is_a?(Array) ? string_or_array : [string_or_array]
|
27
|
+
options = {
|
28
|
+
:charset => "utf-8",
|
29
|
+
:media => "screen, projection",
|
30
|
+
:rel => "stylesheet",
|
31
|
+
:type => "text/css",
|
32
|
+
}.merge(args.extract_options!)
|
33
|
+
|
20
34
|
files.map do |file|
|
21
|
-
path = "
|
22
|
-
|
35
|
+
path = "#{ file.gsub(/\.css/i, "") }.css" # Append .css if needed
|
36
|
+
path = "/stylesheets/#{path}" unless path.include? "://" # Add stylesheets directory to path if not a full URL
|
37
|
+
options[:href] = url_for(path)
|
38
|
+
tag(:link, options)
|
23
39
|
end.join("\n")
|
24
40
|
end
|
25
41
|
|
26
42
|
# Accepts a full URL, an image filename, or a path underneath /public/images/
|
27
|
-
def image_tag(src,options={})
|
28
|
-
options[:src] = src
|
43
|
+
def image_tag(src, options={})
|
44
|
+
options[:src] = url_for(src)
|
29
45
|
tag(:img, options)
|
30
46
|
end
|
31
47
|
|
32
48
|
# Works like link_to, but href is optional. If no href supplied, content is used as href
|
33
49
|
def link_to(content,href=nil,options={})
|
34
50
|
href ||= content
|
35
|
-
options.update :href => href
|
51
|
+
options.update :href => url_for(href)
|
36
52
|
content_tag :a, content, options
|
37
53
|
end
|
38
54
|
|
39
55
|
# Just like Rails' content_tag
|
40
56
|
def content_tag(name,content,options={})
|
41
|
-
|
42
|
-
"<#{name} #{options}>#{content}</#{name}>"
|
57
|
+
"<#{name} #{options.to_html_attrs}>#{content}</#{name}>"
|
43
58
|
end
|
44
59
|
|
45
60
|
# Just like Rails' tag
|
46
61
|
def tag(name,options={})
|
47
|
-
|
48
|
-
"<#{name} #{options} />"
|
62
|
+
"<#{name} #{options.to_html_attrs} />"
|
49
63
|
end
|
50
64
|
|
51
65
|
# Give this helper an array, and get back a string of <li> elements.
|
@@ -59,8 +73,59 @@ module Sinatra
|
|
59
73
|
all << content_tag(:li, item, :class => css.join(" "))
|
60
74
|
end.join("\n")
|
61
75
|
end
|
76
|
+
|
77
|
+
# Construct a link to +url_fragment+, which should be given relative to
|
78
|
+
# the base of this Sinatra app. The mode should be either
|
79
|
+
# <code>:path_only</code>, which will generate an absolute path within
|
80
|
+
# the current domain (the default), or <code>:full</code>, which will
|
81
|
+
# include the site name and port number. (The latter is typically
|
82
|
+
# necessary for links in RSS feeds.) Example usage:
|
83
|
+
#
|
84
|
+
# url_for "/" # Returns "/myapp/"
|
85
|
+
# url_for "/foo" # Returns "/myapp/foo"
|
86
|
+
# url_for "/foo", :full # Returns "http://example.com/myapp/foo"
|
87
|
+
# url_for "http://bar.com" # Returns "http://bar.com"
|
88
|
+
def url_for url_fragment, mode=:path_only
|
89
|
+
return url_fragment if url_fragment.include? "://"
|
90
|
+
url_fragment = "/#{url_fragment}" unless url_fragment.starts_with? "/"
|
91
|
+
case mode
|
92
|
+
when :path_only
|
93
|
+
base = request.script_name
|
94
|
+
when :full
|
95
|
+
scheme = request.scheme
|
96
|
+
if (scheme == 'http' && request.port == 80 ||
|
97
|
+
scheme == 'https' && request.port == 443)
|
98
|
+
port = ""
|
99
|
+
else
|
100
|
+
port = ":#{request.port}"
|
101
|
+
end
|
102
|
+
base = "#{scheme}://#{request.host}#{port}#{request.script_name}"
|
103
|
+
else
|
104
|
+
raise TypeError, "Unknown url_for mode #{mode}"
|
105
|
+
end
|
106
|
+
"#{base}#{url_fragment}"
|
107
|
+
end
|
62
108
|
|
63
109
|
end
|
64
110
|
|
65
111
|
helpers Ratpack
|
112
|
+
end
|
113
|
+
|
114
|
+
class Array
|
115
|
+
def extract_options!
|
116
|
+
last.is_a?(::Hash) ? pop : {}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class Hash
|
121
|
+
def to_html_attrs
|
122
|
+
self.map{ |k,v| "#{k}=\"#{v}\"" }.sort.join(" ")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class String
|
127
|
+
def starts_with?(prefix)
|
128
|
+
prefix = prefix.to_s
|
129
|
+
self[0, prefix.length] == prefix
|
130
|
+
end
|
66
131
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'sinatra_app'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rack/test'
|
4
|
+
|
5
|
+
set :environment, :test
|
6
|
+
|
7
|
+
class RatpackTest < Test::Unit::TestCase
|
8
|
+
include Rack::Test::Methods
|
9
|
+
|
10
|
+
def app
|
11
|
+
Sinatra::Application
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_url_for
|
15
|
+
get '/url_for', {}, 'SCRIPT_NAME' => '/bar'
|
16
|
+
assert last_response.ok?
|
17
|
+
assert_equal last_response.body, <<EOD
|
18
|
+
/bar/
|
19
|
+
/bar/foo
|
20
|
+
http://example.org/bar/foo
|
21
|
+
EOD
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_javascript_include_tag
|
25
|
+
get '/javascript_include_tag', {}, 'SCRIPT_NAME' => '/bar'
|
26
|
+
assert last_response.ok?
|
27
|
+
assert_equal last_response.body, <<EOD
|
28
|
+
<script charset="utf-8" src="/bar/javascripts/summer.js" type="text/javascript"></script>
|
29
|
+
<script charset="utf-8" src="http://example.com/autumn.js" type="text/javascript"></script>
|
30
|
+
<script charset="utf-8" src="/bar/javascripts/day.js" type="text/javascript"></script>
|
31
|
+
<script charset="utf-8" src="/bar/javascripts/night.js" type="text/javascript"></script>
|
32
|
+
EOD
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_stylesheet_link_tag
|
36
|
+
get '/stylesheet_link_tag', {}, 'SCRIPT_NAME' => '/bar'
|
37
|
+
assert last_response.ok?
|
38
|
+
assert_equal last_response.body, <<EOD
|
39
|
+
<link charset="utf-8" href="/bar/stylesheets/winter.css" media="projection" rel="stylesheet" type="text/css" />
|
40
|
+
<link charset="utf-8" href="/bar/stylesheets/summer.css" media="projection" rel="stylesheet" type="text/css" />
|
41
|
+
<link charset="utf-8" href="http://example.com/autumn.css" media="screen, projection" rel="stylesheet" type="text/css" />
|
42
|
+
EOD
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_image_tag
|
46
|
+
get '/image_tag', {}, 'SCRIPT_NAME' => '/bar'
|
47
|
+
assert last_response.ok?
|
48
|
+
assert_equal last_response.body, <<EOD
|
49
|
+
<img alt="[foo image]" src="/bar/images/foo.jpg" />
|
50
|
+
EOD
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_link_to
|
54
|
+
get '/link_to_tag', {}, 'SCRIPT_NAME' => '/bar'
|
55
|
+
assert last_response.ok?
|
56
|
+
assert_equal last_response.body, <<EOD
|
57
|
+
<a href="/bar/topr">Tatry Mountains Rescue Team</a>
|
58
|
+
<a href="/bar/no_label.xyz">no_label.xyz</a>
|
59
|
+
<a href="http://foo.com/party/time">Party</a>
|
60
|
+
<a href="/bar/cheezburger" title="food">Food</a>
|
61
|
+
EOD
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/test/sinatra_app.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
path = File.expand_path("../lib" + File.dirname(__FILE__))
|
2
|
+
$:.unshift(path) unless $:.include?(path)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'sinatra'
|
6
|
+
require 'sinatra/ratpack'
|
7
|
+
|
8
|
+
get "/url_for" do
|
9
|
+
content_type "text/plain"
|
10
|
+
<<"EOD"
|
11
|
+
#{url_for("/")}
|
12
|
+
#{url_for("/foo")}
|
13
|
+
#{url_for("/foo", :full)}
|
14
|
+
EOD
|
15
|
+
end
|
16
|
+
|
17
|
+
get "/image_tag" do
|
18
|
+
content_type "text/plain"
|
19
|
+
<<"EOD"
|
20
|
+
#{image_tag("/images/foo.jpg", :alt => "[foo image]")}
|
21
|
+
EOD
|
22
|
+
end
|
23
|
+
|
24
|
+
get "/stylesheet_link_tag" do
|
25
|
+
content_type "text/plain"
|
26
|
+
<<"EOD"
|
27
|
+
#{stylesheet_link_tag(%w(winter summer), :media => "projection")}
|
28
|
+
#{stylesheet_link_tag("http://example.com/autumn.css")}
|
29
|
+
EOD
|
30
|
+
end
|
31
|
+
|
32
|
+
get "/javascript_include_tag" do
|
33
|
+
content_type "text/plain"
|
34
|
+
<<"EOD"
|
35
|
+
#{javascript_include_tag "summer.js"}
|
36
|
+
#{javascript_include_tag "http://example.com/autumn.js"}
|
37
|
+
#{javascript_include_tag %w(day night)}
|
38
|
+
EOD
|
39
|
+
end
|
40
|
+
|
41
|
+
get "/link_to_tag" do
|
42
|
+
content_type "text/plain"
|
43
|
+
<<"EOD"
|
44
|
+
#{link_to "Tatry Mountains Rescue Team", "/topr"}
|
45
|
+
#{link_to "no_label.xyz"}
|
46
|
+
#{link_to "Party", "http://foo.com/party/time"}
|
47
|
+
#{link_to "Food", "/cheezburger", :title => "food"}
|
48
|
+
EOD
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ratpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeke Sikelianos
|
@@ -9,18 +9,38 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-26 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: rack
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sinatra
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.1
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rack-test
|
17
37
|
type: :development
|
18
38
|
version_requirement:
|
19
39
|
version_requirements: !ruby/object:Gem::Requirement
|
20
40
|
requirements:
|
21
41
|
- - ">="
|
22
42
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
43
|
+
version: 0.3.0
|
24
44
|
version:
|
25
45
|
description: link_to, content_tag, stylesheet_link_tag, javascript_include_tag, etc
|
26
46
|
email: zeke@sikelianos.com
|
@@ -32,16 +52,11 @@ extra_rdoc_files:
|
|
32
52
|
- LICENSE
|
33
53
|
- README.rdoc
|
34
54
|
files:
|
35
|
-
- .
|
36
|
-
- .
|
55
|
+
- lib/sinatra/ratpack.rb
|
56
|
+
- test/ratpack_test.rb
|
57
|
+
- test/sinatra_app.rb
|
37
58
|
- LICENSE
|
38
59
|
- README.rdoc
|
39
|
-
- Rakefile
|
40
|
-
- VERSION
|
41
|
-
- lib/sinatra/ratpack.rb
|
42
|
-
- ratpack.gemspec
|
43
|
-
- test/helper.rb
|
44
|
-
- test/test_ratpack.rb
|
45
60
|
has_rdoc: true
|
46
61
|
homepage: http://github.com/zeke/ratpack
|
47
62
|
licenses: []
|
@@ -71,5 +86,5 @@ signing_key:
|
|
71
86
|
specification_version: 3
|
72
87
|
summary: A set of view helpers for Sinatra. Inspired by Rails' ActionView helpers
|
73
88
|
test_files:
|
74
|
-
- test/
|
75
|
-
- test/
|
89
|
+
- test/ratpack_test.rb
|
90
|
+
- test/sinatra_app.rb
|
data/.document
DELETED
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "ratpack"
|
8
|
-
gem.summary = %Q{A set of view helpers for Sinatra. Inspired by Rails' ActionView helpers}
|
9
|
-
gem.description = %Q{link_to, content_tag, stylesheet_link_tag, javascript_include_tag, etc}
|
10
|
-
gem.email = "zeke@sikelianos.com"
|
11
|
-
gem.homepage = "http://github.com/zeke/ratpack"
|
12
|
-
gem.authors = ["Zeke Sikelianos"]
|
13
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
-
end
|
20
|
-
|
21
|
-
require 'rake/testtask'
|
22
|
-
Rake::TestTask.new(:test) do |test|
|
23
|
-
test.libs << 'lib' << 'test'
|
24
|
-
test.pattern = 'test/**/test_*.rb'
|
25
|
-
test.verbose = true
|
26
|
-
end
|
27
|
-
|
28
|
-
begin
|
29
|
-
require 'rcov/rcovtask'
|
30
|
-
Rcov::RcovTask.new do |test|
|
31
|
-
test.libs << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
task :rcov do
|
37
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
task :test => :check_dependencies
|
42
|
-
|
43
|
-
task :default => :test
|
44
|
-
|
45
|
-
require 'rake/rdoctask'
|
46
|
-
Rake::RDocTask.new do |rdoc|
|
47
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
-
|
49
|
-
rdoc.rdoc_dir = 'rdoc'
|
50
|
-
rdoc.title = "ratpack #{version}"
|
51
|
-
rdoc.rdoc_files.include('README*')
|
52
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.2
|
data/ratpack.gemspec
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{ratpack}
|
8
|
-
s.version = "0.0.2"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Zeke Sikelianos"]
|
12
|
-
s.date = %q{2009-10-21}
|
13
|
-
s.description = %q{link_to, content_tag, stylesheet_link_tag, javascript_include_tag, etc}
|
14
|
-
s.email = %q{zeke@sikelianos.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/sinatra/ratpack.rb",
|
27
|
-
"ratpack.gemspec",
|
28
|
-
"test/helper.rb",
|
29
|
-
"test/test_ratpack.rb"
|
30
|
-
]
|
31
|
-
s.homepage = %q{http://github.com/zeke/ratpack}
|
32
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
-
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.5}
|
35
|
-
s.summary = %q{A set of view helpers for Sinatra. Inspired by Rails' ActionView helpers}
|
36
|
-
s.test_files = [
|
37
|
-
"test/helper.rb",
|
38
|
-
"test/test_ratpack.rb"
|
39
|
-
]
|
40
|
-
|
41
|
-
if s.respond_to? :specification_version then
|
42
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
-
s.specification_version = 3
|
44
|
-
|
45
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
-
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
47
|
-
else
|
48
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
49
|
-
end
|
50
|
-
else
|
51
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
data/test/helper.rb
DELETED