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.



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

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



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

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

#image_nameObject



293
294
295
296
297
298
299
300
301
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 293

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

#load_codeObject



307
308
309
310
311
312
313
314
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 307

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)


303
304
305
# File 'lib/asciidoctor-diagram/diagram_source.rb', line 303

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