Sha256: 8c96b34684e13242a4d85b757514d4155bcacae554d8f8bc414d18031ccc9491

Contents?: true

Size: 1.49 KB

Versions: 11

Compression:

Stored size: 1.49 KB

Contents

module Rabbit
  module Parser
    module Ext
      module BlockDiag
        module_function
        AVAILABLE_FLAG_OPTIONS = ["antialias"]
        # "font" is treated as specially.
        AVAILABLE_VALUE_OPTIONS = []
        def make_image(path, prop, logger)
          image_file = Tempfile.new("rabbit-image-blockdiag")
          command = ["blockdiag",
                     "-T", "svg",
                     "-o", image_file.path]
          font = find_font(prop)
          command.concat(["-f", font]) if font
          AVAILABLE_FLAG_OPTIONS.each do |name|
            command << "--#{name}" if /\A(?:true|yes)\z/i =~ prop[name].to_s
          end
          AVAILABLE_VALUE_OPTIONS.each do |name|
            command.concat(["--#{name}", prop[name]]) if prop.has_key?(name)
          end
          command << path
          if SystemRunner.run(*command)
            image_file
          else
            format = _("tried blockdiag command: %s")
            additional_info = format % command.inspect
            raise BlockDiagCanNotHandleError.new(command.join(' '),
                                                 additional_info)
          end
        end

        def find_font(prop)
          font = prop["font"]
          return font if font and File.exist?(font)
          fonts = prop["fonts"]
          return nil if fonts.nil?
          fonts = fonts.split(/\s*,\s*/) if fonts.is_a?(String)
          fonts.find do |font|
            File.exist?(font)
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rabbit-2.0.0 lib/rabbit/parser/ext/blockdiag.rb
rabbit-1.0.9 lib/rabbit/parser/ext/blockdiag.rb
rabbit-1.0.8 lib/rabbit/parser/ext/blockdiag.rb
rabbit-1.0.7 lib/rabbit/parser/ext/blockdiag.rb
rabbit-1.0.6 lib/rabbit/parser/ext/blockdiag.rb
rabbit-1.0.5 lib/rabbit/parser/ext/blockdiag.rb
rabbit-1.0.4 lib/rabbit/parser/ext/blockdiag.rb
rabbit-1.0.3 lib/rabbit/parser/ext/blockdiag.rb
rabbit-1.0.2 lib/rabbit/parser/ext/blockdiag.rb
rabbit-1.0.1 lib/rabbit/parser/ext/blockdiag.rb
rabbit-1.0.0 lib/rabbit/parser/ext/blockdiag.rb