yard-sinatra 0.2.5 → 0.4.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.
@@ -0,0 +1,59 @@
1
+ YARD::Sinatra
2
+ =============
3
+
4
+ This plugin adds [Sinatra](http://sinatrarb.com) routes to [YARD](http://yardoc.org/) output.
5
+
6
+ BigBand
7
+ -------
8
+
9
+ YARD::Sinatra is part of the [BigBand](http://github.com/rkh/big_band) stack.
10
+ Check it out if you are looking for fancy Sinatra extensions.
11
+
12
+ Usage
13
+ -----
14
+
15
+ Install via gemcutter:
16
+
17
+ gem install yard-sinatra
18
+
19
+ Add comments to your routes (well, that's optional):
20
+
21
+ require "sinatra/base"
22
+ require "user"
23
+
24
+ class ExampleApp < Sinatra::Base
25
+
26
+ # Settings for a given user
27
+ #
28
+ # @param [User] some user
29
+ # @return [Hash] settings for that user
30
+ def settings(some_user)
31
+ raise NotImplementedMethod
32
+ end
33
+
34
+ # Displays a settings page for the current user
35
+ #
36
+ # @see ExampleApp#settings
37
+ get "/settings" do
38
+ haml :settings, {}, :settings => settings(current_user)
39
+ end
40
+
41
+ end
42
+
43
+ The you're ready to go:
44
+
45
+ yardoc example_app.rb
46
+
47
+ YARD will automatically detect the yard-sinatra plugin and load it.
48
+
49
+ Other use cases
50
+ ---------------
51
+
52
+ As with yard, this can be used for other means besides documentation.
53
+ For instance, you might want a list of all routes defined in a given list of files without executing those files:
54
+
55
+ require "yard/sinatra"
56
+ YARD::Registry.load Dir.glob("lib/**/*.rb")
57
+ YARD::Sinatra.routes.each do |route|
58
+ puts route.http_verb, route.http_path, route.file, route.docstring
59
+ end
@@ -0,0 +1,105 @@
1
+ require "yard"
2
+
3
+ module YARD
4
+
5
+ module Sinatra
6
+ def self.routes
7
+ YARD::Handlers::Sinatra::AbstractRouteHandler.routes
8
+ end
9
+ end
10
+
11
+ module CodeObjects
12
+ class RouteObject < MethodObject
13
+ attr_accessor :http_verb, :http_path, :real_name
14
+
15
+ def name(prefix = false)
16
+ return super unless show_real_name?
17
+ prefix ? (sep == ISEP ? "#{sep}#{real_name}" : real_name.to_s) : real_name.to_sym
18
+ end
19
+
20
+ # @see YARD::Handlers::Sinatra::AbstractRouteHandler#register_route
21
+ # @see #name
22
+ def show_real_name?
23
+ real_name and caller[1] =~ /`signature'/
24
+ end
25
+ end
26
+ end
27
+
28
+ module Handlers
29
+
30
+ # Displays Sinatra routes in YARD documentation.
31
+ # Can also be used to parse routes from files without executing those files.
32
+ module Sinatra
33
+
34
+ # Logic both handlers have in common.
35
+ module AbstractRouteHandler
36
+ def self.routes
37
+ @routes ||= []
38
+ end
39
+
40
+ def process
41
+ path = http_path
42
+ path = $1 if path =~ /^"(.*)"$/
43
+ register_route(http_verb, path)
44
+ register_route('HEAD', path) if http_verb == 'GET'
45
+ end
46
+
47
+ def register_route(verb, path, doc = nil)
48
+ # HACK: Removing some illegal letters.
49
+ method_name = "" << verb << "_" << path.gsub(/[^\w_]/, "_")
50
+ real_name = "" << verb << " " << path
51
+ route = register CodeObjects::RouteObject.new(namespace, method_name, :instance) do |o|
52
+ o.visibility = "public"
53
+ o.source = statement.source
54
+ o.signature = real_name
55
+ o.explicit = true
56
+ o.scope = scope
57
+ o.docstring = statement.comments
58
+ o.http_verb = verb
59
+ o.http_path = path
60
+ o.real_name = real_name
61
+ o.add_file(parser.file, statement.line)
62
+ end
63
+ AbstractRouteHandler.routes << route
64
+ yield(route) if block_given?
65
+ end
66
+ end
67
+
68
+ # Route handler for YARD's source parser.
69
+ class RouteHandler < Ruby::Base
70
+ include AbstractRouteHandler
71
+
72
+ handles method_call(:get)
73
+ handles method_call(:post)
74
+ handles method_call(:put)
75
+ handles method_call(:delete)
76
+ handles method_call(:head)
77
+
78
+ def http_verb
79
+ statement.method_name(true).to_s.upcase
80
+ end
81
+
82
+ def http_path
83
+ statement.parameters.first.source
84
+ end
85
+ end
86
+
87
+ # Route handler for YARD's legacy parser.
88
+ module Legacy
89
+ class RouteHandler < Ruby::Legacy::Base
90
+ include AbstractRouteHandler
91
+ handles /\A(get|post|put|delete|head)[\s\(].*/m
92
+
93
+ def http_verb
94
+ statement.tokens.first.text.upcase
95
+ end
96
+
97
+ def http_path
98
+ statement.tokens[2].text
99
+ end
100
+ end
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,26 @@
1
+ require "sinatra/base"
2
+ require "user"
3
+
4
+ class ExampleApp < Sinatra::Base
5
+
6
+ # Settings for a given user
7
+ #
8
+ # @param [User] some user
9
+ # @return [Hash] settings for that user
10
+ def settings(some_user)
11
+ raise NotImplementedMethod
12
+ end
13
+
14
+ # Displays a settings page for the current user
15
+ #
16
+ # @see ExampleApp#settings
17
+ get "/settings" do
18
+ haml :settings, {}, :settings => settings(current_user)
19
+ end
20
+
21
+ put("/settings") { }
22
+ delete("/settings") { }
23
+ post("/settings") { }
24
+ head("/settings") { }
25
+
26
+ end
@@ -0,0 +1,21 @@
1
+ require "yard/sinatra"
2
+
3
+ describe YARD::Sinatra do
4
+ before(:all) do
5
+ $NO_CONTINUATION_WARNING = true
6
+ YARD::Registry.load [File.expand_path("../../example_app.rb", __FILE__)], true
7
+ end
8
+
9
+ it "reads sinatra routes" do
10
+ YARD::Sinatra.routes.size.should == 6
11
+ end
12
+
13
+ it "sets properties correctly" do
14
+ YARD::Sinatra.routes.each do |route|
15
+ %w[GET HEAD POST PUT DELETE].should include(route.http_verb)
16
+ route.http_path.should == "/settings"
17
+ route.file.should =~ /example_app\.rb$/
18
+ route.docstring.should =~ /Displays a settings page for the current user/ if route.http_verb == "GET"
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Konstantin Haase
@@ -9,20 +14,38 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-24 00:00:00 +01:00
17
+ date: 2010-03-02 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
- name: big_band
21
+ name: yard
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 5
30
+ - 3
31
+ version: 0.5.3
17
32
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
20
38
  requirements:
21
- - - "="
39
+ - - ">="
22
40
  - !ruby/object:Gem::Version
23
- version: 0.2.5
24
- version:
25
- description: YARD plugin for parsing sinatra routes See README.rdoc for more infos.
41
+ segments:
42
+ - 1
43
+ - 3
44
+ - 0
45
+ version: 1.3.0
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: Displays Sinatra routes (including comments) in YARD output (part of BigBand).
26
49
  email: konstantin.mailinglists@googlemail.com
27
50
  executables: []
28
51
 
@@ -31,11 +54,12 @@ extensions: []
31
54
  extra_rdoc_files: []
32
55
 
33
56
  files:
34
- - yard-sinatra.gemspec
35
- - lib/yard-sinatra.rb
36
- - lib/big_band/version.rb
37
- has_rdoc: false
38
- homepage: http://github.com/rkh/big_band
57
+ - lib/yard/sinatra.rb
58
+ - spec/example_app.rb
59
+ - spec/yard/sinatra_spec.rb
60
+ - README.md
61
+ has_rdoc: yard
62
+ homepage: http://github.com/rkh/yard-sinatra
39
63
  licenses: []
40
64
 
41
65
  post_install_message:
@@ -47,20 +71,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
71
  requirements:
48
72
  - - ">="
49
73
  - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
50
76
  version: "0"
51
- version:
52
77
  required_rubygems_version: !ruby/object:Gem::Requirement
53
78
  requirements:
54
79
  - - ">="
55
80
  - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
56
83
  version: "0"
57
- version:
58
84
  requirements: []
59
85
 
60
86
  rubyforge_project:
61
- rubygems_version: 1.3.5
87
+ rubygems_version: 1.3.6
62
88
  signing_key:
63
- specification_version: 2
64
- summary: YARD plugin for parsing sinatra routes
89
+ specification_version: 3
90
+ summary: Displays Sinatra routes (including comments) in YARD output (part of BigBand).
65
91
  test_files: []
66
92
 
@@ -1,3 +0,0 @@
1
- require "big_band/integration" unless defined? BigBand
2
- BigBand::VERSION = "0.2.5"
3
- BigBand::DATE = "2010-01-24"
@@ -1,2 +0,0 @@
1
- # This is a dummy file to hook into YARD.load_plugins
2
- require "big_band/integration/yard"
@@ -1,24 +0,0 @@
1
- $LOAD_PATH.unshift "lib"
2
- require "lib/big_band/version"
3
-
4
- YARD_SINATRA_SPEC = Gem::Specification.new do |s|
5
-
6
- s.name = "yard-sinatra"
7
- s.version = BigBand::VERSION
8
- s.date = BigBand::DATE
9
- s.author = "Konstantin Haase"
10
- s.email = "konstantin.mailinglists@googlemail.com"
11
- s.homepage = "http://github.com/rkh/big_band"
12
- s.platform = Gem::Platform::RUBY
13
- s.summary = "YARD plugin for parsing sinatra routes"
14
- s.files = ["yard-sinatra.gemspec", "lib/yard-sinatra.rb", "lib/big_band/version.rb"]
15
- s.require_paths = ['lib']
16
- s.description = s.summary + " See README.rdoc for more infos."
17
- s.has_rdoc = false
18
-
19
- s.add_dependency "big_band", "= #{BigBand::VERSION}"
20
-
21
- s.specification_version = 2 if s.respond_to? :specification_version=
22
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
23
-
24
- end