Class: Asciidoctor::Defmastership::Preprocessor

Inherits:
Extensions::Preprocessor
  • Object
show all
Defined in:
lib/asciidoctor-defmastership/preprocessor.rb,
lib/asciidoctor-defmastership/preprocessor.rb

Overview

Proepocessors class Helpers

Defined Under Namespace

Modules: Helper

Instance Method Summary collapse

Constructor Details

#initialize(_config = {}) ⇒ Preprocessor

Returns a new instance of Preprocessor.

Parameters:

  • _config (Hash) (defaults to: {})

    configuration Hash for this preprocessor instance



48
49
50
51
52
53
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 48

def initialize(_config = {})
  super
  @has_url = Set.new
  @variables = {}
  @parsing_state = ::Defmastership::Core::ParsingState.new
end

Instance Method Details

#attribute_setting(_line, match) ⇒ Array<String>

Process an attribute setting line

This method smells of :reek:UtilityFunction

Parameters:

  • _line (String)

    the original line

  • match (MatchData)

    the match data from the matching Regexp

Returns:

  • (Array<String>)

    the lines to replace the original line



129
130
131
132
133
134
135
136
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 129

def attribute_setting(_line, match)
  attr_name = match[:attr]
  [
    '[.attribute]',
    "[.attribute_prefix.attribute_#{attr_name}_prefix]\#{attr-#{attr_name}-prefix}# " \
    "[.attribute_value.attribute_#{attr_name}_value]##{match[:value]}#."
  ]
end

#build_definition(_line, match) ⇒ Array<String>

Process a definition line

Parameters:

  • _line (String)

    the original line

  • match (MatchData)

    the match data from the matching Regexp

Returns:

  • (Array<String>)

    the lines to replace the original line



71
72
73
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 71

def build_definition(_line, match)
  Helper::DefinitionStringBuilder.new(match, show_explicit_checksum(match)).str_a
end

#build_external_ref(_line, match) ⇒ Array<String>

Process an external ref line

Parameters:

  • _line (String)

    the original line

  • match (MatchData)

    the match data from the matching Regexp

Returns:

  • (Array<String>)

    the lines to replace the original line



100
101
102
103
104
105
106
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 100

def build_external_ref(_line, match)
  return [] unless show_ext_ref(match)

  extrefs = match[:extrefs].split(/\s*,\s*/)
  extref_line = extrefs.map { |ref| build_link(ref, match) }
  ["[.external_reference]\#{eref-#{match[:reference]}-prefix} #{extref_line.join(', ')}.#"]
end

#build_internal_ref(line, _match) ⇒ Array<String>

Process an internal ref line

This method smells of :reek:UtilityFunction

Parameters:

  • line (String)

    the original line

  • _match (MatchData)

    the match data from the matching Regexp

Returns:

  • (Array<String>)

    the lines to replace the original line



114
115
116
117
118
119
120
121
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 114

def build_internal_ref(line, _match)
  [
    line.gsub(REGEXPS.fetch(:iref_def)) do
      intref = Regexp.last_match[:intref]
      "<<#{intref},#{intref}>>"
    end
  ]
end

#process(_document, reader) ⇒ Object

Entry point for the plugin call

This method smells of :reek:FeatureEnvy

Parameters:

  • _document (Asciidoctor::Document)

    the current document

  • reader (Asciidoctor::Reader)

    to retrieve lines from AsciiDoc source file



60
61
62
63
64
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 60

def process(_document, reader)
  return reader if reader.eof?

  reader.unshift_lines(parse_and_replace(reader.read_lines))
end

#set_eref_url_if_any(line, match) ⇒ Array<String>

Process a set url line

Parameters:

  • line (String)

    the original line

  • match (MatchData)

    the match data from the matching Regexp

Returns:

  • (Array<String>)

    the lines to replace the original line



90
91
92
93
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 90

def set_eref_url_if_any(line, match)
  @has_url.add(match[:reference]) if Helper.valid_eref_url?(match)
  [line]
end

#variable_set(line, match) ⇒ Array<String>

Process a variable setting line

Parameters:

  • line (String)

    the original line

  • match (MatchData)

    the match data from the matching Regexp

Returns:

  • (Array<String>)

    the lines to replace the original line



80
81
82
83
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 80

def variable_set(line, match)
  @variables.merge!(Helper.variable_hash(match))
  [line]
end