Class: Neo4j::AsciidoctorExtensions::CourseDocumentAttributesTreeProcessor

Inherits:
Extensions::TreeProcessor
  • Object
show all
Defined in:
lib/neo4j/asciidoctor/extensions/course_document_attributes/extension.rb

Overview

A tree processor that adds attributes about the course. /!\ This extension is tightly coupled to the course publishing project and should not be used for other purposes /!\

Constant Summary collapse

TESTING_SLUG_PREFIX =

TODO: this slug should be configurable

'_testing_'

Instance Method Summary collapse

Instance Method Details

#process(document) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/neo4j/asciidoctor/extensions/course_document_attributes/extension.rb', line 19

def process(document)
  if (module_descriptor_path = document.attr('module-descriptor-path'))
    if File.exist?(module_descriptor_path)
      require 'yaml'
      module_descriptor = YAML.load_file(module_descriptor_path)
      if (document_slug = document.attr('slug')) && document.attr('stage') != 'production'
        document_slug = "#{TESTING_SLUG_PREFIX}#{document_slug}"
        document.set_attr('slug', document_slug)
      end
      set_attributes(document, document_slug, module_descriptor)
      document.set_attribute('module-name', module_descriptor['module_name'])
    end
  end
  document
end