Class: Gollum::Filter::PlantUML

Inherits:
Gollum::Filter show all
Defined in:
lib/gollum-lib/filter/plantuml.rb

Overview

PlantUML Diagrams

This filter replaces PlantUML blocks with HTML img tags. These img tags point to a PlantUML web service that converts the UML text blocks into nice diagrams.

For this to work you must have your own PlantUML server running somewhere. Just follow the instructions on the github page to run your own server:

https://github.com/plantuml/plantuml-server

Once you start you own plantuml server you need to configure this filter to point to it:

Gollum::Filter::PlantUML.configure do |config|
  config.url = "http://localhost:8080/plantuml/png"
end

Then in your wiki pages simply add PlantUML blocks anywhere you want a diagram:

@startuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
@enduml

To learn more about how to create cool PlantUML diagrams check the examples at: plantuml.sourceforge.net/

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

DEFAULT_URL =
"http://www.plantuml.com/plantuml/png"

Constants inherited from Gollum::Filter

PLACEHOLDER_PATTERN

Class Attribute Summary collapse

Attributes inherited from Gollum::Filter

#close_pattern, #open_pattern

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Gollum::Filter

#initialize

Methods included from Helpers

#path_to_link_text, #trim_leading_slashes

Constructor Details

This class inherits a constructor from Gollum::Filter

Class Attribute Details

.configurationObject



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

def self.configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



65
66
67
# File 'lib/gollum-lib/filter/plantuml.rb', line 65

def self.configure
  yield(configuration)
end

Instance Method Details

#extract(data) ⇒ Object

Extract all sequence diagram blocks into the map and replace with placeholders.



71
72
73
74
75
76
77
# File 'lib/gollum-lib/filter/plantuml.rb', line 71

def extract(data)
  data.gsub(/(@startuml\r?\n.+?\r?\n@enduml\r?$)/m) do
    id       = "#{open_pattern}#{Digest::SHA1.hexdigest($1)}#{close_pattern}"
    @map[id] = { :code => $1 }
    id
  end
end

#process(data) ⇒ Object

Process all diagrams from the map and replace the placeholders with the final HTML.



81
82
83
84
85
86
87
88
# File 'lib/gollum-lib/filter/plantuml.rb', line 81

def process(data)
  @map.each do |id, spec|
    data.gsub!(id) do
      render_plantuml(id, spec[:code])
    end
  end
  data
end