Class: MarkdownComposer::TransformRunner

Inherits:
Object
  • Object
show all
Includes:
ContentPlacement, FieldInterpolator, HeadingNumbering, ScopeResolver
Defined in:
lib/markdown_composer/transform_runner.rb,
lib/markdown_composer/transform_runner/scope_resolver.rb,
lib/markdown_composer/transform_runner/content_placement.rb,
lib/markdown_composer/transform_runner/heading_numbering.rb,
lib/markdown_composer/transform_runner/field_interpolator.rb

Defined Under Namespace

Modules: ContentPlacement, FieldInterpolator, HeadingNumbering, ScopeResolver

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer:, transforms:, output:, options:, diagnostics:, stages:, path_prefix: "transform") ⇒ TransformRunner

Returns a new instance of TransformRunner.



17
18
19
20
21
22
23
24
25
# File 'lib/markdown_composer/transform_runner.rb', line 17

def initialize(buffer:, transforms:, output:, options:, diagnostics:, stages:, path_prefix: "transform")
  @buffer = buffer
  @transforms = transforms
  @output = output
  @options = options
  @diagnostics = diagnostics
  @stages = stages
  @path_prefix = path_prefix
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



15
16
17
# File 'lib/markdown_composer/transform_runner.rb', line 15

def buffer
  @buffer
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



15
16
17
# File 'lib/markdown_composer/transform_runner.rb', line 15

def diagnostics
  @diagnostics
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/markdown_composer/transform_runner.rb', line 15

def options
  @options
end

#outputObject (readonly)

Returns the value of attribute output.



15
16
17
# File 'lib/markdown_composer/transform_runner.rb', line 15

def output
  @output
end

#path_prefixObject (readonly)

Returns the value of attribute path_prefix.



15
16
17
# File 'lib/markdown_composer/transform_runner.rb', line 15

def path_prefix
  @path_prefix
end

#stagesObject (readonly)

Returns the value of attribute stages.



15
16
17
# File 'lib/markdown_composer/transform_runner.rb', line 15

def stages
  @stages
end

#transformsObject (readonly)

Returns the value of attribute transforms.



15
16
17
# File 'lib/markdown_composer/transform_runner.rb', line 15

def transforms
  @transforms
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/markdown_composer/transform_runner.rb', line 27

def call
  transforms.each_with_index do |transform, index|
    path = "#{path_prefix}[#{index}]"
    before = buffer.markdown
    apply_transform(transform, path: path)
    diagnostics.warn("transform.noop", "#{transform["transform"]} made no changes", path: "#{path}.transform", details: { stage: "transformed_markdown" }) if before == buffer.markdown
    stages["transform_#{index + 1}"] = buffer.markdown if options.fetch(:stages, false)
  end
  stages["transformed_markdown"] = buffer.markdown if options.fetch(:stages, false)
  stages["final"] = output == "markdown" ? buffer.markdown : nil if options.fetch(:stages, false)
  buffer
end