Class: JekyllRemotePlantUMLPlugin::Block

Inherits:
Liquid::Block
  • Object
show all
Includes:
Utils::Common, Utils::Encode, Utils::PlantUML
Defined in:
lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb

Constant Summary collapse

FORMATS =
%w[png svg].freeze
CONFIG_OPTIONS =
%i[
  provider
  format
  save_images_locally cache_dir
  div_class div_style
  img_class img_style img_id img_width img_height img_alt
].freeze
TAG_OPTIONS =
CONFIG_OPTIONS.dup.tap do |h|
  %i[provider save_images_locally cache_dir].each do |k|
    h.delete(k)
  end
end.freeze
DEFAULT_CONFIG_OPTIONS =
{
  provider: "http://www.plantuml.com/plantuml",
  format: "svg",
  save_images_locally: false,
  cache_dir: "plantuml",
  div_class: "plantuml",
  img_class: "plantuml"
}.freeze
PARAMS_SYNTAX =
/
  ([\w-]+)\s*=\s*
  (?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w.-]+))
/x.freeze

Instance Method Summary collapse

Methods included from Utils::Encode

#append3bytes, #encode, #encode64, #encode6bit

Methods included from Utils::PlantUML

#expand_path, #generate_url, #join_paths

Methods included from Utils::Common

#download_image

Constructor Details

#initialize(tag_name, markup, _) ⇒ Block

Returns a new instance of Block.



37
38
39
40
# File 'lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb', line 37

def initialize(tag_name, markup, _)
  super
  @markup = markup.strip
end

Instance Method Details

#render(context) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb', line 42

def render(context)
  content = super(context).strip
  options = tag_options(context)

  check_format(options[:format])

  url = generate_url(options[:provider], encode(content), options[:format])
  img_src_attr = options[:save_images_locally] ? img_local_src(context, content, url, options) : url
  prepare_html(img_src_attr, options)
end