class Asciidoctor::DefMastership::Preprocessor
Preprocessor
to replace adoc statements
Constants
- ATTR_CONFIG_REGEXP
- ATTR_SET_REGEXP
- DEFINITION_REGEXP
- EREF_CONFIG_REGEXP
- EREF_DEF_REGEXP
- FILTERS
- Filter
- IREF_DEF_REGEXP
Public Class Methods
new(config = {})
click to toggle source
class initialization
Calls superclass method
# File lib/asciidoctor/defmastership/extension.rb, line 57 def initialize(config = {}) super(config) # This is a preprocessor: we need to parse tag attributes @parsing_is_enabled = true @has_url = {} @parsing_state = ::DefMastership::ParsingState.new end
Public Instance Methods
process(_document, reader)
click to toggle source
process the document
# File lib/asciidoctor/defmastership/extension.rb, line 66 def process(_document, reader) return reader if reader.eof? reader.unshift_lines(parse_and_replace(reader.read_lines)) reader end
Private Instance Methods
attribute_setting(_line, matches)
click to toggle source
# File lib/asciidoctor/defmastership/extension.rb, line 134 def attribute_setting(_line, matches) [ '[.attribute]', "{attr-#{matches[:attr]}-prefix} #{matches[:value]}." ] end
build_definition(_line, matches)
click to toggle source
# File lib/asciidoctor/defmastership/extension.rb, line 92 def build_definition(_line, matches) definition_lines = [] explicit_checksum_str = " [.checksum]\#(#{matches[:explicit_checksum]})\#" if matches[:explicit_checksum] explicit_version_str = " [.version]\#(#{matches[:explicit_version]})\#" if matches[:explicit_version] labels_str = " #{labels_strings(matches[:labels]).join(' ')}" if matches[:labels] definition_lines << ".#{matches[:reference]}#{explicit_version_str}#{explicit_checksum_str}#{labels_str}" definition_lines << "[\##{matches[:reference]}.define.#{matches[:type]}]" end
build_external_ref(_line, matches)
click to toggle source
# File lib/asciidoctor/defmastership/extension.rb, line 118 def build_external_ref(_line, matches) extrefs = matches[:extrefs].split(/\s*,\s*/) new_line = "[.external_reference]\#{eref-#{matches[:refname]}-prefix} " extref_line = extrefs.map { |ref| build_link(ref, matches) } @has_url[matches[:refname]] ["#{new_line}#{extref_line.join(', ')}.\#"] end
build_internal_ref(line, _matches)
click to toggle source
# File lib/asciidoctor/defmastership/extension.rb, line 126 def build_internal_ref(line, _matches) [ line.gsub(IREF_DEF_REGEXP) do "<<#{Regexp.last_match[:intref]},#{Regexp.last_match[:intref]}>>" end ] end
build_link(ref, matches)
click to toggle source
# File lib/asciidoctor/defmastership/extension.rb, line 110 def build_link(ref, matches) if @has_url[matches[:refname]] "link:{eref-#{matches[:refname]}-url}\##{ref}\[#{ref}]" else ref end end
labels_strings(labels)
click to toggle source
# File lib/asciidoctor/defmastership/extension.rb, line 102 def labels_strings(labels) labels_strs = [] labels.split(/\s*,\s*/).reject(&:empty?).each do |label| labels_strs << "[.tag.{tag-#{label}-color}]\##{label}\#" end labels_strs end
parse_and_replace(lines)
click to toggle source
# File lib/asciidoctor/defmastership/extension.rb, line 75 def parse_and_replace(lines) lines.reduce([]) do |new_lines, line| shall_parse = @parsing_state.enabled?(line) filter = FILTERS.find { |onefilter| line.match(onefilter.regex) } if filter && shall_parse new_lines + __send__(filter.apply, line, Regexp.last_match) else new_lines + [line] end end end
set_eref_url_if_any(line, matches)
click to toggle source
# File lib/asciidoctor/defmastership/extension.rb, line 87 def set_eref_url_if_any(line, matches) @has_url[matches[:refname]] = true if matches[:symb] == 'url' && matches[:value] != 'none' [line] end