0.03
No commit activity in last 3 years
No release in over 3 years
Dragonfly analyser and processor for SVGs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Dragonfly SVG

Build Status Gem Version Coverage Status

Dragonfly analyser and processors for SVGs.

Uses the nokogiri gem for SVG parsing.

Installation

Add this line to your application's Gemfile:

gem 'dragonfly_svg'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dragonfly_svg

Usage

The analyser and processors are added by configuring the plugin

Dragonfly.app.configure do
  plugin :svg
end

Supported Formats

List of supported formats is available as:

DragonflySvg::SUPPORTED_FORMATS # => ["svg", "svgz", "svg.gz"]

Analyser

The analyser supplies the following methods:

svg.width
svg.height
svg.aspect_ratio
svg.id
svg.portrait?
svg.landscape?

Processors

ExtendIds

Adds a random string to the id. Helpful when embedding SVGs, in which case the id should be unique. You can also supply your own String.

svg.extend_ids
svg.extend_ids('foo')

RemoveNamespaces

Removes the xmlns namespace from the SVG.

svg.remove_namespaces

SetAttribute

Allows to set attribute for specified xpath:

svg.set_attribute('./*[name()="svg"]', 'style', 'margin: 50px;')

SetTagValue

Allows to set tag value for specified xpath:

svg.set_tag_value('./*[name()="text"]', 'Updated text')

SetDimensions

Sets the dimensions of the SVG. Takes two parameters: width and height

svg.set_dimensions(210, 297)

SetNamespace

Sets the xmlns namespace of the SVG. Default is http://www.w3.org/2000/svg unless something is supplied.

svg.set_namespace                     # xmlns="http://www.w3.org/2000/svg"
svg.set_namespace('foo')              # xmlns="foo"

SetPreserveAspectRatio

Sets the preserveAspectRatio attribute of the SVG. Default is xMinYMin meet unless something is supplied.

svg.set_preserve_aspect_ratio         # preserveAspectRatio="xMinYMin meet"
svg.set_preserve_aspect_ratio('foo')  # preserveAspectRatio="foo"

SetViewBox

Sets the viewBox attribute of the SVG. Takes four parameters: min_x, min_y, width and height.

svg.set_view_box(0, 0, 400, 600)       # viewBox="0 0 400 600"

Contributing

  1. Fork it ( https://github.com/tomasc/dragonfly_svg/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request