Class: Chiridion::Engine::TemplateRenderer
- Inherits:
-
Object
- Object
- Chiridion::Engine::TemplateRenderer
- Defined in:
- lib/chiridion/engine/template_renderer.rb
Overview
Renders documentation using Liquid templates.
Templates are loaded from the gem’s templates/ directory by default, but can be overridden by specifying a custom templates_path.
Available templates:
-
index.liquid: Documentation index page
-
document.liquid: Class/module documentation
-
method.liquid: Individual method documentation
-
constants.liquid: Constants table and complex constant sections
Defined Under Namespace
Modules: Filters
Instance Method Summary collapse
-
#initialize(templates_path: nil) ⇒ TemplateRenderer
constructor
A new instance of TemplateRenderer.
-
#render_constants(constants:, complex_constants:) ⇒ String
Render the constants section.
-
#render_document(title:, docstring:, mixins: nil, examples: [], spec_examples: nil, see_also: nil, constants_section: "", types_section: "", attributes_section: "", methods_section: "") ⇒ String
Render a class or module document.
-
#render_file(path:, filename:, line_count: nil, namespaces: [], type_aliases: []) ⇒ String
Render a per-file documentation page.
-
#render_index(title:, description:, classes:, modules:) ⇒ String
Render the index template.
-
#render_method(display_name:, has_params: false, docstring: nil, params: [], return_line: nil, examples: [], behaviors: [], spec_examples: [], inline_source: nil) ⇒ String
Render a single method.
-
#render_methods(methods:) ⇒ String
Render the methods section with separators.
-
#render_type_aliases(title:, description:, namespaces:) ⇒ String
Render the type aliases reference page.
-
#render_types(types:) ⇒ String
Render the types section (type aliases used by a class/module).
Constructor Details
#initialize(templates_path: nil) ⇒ TemplateRenderer
Returns a new instance of TemplateRenderer.
85 86 87 88 89 90 91 |
# File 'lib/chiridion/engine/template_renderer.rb', line 85 def initialize(templates_path: nil) @templates_path = templates_path || default_templates_path @templates = {} @environment = Liquid::Environment.build do |env| env.register_filter(Filters) end end |
Instance Method Details
#render_constants(constants:, complex_constants:) ⇒ String
Render the constants section.
197 198 199 200 201 202 |
# File 'lib/chiridion/engine/template_renderer.rb', line 197 def render_constants(constants:, complex_constants:) render("constants", { "constants" => stringify_keys(constants), "complex_constants" => stringify_keys(complex_constants) }) end |
#render_document(title:, docstring:, mixins: nil, examples: [], spec_examples: nil, see_also: nil, constants_section: "", types_section: "", attributes_section: "", methods_section: "") ⇒ String
Render a class or module document.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/chiridion/engine/template_renderer.rb', line 122 def render_document( title:, docstring:, mixins: nil, examples: [], spec_examples: nil, see_also: nil, constants_section: "", types_section: "", attributes_section: "", methods_section: "" ) render("document", { "title" => title, "docstring" => docstring, "mixins" => mixins, "examples" => stringify_keys(examples), "spec_examples" => spec_examples, "see_also" => see_also, "constants_section" => constants_section, "types_section" => types_section, "attributes_section" => attributes_section, "methods_section" => methods_section }) end |
#render_file(path:, filename:, line_count: nil, namespaces: [], type_aliases: []) ⇒ String
Render a per-file documentation page.
234 235 236 237 238 239 240 241 242 |
# File 'lib/chiridion/engine/template_renderer.rb', line 234 def render_file(path:, filename:, line_count: nil, namespaces: [], type_aliases: []) render("file", { "path" => path, "filename" => filename, "line_count" => line_count, "namespaces" => stringify_keys(namespaces), "type_aliases" => stringify_keys(type_aliases) }) end |
#render_index(title:, description:, classes:, modules:) ⇒ String
Render the index template.
100 101 102 103 104 105 106 107 |
# File 'lib/chiridion/engine/template_renderer.rb', line 100 def render_index(title:, description:, classes:, modules:) render("index", { "title" => title, "description" => description, "classes" => stringify_keys(classes), "modules" => stringify_keys(modules) }) end |
#render_method(display_name:, has_params: false, docstring: nil, params: [], return_line: nil, examples: [], behaviors: [], spec_examples: [], inline_source: nil) ⇒ String
Render a single method.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/chiridion/engine/template_renderer.rb', line 160 def render_method( display_name:, has_params: false, docstring: nil, params: [], return_line: nil, examples: [], behaviors: [], spec_examples: [], inline_source: nil ) render("method", { "display_name" => display_name, "has_params" => has_params, "docstring" => docstring, "params" => params, "return_line" => return_line, "examples" => stringify_keys(examples), "behaviors" => behaviors, "spec_examples" => stringify_keys(spec_examples), "inline_source" => inline_source }) end |
#render_methods(methods:) ⇒ String
Render the methods section with separators.
188 189 190 |
# File 'lib/chiridion/engine/template_renderer.rb', line 188 def render_methods(methods:) = render("methods", { "methods" => methods }) |
#render_type_aliases(title:, description:, namespaces:) ⇒ String
Render the type aliases reference page.
218 219 220 221 222 223 224 |
# File 'lib/chiridion/engine/template_renderer.rb', line 218 def render_type_aliases(title:, description:, namespaces:) render("type_aliases", { "title" => title, "description" => description, "namespaces" => stringify_keys(namespaces) }) end |
#render_types(types:) ⇒ String
Render the types section (type aliases used by a class/module).
208 209 210 |
# File 'lib/chiridion/engine/template_renderer.rb', line 208 def render_types(types:) = render("types", { "types" => stringify_keys(types) }) |