Dragonfly SVG
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
- Fork it ( https://github.com/tomasc/dragonfly_svg/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request