Skip to content
Dragonfly SVG plugin.
Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
samples
test
.coveralls.yml
.gitignore
.travis.yml
CHANGELOG.md
Gemfile
Guardfile
LICENSE
README.md
Rakefile
dragonfly_svg.gemspec

README.md

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_viewbox(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
You can’t perform that action at this time.