sinatra-sextant 0.0.1.pre
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/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +13 -0
- data/dot.rvmrc +1 -0
- data/example/Gemfile +3 -0
- data/example/app.rb +14 -0
- data/lib/sinatra-sextant.rb +1 -0
- data/lib/sinatra/sextant.rb +45 -0
- data/lib/sinatra/sextant/route_description.rb +11 -0
- data/lib/sinatra/sextant/the_route.rb +30 -0
- data/lib/sinatra/sextant/version.rb +5 -0
- data/lib/templates/routes.html.erb +42 -0
- data/sinatra-sextant.gemspec +25 -0
- data/spec/sinatra/sextant_added_routes_spec.rb +30 -0
- data/spec/sinatra/sextant_spec.rb +41 -0
- data/spec/spec_helper.rb +32 -0
- metadata +148 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Uchio KONDO
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Sinatra::Sextant
|
2
|
+
|
3
|
+
A fancy DSL for Sinatra routing.
|
4
|
+
|
5
|
+
Inspired from [sextant gem](https://github.com/schneems/sextant) and [the great Padrino](https://github.com/padrino/padrino-framework), with [Rake](https://github.com/jimweirich/rake)-ish syntax.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'sinatra-sextant'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install sinatra-sextant
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
6
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
7
|
+
spec.rspec_opts = ['--color', '-fs']
|
8
|
+
end
|
9
|
+
rescue LoadError => e
|
10
|
+
$stderr.puts "rspec/core is missing"
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => [:spec]
|
data/dot.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-p327@sinatra-sextant
|
data/example/Gemfile
ADDED
data/example/app.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'sinatra-sextant'
|
3
|
+
|
4
|
+
desc "Sample routing"
|
5
|
+
get '/' do
|
6
|
+
content_type :html
|
7
|
+
"<a href=\"/sinatra/routes\">check it out</a>"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Sample routing ver 2"
|
11
|
+
params :id, "ID for foo bar"
|
12
|
+
get '/:id' do
|
13
|
+
"wow"
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sinatra/sextant'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'sinatra/sextant/version'
|
3
|
+
require 'sinatra/sextant/route_description'
|
4
|
+
require 'sinatra/sextant/the_route'
|
5
|
+
|
6
|
+
module Sinatra
|
7
|
+
module Sextant
|
8
|
+
class InvalidDescriptionDSLError < StandardError
|
9
|
+
end
|
10
|
+
|
11
|
+
def desc(text)
|
12
|
+
@current_routing_definition = RouteDescription.new
|
13
|
+
@current_routing_definition.desc = text
|
14
|
+
end
|
15
|
+
|
16
|
+
def params(name, text=nil)
|
17
|
+
raise InvalidDescriptionDSLError, "params must be put after desc section" unless @current_routing_definition
|
18
|
+
@current_routing_definition.params << [name.to_sym, text]
|
19
|
+
end
|
20
|
+
|
21
|
+
def route(verb, path, *args, &blk)
|
22
|
+
if @current_routing_definition
|
23
|
+
@current_routing_definition.method_verb = verb
|
24
|
+
@current_routing_definition.path = path
|
25
|
+
self.detailed_routes << @current_routing_definition
|
26
|
+
@current_routing_definition = nil
|
27
|
+
end
|
28
|
+
super(verb, path, *args, &blk)
|
29
|
+
end
|
30
|
+
|
31
|
+
def detailed_routes
|
32
|
+
@detailed_routes ||= []
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.registered(base)
|
36
|
+
base.register TheRoute
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module Delegator # add methods to delegate
|
41
|
+
delegate :desc, :params
|
42
|
+
end
|
43
|
+
|
44
|
+
register Sextant
|
45
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
module Sinatra::Sextant
|
3
|
+
module TheRoute
|
4
|
+
TEMPLATE = File.read(File.expand_path("../../templates/routes.html.erb", File.dirname(__FILE__)))
|
5
|
+
class << self
|
6
|
+
def registered(base)
|
7
|
+
base.helpers do
|
8
|
+
def build_routes(routes)
|
9
|
+
labels = {
|
10
|
+
:method_verb => "VERB",
|
11
|
+
:path => "PATH",
|
12
|
+
:desc => "DESCRIPTION",
|
13
|
+
}
|
14
|
+
width = %w(method_verb path desc).each_with_object({}) { |field, dest|
|
15
|
+
dest[field.to_sym] = (routes.map{|r| r.send(field).length } + [labels[field.to_sym].length]).max
|
16
|
+
}
|
17
|
+
format = "%#{width[:method_verb]}s %-#{width[:path]}s %s"
|
18
|
+
([format % labels.values_at(:method_verb, :path, :desc)] +
|
19
|
+
routes.map{|r| format % [r.method_verb, r.path, r.desc] }).
|
20
|
+
join("\n")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
base.get '/sinatra/routes' do
|
25
|
+
erb TEMPLATE, :locals => {:routes => build_routes(base.detailed_routes)}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<title>Routes</title>
|
6
|
+
<style>
|
7
|
+
body { background-color: #fff; color: #333; }
|
8
|
+
|
9
|
+
body, p, ol, ul, td {
|
10
|
+
font-family: helvetica, verdana, arial, sans-serif;
|
11
|
+
font-size: 13px;
|
12
|
+
line-height: 18px;
|
13
|
+
}
|
14
|
+
|
15
|
+
pre {
|
16
|
+
background-color: #eee;
|
17
|
+
padding: 10px;
|
18
|
+
font-size: 11px;
|
19
|
+
white-space: pre-wrap;
|
20
|
+
}
|
21
|
+
|
22
|
+
a { color: #000; }
|
23
|
+
a:visited { color: #666; }
|
24
|
+
a:hover { color: #fff; background-color:#000; }
|
25
|
+
</style>
|
26
|
+
</head>
|
27
|
+
<body>
|
28
|
+
|
29
|
+
<h2>
|
30
|
+
Routes
|
31
|
+
</h2>
|
32
|
+
|
33
|
+
<p>
|
34
|
+
Routes match in priority from top to bottom
|
35
|
+
</p>
|
36
|
+
|
37
|
+
<pre id='route_table'>
|
38
|
+
<%= routes %>
|
39
|
+
</pre>
|
40
|
+
|
41
|
+
</body>
|
42
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sinatra/sextant/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "sinatra-sextant"
|
8
|
+
gem.version = Sinatra::Sextant::VERSION
|
9
|
+
gem.authors = ["Uchio KONDO"]
|
10
|
+
gem.email = ["udzura@udzura.jp"]
|
11
|
+
gem.description = %q{A fancy DSL for Sinatra routing}
|
12
|
+
gem.summary = %q{A fancy DSL for Sinatra routing}
|
13
|
+
gem.homepage = "https://github.com/udzura/sinatra-sextant"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'sinatra', '>= 1.3.0'
|
21
|
+
gem.add_development_dependency 'rspec', '>= 2.10'
|
22
|
+
gem.add_development_dependency 'rack-test', '>= 0'
|
23
|
+
gem.add_development_dependency 'sinatra-contrib', '>= 0'
|
24
|
+
gem.add_development_dependency 'pry', '>= 0'
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sinatra::Sextant do
|
4
|
+
describe 'should add a route for checking defined routes' do
|
5
|
+
before do
|
6
|
+
mock_app do
|
7
|
+
register Sinatra::Sextant
|
8
|
+
desc "Showing foo info for :id"
|
9
|
+
params :id, "ID for foo"
|
10
|
+
get '/users/:id' do
|
11
|
+
"Hello"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
get '/sinatra/routes'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should define `GET /sinatra/routes`' do
|
18
|
+
last_response.should be_ok
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should render a built-in template' do
|
22
|
+
last_response.body.should =~ /<!DOCTYPE html>/
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should render routes defined' do
|
26
|
+
last_response.body.should include "GET", "/users/:id", "Showing foo info for :id"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
describe Sinatra::Sextant do
|
5
|
+
it { should be }
|
6
|
+
|
7
|
+
describe 'routing DSL' do
|
8
|
+
before do
|
9
|
+
mock_app do
|
10
|
+
register Sinatra::Sextant
|
11
|
+
desc "Showing foo info for :id"
|
12
|
+
params :id, "ID for foo"
|
13
|
+
get '/users/:id' do
|
14
|
+
"Hello"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#it { binding.pry }
|
20
|
+
specify { raw_app.ancestors.should include Sinatra::Base }
|
21
|
+
describe "routes defined by 2, 1 default with an application specific route" do
|
22
|
+
specify { raw_app.routes["GET"].should have(1 + 1).item }
|
23
|
+
specify { raw_app.routes["HEAD"].should have(1 + 1).item }
|
24
|
+
end
|
25
|
+
specify { raw_app.detailed_routes.should have(1).item }
|
26
|
+
it "should not break defining routes" do
|
27
|
+
get '/users/1'
|
28
|
+
last_response.should be_ok
|
29
|
+
last_response.body.should == "Hello"
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#detailed_routes.first' do
|
33
|
+
subject { raw_app.detailed_routes.first }
|
34
|
+
its(:desc) { should == "Showing foo info for :id"}
|
35
|
+
its(:params) { should have(1).item }
|
36
|
+
its("params.first") { should == [:id, "ID for foo"] }
|
37
|
+
its(:path) { should == '/users/:id' }
|
38
|
+
its(:method_verb) { should == "GET" }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'rack/test'
|
9
|
+
require 'sinatra/base'
|
10
|
+
require 'sinatra/test_helpers'
|
11
|
+
require 'sinatra-sextant'
|
12
|
+
|
13
|
+
module Sinatra::Sextant::TestingHelpers
|
14
|
+
def raw_app
|
15
|
+
@app
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
21
|
+
config.run_all_when_everything_filtered = true
|
22
|
+
config.filter_run :focus
|
23
|
+
#config.include Rack::Test::Methods
|
24
|
+
config.include Sinatra::TestHelpers
|
25
|
+
config.include Sinatra::Sextant::TestingHelpers
|
26
|
+
|
27
|
+
# Run specs in random order to surface order dependencies. If you find an
|
28
|
+
# order dependency and want to debug it, you can fix the order by providing
|
29
|
+
# the seed, which is printed after each run.
|
30
|
+
# --seed 1234
|
31
|
+
config.order = 'random'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-sextant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.pre
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Uchio KONDO
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.3.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.3.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.10'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.10'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rack-test
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sinatra-contrib
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: pry
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: A fancy DSL for Sinatra routing
|
95
|
+
email:
|
96
|
+
- udzura@udzura.jp
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- dot.rvmrc
|
108
|
+
- example/Gemfile
|
109
|
+
- example/app.rb
|
110
|
+
- lib/sinatra-sextant.rb
|
111
|
+
- lib/sinatra/sextant.rb
|
112
|
+
- lib/sinatra/sextant/route_description.rb
|
113
|
+
- lib/sinatra/sextant/the_route.rb
|
114
|
+
- lib/sinatra/sextant/version.rb
|
115
|
+
- lib/templates/routes.html.erb
|
116
|
+
- sinatra-sextant.gemspec
|
117
|
+
- spec/sinatra/sextant_added_routes_spec.rb
|
118
|
+
- spec/sinatra/sextant_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
homepage: https://github.com/udzura/sinatra-sextant
|
121
|
+
licenses: []
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ! '>'
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 1.3.1
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.8.24
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: A fancy DSL for Sinatra routing
|
144
|
+
test_files:
|
145
|
+
- spec/sinatra/sextant_added_routes_spec.rb
|
146
|
+
- spec/sinatra/sextant_spec.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
has_rdoc:
|