Class: DynamicImageParsers::XmlParser

Inherits:
Object
  • Object
show all
Defined in:
lib/parsers/xml_parser.rb

Overview

XML Parser parses XML documents containing dynamic images. You can give many images into one XML document.

XML document has to be in same hierarchy as in pure ruby. Save, save_endless and treir quality option is given as dynamic_images’s attribute.

Save_endless images limit is gives as attribute too. It’s name is :save_endless_limit.

Save_endless filename has to be given as string attribute. You can set place of index by %{index}. F.e.: "image-%{index}.png".

Options are taken from element attributes. There is same rules like in pure ruby. See DynamicImage.

Example

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE dynamic_images PUBLIC "-//malis//dynamic_images//EN" "https://raw.github.com/malis/dynamic_images/master/lib/parsers/xml.dtd">
<dynamic_images>
 <dynamic_image from_source="earth.jpg" align="center" valign="middle" background="red 0.5" save="test_from.jpg" quality="90">
  <text font="Arial bold 15">testing <u>adding</u> some text to image</text>
  <block background="red">
    <image w="50" h="50">kostky.png</image>
  </block>
  <table>
    <row>
      <cell>
        <text><b>Left table header</b></text>
      </cell>
      <cell>
        <text><b>Right table header</b></text>
      </cell>
    </row>
    <row>
      <cell>
        <text>Table value 1</text>
      </cell>
      <cell>
        <text>Table value 2</text>
      </cell>
    </row>
  </table>
 </dynamic_image>
</dynamic_images>

Instance Method Summary collapse

Constructor Details

#initialize(filename_or_xml, render_only_first_to = nil, options = {}) ⇒ XmlParser

Accepts filename or String containing XML document and processes it with dynamic_images library.



48
49
50
51
52
53
54
55
56
57
# File 'lib/parsers/xml_parser.rb', line 48

def initialize(filename_or_xml, render_only_first_to = nil, options = {})
  @render_only_first_to = render_only_first_to
  @options = options
  filename_or_xml = File.read(filename_or_xml) if File.exists? filename_or_xml
  doc = REXML::Document.new(filename_or_xml)
  doc.elements.first.each_element do |image|
    dynamic_image image
    return if @render_only_first_to
  end
end