Module: Sinatra::Croon

Defined in:
lib/sinatra/croon.rb

Defined Under Namespace

Modules: Helpers, Parser

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sinatra/croon.rb', line 8

def self.registered(app)
  app.helpers Croon::Helpers
  @app = app

  app.get '/docs.css' do
    pass do
      content_type "text/css"
      template = File.read(File.expand_path("../croon/views/docs.sass", __FILE__))
      sass template
    end
  end

  app.get %r{^/docs/?([\w]+)?/?$} do |section|
    pass do
      template = File.read(File.expand_path("../croon/views/docs.haml", __FILE__))
      sections = documentation.map { |doc| doc[:section] }.sort_by { |s| s.to_s }
      haml template, :locals => {
        :docs => documentation.group_by { |doc| doc[:section] },
        :current_section => sections.detect { |s| urlify_section(s) == section }
      }
    end
  end
end

.route_added(verb, path, block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sinatra/croon.rb', line 32

def self.route_added(verb, path, block)
  return if verb.to_s == "HEAD"

  route_location = caller(1).reject { |line| line =~ /sinatra\/base/ }.first
  file, line = route_location.split(':')
  doc = Croon::Parser.parse_route_documentation(file, line.to_i)

  if doc[:description]
    doc[:verb] = verb
    doc[:uri] = path
    @app.documentation << doc
  end
end

Instance Method Details

#documentationObject



46
47
48
# File 'lib/sinatra/croon.rb', line 46

def documentation
  @documentation ||= []
end