Class: Webgen::Tag::TikZ
- Inherits:
-
Object
- Object
- Webgen::Tag::TikZ
- Includes:
- Base, WebsiteAccess
- Defined in:
- lib/webgen/tag/tikz.rb
Overview
This tag allows the creation and inclusion of complex graphics using the PGF/TikZ library of LaTeX. You will need a current LaTeX distribution and the convert
utility from ImageMagick.
Constant Summary collapse
- LATEX_TEMPLATE =
<<EOF \\nonstopmode \\documentclass{article} \\usepackage{tikz} \\pagestyle{empty} <% if param('tag.tikz.libraries') %> \\usetikzlibrary{<%= param('tag.tikz.libraries').join(',') %>} <% end %> \\begin{document} <% if param('tag.tikz.opts') %> \\begin{tikzpicture}[<%= param('tag.tikz.opts') %>] <% else %> \\begin{tikzpicture} <% end %> <%= body %> \\end{tikzpicture} \\end{document} EOF
Instance Method Summary collapse
-
#call(tag, body, context) ⇒ Object
Create a graphic from the commands in the body of the tag.
Methods included from WebsiteAccess
Methods included from Base
#create_tag_params, #param, #set_params
Methods included from Loggable
Instance Method Details
#call(tag, body, context) ⇒ Object
Create a graphic from the commands in the body of the tag.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/webgen/tag/tikz.rb', line 33 def call(tag, body, context) path = param('tag.tikz.path') path = Webgen::Common.absolute_path(path, context.ref_node.parent.absolute_lcn) mem_handler = website.cache.instance('Webgen::SourceHandler::Memory') src_path = context.ref_node.node_info[:src] parent = website.blackboard.invoke(:create_directories, context.ref_node.tree.root, File.dirname(path), src_path) params = @params node = website.blackboard.invoke(:create_nodes, parent.tree, parent.absolute_lcn, Webgen::Path.new(path, src_path), mem_handler) do |node_parent, node_path| mem_handler.create_node(node_parent, node_path, context.ref_node.absolute_lcn) do |pic_node| set_params(params) document = ERB.new(LATEX_TEMPLATE).result(binding) pic_path = compile(document, File.extname(path), context) set_params(nil) if pic_path io = Webgen::Path::SourceIO.new { File.open(pic_path, 'rb') } else pic_node.flag(:dirty) nil end end end.first attrs = param('tag.tikz.img_attr').collect {|name,value| "#{name.to_s}=\"#{value}\"" }.sort.unshift('').join(' ') "<img src=\"#{context.dest_node.route_to(node)}\"#{attrs} />" end |