Sha256: 1f6fa9d486e200f0b4cdc517304a7d6953247fd5a5884f06f91f9bafc04e4860

Contents?: true

Size: 1.71 KB

Versions: 50

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

require 'avm/eac_asciidoctor_base0/instances/macros/base'
require 'eac_ruby_utils/core_ext'

module Avm
  module EacAsciidoctorBase0
    module Instances
      module Macros
        class ChildDocs < ::Avm::EacAsciidoctorBase0::Instances::Macros::Base
          class DocumentBuilder
            common_constructor :child_docs, :document, :depth, default: [0]
            compare_by :title, :address

            # @return [Pathname]
            def address
              root_document.href_to_other_body(document)
            end

            # @return [Array] Document's children mapped to document builders.
            def children
              document.children.map { |c| self.class.new(child_docs, c, depth + 1) }.sort
            end

            # @return [Boolean]
            def lines_for_children?
              child_docs.maximum_depth.negative? || child_docs.maximum_depth <= depth
            end

            # @return [String]
            def link
              "link:#{address}[#{title}]"
            end

            # @return [Array<String>]
            def result
              children.flat_map do |child|
                r = [child.self_line]
                r += child.result if lines_for_children?
                r
              end
            end

            # @return [Avm::EacAsciidoctorBase0::Instances::Build::Document]
            def root_document
              child_docs.document
            end

            # @return [String]
            def self_line
              "#{'*' * depth} #{link}"
            end

            # @return [String]
            def title
              document.source_document.title
            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/macros/child_docs/document_builder.rb
eac_tools-0.97.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
avm-eac_asciidoctor_base0-0.24.0 lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.96.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
avm-eac_asciidoctor_base0-0.23.0 lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.88.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.87.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
avm-eac_asciidoctor_base0-0.22.1 lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.86.13 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
avm-eac_asciidoctor_base0-0.22.0 lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.85.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.84.2 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.84.1 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
avm-eac_asciidoctor_base0-0.21.0 lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.84.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
avm-eac_asciidoctor_base0-0.20.0 lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.83.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.82.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.81.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb
eac_tools-0.80.0 sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb