Class: FilterIncludeDirectives

Inherits:
Asciidoctor::Extensions::IncludeProcessor
  • Object
show all
Defined in:
lib/dita-topic/filter.rb

Instance Method Summary collapse

Instance Method Details

#handles?(target) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dita-topic/filter.rb', line 28

def handles? target
  target.end_with? '.adoc', '.asciidoc', '.asc', '.ad'
end

#process(doc, reader, target, attributes) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dita-topic/filter.rb', line 32

def process doc, reader, target, attributes
  file_path   = Pathname.new(doc.base_dir) + target

  begin
    logger = Asciidoctor::LoggerManager.logger
    include_doc = Asciidoctor.load_file file_path, safe: :secure, logger: false
  ensure
    Asciidoctor::LoggerManager.logger = logger
  end

  return reader unless supported_type? include_doc.attributes

  reader.push_include File.read(file_path), target, target, 1, attributes
  return reader
end

#supported_type?(attributes) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
# File 'lib/dita-topic/filter.rb', line 48

def supported_type? attributes
  type = attributes['_mod-docs-content-type'] ? attributes['_mod-docs-content-type'].downcase : nil
  type = attributes['_content-type'] ? attributes['_content-type'].downcase : nil unless type
  type = attributes['_module-type'] ? attributes['_module-type'].downcase : nil unless type

  ['attributes', 'snippet'].include? type
end