Class: Asciidoctor::Diagram::FileSource

Inherits:
BasicSource show all
Defined in:
lib/asciidoctor-diagram/diagram_source.rb

Overview

A diagram source that retrieves the code for a diagram from an external source file.

Instance Attribute Summary

Attributes inherited from BasicSource

#attributes

Instance Method Summary collapse

Methods inherited from BasicSource

#attr, #checksum, #config, #create_image_metadata, #diagram_type, #resolve_path

Methods included from DiagramSource

#attr, #code, #config, #create_image_metadata, #diagram_type, #find_command, #global_attr, #resolve_path, #to_s

Constructor Details

#initialize(block_processor, parent_block, file_name, attributes) ⇒ FileSource

Returns a new instance of FileSource.



247
248
249
250
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 247

def initialize(block_processor, parent_block, file_name, attributes)
  super(block_processor, parent_block, attributes)
  @file_name = file_name
end

Instance Method Details

#base_dirObject



252
253
254
255
256
257
258
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 252

def base_dir
  if @file_name
    File.dirname(@file_name)
  else
    super
  end
end

#image_nameObject



260
261
262
263
264
265
266
267
268
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 260

def image_name
  if @attributes['target']
    super
  elsif @file_name
    File.basename(@file_name, File.extname(@file_name))
  else
    checksum
  end
end

#load_codeObject



274
275
276
277
278
279
280
281
282
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 274

def load_code
  if @file_name
    lines = File.readlines(@file_name)
    lines = prepare_source_array(lines)
    @parent_block.apply_subs(lines, resolve_diagram_subs).join("\n")
  else
    ''
  end
end

#should_process?(image_file, image_metadata) ⇒ Boolean

Returns:

  • (Boolean)


270
271
272
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 270

def should_process?(image_file, )
  (@file_name && File.mtime(@file_name) > File.mtime(image_file)) || super
end