class JekyllRemotePlantUMLPlugin::Block
Constants
- CONFIG_OPTIONS
- DEFAULT_CONFIG_OPTIONS
- FORMATS
- PARAMS_SYNTAX
- TAG_OPTIONS
Public Class Methods
new(tag_name, markup, _)
click to toggle source
Calls superclass method
# File lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb, line 37 def initialize(tag_name, markup, _) super @markup = markup.strip end
Public Instance Methods
render(context)
click to toggle source
Calls superclass method
# 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
Private Instance Methods
check_format(format)
click to toggle source
# File lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb, line 119 def check_format(format) raise "Invalid PlantUML diagram format \"#{format}\"" unless FORMATS.include?(format) end
configuration_options()
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb, line 81 def configuration_options @configuration_options ||= Jekyll.configuration({})["plantuml"].transform_keys(&:to_sym).tap do |conf| # delete unsupported options conf.each { |key, _| conf.delete(key) unless CONFIG_OPTIONS.include?(key) } # set defaults DEFAULT_CONFIG_OPTIONS.each { |key, value| conf[key] = value if conf[key].nil? } end end
img_local_src(context, content, url, options)
click to toggle source
# File lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb, line 91 def img_local_src(context, content, url, options) # prepare source image path site = context.registers[:site] image_basename = "#{Digest::SHA1.hexdigest encode(content)}.#{options[:format]}" source_image_path = File.join(site.source, options[:cache_dir], image_basename) unless File.exist?(source_image_path) begin download_image(url, source_image_path) rescue StandardError => e raise <<~TEXT The download of the PlantUML diagram image failed: #{e} === CONTENT START #{content} === CONTENT END URL: #{url} TEXT end # make the image available in the destination directory site.static_files << Jekyll::StaticFile.new(site, site.source, options[:cache_dir], image_basename) end "/#{join_paths(site.baseurl, options[:cache_dir], image_basename)}" end
parse_params(context)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb, line 66 def parse_params(context) {}.tap do |params| @markup.scan(PARAMS_SYNTAX) do |key, d_quoted, s_quoted, variable| params[key] = if d_quoted d_quoted.include?('\\"') ? d_quoted.gsub('\\"', '"') : d_quoted elsif s_quoted s_quoted.include?("\\'") ? s_quoted.gsub("\\'", "'") : s_quoted elsif variable context[variable] end end end.transform_keys(&:to_sym) end
prepare_html(img_src_attr, options)
click to toggle source
# File lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb, line 123 def prepare_html(img_src_attr, options) div_tag = "" div_tag += "<div#{prepare_optional_attrs_content("div_", options)}>" img_tag = "<img src=\"#{img_src_attr}\"#{prepare_optional_attrs_content("img_", options)} />" div_tag += "\n #{img_tag}\n" "#{div_tag}</div>" end
prepare_optional_attrs_content(prefix, options)
click to toggle source
# File lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb, line 131 def prepare_optional_attrs_content(prefix, options) result = "" TAG_OPTIONS.each do |key| next if !key.to_s.start_with?(prefix) || options[key].nil? || options[key].empty? attribute_name = key.to_s.reverse.chomp(prefix.reverse).reverse attribute_value = options[key] result += " #{attribute_name}=\"#{attribute_value}\"" end result end
tag_options(context)
click to toggle source
# File lib/jekyll_remote_plantuml_plugin/jekyll_remote_plantuml_plugin.rb, line 55 def tag_options(context) tag_options = parse_params(context) # delete unsupported options tag_options.each { |key, _| tag_options.delete(key) unless TAG_OPTIONS.include?(key) } # merge with config options configuration_options.merge(tag_options) end