Class: Asciidoctor::Diagram::FileSource
- Inherits:
-
BasicSource
- Object
- BasicSource
- Asciidoctor::Diagram::FileSource
- 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
Instance Method Summary collapse
- #base_dir ⇒ Object
- #image_name ⇒ Object
-
#initialize(block_processor, parent_block, file_name, attributes) ⇒ FileSource
constructor
A new instance of FileSource.
- #load_code ⇒ Object
- #should_process?(image_file, image_metadata) ⇒ Boolean
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.(file_name) end |
Instance Method Details
#base_dir ⇒ Object
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_name ⇒ Object
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_code ⇒ Object
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
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 |