Sha256: dba872d171554d91c71443a03cae3294507b596c56e0ab8b29c285ce7257e91f

Contents?: true

Size: 1.48 KB

Versions: 16

Compression:

Stored size: 1.48 KB

Contents

# -*- encoding: utf-8 -*-

require 'webgen/path'

module Webgen
  class Tag

    # This tag allows you to create and use complex graphics using the PGF/TikZ library of LaTeX. It
    # uses Webgen::ContentProcessor::Tikz for doing the hard work.
    module Tikz

      # Create a graphic (i.e. an HTML img tag) from the commands in the body of the tag.
      def self.call(tag, body, context)
        path = Webgen::Path.append(context.ref_node.parent.alcn, context[:config]['tag.tikz.path'])
        path = Webgen::Path.new(path)

        add_tikz_options!(path, context)
        node = context.website.ext.path_handler.create_secondary_nodes(path, body, context.ref_node.alcn).first

        attrs = {'alt' => ''}.merge(context[:config]['tag.tikz.img_attr']).collect do |name, value|
          "#{name.to_s}=\"#{value}\""
        end.sort.unshift('').join(' ')
        "<img src=\"#{context.dest_node.route_to(node)}\"#{attrs} />"
      end

      # Add all needed options for Webgen::ContentProcessor::Tikz to the given path.
      def self.add_tikz_options!(path, context)
        %w[content_processor.tikz.resolution content_processor.tikz.transparent
           content_processor.tikz.libraries content_processor.tikz.opts
           content_processor.tikz.template].each do |opt|
          path.meta_info[opt] = context[:config][opt]
        end
        path.meta_info['pipeline'] = 'tikz'
        path.meta_info['handler'] = 'copy'
      end
      private_class_method :add_tikz_options!

    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
webgen-1.7.3 lib/webgen/tag/tikz.rb
webgen-1.7.2 lib/webgen/tag/tikz.rb
webgen-1.7.1 lib/webgen/tag/tikz.rb
webgen-1.7.0 lib/webgen/tag/tikz.rb
webgen-1.6.0 lib/webgen/tag/tikz.rb
webgen-1.5.2 lib/webgen/tag/tikz.rb
webgen-1.5.1 lib/webgen/tag/tikz.rb
webgen-1.5.0 lib/webgen/tag/tikz.rb
webgen-1.4.1 lib/webgen/tag/tikz.rb
webgen-1.4.0 lib/webgen/tag/tikz.rb
webgen-1.3.0 lib/webgen/tag/tikz.rb
webgen-1.2.1 lib/webgen/tag/tikz.rb
webgen-1.2.0 lib/webgen/tag/tikz.rb
webgen-1.1.0 lib/webgen/tag/tikz.rb
webgen-1.0.0 lib/webgen/tag/tikz.rb
webgen-1.0.0.beta3 lib/webgen/tag/tikz.rb