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.
62
63
64
|
# File 'lib/brainstem/api_docs/presenter.rb', line 62
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
72
73
74
|
# File 'lib/brainstem/api_docs/presenter.rb', line 72
def filename_link_pattern
@filename_link_pattern ||= Brainstem::ApiDocs.presenter_filename_link_pattern
end
|
#filename_pattern ⇒ Object
68
69
70
|
# File 'lib/brainstem/api_docs/presenter.rb', line 68
def filename_pattern
@filename_pattern ||= Brainstem::ApiDocs.presenter_filename_pattern
end
|
#include_internal ⇒ Object
Returns the value of attribute include_internal.
29
30
31
|
# File 'lib/brainstem/api_docs/presenter.rb', line 29
def include_internal
@include_internal
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
87
88
89
|
# File 'lib/brainstem/api_docs/presenter.rb', line 87
def brainstem_keys
const.possible_brainstem_keys.to_a.sort
end
|
#conditionals ⇒ Object
180
181
182
|
# File 'lib/brainstem/api_docs/presenter.rb', line 180
def conditionals
configuration[:conditionals]
end
|
#contextual_documentation(key) ⇒ Object
Returns a key if it exists and is documentable.
199
200
201
202
203
|
# File 'lib/brainstem/api_docs/presenter.rb', line 199
def contextual_documentation(key)
configuration.has_key?(key) &&
!nodoc_for?(configuration[key]) &&
configuration[key][:info]
end
|
#default_sort_direction ⇒ Object
192
193
194
|
# File 'lib/brainstem/api_docs/presenter.rb', line 192
def default_sort_direction
@default_sort_direction ||= (default_sort_order.split(":")[1] || nil)
end
|
#default_sort_field ⇒ Object
188
189
190
|
# File 'lib/brainstem/api_docs/presenter.rb', line 188
def default_sort_field
@default_sort_field ||= (default_sort_order.split(":")[0] || nil)
end
|
#default_sort_order ⇒ Object
184
185
186
|
# File 'lib/brainstem/api_docs/presenter.rb', line 184
def default_sort_order
configuration[:default_sort_order] || ""
end
|
#description ⇒ Object
91
92
93
|
# File 'lib/brainstem/api_docs/presenter.rb', line 91
def description
contextual_documentation(:description) || ""
end
|
#documentable_association?(_, association) ⇒ Bool
Returns whether this association should be documented based on nodoc and empty description.
172
173
174
175
176
177
178
|
# File 'lib/brainstem/api_docs/presenter.rb', line 172
def documentable_association?(_, association)
!nodoc_for?(association.options) && (
document_empty_associations? || !(association.description.nil? || association.description.empty?) )
end
|
#documentable_filter?(_, filter) ⇒ Boolean
135
136
137
138
139
140
141
|
# File 'lib/brainstem/api_docs/presenter.rb', line 135
def documentable_filter?(_, filter)
!nodoc_for?(filter) &&
(
document_empty_filters? || !(filter[:info] || "").empty? )
end
|
#extension ⇒ Object
64
65
66
|
# File 'lib/brainstem/api_docs/presenter.rb', line 64
def extension
@extension ||= Brainstem::ApiDocs.output_extension
end
|
#invalid_field?(field) ⇒ Boolean
102
103
104
|
# File 'lib/brainstem/api_docs/presenter.rb', line 102
def invalid_field?(field)
nodoc_for?(field.options)
end
|
#link_for_association(association) ⇒ Object
157
158
159
160
161
162
163
164
|
# File 'lib/brainstem/api_docs/presenter.rb', line 157
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
106
107
108
|
# File 'lib/brainstem/api_docs/presenter.rb', line 106
def nested_field?(field)
field.respond_to?(:configuration)
end
|
#nodoc? ⇒ Boolean
79
80
81
|
# File 'lib/brainstem/api_docs/presenter.rb', line 79
def nodoc?
nodoc_for?(configuration)
end
|
#optional_field?(field) ⇒ Boolean
110
111
112
|
# File 'lib/brainstem/api_docs/presenter.rb', line 110
def optional_field?(field)
field.options[:optional]
end
|
#optional_field_names(fields = , buffer = []) ⇒ Object
Also known as:
optional_field_names_in
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/brainstem/api_docs/presenter.rb', line 114
def optional_field_names(fields = configuration[:fields], buffer = [])
fields.to_h.each do |field_name, field_config|
next if invalid_field?(field_config)
if optional_field?(field_config)
buffer << field_name
elsif nested_field?(field_config)
optional_field_names_in(field_config.configuration, buffer)
end
end
buffer
end
|
#relative_path_to_presenter(presenter, format) ⇒ Object
Returns the relative path between this presenter and another given presenter.
209
210
211
212
213
214
|
# File 'lib/brainstem/api_docs/presenter.rb', line 209
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
|
#searchable? ⇒ Boolean
143
144
145
|
# File 'lib/brainstem/api_docs/presenter.rb', line 143
def searchable?
configuration[:search].present?
end
|
#suggested_filename(format) ⇒ Object
50
51
52
53
54
|
# File 'lib/brainstem/api_docs/presenter.rb', line 50
def suggested_filename(format)
filename_pattern
.gsub('{{name}}', target_class.to_s.underscore)
.gsub('{{extension}}', extension)
end
|
#suggested_filename_link(format) ⇒ Object
56
57
58
59
60
|
# File 'lib/brainstem/api_docs/presenter.rb', line 56
def suggested_filename_link(format)
filename_link_pattern
.gsub('{{name}}', target_class.to_s.underscore)
.gsub('{{extension}}', extension)
end
|
#title ⇒ Object
83
84
85
|
# File 'lib/brainstem/api_docs/presenter.rb', line 83
def title
contextual_documentation(:title) || const.to_s.demodulize
end
|
#valid_associations ⇒ Object
151
152
153
154
155
|
# File 'lib/brainstem/api_docs/presenter.rb', line 151
def valid_associations
configuration[:associations]
.to_h
.keep_if(&method(:documentable_association?))
end
|
#valid_fields(fields = ) ⇒ Object
Also known as:
valid_fields_in
95
96
97
98
99
|
# File 'lib/brainstem/api_docs/presenter.rb', line 95
def valid_fields(fields = configuration[:fields])
fields.to_h.reject do |_, field|
invalid_field?(field) || (nested_field?(field) && valid_fields_in(field).none?)
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
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/brainstem/api_docs/presenter.rb', line 17
def valid_options
super | [
:const,
:target_class,
:filename_pattern,
:filename_link_pattern,
:document_empty_associations,
:document_empty_filters,
:include_internal
]
end
|
#valid_sort_orders ⇒ Object
147
148
149
|
# File 'lib/brainstem/api_docs/presenter.rb', line 147
def valid_sort_orders
configuration[:sort_orders].to_h.reject {|_k, v| nodoc_for?(v) }
end
|