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.
39
40
41
42
43
44
45
46
|
# File 'lib/brainstem/api_docs/presenter.rb', line 39
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.
60
61
62
|
# File 'lib/brainstem/api_docs/presenter.rb', line 60
def atlas
@atlas
end
|
#const ⇒ Object
Returns the value of attribute const.
28
29
30
|
# File 'lib/brainstem/api_docs/presenter.rb', line 28
def const
@const
end
|
#document_empty_associations ⇒ Object
Also known as:
document_empty_associations?
Returns the value of attribute document_empty_associations.
28
29
30
|
# File 'lib/brainstem/api_docs/presenter.rb', line 28
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.
28
29
30
|
# File 'lib/brainstem/api_docs/presenter.rb', line 28
def document_empty_filters
@document_empty_filters
end
|
#filename_link_pattern ⇒ Object
70
71
72
|
# File 'lib/brainstem/api_docs/presenter.rb', line 70
def filename_link_pattern
@filename_link_pattern ||= Brainstem::ApiDocs.presenter_filename_link_pattern
end
|
#filename_pattern ⇒ Object
66
67
68
|
# File 'lib/brainstem/api_docs/presenter.rb', line 66
def filename_pattern
@filename_pattern ||= Brainstem::ApiDocs.presenter_filename_pattern
end
|
#target_class ⇒ Object
Returns the value of attribute target_class.
28
29
30
|
# File 'lib/brainstem/api_docs/presenter.rb', line 28
def target_class
@target_class
end
|
Instance Method Details
#brainstem_keys ⇒ Object
85
86
87
|
# File 'lib/brainstem/api_docs/presenter.rb', line 85
def brainstem_keys
const.possible_brainstem_keys.to_a.sort
end
|
#conditionals ⇒ Object
178
179
180
|
# File 'lib/brainstem/api_docs/presenter.rb', line 178
def conditionals
configuration[:conditionals]
end
|
#contextual_documentation(key) ⇒ Object
Returns a key if it exists and is documentable.
197
198
199
200
201
|
# File 'lib/brainstem/api_docs/presenter.rb', line 197
def contextual_documentation(key)
configuration.has_key?(key) &&
!configuration[key][:nodoc] &&
configuration[key][:info]
end
|
#default_sort_direction ⇒ Object
190
191
192
|
# File 'lib/brainstem/api_docs/presenter.rb', line 190
def default_sort_direction
@default_sort_direction ||= (default_sort_order.split(":")[1] || nil)
end
|
#default_sort_field ⇒ Object
186
187
188
|
# File 'lib/brainstem/api_docs/presenter.rb', line 186
def default_sort_field
@default_sort_field ||= (default_sort_order.split(":")[0] || nil)
end
|
#default_sort_order ⇒ Object
182
183
184
|
# File 'lib/brainstem/api_docs/presenter.rb', line 182
def default_sort_order
configuration[:default_sort_order] || ""
end
|
#description ⇒ Object
89
90
91
|
# File 'lib/brainstem/api_docs/presenter.rb', line 89
def description
contextual_documentation(:description) || ""
end
|
#documentable_association?(_, association) ⇒ Bool
Returns whether this association should be documented based on nodoc and empty description.
170
171
172
173
174
175
176
|
# File 'lib/brainstem/api_docs/presenter.rb', line 170
def documentable_association?(_, association)
!association.options[:nodoc] && (
document_empty_associations? || !(association.description.nil? || association.description.empty?) )
end
|
#documentable_filter?(_, filter) ⇒ Boolean
133
134
135
136
137
138
139
|
# File 'lib/brainstem/api_docs/presenter.rb', line 133
def documentable_filter?(_, filter)
!filter[:nodoc] &&
(
document_empty_filters? || !(filter[:info] || "").empty? )
end
|
#extension ⇒ Object
62
63
64
|
# File 'lib/brainstem/api_docs/presenter.rb', line 62
def extension
@extension ||= Brainstem::ApiDocs.output_extension
end
|
#invalid_field?(field) ⇒ Boolean
100
101
102
|
# File 'lib/brainstem/api_docs/presenter.rb', line 100
def invalid_field?(field)
field.options[:nodoc]
end
|
#link_for_association(association) ⇒ Object
155
156
157
158
159
160
161
162
|
# File 'lib/brainstem/api_docs/presenter.rb', line 155
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
104
105
106
|
# File 'lib/brainstem/api_docs/presenter.rb', line 104
def nested_field?(field)
field.respond_to?(:configuration)
end
|
#nodoc? ⇒ Boolean
77
78
79
|
# File 'lib/brainstem/api_docs/presenter.rb', line 77
def nodoc?
configuration[:nodoc]
end
|
#optional_field?(field) ⇒ Boolean
108
109
110
|
# File 'lib/brainstem/api_docs/presenter.rb', line 108
def optional_field?(field)
field.options[:optional]
end
|
#optional_field_names(fields = , buffer = []) ⇒ Object
Also known as:
optional_field_names_in
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/brainstem/api_docs/presenter.rb', line 112
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.
207
208
209
210
211
212
|
# File 'lib/brainstem/api_docs/presenter.rb', line 207
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
141
142
143
|
# File 'lib/brainstem/api_docs/presenter.rb', line 141
def searchable?
configuration[:search].present?
end
|
#suggested_filename(format) ⇒ Object
48
49
50
51
52
|
# File 'lib/brainstem/api_docs/presenter.rb', line 48
def suggested_filename(format)
filename_pattern
.gsub('{{name}}', target_class.to_s.underscore)
.gsub('{{extension}}', extension)
end
|
#suggested_filename_link(format) ⇒ Object
54
55
56
57
58
|
# File 'lib/brainstem/api_docs/presenter.rb', line 54
def suggested_filename_link(format)
filename_link_pattern
.gsub('{{name}}', target_class.to_s.underscore)
.gsub('{{extension}}', extension)
end
|
#title ⇒ Object
81
82
83
|
# File 'lib/brainstem/api_docs/presenter.rb', line 81
def title
contextual_documentation(:title) || const.to_s.demodulize
end
|
#valid_associations ⇒ Object
149
150
151
152
153
|
# File 'lib/brainstem/api_docs/presenter.rb', line 149
def valid_associations
configuration[:associations]
.to_h
.keep_if(&method(:documentable_association?))
end
|
#valid_fields(fields = ) ⇒ Object
Also known as:
valid_fields_in
93
94
95
96
97
|
# File 'lib/brainstem/api_docs/presenter.rb', line 93
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
127
128
129
130
131
|
# File 'lib/brainstem/api_docs/presenter.rb', line 127
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
|
# 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
]
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
|