Class: MarkdownComposer::Executor
- Inherits:
-
Object
- Object
- MarkdownComposer::Executor
- Defined in:
- lib/markdown_composer/executor.rb
Instance Attribute Summary collapse
-
#diagnostics ⇒ Object
readonly
Returns the value of attribute diagnostics.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#plan ⇒ Object
readonly
Returns the value of attribute plan.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#stages ⇒ Object
readonly
Returns the value of attribute stages.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(sources:, plan:, options: {}) ⇒ Executor
constructor
A new instance of Executor.
Constructor Details
#initialize(sources:, plan:, options: {}) ⇒ Executor
Returns a new instance of Executor.
7 8 9 10 11 12 13 |
# File 'lib/markdown_composer/executor.rb', line 7 def initialize(sources:, plan:, options: {}) @sources = Array(sources).map { |source| Source.build(source) } @plan = plan @options = @diagnostics = Diagnostics.new @stages = {} end |
Instance Attribute Details
#diagnostics ⇒ Object (readonly)
Returns the value of attribute diagnostics.
5 6 7 |
# File 'lib/markdown_composer/executor.rb', line 5 def diagnostics @diagnostics end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/markdown_composer/executor.rb', line 5 def @options end |
#plan ⇒ Object (readonly)
Returns the value of attribute plan.
5 6 7 |
# File 'lib/markdown_composer/executor.rb', line 5 def plan @plan end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
5 6 7 |
# File 'lib/markdown_composer/executor.rb', line 5 def sources @sources end |
#stages ⇒ Object (readonly)
Returns the value of attribute stages.
5 6 7 |
# File 'lib/markdown_composer/executor.rb', line 5 def stages @stages end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/markdown_composer/executor.rb', line 15 def call Validator.new(plan, sources: sources, options: , diagnostics: diagnostics).call return result(CompositionBuffer.new(diagnostics: diagnostics), html: nil) if diagnostics.any_errors? buffer = CompositionBuffer.new(initial_buffer, diagnostics: diagnostics) return result(buffer, html: nil) if diagnostics.any_errors? indexes = {} previous_source = nil plan.steps.each_with_index do |step, index| row_path = "compose[#{index}]" source_ref = effective_source_ref(step["source"], previous_source) source_index = source_index_for(source_ref, buffer, indexes, path: "#{row_path}.source") next unless source_index resolver = SelectionResolver.new(index: source_index, options: , diagnostics: diagnostics, path: "#{row_path}.select") units = if step["action"] == "remove_buffer_target" [] else resolver.resolve_with_includes(step["select"], step["include"]) end diagnostics.warn("selection.empty", "Step selected no content", path: row_path) if units.empty? && step["action"] != "remove_buffer_target" apply_action(buffer, step, units, row_path: row_path) stages["step_#{index + 1}"] = buffer.markdown if .fetch(:stages, false) previous_source = source_ref end stages["composed"] = buffer.markdown if .fetch(:stages, false) TransformRunner.new(buffer: buffer, transforms: plan.transforms, output: plan.output, options: , diagnostics: diagnostics, stages: stages).call html = if plan.output == "html" rendered = MarkdownRenderer.to_html(buffer.markdown, diagnostics: diagnostics) MarkdownRenderer.apply_link_modes(rendered, html_link_modes, diagnostics: diagnostics) end result(buffer, html: html) end |