Class: Fdoc::ServicePresenter

Inherits:
BasePresenter show all
Extended by:
Forwardable
Defined in:
lib/fdoc/presenters/service_presenter.rb

Overview

An BasePresenter for Fdoc::Service

Instance Attribute Summary collapse

Attributes inherited from BasePresenter

#options

Instance Method Summary collapse

Methods inherited from BasePresenter

#css_path, #get_binding, #html_directory, #index_path, #render_erb, #render_markdown, #tag_with_anchor

Constructor Details

#initialize(service, options = {}) ⇒ ServicePresenter

Returns a new instance of ServicePresenter.



10
11
12
13
# File 'lib/fdoc/presenters/service_presenter.rb', line 10

def initialize(service, options = {})
  super(options)
  @service = service
end

Instance Attribute Details

#serviceObject (readonly)

Returns the value of attribute service.



3
4
5
# File 'lib/fdoc/presenters/service_presenter.rb', line 3

def service
  @service
end

Instance Method Details

#description(options = {:render => true}) ⇒ Object



58
59
60
# File 'lib/fdoc/presenters/service_presenter.rb', line 58

def description(options = {:render => true})
  options[:render] ? render_markdown(service.description) : service.description
end

#discussion(options = {:render => true}) ⇒ Object



62
63
64
# File 'lib/fdoc/presenters/service_presenter.rb', line 62

def discussion(options = {:render => true})
  options[:render] ? render_markdown(service.discussion) : service.discussion
end

#endpointsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fdoc/presenters/service_presenter.rb', line 36

def endpoints
  if !@endpoints
    @endpoints = []
    prefix = nil

    service.endpoints.sort_by(&:endpoint_path).each do |endpoint|
      presenter = Fdoc::EndpointPresenter.new(endpoint, options)
      presenter.service_presenter = self
      presenter

      current_prefix = presenter.prefix

      @endpoints << [] if prefix != current_prefix
      @endpoints.last << presenter

      prefix = current_prefix
    end
  end

  @endpoints
end


23
24
25
26
# File 'lib/fdoc/presenters/service_presenter.rb', line 23

def name_as_link(options = {})
  path = service.meta_service ? index_path(slug_name) : index_path
  '<a href="%s">%s %s</a>' % [ path, options[:prefix], service.name ]
end

#relative_meta_service_path(file_name = nil) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/fdoc/presenters/service_presenter.rb', line 66

def relative_meta_service_path(file_name = nil)
  service_path = service_dir.gsub(meta_service.meta_service_dir, "")
  service_path = service_path.count("/").times.map { "../" }.join
  if file_name
    service_path = File.join(service_path, file_name)
  end
  service_path
end

#slug_nameObject



28
29
30
# File 'lib/fdoc/presenters/service_presenter.rb', line 28

def slug_name
  service.name.downcase.gsub(/[ \/]/, '_')
end

#to_htmlObject



15
16
17
# File 'lib/fdoc/presenters/service_presenter.rb', line 15

def to_html
  render_erb('service.html.erb')
end

#to_markdownObject



19
20
21
# File 'lib/fdoc/presenters/service_presenter.rb', line 19

def to_markdown
  render_erb('service.md.erb')
end

#url(extension = ".html") ⇒ Object



32
33
34
# File 'lib/fdoc/presenters/service_presenter.rb', line 32

def url(extension = ".html")
  '%s-%s%s' % [ @endpoint.path, @endpoint.verb, extension ]
end