kazoo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +5 -0
- data/Rakefile +12 -0
- data/kazoo.gemspec +32 -0
- data/lib/kazoo/router.rb +48 -0
- data/lib/kazoo/sinatra.rb +80 -0
- data/lib/kazoo.rb +4 -0
- data.tar.gz.sig +2 -0
- metadata +99 -0
- metadata.gz.sig +1 -0
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('kazoo', '0.0.1') do |p|
|
6
|
+
p.description = "Make your Ruby Rack apps act like one"
|
7
|
+
p.url = "http://rubykazoo.com"
|
8
|
+
p.author = "Jeremy Nicoll"
|
9
|
+
p.email = "jnicoll @nspam@ accentuate.me"
|
10
|
+
p.ignore_pattern = ['*.kpf', "tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
data/kazoo.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{kazoo}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Jeremy Nicoll"]
|
9
|
+
s.cert_chain = ["/Users/eltiare/keys/gem-public_cert.pem"]
|
10
|
+
s.date = %q{2011-01-26}
|
11
|
+
s.description = %q{Make your Ruby Rack apps act like one}
|
12
|
+
s.email = %q{jnicoll @nspam@ accentuate.me}
|
13
|
+
s.extra_rdoc_files = ["lib/kazoo.rb", "lib/kazoo/router.rb", "lib/kazoo/sinatra.rb"]
|
14
|
+
s.files = ["Manifest", "Rakefile", "lib/kazoo.rb", "lib/kazoo/router.rb", "lib/kazoo/sinatra.rb", "kazoo.gemspec"]
|
15
|
+
s.homepage = %q{http://rubykazoo.com}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Kazoo"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{kazoo}
|
19
|
+
s.rubygems_version = %q{1.3.7}
|
20
|
+
s.signing_key = %q{/Users/eltiare/keys/gem-private_key.pem}
|
21
|
+
s.summary = %q{Make your Ruby Rack apps act like one}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
data/lib/kazoo/router.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class Kazoo::Router
|
2
|
+
|
3
|
+
def self.map(&blk)
|
4
|
+
instance = new
|
5
|
+
instance.instance_eval(&blk)
|
6
|
+
instance
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@routes = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def match(path, options = {})
|
14
|
+
raise "You must match a route to an app using :to" unless options[:to] && options[:to].respond_to?(:call)
|
15
|
+
if path.is_a?(Regexp)
|
16
|
+
@routes << [ path, options[:to] ]
|
17
|
+
elsif path.is_a?(String)
|
18
|
+
@routes << [ Regexp.new("^#{path}"), options[:to] ]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def error_handler(app)
|
23
|
+
@error_handler = app
|
24
|
+
end
|
25
|
+
|
26
|
+
def call(env)
|
27
|
+
@routes.each do |route|
|
28
|
+
if matches = route[0].match(env['REQUEST_PATH'])
|
29
|
+
env['HTTP_PREFIX'] = matches[0]
|
30
|
+
env['PATH_INFO'] = env['PATH_INFO'].sub(route[0], '')
|
31
|
+
response = route[1].call(env)
|
32
|
+
return response if response[1]['X-Cascade'] != 'pass'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# If no routes found
|
37
|
+
default_response = [404, {'Content-Type' => 'text/plain', "X-Cascade" => "pass"}, 'The requested URI is not found']
|
38
|
+
if @error_handler
|
39
|
+
env['error'] = 'not_found'
|
40
|
+
env['default_response'] = default_response
|
41
|
+
@error_handler.call(env)
|
42
|
+
else
|
43
|
+
default_response
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
class Kazoo::Sinatra < Sinatra::Base
|
4
|
+
|
5
|
+
def render(engine, data, options = {}, *args)
|
6
|
+
|
7
|
+
if !options[:views] && data.is_a?(Symbol) && !data.to_s.match('/')
|
8
|
+
data = :"#{decamelize(self.class.name)}/#{data}"
|
9
|
+
options[:layout] ||= :'layouts/application'
|
10
|
+
end
|
11
|
+
|
12
|
+
if options[:layout] && !options[:layout].to_s.match('/')
|
13
|
+
options[:layout] = :"layouts/#{options[:layout]}"
|
14
|
+
end
|
15
|
+
|
16
|
+
super(engine, data, options, *args)
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def self.set_paths(opts)
|
22
|
+
opts.each { |k,v| path(k,v) }
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def self.path(name, path = nil)
|
27
|
+
if path
|
28
|
+
raise ArgumentError, "Path must be a string" unless path.is_a?(String)
|
29
|
+
paths[name.to_sym] = path
|
30
|
+
path
|
31
|
+
else
|
32
|
+
paths[name.to_sym]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.paths
|
37
|
+
@paths ||= {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def path(name,path)
|
41
|
+
self.class.path(name,path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def paths
|
45
|
+
self.class.paths
|
46
|
+
end
|
47
|
+
|
48
|
+
def url(name, opts = {})
|
49
|
+
n = name.to_sym
|
50
|
+
raise ArgumentError, "Invalid url name: #{name}" unless paths[n]
|
51
|
+
|
52
|
+
url_path = paths[n].split('/').map { |part|
|
53
|
+
next unless part.is_a?(String)
|
54
|
+
if matches = part.match(/^:([a-z_]+)$/i)
|
55
|
+
matched = matches[1].downcase
|
56
|
+
opts[matched] || opts[matched.to_sym] || params[matched] || raise("You need to pass '#{matched}' to generate URL")
|
57
|
+
else
|
58
|
+
part
|
59
|
+
end
|
60
|
+
}.join('/')
|
61
|
+
|
62
|
+
# Check for prefix
|
63
|
+
full_path = request.env['HTTP_PREFIX'] ? File.join(request.env['HTTP_PREFIX'], url_path) : url_path
|
64
|
+
|
65
|
+
format = opts[:format] || opts['format']
|
66
|
+
full_path << ".#{format}" if format
|
67
|
+
|
68
|
+
full_path
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def decamelize(class_name)
|
74
|
+
parts = class_name.split('::')
|
75
|
+
parts.map { |part|
|
76
|
+
part.gsub(/([A-Z])/, '_\1').gsub(/(^\_)|(\_$)/, '').downcase
|
77
|
+
}.join('/')
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/lib/kazoo.rb
ADDED
data.tar.gz.sig
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kazoo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jeremy Nicoll
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain:
|
17
|
+
- |
|
18
|
+
-----BEGIN CERTIFICATE-----
|
19
|
+
MIIDODCCAiCgAwIBAgIBADANBgkqhkiG9w0BAQUFADBCMRAwDgYDVQQDDAdqbmlj
|
20
|
+
b2xsMRowG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Pf
|
35
|
+
Q2gRkRMt01m9Q97Pi5o8tsOyT/LCERHZK2/KQUAPom/n0NO2sydX51cLhw41EaXw
|
36
|
+
ZVeyFF4suKZEIEKi
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
|
39
|
+
date: 2011-01-26 00:00:00 -07:00
|
40
|
+
default_executable:
|
41
|
+
dependencies: []
|
42
|
+
|
43
|
+
description: Make your Ruby Rack apps act like one
|
44
|
+
email: jnicoll @nspam@ accentuate.me
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
extra_rdoc_files:
|
50
|
+
- lib/kazoo.rb
|
51
|
+
- lib/kazoo/router.rb
|
52
|
+
- lib/kazoo/sinatra.rb
|
53
|
+
files:
|
54
|
+
- Manifest
|
55
|
+
- Rakefile
|
56
|
+
- lib/kazoo.rb
|
57
|
+
- lib/kazoo/router.rb
|
58
|
+
- lib/kazoo/sinatra.rb
|
59
|
+
- kazoo.gemspec
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://rubykazoo.com
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --line-numbers
|
67
|
+
- --inline-source
|
68
|
+
- --title
|
69
|
+
- Kazoo
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 11
|
87
|
+
segments:
|
88
|
+
- 1
|
89
|
+
- 2
|
90
|
+
version: "1.2"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: kazoo
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Make your Ruby Rack apps act like one
|
98
|
+
test_files: []
|
99
|
+
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
�ɔ�O.���R���������W�a4�£�4�eD���l襮oLK^�6�)��w�f`9<%��B���,9�e`e5Ә�B|�s�a��kτ�� ��fKnö���=��x[:����*XEN�R.\�oA���8F��aZXi�p'?5�)�6w��U`:� ~����T>3��i����p���b��Q�Ɠ5�J��f��?i5I�yT�sw�ǟۭ��� #1�g��%���j_.j�-�u�9Ń�Ó?
|