Sha256: 7ee6f80772b0ca76a76ee5709f19abf5120ba49a4571479f481559eb8f3dc558

Contents?: true

Size: 1.49 KB

Versions: 50

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Avm
  module EacAsciidoctorBase0
    module Instances
      class Build
        class Document
          class PreProcessLine
            enable_method_class
            enable_simple_cache

            ARGUMENT_SEPARATOR = ','
            MACRO_PARSER = %r{\A\s*//\#(\S+)(?:\s+(.+))?\s*?\z}.to_parser do |m|
              ::Struct.new(:name, :arguments).new(m[1],
                                                  m[2].to_s.split(ARGUMENT_SEPARATOR).map(&:strip))
            end

            common_constructor :document, :line

            # @return [Array<String>]
            def result
              if macro?
                macro_value
              else
                [line]
              end
            end

            def macro?
              macro_name.present?
            end

            # @return [Array<String>, nil]
            def macro_arguments
              parsed_macro.if_present(&:arguments)
            end

            # @return [String, nil]
            def macro_name
              parsed_macro.if_present(&:name)
            end

            def macro_parser
              MACRO_PARSER
            end

            # @return [Array<String>]
            def macro_value
              document.macro_lines(macro_name, macro_arguments)
            end

            private

            def parsed_macro_uncached
              macro_parser.parse(line)
            end
          end
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
avm-eac_asciidoctor_base0-0.25.0 lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.97.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
avm-eac_asciidoctor_base0-0.24.0 lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.96.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
avm-eac_asciidoctor_base0-0.23.0 lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.88.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.87.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
avm-eac_asciidoctor_base0-0.22.1 lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.86.13 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
avm-eac_asciidoctor_base0-0.22.0 lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.85.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.84.2 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.84.1 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
avm-eac_asciidoctor_base0-0.21.0 lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.84.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
avm-eac_asciidoctor_base0-0.20.0 lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.83.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.82.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.81.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb
eac_tools-0.80.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb