Module: Asciidoctor::Defmastership::Preprocessor::Helper

Defined in:
lib/asciidoctor-defmastership/preprocessor.rb

Overview

Helpers for Preprocessor class

Defined Under Namespace

Classes: DefinitionStringBuilder

Class Method Summary collapse

Class Method Details

.explicit_version_str(explicit_version) ⇒ String

Returns the replacement string for explicit version.

Parameters:

  • explicit_version (String)

    an explicit version setting

Returns:

  • (String)

    the replacement string for explicit version



229
230
231
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 229

def self.explicit_version_str(explicit_version)
  " [.version]#(#{explicit_version})#" if explicit_version
end

.labels_str(labels) ⇒ String

Returns the replacement string for labels.

Parameters:

  • labels (Array[String])

    List of labels of a definition

Returns:

  • (String)

    the replacement string for labels



217
218
219
220
221
222
223
224
225
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 217

def self.labels_str(labels)
  return unless labels

  labels_strings =
    labels.split(/\s*,\s*/).reduce([]) do |acc, label|
      acc << "[.tag.{tag-#{label}-color}]##{label}#"
    end
  " #{labels_strings.join(' ')}"
end

.valid_eref_url?(match) ⇒ Boolean

Returns true if the match data includes a valid URL.

Parameters:

  • match (MatchData)

    match data from external ref setting Regexp

Returns:

  • (Boolean)

    true if the match data includes a valid URL



211
212
213
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 211

def self.valid_eref_url?(match)
  match[:symb] == 'url' && !match[:value].eql?('none')
end

.variable_hash(match) ⇒ [Hash{String => Object}]

Returns the hash corresponding to the variable setting.

Parameters:

  • match (MatchData)

    the match data from the matching variable setting Regexp

Returns:

  • ([Hash{String => Object}])

    the hash corresponding to the variable setting



235
236
237
# File 'lib/asciidoctor-defmastership/preprocessor.rb', line 235

def self.variable_hash(match)
  { match[:varname] => match[:value] }
end