class ImageParadise::GenerateGraphvizImage

Constants

TRY_TO_REDUCE_THE_FILESIZE_FOR_GENERATED_PNG_FILES
#

TRY_TO_REDUCE_THE_FILESIZE_FOR_GENERATED_PNG_FILES

#

Public Class Methods

[](i = '') click to toggle source
#

ImageParadise::GenerateGraphvizImage[]

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 266
def self.[](i = '')
  new(i)
end
new( commandline_arguments = nil, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 44
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  # ======================================================================= #
  # === Handle blocks
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :use_bold_font
    # ===================================================================== #
    when :use_bold_font
      use_bold_font
    # ===================================================================== #
    # === :use_bold_font_and_german
    # ===================================================================== #
    when :use_bold_font_and_german
      use_bold_font
      use_german
    end
  end
  run if run_already
end

Public Instance Methods

check_whether_the_first_argument_is_a_hash() click to toggle source
#

check_whether_the_first_argument_is_a_hash

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 155
  def check_whether_the_first_argument_is_a_hash
    into = 'module_dependencies.dot'
    _ = ''.dup
    _ << "#     dot -Tpng #{into} -o outfile.png\n"
    _ << 'digraph graphname {

node [color=Red,fontname="'+@use_this_fontname+'",shape=box, fontsize=28] // All nodes will this shape and colour
edge [color=Blue, style=dashed]             // All the lines look like this
'
    first_argument = first_argument?
    if first_argument.is_a? Hash
      if @penwidth
        @append_this_string_to_each_node << " [penwidth=#{@penwidth}]"
      end
      sorted = first_argument.sort_by {|key, value|
        key.delete('M').to_i
      }
      sorted.each {|module_number, module_dependencies|
        # Iterate over the module dependencies next.
        module_dependencies.each {|this_module|
          this_module.delete!('"')
          unless this_module.include?('None')
            source_module = '"'+return_english_or_german_name_for_a_module+' '+module_number+'"'
            target_module = '"'+return_english_or_german_name_for_a_module+' '+this_module+'"'
            unless source_module == target_module
              _ << "#{target_module} -> #{source_module}"
              unless @append_this_string_to_each_node.empty?
                _ << @append_this_string_to_each_node
              end
              _ << ';'
              _ << N
            end
          end
        }
        _ << "\n"
      }
      _ << '}'
      # ===================================================================== #
      # Remove the old file if it exists.
      # ===================================================================== #
      puts "Saving into the file #{into} next."
      if File.exist? into
        File.delete(into)
      end
      write_what_into(_, into)
      if File.exist? into
        run_dot_command_to_create_the_image(into)
      end
    end
  end
commandline_arguments?() click to toggle source
#

commandline_arguments?

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 141
def commandline_arguments?
  @commandline_arguments
end
dataset?()
Alias for: first_argument?
first_argument?() click to toggle source
#

first_argument?

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 148
def first_argument?
  @commandline_arguments.first
end
Also aliased as: dataset?
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method ImageParadise::Base#reset
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 77
def reset
  super()
  # ======================================================================= #
  # === @append_this_string_to_each_node
  #
  # This string here will be appended to each node-line.
  # ======================================================================= #
  @append_this_string_to_each_node = ''.dup
  # ======================================================================= #
  # === @use_this_fontname
  # ======================================================================= #
  @use_this_fontname = 'Courier'
  # ======================================================================= #
  # === @penwidth
  # ======================================================================= #
  @penwidth = 2
  # ======================================================================= #
  # === @use_english_or_german_for_this_class
  # ======================================================================= #
  @use_english_or_german_for_this_class = :english
end
return_english_or_german_name_for_a_module() click to toggle source
#

return_english_or_german_name_for_a_module

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 109
def return_english_or_german_name_for_a_module
  case @use_english_or_german_for_this_class
  when :english
    'Module'
  when :german
    'Modul'
  end
end
run() click to toggle source
#

run (run tag)

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 259
def run
  check_whether_the_first_argument_is_a_hash
end
run_dot_command_to_create_the_image(i) click to toggle source
#

run_dot_command_to_create_the_image

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 209
def run_dot_command_to_create_the_image(i)
  output_file = 'outfile.png'
  if File.exist? output_file
    File.delete(output_file)
  end
  cmd_to_run = "dot -Tpng #{i} -o #{output_file}"
  e
  e "  #{cmd_to_run}"
  e
  result = `#{cmd_to_run} 2>&1`
  if result.include? 'Error: '
    # ===================================================================== #
    # Handle situations such as this one here:
    #   Error: module_dependencies.dot: syntax error in line 4 near ','
    # ===================================================================== #
    e 'Some error happened. The error will be shown next:'
    e
    e Colours.crimson("  #{result.strip}")
    e
  else
    # ===================================================================== #
    # Try to optimize the .png file at hand.
    # ===================================================================== #
    if TRY_TO_REDUCE_THE_FILESIZE_FOR_GENERATED_PNG_FILES and
       output_file.end_with?('.png') and
       File.exist?(output_file)
      new_file = 'OUT_'+output_file
      e
      e 'Running pngquant next:'
      e
      esystem "pngquant #{output_file} --output #{new_file}"
      e
      if File.exist?(new_file) and File.exist?(output_file)
        FileUtils.mv(new_file, output_file)
      end
    end
    # ===================================================================== #
    # Open the existing file in the browser next, if present.
    # ===================================================================== #
    if File.exist?(output_file) and is_on_roebe?
      require 'roebe/toplevel_methods/open_in_browser.rb'
      e "Now opening #{sfile(output_file)} in the browser."
      Open.in_browser(output_file)
    end
  end
end
set_commandline_arguments(i = '') click to toggle source
#

set_commandline_arguments

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 133
def set_commandline_arguments(i = '')
  i = [i].flatten.compact
  @commandline_arguments = i
end
to_german() click to toggle source
#

to_german

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 102
def to_german
  @use_english_or_german_for_this_class = :german
end
Also aliased as: use_german
use_bold_font( i = 'Cascadia Mono PL Bold' ) click to toggle source
#

use_bold_font

This will use a hardcoded font by default. The user is expected to supply another font if he/she seeks to change the font.

#
# File lib/image_paradise/graphviz/generate_graphviz_image.rb, line 124
def use_bold_font(
    i = 'Cascadia Mono PL Bold'
  )
  @use_this_fontname = i
end
use_german()
Alias for: to_german