Class: Jekyll::Spaceship::PlantUMLProcessor
- Defined in:
- lib/jekyll-spaceship/processors/plantuml-processor.rb
Instance Method Summary collapse
Methods inherited from Processor
#content_tag, #initialize, register, #register
Constructor Details
This class inherits a constructor from Jekyll::Spaceship::Processor
Instance Method Details
#handle_plantuml(code) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jekyll-spaceship/processors/plantuml-processor.rb', line 36 def handle_plantuml(code) # wrap plantuml code uml = "@startuml#{code}@enduml" dir = File.dirname(__FILE__) jar = dir + "/../utils/plantuml/plantuml.jar" echo = "echo -e \"#{uml.gsub('"', '\"')}\"" plantuml = "java -jar \"#{jar}\" -pipe 2>/dev/null" # exec plantuml.jar and output base64 data base64 = `#{echo} | #{plantuml} | base64` # return img tag "<img src=\"data:image/png;base64, #{base64}\">" end |
#on_posts_pre_render(post) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jekyll-spaceship/processors/plantuml-processor.rb', line 7 def on_posts_pre_render(post) # match default plantuml block and code block pattern = Regexp.union( /(\\?@startuml((?:.|\n)*?)@enduml)/, /(`{3}\s*plantuml((?:.|\n)*?)`{3})/ ) post.content.scan pattern do |match| match = match.select { |m| not m.nil? } block = match[0] code = match[1] # skip escape default plantuml block if block.match? /(^\\@startuml|\\@enduml$)/ next end Logger.log "handle plantuml block - #{post.path.gsub(/.*_posts\//, '')}" post.content = post.content.gsub( block, handle_plantuml(code) ) end # handle escape default plantuml block post.content = post.content.gsub(/\\(@startuml|@enduml)/, '\1') end |