svgeez 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +49 -0
- data/README.md +16 -7
- data/lib/svgeez/command.rb +2 -2
- data/lib/svgeez/sprite_builder.rb +37 -21
- data/lib/svgeez/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5457b1190e893a9dfac8629a5c06463147685837
|
4
|
+
data.tar.gz: 6c0998ebc8e795b5b5aa2a1953b8824d18c300c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70edd657348bc0d4b44add8f3516b20fcc715e56e9f99601f944f067adee1856a4ae2e4f4b0c16e33dcd5b9242c8449c03c7d1c7b8d0f9e141e3e53cc0facce4
|
7
|
+
data.tar.gz: 6472cae9a52960be99f3349db60283c42cc342b3aad1027c60b58639be049c48a8a08530b010699b991ffb02d648de1d28186c92a762a48a6faaf53595881031
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributing to svgeez
|
2
|
+
|
3
|
+
I'd love to have your help improving svgeez! If you'd like to pitch in, you can do so in a number of ways:
|
4
|
+
|
5
|
+
1. Look through open [Issues](https://github.com/jgarber623/svgeez/issues).
|
6
|
+
1. Review any open [Pull Requests](https://github.com/jgarber623/svgeez/pulls).
|
7
|
+
1. [Fork svgeez](#get-set-up-to-contribute) and fix an open Issue or add your own feature.
|
8
|
+
1. File new Issues if you have a good idea or see a bug and don't know how to fix it yourself. _Only do this after you've made sure the behavior or problem you're seeing isn't already documented in an open Issue._
|
9
|
+
|
10
|
+
I definitely appreciate your interest in (and help improving) svgeez. Thanks!
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
svgeez is a written in [Ruby](https://www.ruby-lang.org/en/) (version 2.2.3) and development dependencies are managed using the [Bundler](http://bundler.io/) gem.
|
15
|
+
|
16
|
+
I manage Ruby versions with [rbenv](https://github.com/rbenv/rbenv). I'd recommend you do the same or use a similar Ruby version manager ([chruby](https://github.com/postmodern/chruby/) or [RVM](https://rvm.io/) come to mind). Once you've installed Ruby 2.2.3 using your method of choice, install the project's gems by running:
|
17
|
+
|
18
|
+
```sh
|
19
|
+
bundle install
|
20
|
+
```
|
21
|
+
|
22
|
+
…from the root of the project.
|
23
|
+
|
24
|
+
## Get set up to contribute
|
25
|
+
|
26
|
+
Contributing to svgeez is pretty straightforward:
|
27
|
+
|
28
|
+
1. Fork the svgeez repo and clone it.
|
29
|
+
1. Install development dependencies by running `bundle install` from the root of the project.
|
30
|
+
1. Create a feature branch for the issue or new feature you're looking to tackle: `git checkout -b your-descriptive-branch-name`.
|
31
|
+
1. _Write some code!_
|
32
|
+
1. Build (`rake build`) and install (`rake install`) your updated code.
|
33
|
+
1. If your changes would benefit from testing, add the necessary tests and verify everything passes by running `rake`.
|
34
|
+
1. Commit your changes: `git commit -am 'Add some new feature or fix some issue'`.
|
35
|
+
1. Push the branch to your fork of svgeez: `git push origin your-descriptive-branch-name`.
|
36
|
+
1. Create a new Pull Request and I'll give it a look!
|
37
|
+
|
38
|
+
## Code Style
|
39
|
+
|
40
|
+
Code styles are like opinions: Everyone's got one and yours is better than mine. Here's how svgeez should be written:
|
41
|
+
|
42
|
+
- Use two-space indentation in Ruby.
|
43
|
+
- No trailing whitespace and blank lines should have whitespace removed.
|
44
|
+
- Prefer single quotes over double quotes unless interpolating.
|
45
|
+
- Follow the conventions you see in the existing source code as best as you can.
|
46
|
+
|
47
|
+
svgeez's formatting guidelines are defined in the `.editorconfig` file which uses the [EditorConfig](http://editorconfig.org/) syntax. There are [a number of great plugins for a variety of editors](http://editorconfig.org/#download) that utilize the settings in the `.editorconfig` file. Using EditorConfig will make your time spent coding a little bit easier.
|
48
|
+
|
49
|
+
Your bug fix or feature addition won't be rejected if it runs afoul of any (or all) of these guidelines, but following the guidelines will definitely make everyone's lives a little easier.
|
data/README.md
CHANGED
@@ -4,8 +4,9 @@
|
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/svgeez.svg)](https://badge.fury.io/rb/svgeez)
|
6
6
|
[![Build Status](https://travis-ci.org/jgarber623/svgeez.svg?branch=master)](https://travis-ci.org/jgarber623/svgeez)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/jgarber623/svgeez/badges/gpa.svg)](https://codeclimate.com/github/jgarber623/svgeez)
|
7
8
|
|
8
|
-
If you're using an [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) icon system in your Web projects, svgeez can help speed up your workflow by automating the SVG sprite generation process. Simply run svgeez alongside your existing project (or integrate it into your current build system); add, edit, or delete SVG files from a
|
9
|
+
If you're using an [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) icon system in your Web projects, svgeez can help speed up your workflow by automating the SVG sprite generation process. Simply run svgeez alongside your existing project (or integrate it into your current build system); add, edit, or delete SVG files from a folder; and marvel as svgeez generates a single SVG sprite file ready for inclusion in your user interface.
|
9
10
|
|
10
11
|
_For more on why SVG sprites are the bee's knees as far as icon systems go, give Chris Coyier's original post, [Icon System with SVG Sprites](https://css-tricks.com/svg-sprites-use-better-icon-fonts/), and his follow-up article, [SVG \`symbol\` a Good Choice for Icons](https://css-tricks.com/svg-symbol-good-choice-icons/) a read-through._
|
11
12
|
|
@@ -47,15 +48,23 @@ svgeez is a command line program with several useful subcommands. From the root
|
|
47
48
|
|
48
49
|
### The `build` command
|
49
50
|
|
50
|
-
You can manually generate an SVG sprite from a folder of SVGs with the `build` command which takes two options, a path to your folder of individual SVGs and a path to the desired
|
51
|
+
You can manually generate an SVG sprite from a folder of SVGs with the `build` command which takes two options, a path to your folder of individual SVGs and a path to the desired destination folder. _These paths must be different!_
|
51
52
|
|
52
53
|
A basic example:
|
53
54
|
|
54
55
|
```sh
|
55
|
-
$ svgeez build --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images
|
56
|
+
$ svgeez build --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images/icons.svg
|
56
57
|
```
|
57
58
|
|
58
|
-
The above example will combine all SVG files in `~/Sites/sixtwothree.org/images/icons` into a single SVG sprite in `~/Sites/sixtwothree.org/images`.
|
59
|
+
The above example will combine all SVG files in `~/Sites/sixtwothree.org/images/icons` into a single SVG sprite file (`icons.svg`) in `~/Sites/sixtwothree.org/images`.
|
60
|
+
|
61
|
+
#### Options and Defaults
|
62
|
+
|
63
|
+
|Option|Description|
|
64
|
+
|---|---|
|
65
|
+
|`-s`<br>`--source`|Path to the folder of source SVGs (defaults to `./`).|
|
66
|
+
|`-d`<br>`--destination`|Path to the destination file or folder (defaults to `./_svgeez/svgeez.svg`)|
|
67
|
+
|`--with-svgo`|Optimize source SVGs with [SVGO](https://github.com/svg/svgo/) before sprite generation (non-destructive)|
|
59
68
|
|
60
69
|
### The `watch` command
|
61
70
|
|
@@ -64,7 +73,7 @@ The `watch` command takes the same arguments as the `build` command but uses the
|
|
64
73
|
Tweaking the example from above:
|
65
74
|
|
66
75
|
```sh
|
67
|
-
$ svgeez watch --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images
|
76
|
+
$ svgeez watch --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images/icons.svg
|
68
77
|
```
|
69
78
|
|
70
79
|
svgeez will remaing running, watching for new, removed, or updated SVG files in the provided source folder. As SVG files are added, deleted, or modified in the source folder, svgeez will keep pumping out updated SVG sprite files to the destination folder.
|
@@ -74,10 +83,10 @@ svgeez will remaing running, watching for new, removed, or updated SVG files in
|
|
74
83
|
If you have the excellent [SVGO](https://github.com/svg/svgo/) utility installed on your system (and the `svgo` command is available in your PATH), you can use the `--with-svgo` option and optimize source SVGs before generating the sprite file.
|
75
84
|
|
76
85
|
```sh
|
77
|
-
$ svgeez build --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images --with-svgo
|
86
|
+
$ svgeez build --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images/icons.svg --with-svgo
|
78
87
|
```
|
79
88
|
|
80
|
-
Optimizing source SVG files with SVGO is done on-the-fly and the original files are left intact. Depending on the number of individual SVG files in the source
|
89
|
+
Optimizing source SVG files with SVGO is done on-the-fly and the original files are left intact. Depending on the number of individual SVG files in the source folder, using the `--with-svgo` option can add considerable time to SVG sprite generation.
|
81
90
|
|
82
91
|
## Working with SVG sprites
|
83
92
|
|
data/lib/svgeez/command.rb
CHANGED
@@ -11,8 +11,8 @@ module Svgeez
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def add_build_options(c)
|
14
|
-
c.option 'source', '-s', '--source [
|
15
|
-
c.option 'destination', '-d', '--destination [
|
14
|
+
c.option 'source', '-s', '--source [FOLDER]', 'Source folder (defaults to ./)'
|
15
|
+
c.option 'destination', '-d', '--destination [OUTPUT]', 'Destination file or folder (defaults to ./_svgeez/svgeez.svg)'
|
16
16
|
c.option 'svgo', '--with-svgo', 'Optimize source SVGs with SVGO before sprite generation (non-destructive)'
|
17
17
|
end
|
18
18
|
end
|
@@ -2,17 +2,17 @@ module Svgeez
|
|
2
2
|
class SpriteBuilder
|
3
3
|
def initialize(options)
|
4
4
|
@source = File.expand_path(options.fetch('source', './'))
|
5
|
-
@destination = File.expand_path(options.fetch('destination', './_svgeez'))
|
5
|
+
@destination = File.expand_path(options.fetch('destination', './_svgeez/svgeez.svg'))
|
6
6
|
@with_svgo = options['svgo']
|
7
7
|
end
|
8
8
|
|
9
9
|
def build
|
10
10
|
unless source_is_destination?
|
11
|
-
if
|
12
|
-
Svgeez.logger.info %{Generating sprite at `#{
|
11
|
+
if source_file_paths.any?
|
12
|
+
Svgeez.logger.info %{Generating sprite at `#{destination_file_path}` from #{source_file_paths.length} SVG#{'s' if source_file_paths.length > 1}...}
|
13
13
|
|
14
|
-
# Make destination
|
15
|
-
FileUtils.mkdir_p(
|
14
|
+
# Make destination folder
|
15
|
+
FileUtils.mkdir_p(destination_folder_path)
|
16
16
|
|
17
17
|
# Notify if SVGO requested but not found
|
18
18
|
if @with_svgo && !svgo_installed?
|
@@ -20,11 +20,11 @@ module Svgeez
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# Write the file
|
23
|
-
File.open(
|
24
|
-
f.write
|
23
|
+
File.open(destination_file_path, 'w') do |f|
|
24
|
+
f.write build_destination_file_contents
|
25
25
|
end
|
26
26
|
|
27
|
-
Svgeez.logger.info %{Successfully generated sprite at `#{
|
27
|
+
Svgeez.logger.info %{Successfully generated sprite at `#{destination_file_path}`.}
|
28
28
|
else
|
29
29
|
Svgeez.logger.warn %{No SVGs were found in `#{@source}`.}
|
30
30
|
end
|
@@ -33,36 +33,52 @@ module Svgeez
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
%{<svg id="#{
|
38
|
-
# Loop over all
|
39
|
-
|
36
|
+
def build_destination_file_contents
|
37
|
+
%{<svg id="#{destination_file_id}" style="display: none;" version="1.1">}.tap do |destination_file_contents|
|
38
|
+
# Loop over all source files, grabbing their content, and appending to `destination_file_contents`
|
39
|
+
source_file_paths.each do |file_path|
|
40
40
|
file_contents = use_svgo? ? `svgo -i #{file_path} -o -` : IO.read(file_path)
|
41
41
|
pattern = /^<svg.*?(?<viewbox>viewBox=".*?").*?>(?<content>.*?)<\/svg>/m
|
42
42
|
|
43
43
|
file_contents.match(pattern) do |matches|
|
44
|
-
|
44
|
+
destination_file_contents << %{<symbol id="#{destination_file_id}-#{File.basename(file_path, '.svg').downcase}" #{matches[:viewbox]}>#{matches[:content]}</symbol>}
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
destination_file_contents << '</svg>'
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
53
|
-
|
52
|
+
def destination_file_id
|
53
|
+
@destination_file_id ||= File.basename(destination_file_name, '.svg').gsub(' ', '-')
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
57
|
-
|
56
|
+
def destination_file_name
|
57
|
+
if @destination.end_with?('.svg')
|
58
|
+
File.split(@destination)[1]
|
59
|
+
else
|
60
|
+
'svgeez.svg'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def destination_file_path
|
65
|
+
@destination_file_path ||= File.join(destination_folder_path, destination_file_name)
|
66
|
+
end
|
67
|
+
|
68
|
+
def destination_folder_path
|
69
|
+
if @destination.end_with?('.svg')
|
70
|
+
File.split(@destination)[0]
|
71
|
+
else
|
72
|
+
@destination
|
73
|
+
end
|
58
74
|
end
|
59
75
|
|
60
|
-
def
|
61
|
-
@
|
76
|
+
def source_file_paths
|
77
|
+
@source_file_paths ||= Dir.glob(File.join(@source, '*.svg'))
|
62
78
|
end
|
63
79
|
|
64
80
|
def source_is_destination?
|
65
|
-
@source ==
|
81
|
+
@source == destination_folder_path
|
66
82
|
end
|
67
83
|
|
68
84
|
def svgo_installed?
|
data/lib/svgeez/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svgeez
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Garber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11
|
11
|
+
date: 2015-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: listen
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- ".ruby-version"
|
95
95
|
- ".travis.yml"
|
96
96
|
- CODE_OF_CONDUCT.md
|
97
|
+
- CONTRIBUTING.md
|
97
98
|
- Gemfile
|
98
99
|
- LICENSE
|
99
100
|
- README.md
|