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, #ensure_gem, #find_command, #global_attr, #global_opt, #opt, #resolve_path, #to_s

Constructor Details

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

Returns a new instance of FileSource.



272
273
274
275
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 272

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

Instance Method Details

#base_dirObject



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

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

#image_nameObject



285
286
287
288
289
290
291
292
293
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 285

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

#load_codeObject



299
300
301
302
303
304
305
306
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 299

def load_code
  if @file_name
    lines = prepare_source_array(File.read(@file_name, :mode => 'rb'))
    @parent_block.apply_subs(lines, resolve_diagram_subs).join("\n")
  else
    ''
  end
end

#should_process?(image_file, image_metadata) ⇒ Boolean

Returns:

  • (Boolean)


295
296
297
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 295

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