Class: Asciidoctor::PlantUml::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor-plantuml/plantuml.rb

Constant Summary collapse

FORMATS =
["png", "svg", "txt"]
DEFAULT_FORMAT =

Class Method Summary collapse

Class Method Details

.enabled?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/asciidoctor-plantuml/plantuml.rb', line 61

def enabled?
  txt_enabled? || png_enabled? || svg_enabled?
end

.gen_url(text, format) ⇒ Object

Compression code used to generate PlantUML URLs. Taken directly from the Transcoder class in the PlantUML java code.



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/asciidoctor-plantuml/plantuml.rb', line 95

def gen_url(text, format)
  result = ""
  compressedData = Zlib::Deflate.deflate(text)
  compressedData.chars.each_slice(3) do |bytes|
    #print bytes[0], ' ' , bytes[1] , ' ' , bytes[2]
    b1 = bytes[0].nil? ? 0 : (bytes[0].ord & 0xFF)
    b2 = bytes[1].nil? ? 0 : (bytes[1].ord & 0xFF)
    b3 = bytes[2].nil? ? 0 : (bytes[2].ord & 0xFF)
    result += append3bytes(b1, b2, b3)
  end
  join_paths(server_url, "/#{format}/", result).to_s
end

.plantuml_content(code, attrs = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/asciidoctor-plantuml/plantuml.rb', line 65

def plantuml_content(code, attrs = {})

  format = attrs["format"] || DEFAULT_FORMAT

  if !enabled?
    return plantuml_disabled_content(code, attrs)
  end

  if !valid_uri?(server_url)
    return plantuml_server_unavailable_content(server_url, attrs)
  end

  case format
  when "png"
    plantuml_img_content(code, format, attrs)
  when "txt"
    if txt_enabled?
      plantuml_txt_content(code, format, attrs)
    else
      plantuml_invalid_content(format, attrs)
    end
  when "svg"
    plantuml_img_content(code, format, attrs)
  else
    plantuml_invalid_content(format, attrs)
  end
end

.png_enabled?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/asciidoctor-plantuml/plantuml.rb', line 53

def png_enabled?
  PlantUml::configuration.png_enable
end

.server_urlObject



45
46
47
# File 'lib/asciidoctor-plantuml/plantuml.rb', line 45

def server_url
  PlantUml::configuration.url
end

.svg_enabled?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/asciidoctor-plantuml/plantuml.rb', line 57

def svg_enabled?
  PlantUml::configuration.svg_enable
end

.txt_enabled?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/asciidoctor-plantuml/plantuml.rb', line 49

def txt_enabled?
  PlantUml::configuration.txt_enable
end

.valid_format?(format) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/asciidoctor-plantuml/plantuml.rb', line 41

def valid_format?(format)
  FORMATS.include?(format)
end