Class: Asciidoctor::Standoc::PlantUMLBlockMacroBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor/standoc/macros.rb

Class Method Summary collapse

Class Method Details

.generate_attrs(attrs) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/asciidoctor/standoc/macros.rb', line 142

def self.generate_attrs attrs
  through_attrs = %w(id align float title role width height alt).
    inject({}) do |memo, key|
    memo[key] = attrs[key] if attrs.has_key? key
    memo
  end
end

.generate_file(parent, reader) ⇒ Object

if no :imagesdir: leave image file in plantuml



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/asciidoctor/standoc/macros.rb', line 112

def self.generate_file parent, reader
  localdir = Utils::localdir(parent.document)
  fn = save_plantuml parent, reader, localdir
  umlfile = Pathname.new(localdir) + "plantuml" + "#{fn}.pml"
  system "plantuml #{umlfile}"
  # sleep need for windows because dot works in separate process and plantuml process may
  # finish erlier then dot, as result png file maybe not created yet after plantuml finish
  sleep(2) if Gem.win_platform?
  outfile = parent.image_uri("#{fn}.png")
  if outfile == "#{fn}.png"
    (Pathname.new("plantuml") + "#{fn}.png").to_s
  else
    FileUtils.mv (Pathname.new(localdir) + "plantuml" + "#{fn}.png").to_s,
      (Pathname.new(localdir) + outfile).to_s
    (Pathname.new("#{fn}.png")).to_s
  end
end

.plantuml_installed?Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
107
108
109
# File 'lib/asciidoctor/standoc/macros.rb', line 99

def self.plantuml_installed?
  cmd = "plantuml"
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  nil
end

.save_plantuml(parent, reader, localdir) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/asciidoctor/standoc/macros.rb', line 130

def self.save_plantuml parent, reader, localdir
  src = reader.source
  reader.lines.first.sub(/\s+$/, "").match /^@startuml($| )/ or
    src = "@startuml\n#{src}\n@enduml\n"
  /^@startuml (?<fn>[^\n]+)\n/ =~ src
  fn ||= UUIDTools::UUID.random_create
  path = Pathname.new(localdir) + "plantuml"
  path.mkpath()
  (path + "#{fn}.pml").write(src)
  fn
end