Class: Avm::EacAsciidoctorBase0::Instances::Build::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/avm/eac_asciidoctor_base0/instances/build/document.rb,
lib/avm/eac_asciidoctor_base0/instances/build/document/media.rb,
lib/avm/eac_asciidoctor_base0/instances/build/document/header_lines.rb,
lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb,
lib/avm/eac_asciidoctor_base0/instances/build/document/child_docs_macro_value.rb,
lib/avm/eac_asciidoctor_base0/instances/build/document/breadcrumbs_macro_value.rb

Defined Under Namespace

Modules: Media Classes: BreadcrumbsMacroValue, ChildDocsMacroValue, HeaderLines, PreProcessLine

Constant Summary collapse

BODY_TARGET_BASENAME =
'index.html'

Instance Method Summary collapse

Instance Method Details

#body_target_pathPathname

Absolute path to the output of Asciidoctor’s source file.

Returns:

  • (Pathname)


28
29
30
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 28

def body_target_path
  build.target_directory.join(source_document.subpath).join(BODY_TARGET_BASENAME)
end

#build_bodyAsciidoctor::Document

Returns:

  • (Asciidoctor::Document)


33
34
35
36
37
38
39
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 33

def build_body
  ::Asciidoctor.convert(
    pre_processed_body_source_content,
    base_dir: convert_base_dir,
    to_file: body_target_path.to_path, safe: :unsafe, mkdirs: true
  )
end

#child(basename) ⇒ Avm::EacAsciidoctorBase0::Instances::Build::Document?

Parameters:

  • basename (String)

Returns:



43
44
45
46
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 43

def child(basename)
  basename = basename.to_s
  children.find { |c| c.source_document.root_path.basename.to_path == basename }
end

#child!(basename) ⇒ Avm::EacAsciidoctorBase0::Instances::Build::Document

Parameters:

  • basename (String)

Returns:



50
51
52
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 50

def child!(basename)
  child(basename) || raise("Child not found with basename \"#{basename}\"")
end

#convert_base_dirPathname

Returns:

  • (Pathname)


55
56
57
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 55

def convert_base_dir
  source_document.root_path
end

#href_to_other_body(other) ⇒ String

Parameters:

Returns:

  • (String)


21
22
23
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 21

def href_to_other_body(other)
  other.body_target_path.relative_path_from(body_target_path.dirname)
end

#performObject



59
60
61
62
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 59

def perform
  perform_self
  perform_children
end

#perform_childrenObject



70
71
72
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 70

def perform_children
  children.each(&:perform)
end

#perform_selfObject



64
65
66
67
68
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 64

def perform_self
  infov 'Building', source_document.subpath
  build_body
  copy_media_directory
end

#pre_processed_body_source_contentString

Returns:

  • (String)


75
76
77
78
79
80
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 75

def pre_processed_body_source_content
  (
    header_lines + [''] + source_document.body_path.read.each_line
    .flat_map { |line| pre_process_line(line.rstrip) }
  ).map { |line| "#{line.rstrip}\n" }.join
end

#tree_documents_countObject



82
83
84
# File 'lib/avm/eac_asciidoctor_base0/instances/build/document.rb', line 82

def tree_documents_count
  children.inject(1) { |a, e| a + e.tree_documents_count }
end