https://github.com/tomasc/dragonfly_svg
Dragonfly SVG plugin.
https://github.com/tomasc/dragonfly_svg
Last synced: about 1 year ago
JSON representation
Dragonfly SVG plugin.
- Host: GitHub
- URL: https://github.com/tomasc/dragonfly_svg
- Owner: tomasc
- License: mit
- Created: 2014-07-09T09:01:16.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2021-03-22T09:06:55.000Z (about 5 years ago)
- Last Synced: 2025-04-16T06:08:12.904Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 36.1 KB
- Stars: 4
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Dragonfly SVG
[](https://travis-ci.org/tomasc/dragonfly_svg) [](http://badge.fury.io/rb/dragonfly_svg) [](https://coveralls.io/r/tomasc/dragonfly_svg)
[Dragonfly](https://github.com/markevans/dragonfly) analyser and processors for SVGs.
Uses the [nokogiri](http://nokogiri.org) 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
```ruby
Dragonfly.app.configure do
plugin :svg
end
```
## Supported Formats
List of supported formats is available as:
```ruby
DragonflySvg::SUPPORTED_FORMATS # => ["svg", "svgz", "svg.gz"]
```
## Analyser
The analyser supplies the following methods:
```ruby
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.
```ruby
svg.extend_ids
svg.extend_ids('foo')
```
### RemoveNamespaces
Removes the `xmlns` namespace from the SVG.
```ruby
svg.remove_namespaces
```
### SetAttribute
Allows to set attribute for specified `xpath`:
```ruby
svg.set_attribute('./*[name()="svg"]', 'style', 'margin: 50px;')
```
### SetTagValue
Allows to set tag value for specified `xpath`:
```ruby
svg.set_tag_value('./*[name()="text"]', 'Updated text')
```
### SetDimensions
Sets the dimensions of the SVG. Takes two parameters: `width` and `height`
```ruby
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.
```ruby
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.
```ruby
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`.
```ruby
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