Class: Brainstem::ApiDocs::Presenter
Instance Attribute Summary collapse
#formatters
Instance Method Summary
collapse
#formatted_as, #formatter_type
Constructor Details
#initialize(atlas, options = {}) {|_self| ... } ⇒ Presenter
Returns a new instance of Presenter.
41
42
43
44
45
46
47
48
|
# File 'lib/brainstem/api_docs/presenter.rb', line 41
def initialize(atlas, options = {})
self.atlas = atlas
self.document_empty_associations = Brainstem::ApiDocs.document_empty_presenter_associations
self.document_empty_filters = Brainstem::ApiDocs.document_empty_presenter_filters
super options
yield self if block_given?
end
|
Instance Attribute Details
#atlas ⇒ Object
Returns the value of attribute atlas.
65
66
67
|
# File 'lib/brainstem/api_docs/presenter.rb', line 65
def atlas
@atlas
end
|
#const ⇒ Object
Returns the value of attribute const.
29
30
31
|
# File 'lib/brainstem/api_docs/presenter.rb', line 29
def const
@const
end
|
#document_empty_associations ⇒ Object
Also known as:
document_empty_associations?
Returns the value of attribute document_empty_associations.
29
30
31
|
# File 'lib/brainstem/api_docs/presenter.rb', line 29
def document_empty_associations
@document_empty_associations
end
|
#document_empty_filters ⇒ Object
Also known as:
document_empty_filters?
Returns the value of attribute document_empty_filters.
29
30
31
|
# File 'lib/brainstem/api_docs/presenter.rb', line 29
def document_empty_filters
@document_empty_filters
end
|
#filename_link_pattern ⇒ Object
78
79
80
|
# File 'lib/brainstem/api_docs/presenter.rb', line 78
def filename_link_pattern
@filename_link_pattern ||= Brainstem::ApiDocs.presenter_filename_link_pattern
end
|
#filename_pattern ⇒ Object
73
74
75
|
# File 'lib/brainstem/api_docs/presenter.rb', line 73
def filename_pattern
@filename_pattern ||= Brainstem::ApiDocs.presenter_filename_pattern
end
|
#target_class ⇒ Object
Returns the value of attribute target_class.
29
30
31
|
# File 'lib/brainstem/api_docs/presenter.rb', line 29
def target_class
@target_class
end
|
Instance Method Details
#brainstem_keys ⇒ Object
97
98
99
|
# File 'lib/brainstem/api_docs/presenter.rb', line 97
def brainstem_keys
const.possible_brainstem_keys.to_a.sort
end
|
#conditionals ⇒ Object
183
184
185
|
# File 'lib/brainstem/api_docs/presenter.rb', line 183
def conditionals
configuration[:conditionals]
end
|
#contextual_documentation(key) ⇒ Object
Returns a key if it exists and is documentable.
206
207
208
209
210
|
# File 'lib/brainstem/api_docs/presenter.rb', line 206
def contextual_documentation(key)
configuration.has_key?(key) &&
!configuration[key][:nodoc] &&
configuration[key][:info]
end
|
#default_sort_direction ⇒ Object
198
199
200
|
# File 'lib/brainstem/api_docs/presenter.rb', line 198
def default_sort_direction
@default_sort_direction ||= (default_sort_order.split(":")[1] || nil)
end
|
#default_sort_field ⇒ Object
193
194
195
|
# File 'lib/brainstem/api_docs/presenter.rb', line 193
def default_sort_field
@default_sort_field ||= (default_sort_order.split(":")[0] || nil)
end
|
#default_sort_order ⇒ Object
188
189
190
|
# File 'lib/brainstem/api_docs/presenter.rb', line 188
def default_sort_order
configuration[:default_sort_order] || ""
end
|
#description ⇒ Object
102
103
104
|
# File 'lib/brainstem/api_docs/presenter.rb', line 102
def description
contextual_documentation(:description) || ""
end
|
#documentable_association?(_, association) ⇒ Bool
Returns whether this association should be documented based on nodoc and empty description.
174
175
176
177
178
179
180
|
# File 'lib/brainstem/api_docs/presenter.rb', line 174
def documentable_association?(_, association)
!association.options[:nodoc] && (
document_empty_associations? || !(association.description.nil? || association.description.empty?) )
end
|
#documentable_filter?(_, filter) ⇒ Boolean
136
137
138
139
140
141
142
|
# File 'lib/brainstem/api_docs/presenter.rb', line 136
def documentable_filter?(_, filter)
!filter[:nodoc] &&
(
document_empty_filters? || !(filter[:info] || "").empty? )
end
|
#extension ⇒ Object
68
69
70
|
# File 'lib/brainstem/api_docs/presenter.rb', line 68
def extension
@extension ||= Brainstem::ApiDocs.output_extension
end
|
#invalid_field?(field) ⇒ Boolean
119
120
121
|
# File 'lib/brainstem/api_docs/presenter.rb', line 119
def invalid_field?(field)
field.options[:nodoc]
end
|
#link_for_association(association) ⇒ Object
158
159
160
161
162
163
164
165
|
# File 'lib/brainstem/api_docs/presenter.rb', line 158
def link_for_association(association)
if (associated_presenter = find_by_class(association.target_class)) &&
!associated_presenter.nodoc?
relative_path_to_presenter(associated_presenter, :markdown)
else
nil
end
end
|
#nested_field?(field) ⇒ Boolean
124
125
126
|
# File 'lib/brainstem/api_docs/presenter.rb', line 124
def nested_field?(field)
!field.respond_to?(:options)
end
|
#nodoc? ⇒ Boolean
87
88
89
|
# File 'lib/brainstem/api_docs/presenter.rb', line 87
def nodoc?
configuration[:nodoc]
end
|
#relative_path_to_presenter(presenter, format) ⇒ Object
Returns the relative path between this presenter and another given presenter.
217
218
219
220
221
222
|
# File 'lib/brainstem/api_docs/presenter.rb', line 217
def relative_path_to_presenter(presenter, format)
my_path = Pathname.new(File.dirname(suggested_filename_link(format)))
presenter_path = Pathname.new(presenter.suggested_filename_link(format))
presenter_path.relative_path_from(my_path).to_s
end
|
#suggested_filename(format) ⇒ Object
51
52
53
54
55
|
# File 'lib/brainstem/api_docs/presenter.rb', line 51
def suggested_filename(format)
filename_pattern
.gsub('{{name}}', target_class.to_s.underscore)
.gsub('{{extension}}', extension)
end
|
#suggested_filename_link(format) ⇒ Object
58
59
60
61
62
|
# File 'lib/brainstem/api_docs/presenter.rb', line 58
def suggested_filename_link(format)
filename_link_pattern
.gsub('{{name}}', target_class.to_s.underscore)
.gsub('{{extension}}', extension)
end
|
#title ⇒ Object
92
93
94
|
# File 'lib/brainstem/api_docs/presenter.rb', line 92
def title
contextual_documentation(:title) || const.to_s.demodulize
end
|
#valid_associations ⇒ Object
150
151
152
153
154
|
# File 'lib/brainstem/api_docs/presenter.rb', line 150
def valid_associations
configuration[:associations]
.to_h
.keep_if(&method(:documentable_association?))
end
|
#valid_fields(fields = ) ⇒ Object
Also known as:
valid_fields_in
107
108
109
110
111
112
113
114
115
|
# File 'lib/brainstem/api_docs/presenter.rb', line 107
def valid_fields(fields = configuration[:fields])
fields.to_h.reject do |k, v|
if nested_field?(v)
valid_fields_in(v).none?
else
invalid_field?(v)
end
end
end
|
#valid_filters ⇒ Object
129
130
131
132
133
|
# File 'lib/brainstem/api_docs/presenter.rb', line 129
def valid_filters
configuration[:filters]
.to_h
.keep_if(&method(:documentable_filter?))
end
|
#valid_options ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/brainstem/api_docs/presenter.rb', line 18
def valid_options
super | [
:const,
:target_class,
:filename_pattern,
:filename_link_pattern,
:document_empty_associations,
:document_empty_filters
]
end
|
#valid_sort_orders ⇒ Object
145
146
147
|
# File 'lib/brainstem/api_docs/presenter.rb', line 145
def valid_sort_orders
configuration[:sort_orders].to_h.reject {|k, v| v[:nodoc] }
end
|