yard-sinatra-1.0.0/0000700000175000017500000000000011646622663013110 5ustar lucaslucasyard-sinatra-1.0.0/README.md0000600000175000017500000000276711646622663014405 0ustar lucaslucasYARD::Sinatra ============= This plugin adds [Sinatra](http://sinatrarb.com) routes to [YARD](http://yardoc.org/) output. Usage ----- Install via rubygems: gem install yard-sinatra Add comments to your routes (well, that's optional): require "sinatra/base" require "user" class ExampleApp < Sinatra::Base # Settings for a given user # # @param [User] some user # @return [Hash] settings for that user def settings(some_user) raise NotImplementedMethod end # Displays a settings page for the current user # # @see ExampleApp#settings get "/settings" do haml :settings, {}, :settings => settings(current_user) end # Error 404 Page Not Found not_found do haml :'404' end end The you're ready to go: yardoc example_app.rb YARD will automatically detect the yard-sinatra plugin and load it. Other use cases --------------- As with yard, this can be used for other means besides documentation. For instance, you might want a list of all routes defined in a given list of files without executing those files: require "yard/sinatra" YARD::Registry.load Dir.glob("lib/**/*.rb") YARD::Sinatra.routes.each do |route| puts route.http_verb, route.http_path, route.file, route.docstring end Thanks ------ * Ryan Sobol for implementing `not_found` documentation. * Loren Segal for making it seamlessly work as YARD plugin. Well, and for YARD. yard-sinatra-1.0.0/LICENSE0000600000175000017500000000307711646622663014126 0ustar lucaslucascopyright (c) 2010 Konstantin Haase. All rights reserved. Developed by: Konstantin Haase http://github.com/rkh/big_band Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with 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: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution. 3. Neither the name of Konstantin Haase, nor the names of other contributors may be used to endorse or promote products derived from this Software without specific prior written permission. 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 CONTRIBUTORS 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 WITH THE SOFTWARE. yard-sinatra-1.0.0/metadata.yml0000600000175000017500000000325711646622663015424 0ustar lucaslucas--- !ruby/object:Gem::Specification name: yard-sinatra version: !ruby/object:Gem::Version version: 1.0.0 prerelease: platform: ruby authors: - Konstantin Haase autorequire: bindir: bin cert_chain: [] date: 2011-08-17 00:00:00.000000000Z dependencies: - !ruby/object:Gem::Dependency name: yard requirement: &2151922380 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '0.7' type: :runtime prerelease: false version_requirements: *2151922380 - !ruby/object:Gem::Dependency name: rspec requirement: &2151921560 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '2.6' type: :development prerelease: false version_requirements: *2151921560 description: Displays Sinatra routes (including comments) in YARD output. email: konstantin.mailinglists@googlemail.com executables: [] extensions: [] extra_rdoc_files: [] files: - lib/yard/sinatra.rb - lib/yard-sinatra.rb - spec/example_app.rb - spec/yard/sinatra_spec.rb - README.md - LICENSE homepage: http://github.com/rkh/yard-sinatra licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 1.8.6 signing_key: specification_version: 3 summary: Displays Sinatra routes (including comments) in YARD output. test_files: [] yard-sinatra-1.0.0/spec/0000700000175000017500000000000011646622663014042 5ustar lucaslucasyard-sinatra-1.0.0/spec/example_app.rb0000600000175000017500000000110611646622663016662 0ustar lucaslucasrequire "sinatra/base" require "user" class ExampleApp < Sinatra::Base # Settings for a given user # # @param [User] some user # @return [Hash] settings for that user def settings(some_user) raise NotImplementedMethod end # Displays a settings page for the current user # # @see ExampleApp#settings get "/settings" do haml :settings, {}, :settings => settings(current_user) end # Error 404 Page Not Found not_found do haml :'404' end put("/settings") { } delete("/settings") { } post("/settings") { } head("/settings") { } endyard-sinatra-1.0.0/spec/yard/0000700000175000017500000000000011646622663015001 5ustar lucaslucasyard-sinatra-1.0.0/spec/yard/sinatra_spec.rb0000600000175000017500000000205211646622663020002 0ustar lucaslucasrequire "yard/sinatra" describe YARD::Sinatra do before(:all) do $NO_CONTINUATION_WARNING = true YARD::Registry.load [File.expand_path("../../example_app.rb", __FILE__)], true end it "reads sinatra routes" do YARD::Sinatra.routes.size.should == 5 end it "sets properties correctly" do YARD::Sinatra.routes.each do |route| %w[GET HEAD POST PUT DELETE].should include(route.http_verb) route.http_path.should == "/settings" route.file.should =~ /example_app\.rb$/ route.docstring.should =~ /Displays a settings page for the current user/ if route.http_verb == "GET" end end it "reads sinatra error handlers" do YARD::Sinatra.error_handlers.size.should == 1 end it "sets error handlers correctly" do YARD::Sinatra.error_handlers.each do |error_handler| %w[NOT_FOUND].should include(error_handler.http_verb) error_handler.file.should =~ /example_app\.rb$/ error_handler.docstring.should =~ /Error 404 Page Not Found/ if error_handler.http_verb == "NOT_FOUND" end end end yard-sinatra-1.0.0/lib/0000700000175000017500000000000011646622663013656 5ustar lucaslucasyard-sinatra-1.0.0/lib/yard-sinatra.rb0000600000175000017500000000002711646622663016602 0ustar lucaslucasrequire 'yard/sinatra' yard-sinatra-1.0.0/lib/yard/0000700000175000017500000000000011646622663014615 5ustar lucaslucasyard-sinatra-1.0.0/lib/yard/sinatra.rb0000600000175000017500000000730711646622663016614 0ustar lucaslucasrequire "yard" module YARD module Sinatra def self.routes YARD::Handlers::Sinatra::AbstractRouteHandler.routes end def self.error_handlers YARD::Handlers::Sinatra::AbstractRouteHandler.error_handlers end end module CodeObjects class RouteObject < MethodObject attr_accessor :http_verb, :http_path, :real_name def name(prefix = false) return super unless show_real_name? prefix ? (sep == ISEP ? "#{sep}#{real_name}" : real_name.to_s) : real_name.to_sym end # @see YARD::Handlers::Sinatra::AbstractRouteHandler#register_route # @see #name def show_real_name? real_name and caller[1] =~ /`signature'/ end end end module Handlers # Displays Sinatra routes in YARD documentation. # Can also be used to parse routes from files without executing those files. module Sinatra # Logic both handlers have in common. module AbstractRouteHandler def self.routes @routes ||= [] end def self.error_handlers @error_handlers ||= [] end def process case http_verb when 'NOT_FOUND' register_error_handler(http_verb) else path = http_path path = $1 if path =~ /^"(.*)"$/ register_route(http_verb, path) end end def register_route(verb, path, doc = nil) # HACK: Removing some illegal letters. method_name = "" << verb << "_" << path.gsub(/[^\w_]/, "_") real_name = "" << verb << " " << path route = register CodeObjects::RouteObject.new(namespace, method_name, :instance) do |o| o.visibility = "public" o.source = statement.source o.signature = real_name o.explicit = true o.scope = scope o.docstring = statement.comments o.http_verb = verb o.http_path = path o.real_name = real_name o.add_file(parser.file, statement.line) end AbstractRouteHandler.routes << route yield(route) if block_given? end def register_error_handler(verb, doc = nil) error_handler = register CodeObjects::RouteObject.new(namespace, verb, :instance) do |o| o.visibility = "public" o.source = statement.source o.signature = verb o.explicit = true o.scope = scope o.docstring = statement.comments o.http_verb = verb o.real_name = verb o.add_file(parser.file, statement.line) end AbstractRouteHandler.error_handlers << error_handler yield(error_handler) if block_given? end end # Route handler for YARD's source parser. class RouteHandler < Ruby::Base include AbstractRouteHandler handles method_call(:get) handles method_call(:post) handles method_call(:put) handles method_call(:delete) handles method_call(:head) handles method_call(:not_found) def http_verb statement.method_name(true).to_s.upcase end def http_path statement.parameters.first.source end end # Route handler for YARD's legacy parser. module Legacy class RouteHandler < Ruby::Legacy::Base include AbstractRouteHandler handles /\A(get|post|put|delete|head|not_found)[\s\(].*/m def http_verb statement.tokens.first.text.upcase end def http_path statement.tokens[2].text end end end end end end