brainstem 1.0.0.pre.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +383 -32
  5. data/bin/brainstem +6 -0
  6. data/brainstem.gemspec +2 -0
  7. data/docs/api_doc_generator.markdown +175 -0
  8. data/docs/brainstem_executable.markdown +32 -0
  9. data/docs/docgen.png +0 -0
  10. data/docs/docgen_ascii.txt +63 -0
  11. data/docs/executable.png +0 -0
  12. data/docs/executable_ascii.txt +10 -0
  13. data/lib/brainstem/api_docs.rb +146 -0
  14. data/lib/brainstem/api_docs/abstract_collection.rb +116 -0
  15. data/lib/brainstem/api_docs/atlas.rb +158 -0
  16. data/lib/brainstem/api_docs/builder.rb +167 -0
  17. data/lib/brainstem/api_docs/controller.rb +122 -0
  18. data/lib/brainstem/api_docs/controller_collection.rb +40 -0
  19. data/lib/brainstem/api_docs/endpoint.rb +234 -0
  20. data/lib/brainstem/api_docs/endpoint_collection.rb +58 -0
  21. data/lib/brainstem/api_docs/exceptions.rb +8 -0
  22. data/lib/brainstem/api_docs/formatters/abstract_formatter.rb +64 -0
  23. data/lib/brainstem/api_docs/formatters/markdown/controller_formatter.rb +76 -0
  24. data/lib/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter.rb +73 -0
  25. data/lib/brainstem/api_docs/formatters/markdown/endpoint_formatter.rb +169 -0
  26. data/lib/brainstem/api_docs/formatters/markdown/helper.rb +76 -0
  27. data/lib/brainstem/api_docs/formatters/markdown/presenter_formatter.rb +200 -0
  28. data/lib/brainstem/api_docs/introspectors/abstract_introspector.rb +100 -0
  29. data/lib/brainstem/api_docs/introspectors/rails_introspector.rb +232 -0
  30. data/lib/brainstem/api_docs/presenter.rb +225 -0
  31. data/lib/brainstem/api_docs/presenter_collection.rb +97 -0
  32. data/lib/brainstem/api_docs/resolver.rb +73 -0
  33. data/lib/brainstem/api_docs/sinks/abstract_sink.rb +37 -0
  34. data/lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb +93 -0
  35. data/lib/brainstem/api_docs/sinks/stdout_sink.rb +44 -0
  36. data/lib/brainstem/cli.rb +146 -0
  37. data/lib/brainstem/cli/abstract_command.rb +97 -0
  38. data/lib/brainstem/cli/generate_api_docs_command.rb +169 -0
  39. data/lib/brainstem/concerns/controller_dsl.rb +300 -0
  40. data/lib/brainstem/concerns/controller_param_management.rb +30 -9
  41. data/lib/brainstem/concerns/formattable.rb +38 -0
  42. data/lib/brainstem/concerns/inheritable_configuration.rb +3 -2
  43. data/lib/brainstem/concerns/optional.rb +43 -0
  44. data/lib/brainstem/concerns/presenter_dsl.rb +76 -15
  45. data/lib/brainstem/controller_methods.rb +6 -3
  46. data/lib/brainstem/dsl/association.rb +6 -3
  47. data/lib/brainstem/dsl/associations_block.rb +6 -3
  48. data/lib/brainstem/dsl/base_block.rb +2 -4
  49. data/lib/brainstem/dsl/conditional.rb +7 -3
  50. data/lib/brainstem/dsl/conditionals_block.rb +4 -4
  51. data/lib/brainstem/dsl/configuration.rb +184 -8
  52. data/lib/brainstem/dsl/field.rb +6 -3
  53. data/lib/brainstem/dsl/fields_block.rb +2 -3
  54. data/lib/brainstem/help_text.txt +8 -0
  55. data/lib/brainstem/presenter.rb +27 -6
  56. data/lib/brainstem/presenter_validator.rb +5 -2
  57. data/lib/brainstem/time_classes.rb +1 -1
  58. data/lib/brainstem/version.rb +1 -1
  59. data/spec/brainstem/api_docs/abstract_collection_spec.rb +156 -0
  60. data/spec/brainstem/api_docs/atlas_spec.rb +353 -0
  61. data/spec/brainstem/api_docs/builder_spec.rb +100 -0
  62. data/spec/brainstem/api_docs/controller_collection_spec.rb +92 -0
  63. data/spec/brainstem/api_docs/controller_spec.rb +225 -0
  64. data/spec/brainstem/api_docs/endpoint_collection_spec.rb +144 -0
  65. data/spec/brainstem/api_docs/endpoint_spec.rb +346 -0
  66. data/spec/brainstem/api_docs/formatters/abstract_formatter_spec.rb +30 -0
  67. data/spec/brainstem/api_docs/formatters/markdown/controller_formatter_spec.rb +126 -0
  68. data/spec/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter_spec.rb +85 -0
  69. data/spec/brainstem/api_docs/formatters/markdown/endpoint_formatter_spec.rb +261 -0
  70. data/spec/brainstem/api_docs/formatters/markdown/helper_spec.rb +100 -0
  71. data/spec/brainstem/api_docs/formatters/markdown/presenter_formatter_spec.rb +485 -0
  72. data/spec/brainstem/api_docs/introspectors/abstract_introspector_spec.rb +192 -0
  73. data/spec/brainstem/api_docs/introspectors/rails_introspector_spec.rb +170 -0
  74. data/spec/brainstem/api_docs/presenter_collection_spec.rb +84 -0
  75. data/spec/brainstem/api_docs/presenter_spec.rb +519 -0
  76. data/spec/brainstem/api_docs/resolver_spec.rb +72 -0
  77. data/spec/brainstem/api_docs/sinks/abstract_sink_spec.rb +16 -0
  78. data/spec/brainstem/api_docs/sinks/controller_presenter_multifile_sink_spec.rb +56 -0
  79. data/spec/brainstem/api_docs/sinks/stdout_sink_spec.rb +22 -0
  80. data/spec/brainstem/api_docs_spec.rb +58 -0
  81. data/spec/brainstem/cli/abstract_command_spec.rb +91 -0
  82. data/spec/brainstem/cli/generate_api_docs_command_spec.rb +125 -0
  83. data/spec/brainstem/cli_spec.rb +67 -0
  84. data/spec/brainstem/concerns/controller_dsl_spec.rb +471 -0
  85. data/spec/brainstem/concerns/controller_param_management_spec.rb +36 -16
  86. data/spec/brainstem/concerns/formattable_spec.rb +30 -0
  87. data/spec/brainstem/concerns/inheritable_configuration_spec.rb +104 -4
  88. data/spec/brainstem/concerns/optional_spec.rb +48 -0
  89. data/spec/brainstem/concerns/presenter_dsl_spec.rb +202 -31
  90. data/spec/brainstem/dsl/association_spec.rb +18 -2
  91. data/spec/brainstem/dsl/conditional_spec.rb +25 -2
  92. data/spec/brainstem/dsl/configuration_spec.rb +1 -1
  93. data/spec/brainstem/dsl/field_spec.rb +18 -2
  94. data/spec/brainstem/presenter_collection_spec.rb +10 -2
  95. data/spec/brainstem/presenter_spec.rb +32 -0
  96. data/spec/brainstem/presenter_validator_spec.rb +12 -7
  97. data/spec/dummy/rails.rb +49 -0
  98. data/spec/shared/atlas_taker.rb +18 -0
  99. data/spec/shared/formattable.rb +14 -0
  100. data/spec/spec_helper.rb +2 -0
  101. data/spec/spec_helpers/db.rb +1 -1
  102. data/spec/spec_helpers/presenters.rb +20 -14
  103. metadata +106 -6
data/bin/brainstem ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.push File.expand_path(File.join('..', '..', 'lib'), __FILE__)
4
+ require 'brainstem/cli'
5
+
6
+ Brainstem::Cli.call(ARGV)
data/brainstem.gemspec CHANGED
@@ -17,6 +17,8 @@ Gem::Specification.new do |gem|
17
17
  gem.require_paths = ["lib"]
18
18
  gem.version = Brainstem::VERSION
19
19
 
20
+ gem.executables << 'brainstem'
21
+
20
22
  gem.add_dependency "activerecord", ">= 4.1"
21
23
  gem.add_dependency "activesupport", ">= 4.1"
22
24
 
@@ -0,0 +1,175 @@
1
+ # API Doc Generator: Developer's Guide
2
+
3
+ This documentation explains the intricacies of Brainstem's built-in API
4
+ documentation generation capabilities. For brevity, we refer to this
5
+ particular application as 'docgen'.
6
+
7
+ ## Execution
8
+
9
+ `bundle exec brainstem generate [ARGS]`
10
+
11
+ ## Customizing Output
12
+
13
+ #### Making Small Customizations to the Existing Formatters
14
+
15
+ It is easy to make small customizations to the formatters simply by subclassing
16
+ them, customizing behaviour as you'd like, and then registering over top of an
17
+ existing formatter.
18
+
19
+ For instance, if you wanted to add a horizontal rule after an endpoint's title:
20
+
21
+ ```ruby
22
+ # config/initializers/brainstem.rb
23
+ require 'brainstem/api_docs/formatters/markdown/endpoint_formatter'
24
+
25
+ class MyEndpointFormatter < Brainstem::ApiDocs::Formatters::Markdown::EndpointFormatter
26
+ def format_title!
27
+ super
28
+ output << md_hr
29
+ end
30
+ end
31
+
32
+ Brainstem::ApiDocs::FORMATTERS[:endpoint][:markdown] = MyFormatter.method(:call)
33
+ ```
34
+
35
+ You can refer to [all the formatters](../lib/brainstem/api_docs/formatters) to
36
+ see what is possible.
37
+
38
+ #### Adding Custom Formats
39
+
40
+ Do exactly as above, but instead of declaring it as an existing formatter,
41
+ declare the formatter as one of your own choosing:
42
+
43
+ ```ruby
44
+ Brainstem::ApiDocs::FORMATTERS[:endpoint][:my_format] = MyFormatter.method(:call)
45
+ ```
46
+
47
+ Instead of choosing to inherit from an existing format, you can choose also to
48
+ inherit from `Brainstem::ApiDocs::Formatters::AbstractFormatter` as well.
49
+
50
+ Note that formatters at this time make concrete references to their own format,
51
+ so if you decide to inherit from existing formatters, you will have to make
52
+ sure these references are changed appropriately.
53
+
54
+ #### Accessing sibling data from formatters
55
+
56
+ A formatter formats a wrapping object which serves as a viewmodel to an actual
57
+ entity in your application, such as an `ActionController::Base` or a
58
+ `Brainstem::Presenter`. There are also additional wrapping objects which hold
59
+ collections of these singular wrappers.
60
+
61
+ These wrappers include the following:
62
+
63
+ - `Brainstem::ApiDocs::Presenter`
64
+ - `Brainstem::ApiDocs::Endpoint`
65
+ - `Brainstem::ApiDocs::Controller`
66
+ - `Brainstem::ApiDocs::PresenterCollection`
67
+ - `Brainstem::ApiDocs::EndpointCollection`
68
+ - `Brainstem::ApiDocs::Controller`
69
+
70
+ In some situations, you may want to include documentation for adjacent or or
71
+ similar but unrelated wrapper object. Each of these wrapping objects has a
72
+ method called `find_by_class`, which can return these adjacent objects.
73
+
74
+ At the moment, finding the following is supported:
75
+
76
+ - `Presenter`:
77
+ - find by `target_class`, e.g.
78
+ - `presenter = find_by_class(association.target_class)`
79
+ - `presenter = find_by_class(User)`
80
+
81
+ The object responsible for the lookup functionality is the
82
+ `Brainstem::ApiDocs::Resolver`, which can be reopened if necessary to provide
83
+ further lookups.
84
+
85
+ #### Adding Additional Configurable Options
86
+
87
+ The `Brainstem::ApiDocs` module serves double-duty as the receptacle for
88
+ configuration information, and is used throughout the docgen application in
89
+ order to provide alternatives to defaults.
90
+
91
+ This can be very handy in any of your customizations, and it is relatively easy
92
+ to add, so long as your configuration is used after the host application is
93
+ booted up (see [Phases](#phases)). Simply re-open the module in your
94
+ initializer, add your desired `config_accessor`, and refer to the constant in
95
+ your formatters:
96
+
97
+ ```ruby
98
+ # config/initializers/brainstem.rb
99
+
100
+ module Brainstem
101
+ module ApiDocs
102
+ config_accessor(:my_config_option) { false }
103
+ end
104
+ end
105
+ ```
106
+
107
+ ```ruby
108
+ # my_formatter.rb
109
+
110
+ Brainstem::ApiDocs.my_config_option
111
+ ```
112
+
113
+ ## Architectural Overview
114
+
115
+ ### Primary Phases
116
+
117
+ 1. ApiDocs namespace and required classes are loaded.
118
+ 2. Host application is loaded and required information is extracted
119
+ (introspection).
120
+ 3. Information is repackaged into wrapping objects (atlas creation).
121
+ 4. Sink interrogates atlas for specific formatted wrappers (serialization) and
122
+ persists serialized data to disk (persistence).
123
+
124
+
125
+ ### Detailed Overview
126
+
127
+ ![DocGen overview](./docgen.png)
128
+
129
+
130
+ 1. `Brainstem::CLI::GenerateApiDocsCommand` instantiates a builder and a sink,
131
+ and hands the output of the builder to the sink, which serializes and stores
132
+ the input somewhere. It also merges the options given to it on the command
133
+ line with the default options defined in `Brainstem::ApiDocs`.
134
+ 2. `Brainstem::ApiDocs::Builder` is responsible for retrieving information from
135
+ the host application to be exposed to a sink through a
136
+ `Brainstem::ApiDocs::Introspectors::AbstractIntrospector` subclass. It wraps
137
+ this information in more friendly and documentable ways, producing a series
138
+ of collections that can be iterated or reduced from which to produce
139
+ documentation. It exposes this data through its `atlas` method, which is an
140
+ instance of `Brainstem::ApiDocs::Atlas`.
141
+ 3. `Brainstem::ApiDocs::Introspectors::AbstractIntrospector` defines an
142
+ interface for objects to return data from the host application. Provided
143
+ with Brainstem is an implementation of
144
+ `Brainstem::ApiDocs::Introspectors::RailsIntrospector`, which can be used to
145
+ extract the required information from a Rails 4 application.
146
+ 4. `Brainstem::ApiDocs::Atlas` is an object which receives the data from an
147
+ introspector and transforms it into a series of collections useful for
148
+ producing documentation. It does so by wrapping domain entities and providing
149
+ intelligent interfaces on these collections by which to mutate them. It wraps:
150
+ - Routes into `Brainstem::ApiDocs::Endpoint` objects, and these into a
151
+ `Brainstem::ApiDocs::EndpointCollection`;
152
+ - Controllers into `Brainstem::ApiDocs::Controller` objects, and these into
153
+ a `Brainstem::ApiDocs::ControllerCollection`;
154
+ - Presenters into `Brainstem::ApiDocs::Presenter` objects, and these into a
155
+ `Brainstem::ApiDocs::PresenterCollection`.
156
+ 5. Each of these collection and entity objects includes
157
+ `Brainstem::Concerns::Formattable`, which enables them to be formatted by
158
+ passing them `formatted_as(format, options)`. Formatters inherit from
159
+ `Brainstem::ApiDocs::Formatters::AbstractFormatter`, are loaded by
160
+ `Cerebellum::ApiDocs`, and are stored by self-assigned type. Some or all of
161
+ these formatters may be provided for this type, depending on the desired
162
+ behaviour. Brainstem includes an implementation of a `Markdown` formatter,
163
+ stored under the type `:markdown`, and has a
164
+ `Brainstem::ApiDocs::Formatters::Markdown::EndpointCollectionFormatter` as
165
+ well as an `Endpoint-`, `Controller-`, and `PresenterFormatter`. Note that
166
+ there is not a `ControllerCollectionFormatter`, nor a
167
+ `PresenterCollectionFormatter` included: this is because the Sink shares
168
+ partial responsibility for collection formatting, and in the case of the
169
+ `Brainstem::ApiDocs::Sinks::ControllerPresenterMultifileSink`, outputs each
170
+ controller and presenter as its own file, rather than as a concatenated
171
+ collection.
172
+ 6. This sink, having received an instance of the `Atlas`, is responsible for
173
+ serializing&mdash;primarily invoking formatting&mdash;and then outputting
174
+ the result somewhere, whether to `$stdout`, a file or files on disk, or a
175
+ remote location.
@@ -0,0 +1,32 @@
1
+ # Brainstem Command-line Utility
2
+
3
+ ## Usage
4
+
5
+ Usage: `brainstem SUBCOMMAND options`
6
+
7
+ e.g. `brainstem generate --markdown`
8
+
9
+ Get help by running `brainstem help generate`, or `brainstem generate --help`.
10
+
11
+
12
+ ## Brainstem Developer Overview
13
+
14
+ ![Brainstem Executable Diagram](./executable.png)
15
+
16
+ 1. The `brainstem` executable instantiates and invokes `Brainstem::Cli`.
17
+ 2. `Brainstem::Cli` holds a map of acceptable subcommands and the objects that
18
+ contain their logic. It also knows how to extract options and invoke
19
+ execution of these objects, so long as they provide the interface specified
20
+ in `Brainstem::CLI::AbstractCommand`.
21
+ 3. `Brainstem::CLI::AbstractCommand` is an interface whose descendants define
22
+ an entry point into the application logic. They should expose an option
23
+ parser through their `option_parser` method, one which mutates the `options`
24
+ instance method. The parser is evaluated before the instance of the command
25
+ is `call`ed.
26
+
27
+ #### Specific Commands
28
+
29
+ - `Brainstem::CLI::GenerateApiDocsCommand` contains the application logic to
30
+ generate the API docs annotated by Brainstem. See the [Api Doc Generator
31
+ documentation](./api_doc_generator.markdown) for more info.
32
+
data/docs/docgen.png ADDED
Binary file
@@ -0,0 +1,63 @@
1
+ Load the following rows into asciiflow.com to edit:
2
+
3
+
4
+
5
+ +----------------------------------------+ +-----------------------------+ +---------------------------------------------------------+
6
+ | Brainstem::CLI::GenerateApiDocsCommand +------+-----> Brainstem::ApiDocs::Builder +-------+----> Brainstem::ApiDocs::Introspectors::AbstractIntrospector <-----+
7
+ +----------------------------------------+ | +-----------------------------+ | +---------------------------------------------------------+ | U
8
+ | | | | S
9
+ | | | +------------------------------------------------------+ | E
10
+ | | +----> Brainstem::ApiDocs::Introspectors::RailsIntrospector <---+ S
11
+ | | +------------------------------------------------------+ |
12
+ | | |
13
+ | | +------------------------------------+
14
+ | | |
15
+ | | +--------------------------++ +----------------------------------------+
16
+ | +----> Brainstem::ApiDocs::Atlas +------------> Brainstem::ApiDocs::AbstractCollection |
17
+ | | +------------------------^--+ +----------------------------------------+
18
+ | | | |
19
+ | | | | +----------------------------------------+ +------------------------------+
20
+ | | | +----> Brainstem::ApiDocs::EndpointCollection +---+---------> Brainstem::ApiDocs::Endpoint +---+
21
+ | | | | +----------------------------------------+ | +------------------------------+ |
22
+ | | | | | |
23
+ | | | | +------------------------------------------+ | +--------------------------------+ |
24
+ | | | +----> Brainstem::ApiDocs::ControllerCollection +-----------> Brainstem::ApiDocs::Controller +---+
25
+ | | | | +------------------------------------------+ | +--------------------------------+ | |
26
+ | | | | | | |
27
+ | | | | +-----------------------------------------+ | +-------------------------------+ | |
28
+ | | | +----> Brainstem::ApiDocs::PresenterCollection +------------> Brainstem::ApiDocs::Presenter +------+
29
+ | | | +-----------------------------------------+ | +-------------------------------+ | | |
30
+ | | | | | | |
31
+ | | +-------------------------------------------+ | | | |
32
+ | | | U | | | |
33
+ | | +-----------------------------------------+ | S | | | | U
34
+ | +----> Brainstem::ApiDocs::Sinks::AbstractSink +--------------------------> E | | | | S
35
+ | +-----------------------------------------+ | S | | | | E
36
+ | | | | | | | S
37
+ | | +-------------------------------------------------------------+ | | | | |
38
+ | +----> Brainstem::ApiDocs::Sinks::ControllerPresenterMultifileSink +-+ | | | |
39
+ | +-------------------------------------------------------------+ | | | |
40
+ | | | | |
41
+ | | | | |
42
+ | | | | |
43
+ | | | | |
44
+ | | | | |
45
+ | +--------------------+ +---------------------------------------------------+ | | | |
46
+ +-----> Brainstem::ApiDocs +---------------------> Brainstem::ApiDocs::Formatters::AbstractFormatter | | | | |
47
+ +--------------------+ +---------------------------------------------------+ | | | |
48
+ | | | | |
49
+ | +-----------------------------------------------------------------------+ | | | |
50
+ +----> Brainstem::ApiDocs::Formatters::Markdown::EndpointCollectionFormatter <-------------+ | | |
51
+ | +-----------------------------------------------------------------------+ | | |
52
+ | | | |
53
+ | +-------------------------------------------------------------+ | | |
54
+ +----> Brainstem::ApiDocs::Formatters::Markdown::EndpointFormatter <--------------------------------------------------------------------+ | |
55
+ | +-------------------------------------------------------------+ | |
56
+ | | |
57
+ | +---------------------------------------------------------------+ | |
58
+ +----> Brainstem::ApiDocs::Formatters::Markdown::ControllerFormatter <--------------------------------------------------------------------+ |
59
+ | +---------------------------------------------------------------+ |
60
+ | |
61
+ | +--------------------------------------------------------------+ |
62
+ +----> Brainstem::ApiDocs::Formatters::Markdown::PresenterFormatter <-----------------------------------------------------------------------+
63
+ +--------------------------------------------------------------+
Binary file
@@ -0,0 +1,10 @@
1
+ Load the following rows into asciiflow.com to edit:
2
+
3
+
4
+ +------------------------+ +----------------+ +---------------------------------+
5
+ | brainstem (executable) +-------> Brainstem::Cli +----------> Brainstem::CLI::AbstractCommand |
6
+ +------------------------+ +----------------+ ++--------------------------------+
7
+ |
8
+ | +----------------------------------------+
9
+ +--> Brainstem::CLI::GenerateApiDocsCommand |
10
+ +----------------------------------------+
@@ -0,0 +1,146 @@
1
+ require 'active_support/configurable'
2
+
3
+ module Brainstem
4
+ module ApiDocs
5
+ include ActiveSupport::Configurable
6
+
7
+ config_accessor(:write_path) do
8
+ File.expand_path("./brainstem_docs")
9
+ end
10
+
11
+
12
+ #
13
+ # Defines the naming pattern of each controller documentation file.
14
+ #
15
+ # The following tokens will be substituted:
16
+ #
17
+ # - {{namespace}} : the namespace of the controller underscored,
18
+ # i.e. 'api/v1'
19
+ # - {{name}} : the underscored name of the controller without
20
+ # 'controller'
21
+ # - {{extension} : the specified file extension
22
+ #
23
+ # @see #output_extension
24
+ #
25
+ config_accessor(:controller_filename_pattern) do
26
+ File.join("endpoints", "{{name}}.{{extension}}")
27
+ end
28
+
29
+
30
+ #
31
+ # Defines the naming pattern of each presenter documentation file.
32
+ #
33
+ # The following tokens will be substituted:
34
+ #
35
+ # - {{name}} : the demodulized underscored name of the presenter
36
+ # - {{extension} : the specified file extension
37
+ #
38
+ # @see #output_extension
39
+ #
40
+ config_accessor(:presenter_filename_pattern) do
41
+ File.join("objects", "{{name}}.{{extension}}")
42
+ end
43
+
44
+
45
+ #
46
+ # Defines the naming pattern for the relative link to each controller documentation file.
47
+ #
48
+ # The following tokens will be substituted:
49
+ #
50
+ # - {{name}} : the underscored name of the controller without 'controller'
51
+ # - {{extension} : the specified file extension
52
+ #
53
+ # @see #output_extension
54
+ #
55
+ config_accessor(:controller_filename_link_pattern) do
56
+ controller_filename_pattern
57
+ end
58
+
59
+
60
+ #
61
+ # Defines the naming pattern for the relative link to each presenter documentation file.
62
+ #
63
+ # The following tokens will be substituted:
64
+ #
65
+ # - {{name}} : the demodulized underscored name of the presenter
66
+ # - {{extension} : the specified file extension
67
+ #
68
+ # @see #output_extension
69
+ #
70
+ config_accessor(:presenter_filename_link_pattern) do
71
+ presenter_filename_pattern
72
+ end
73
+
74
+
75
+ #
76
+ # Defines the extension that should be used for output files.
77
+ #
78
+ # Excludes the '.'.
79
+ #
80
+ config_accessor(:output_extension) { "markdown" }
81
+
82
+
83
+ #
84
+ # Defines the class that all presenters should inherit from / be drawn
85
+ # from.
86
+ #
87
+ # Is a string because most relevant classes are not loaded until much
88
+ # later.
89
+ #
90
+ # @see Brainstem::ApiDocs::RailsIntrospector#base_presenter_class=
91
+ #
92
+ config_accessor(:base_presenter_class) do
93
+ "::Brainstem::Presenter"
94
+ end
95
+
96
+
97
+ #
98
+ # Defines the class that all controllers should inherit from / be drawn
99
+ # from.
100
+ #
101
+ # Is a string because most relevant classes are not loaded until much
102
+ # later.
103
+ #
104
+ # @see Brainstem::ApiDocs::RailsIntrospector#base_presenter_class=
105
+ #
106
+ config_accessor(:base_controller_class) do
107
+ "::ApplicationController"
108
+ end
109
+
110
+
111
+ #
112
+ # If associations on a presenter have no description, i.e. no documentation,
113
+ # should they be documented anyway?
114
+ #
115
+ config_accessor(:document_empty_presenter_associations) { true }
116
+
117
+
118
+ #
119
+ # If filters on a presenter have no `:info` key, i.e. no documentation,
120
+ # should they be documented anyway?
121
+ #
122
+ config_accessor(:document_empty_presenter_filters) { true }
123
+
124
+
125
+
126
+ FORMATTERS = {
127
+
128
+ # Formatter for entire response
129
+ document: {},
130
+
131
+ # Formatters for collections
132
+ controller_collection: {},
133
+ endpoint_collection: {},
134
+ presenter_collection: {},
135
+
136
+ # Formatters for individual entities
137
+ controller: {},
138
+ endpoint: {},
139
+ presenter: {},
140
+
141
+ }
142
+ end
143
+ end
144
+
145
+ formatter_path = File.expand_path('../formatters/**/*.rb', __FILE__)
146
+ Dir.glob(formatter_path).each { |f| require f }