Class: SelfDocAPI
- Inherits:
-
Debci::App
- Object
- Sinatra::Base
- Debci::App
- SelfDocAPI
- Defined in:
- lib/debci/api.rb
Direct Known Subclasses
Class Method Summary collapse
- .doc(d = nil) ⇒ Object
- .format_doc(text) ⇒ Object
- .get(path, *args) ⇒ Object
- .post(path, *args) ⇒ Object
- .register_doc(method, path) ⇒ Object
Methods inherited from Debci::App
Class Method Details
.doc(d = nil) ⇒ Object
22 23 24 25 |
# File 'lib/debci/api.rb', line 22 def doc(d=nil) @last_doc = format_doc(d) @doc ||= [] end |
.format_doc(text) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/debci/api.rb', line 37 def format_doc(text) return nil unless text lines = text.lines if lines.first && lines.first.strip == "" lines.first.shift end lines.first =~ /^\s+/; prefix = $& if prefix lines.map! do |line| line.sub(/^#{prefix}/, '') end end formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil) RDoc::Markdown.parse(lines.join).accept(formatter) end |
.get(path, *args) ⇒ Object
53 54 55 56 |
# File 'lib/debci/api.rb', line 53 def get(path, *args) register_doc('GET', path) super(path, *args) end |
.post(path, *args) ⇒ Object
57 58 59 60 |
# File 'lib/debci/api.rb', line 57 def post(path, *args) register_doc('POST', path) super(path, *args) end |
.register_doc(method, path) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/debci/api.rb', line 26 def register_doc(method, path) return unless @last_doc entry = { :method => method, :path => path, :text => @last_doc, :anchor => [method, path].join('_'), } @last_doc = nil doc.push(entry) end |