Class: Lurker::ServicePresenter
- Inherits:
-
BasePresenter
show all
- Extended by:
- Forwardable
- Defined in:
- lib/lurker/presenters/service_presenter.rb
Overview
An BasePresenter for Lurker::Service
Instance Attribute Summary collapse
#options
Instance Method Summary
collapse
#asset_path, #assets, #html_directory, #index_path, #markup, #tag_with_anchor, #url_base_path
Constructor Details
#initialize(service, options = {}, &block) ⇒ ServicePresenter
Returns a new instance of ServicePresenter.
11
12
13
14
15
|
# File 'lib/lurker/presenters/service_presenter.rb', line 11
def initialize(service, options = {}, &block)
super(options)
@service = service
@filtering_block = block
end
|
Instance Attribute Details
#service ⇒ Object
Returns the value of attribute service.
6
7
8
|
# File 'lib/lurker/presenters/service_presenter.rb', line 6
def service
@service
end
|
Instance Method Details
#default_domain ⇒ Object
42
43
44
45
|
# File 'lib/lurker/presenters/service_presenter.rb', line 42
def default_domain
return service_domains.to_a[0][1] if service_domains.present?
'/'
end
|
52
53
54
|
# File 'lib/lurker/presenters/service_presenter.rb', line 52
def default_request_media_type
request_media_types[0]
end
|
#documentation ⇒ Object
29
30
31
|
# File 'lib/lurker/presenters/service_presenter.rb', line 29
def documentation
markup @service.documentation
end
|
#domains ⇒ Object
37
38
39
40
|
# File 'lib/lurker/presenters/service_presenter.rb', line 37
def domains
return service_domains if service_domains.present?
{ '/' => 'Local' }
end
|
#endpoints ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/lurker/presenters/service_presenter.rb', line 81
def endpoints
unless @endpoints
@endpoints = []
prefix = nil
service.endpoints.sort_by(&:endpoint_path).each do |endpoint|
presenter = Lurker::EndpointPresenter.new(endpoint, options)
presenter.service_presenter = self
if @filtering_block
presenter = @filtering_block.call(presenter)
next if presenter.nil?
end
current_prefix = presenter.prefix
@endpoints << [] if prefix != current_prefix
@endpoints.last << presenter
prefix = current_prefix
end
end
@endpoints
end
|
#endpoints_by_prefix ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/lurker/presenters/service_presenter.rb', line 107
def endpoints_by_prefix
@endpoints_by_prefix ||= begin
hash = Hash.new { |h, k| h[k] = Array.new }
service.endpoints.sort_by(&:endpoint_path).each do |endpoint|
presenter = Lurker::EndpointPresenter.new(endpoint, options)
presenter.service_presenter = self
if @filtering_block
presenter = @filtering_block.call(presenter)
next if presenter.nil?
end
hash[presenter.prefix] << presenter
end
hash
end
end
|
73
74
75
|
# File 'lib/lurker/presenters/service_presenter.rb', line 73
def
@footer ||= options[:footer].present? ? "Revision #{options[:footer]}".html_safe : ''
end
|
#lurker ⇒ Object
77
78
79
|
# File 'lib/lurker/presenters/service_presenter.rb', line 77
def lurker
@lurker ||= options[:lurker] || ''
end
|
#name_as_link(options = {}) ⇒ Object
56
57
58
59
|
# File 'lib/lurker/presenters/service_presenter.rb', line 56
def name_as_link(options = {})
path = index_path
'<a href="%s">%s %s</a>' % [path, options[:prefix], service.name]
end
|
47
48
49
50
|
# File 'lib/lurker/presenters/service_presenter.rb', line 47
def request_media_types
return service.request_media_types if service.request_media_types.present?
['application/x-www-form-urlencoded']
end
|
#slug_name ⇒ Object
61
62
63
|
# File 'lib/lurker/presenters/service_presenter.rb', line 61
def slug_name
@slug_name ||= service.name.downcase.gsub(/[ \/]/, '_')
end
|
#title ⇒ Object
33
34
35
|
# File 'lib/lurker/presenters/service_presenter.rb', line 33
def title
"#{name}"
end
|
#to_html(options = {}, &block) ⇒ Object
17
18
19
20
21
|
# File 'lib/lurker/presenters/service_presenter.rb', line 17
def to_html(options={}, &block)
controller = Lurker::RenderingController.new
controller.service_presenter = self
controller.render_to_string 'index', options
end
|
#to_print(options = {}) ⇒ Object
23
24
25
26
27
|
# File 'lib/lurker/presenters/service_presenter.rb', line 23
def to_print(options = {})
controller = Lurker::RenderingController.new
controller.service_presenter = self
controller.render_to_string 'all', { layout: 'print' }.merge(options)
end
|
#url(extension = ".html") ⇒ Object
69
70
71
|
# File 'lib/lurker/presenters/service_presenter.rb', line 69
def url(extension = ".html")
'%s-%s%s' % [@endpoint.path, @endpoint.verb, extension]
end
|
#url_name ⇒ Object
65
66
67
|
# File 'lib/lurker/presenters/service_presenter.rb', line 65
def url_name
@url_name ||= name.gsub(/[^a-z0-9\-_]+/i, '_')
end
|