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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa1d11cc37ab394b50c0dd37232f56545a5ba9d9
4
- data.tar.gz: 59f46fd6e13ee2a43e6e794cc7d24b6d5c38cd4f
3
+ metadata.gz: 5457b1190e893a9dfac8629a5c06463147685837
4
+ data.tar.gz: 6c0998ebc8e795b5b5aa2a1953b8824d18c300c0
5
5
  SHA512:
6
- metadata.gz: 1cccbf1eea252f0dca0d8d3a16516f06c6214d0262fdd4cb635fa8bfde6df1a7f31c952e960cbfac11daccdcd8cb1ef40571df31c5c79a2e9ca7387d18d3e24f
7
- data.tar.gz: a11b06cd02239d19adf123f8790ec18d86f62befcc0b37a4f7d076f5df14c2a6241dad35530dff5c6af46a88ecadbd716c7e0470dc9ad65c2577b4df766ddff4
6
+ metadata.gz: 70edd657348bc0d4b44add8f3516b20fcc715e56e9f99601f944f067adee1856a4ae2e4f4b0c16e33dcd5b9242c8449c03c7d1c7b8d0f9e141e3e53cc0facce4
7
+ data.tar.gz: 6472cae9a52960be99f3349db60283c42cc342b3aad1027c60b58639be049c48a8a08530b010699b991ffb02d648de1d28186c92a762a48a6faaf53595881031
@@ -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 directory; and marvel as svgeez generates a single SVG sprite file ready for inclusion in your user interface.
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 output folder. _These paths must be different!_
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`. The resulting sprite file will be named `icons.svg` (this file name is derived from the name of the provided source folder).
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 directory, using the `--with-svgo` option can add considerable time to SVG sprite generation.
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
 
@@ -11,8 +11,8 @@ module Svgeez
11
11
  end
12
12
 
13
13
  def add_build_options(c)
14
- c.option 'source', '-s', '--source [DIR]', 'Source directory (defaults to ./)'
15
- c.option 'destination', '-d', '--destination [DIR]', 'Destination directory (defaults to ./_svgeez)'
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 input_file_paths.any?
12
- Svgeez.logger.info %{Generating sprite at `#{output_file_path}` from #{input_file_paths.length} SVG#{'s' if input_file_paths.length > 1}...}
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 directory
15
- FileUtils.mkdir_p(@destination)
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(output_file_path, 'w') do |f|
24
- f.write build_output_file_contents
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 `#{output_file_path}`.}
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 build_output_file_contents
37
- %{<svg id="#{source_basename}" style="display: none;" version="1.1">}.tap do |output_file_contents|
38
- # Loop over all input files, grabbing their content, and appending to `output_file_contents`
39
- input_file_paths.each do |file_path|
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
- output_file_contents << %{<symbol id="#{source_basename}-#{File.basename(file_path, '.svg').downcase}" #{matches[:viewbox]}>#{matches[:content]}</symbol>}
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
- output_file_contents << '</svg>'
48
+ destination_file_contents << '</svg>'
49
49
  end
50
50
  end
51
51
 
52
- def input_file_paths
53
- Dir.glob(File.join(@source, '*.svg'))
52
+ def destination_file_id
53
+ @destination_file_id ||= File.basename(destination_file_name, '.svg').gsub(' ', '-')
54
54
  end
55
55
 
56
- def output_file_path
57
- File.join(@destination, %{#{source_basename}.svg})
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 source_basename
61
- @source_basename ||= File.basename(@source)
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 == @destination
81
+ @source == destination_folder_path
66
82
  end
67
83
 
68
84
  def svgo_installed?
@@ -1,3 +1,3 @@
1
1
  module Svgeez
2
- VERSION = '0.1.4'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.4
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-19 00:00:00.000000000 Z
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