Class: GrapeDoc::ApiDocumentation

Inherits:
Array
  • Object
show all
Defined in:
lib/grape/doc/doc_class.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ApiDocumentation

Returns a new instance of ApiDocumentation.

Raises:

  • (ArgumentError)


5
6
7
8
# File 'lib/grape/doc/doc_class.rb', line 5

def initialize(opts={})
  raise(ArgumentError) unless opts.class <= Hash
  @opts = opts.reduce({}){|m,o| m.merge!(o[0].to_s => o[1].to_s.downcase) ;m}
end

Instance Method Details

#add(type, *args) ⇒ Object



15
16
17
# File 'lib/grape/doc/doc_class.rb', line 15

def add(type,*args)
  self.push(create(type,*args))
end

#add_toc(*args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/grape/doc/doc_class.rb', line 19

def add_toc(*args)
  @toc_added ||= ->{
    case @opts['format']

      when 'redmine'
        self.insert(1,'{{toc}}')

      else
        args.map!{|e| Helpers.constantize("GrapeDoc::ApiDocParts::#{Helpers.camelize(e)}") }
        self.insert(1,ApiDocParts::TOC.new(*self.select{|e| args.any?{|klass| e.class == klass }}))

    end
    true

  }.call
end

#build(type, *args) ⇒ Object Also known as: create

Raises:

  • (ArgumentError)


10
11
12
13
# File 'lib/grape/doc/doc_class.rb', line 10

def build(type,*args)
  raise(ArgumentError,'invalid type') unless [String,Symbol].any?{ |klass| type.class <= klass }
  return Helpers.constantize("GrapeDoc::ApiDocParts::#{Helpers.camelize(type)}").new(*args)
end

#to_textileObject Also known as: to_s



36
37
38
39
# File 'lib/grape/doc/doc_class.rb', line 36

def to_textile
  require 'RedCloth'
  RedCloth.new(self.map{|e| e.respond_to?(:to_textile) ? e.to_textile : e.to_s }.join("\n\n"))
end