Sha256: 0a8aa7ea67b889ad590937b6e73806ac1fc250ee1ae594b88c270afd373268fa

Contents?: true

Size: 1.72 KB

Versions: 25

Compression:

Stored size: 1.72 KB

Contents

# -*- coding: utf-8 -*-
# create image by PlantUML http://plantuml.com/
#
# Copyright (c) tamoot <tamoot+tdiary@gmail.com>
# Distributed under the GPL
#

require 'uri'
require 'zlib'
require 'digest/md5'

module ::PlantUML
   module Deflate

      CHARS ||= ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a + ['-', '_']

      def self.compress(text)
         compressed = Zlib::Deflate.deflate(text, Zlib::BEST_COMPRESSION)
         compressed.chars.each_slice(3).map do |chars|
            append3bytes(chars[0].ord, chars[1]&.ord.to_i, chars[2]&.ord.to_i)
         end.join
      end

      private

      def self.append3bytes(b1, b2, b3)
         [
            b1 >> 2,
            ((b1 & 0x3) << 4) | (b2 >> 4),
            ((b2 & 0xF) << 2) | (b3 >> 6),
            b3 & 0x3F,
         ].map { |c| CHARS[c & 0x3F] || '?' }.join
      end
   end

end

def plantuml(text)
   html = %Q|<div class="plantuml">|

   begin
      uri = URI::parse( @conf['plantuml.server'] )
      uri.path.gsub!(/\/+$/, "")
      uri.path << '/png/' << PlantUML::Deflate::compress(text)
      html << %Q|<img src=#{uri}></img>|
   rescue
      html << %Q|Error: #{$!.message}|
   end

   html << %Q|</div>|

end

add_conf_proc('plantuml_server', 'PlantUMLサーバ') do
   if @mode == 'saveconf'
      @conf['plantuml.server'] = @cgi.params['plantuml.server'][0]
   end

   r = <<-_HTML
   <h3>Summary</h3>
   <p>The image is generated by using specified PlantUML server.</p>
   <h3>URL</h3>
   <p>Please specify the PlantUML server URL (official site or your own PlantUML server)
   <li> Official PlantUML server: http://www.plantuml.com/plantuml/</li>
   <p><input type="text" name="plantuml.server" size="100" value="#{@conf['plantuml.server']}"></p>
   _HTML

   r
end

Version data entries

25 entries across 24 versions & 2 rubygems

Version Path
tdiary-contrib-5.3.0 plugin/plantuml.rb
tdiary-contrib-5.2.4 plugin/plantuml.rb
tdiary-contrib-5.2.3 plugin/plantuml.rb
tdiary-contrib-5.2.2 plugin/plantuml.rb
tdiary-contrib-5.2.1 plugin/plantuml.rb
tdiary-contrib-5.2.0 plugin/plantuml.rb
tdiary-contrib-5.1.7 plugin/plantuml.rb
tdiary-contrib-5.1.6 plugin/plantuml.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-contrib-5.1.4/plugin/plantuml.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/bundler/gems/tdiary-contrib-d1e41204db13/plugin/plantuml.rb
tdiary-contrib-5.1.5 plugin/plantuml.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-contrib-5.1.4/plugin/plantuml.rb
tdiary-contrib-5.1.4 plugin/plantuml.rb
tdiary-contrib-5.1.3 plugin/plantuml.rb
tdiary-contrib-5.1.2 plugin/plantuml.rb
tdiary-contrib-5.1.1 plugin/plantuml.rb
tdiary-contrib-5.1.0 plugin/plantuml.rb
tdiary-contrib-5.0.13 plugin/plantuml.rb
tdiary-contrib-5.0.12 plugin/plantuml.rb
tdiary-contrib-5.0.11 plugin/plantuml.rb