svgsprite 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e30b8d45143456fa8b7e786a6a9869df9160b16a
4
+ data.tar.gz: 239e29d77b3e6124aa3231028442b21258a354fc
5
+ SHA512:
6
+ metadata.gz: 35a44a2fffa2f05253cef8e5c2438426486f2c1bbae6ce263249ee61cc9512c2560674024cb729c80ee9197d53b38b8e062bd251e95e3b25bd40614c4a09f736
7
+ data.tar.gz: 2fb649cc55e531d71433d781fcfa43c0125c15ec1ba81e7b765121cde54fe069dec93a0629b27121198110458f136f5b38b18df40e4f41fc049d1f350dc1139e
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Etienne Lemay
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # SVGSprite
2
+ Very early stage of an untested tool that merges a folder of SVGs together into a single SVG file.<br>
3
+ See [Chris Coyier’s article](http://css-tricks.com/svg-sprites-use-better-icon-fonts) about SVG sprites.
4
+
5
+ ## Usage
6
+ ```sh
7
+ $ svgsprite Wed 21 May 2014 16:09:39 EDT
8
+ SVGSprite commands:
9
+ svgsprite help [COMMAND] # Describe available commands or one specific command
10
+ svgsprite merge [OPTIONS] # Merge SVGs from a folder
11
+
12
+ Options:
13
+ -i, [--input=INPUT] # The folder where the separated SVGs are.
14
+ # Default: ./svgsprite/svgs
15
+
16
+ -o, [--output=OUTPUT] # Where the merged SVG is saved.
17
+ # Default: ./app/assets/images
18
+
19
+ -s, [--stdout], [--no-stdout] # Outputs the result to STDOUT.
20
+
21
+ -f, [--filename=FILENAME] # Merged file name.
22
+ # Default: svgsprite
23
+
24
+ -p, [--prefix=PREFIX] # SVG IDs prefix.
25
+ # Default: icon
26
+ ```
27
+
28
+ ### Static HTML
29
+ ```sh
30
+ $ svgsprite merge --stdout | pbcopy
31
+ ```
32
+
33
+ Then paste into your HTML file.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/svgsprite ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'svgsprite/cli'
6
+ SVGSprite::CLI.start(ARGV)
@@ -0,0 +1,9 @@
1
+ module SVGSprite
2
+ class Base
3
+ def initialize(options)
4
+ @options = options
5
+ svgs = SVGSprite::Extractor.extract!(@options)
6
+ SVGSprite::Exporter.export!(svgs, @options)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ require 'thor'
2
+ require 'svgsprite'
3
+
4
+ module SVGSprite
5
+ class CLI < Thor
6
+ package_name 'SVGSprite'
7
+
8
+ class_option :input, aliases: '-i', type: :string,
9
+ desc: 'The folder where the separated SVGs are.',
10
+ default: './svgsprite/svgs'
11
+
12
+ class_option :output, aliases: '-o', type: :string,
13
+ desc: 'Where the merged SVG is saved.',
14
+ default: './app/assets/images'
15
+
16
+ class_option :stdout, aliases: '-s', type: :boolean,
17
+ desc: 'Outputs the result to STDOUT.',
18
+ default: true
19
+
20
+ class_option :filename, aliases: '-f', type: :string,
21
+ desc: 'Merged file name.',
22
+ default: 'svgsprite'
23
+
24
+ class_option :prefix, aliases: '-p', type: :string,
25
+ desc: 'SVG IDs prefix.',
26
+ default: 'icon'
27
+
28
+ desc 'merge [OPTIONS]', 'Merge SVGs from a folder'
29
+ def merge
30
+ Base.new(options)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,56 @@
1
+ module SVGSprite
2
+ class Exporter
3
+ XMLNS = {
4
+ 'xmlns' => 'http://www.w3.org/2000/svg',
5
+ 'xmlns:sketch' => 'http://www.bohemiancoding.com/sketch/ns',
6
+ 'xmlns:xlink' => 'http://www.w3.org/1999/xlink'
7
+ }
8
+
9
+ # Class methods
10
+ def self.export!(svgs, options)
11
+ exporter = self.new(svgs, options)
12
+ exporter.create_output_dir!
13
+
14
+ if options[:stdout]
15
+ exporter.export_to_stdout
16
+ else
17
+ exporter.export_to_file
18
+ end
19
+ end
20
+
21
+ # Instance methods
22
+ def initialize(svgs, options)
23
+ @options = options
24
+ @svgs = svgs
25
+ end
26
+
27
+ def create_output_dir!
28
+ FileUtils.mkdir_p(@options[:output])
29
+ end
30
+
31
+ def export_to_stdout
32
+ STDOUT.write(svg_string)
33
+ end
34
+
35
+ def export_to_file
36
+ output_file = "#{@options[:output]}/#{@options[:filename]}.svg"
37
+ File.open(output_file, 'w') { |f| f.write(svg_string) }
38
+ end
39
+
40
+ def svg_string
41
+ icon_nodes = @svgs.map { |svg_hash| icon_node(svg_hash) }
42
+ xmlns = XMLNS.map { |k, v| %(#{k}="#{v}") }.join(' ')
43
+
44
+ %(<svg style="display: none" #{xmlns}><defs>#{icon_nodes.join('')}</defs></svg>)
45
+ end
46
+
47
+ def icon_node(svg_hash)
48
+ prefix = @options[:prefix]
49
+ svg = svg_hash[:svg]
50
+ filename = svg_hash[:filename]
51
+ id = "#{prefix}-#{filename}"
52
+
53
+ %(<g id="#{id}">#{svg}</g>)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,34 @@
1
+ require 'nokogiri'
2
+
3
+ module SVGSprite
4
+ class Extractor
5
+ # Class methods
6
+ def self.extract!(options)
7
+ self.new(options).extract_svgs
8
+ end
9
+
10
+ # Instance methods
11
+ def initialize(options)
12
+ @options = options
13
+ @input = @options[:input]
14
+ end
15
+
16
+ def extract_svgs
17
+ Dir.glob("#{@input}/*.svg").map do |filepath|
18
+ filename = File.basename(filepath, '.svg')
19
+ file = File.open(filepath)
20
+
21
+ {
22
+ filename: filename,
23
+ svg: extract_svg_from(file)
24
+ }
25
+ end
26
+ end
27
+
28
+ def extract_svg_from(file)
29
+ doc = Nokogiri::HTML(file)
30
+ node = doc.css('g').last.children
31
+ node.to_s.strip
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module SVGSprite
2
+ VERSION = '0.0.1'
3
+ end
data/lib/svgsprite.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'svgsprite/version'
2
+ require 'svgsprite/base'
3
+ require 'svgsprite/extractor'
4
+ require 'svgsprite/exporter'
5
+
6
+ module SVGSprite
7
+ end
data/svgsprite.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'svgsprite/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'svgsprite'
7
+ gem.version = SVGSprite::VERSION
8
+ gem.authors = ['Etienne Lemay']
9
+ gem.email = ['etienne@heliom.ca']
10
+ gem.summary = 'Merge SVGs from a folder'
11
+ gem.homepage = 'https://github.com/EtienneLem/svgsprite'
12
+ gem.license = 'MIT'
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.test_files = gem.files.grep(%r{^(test|spec)/})
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.bindir = 'bin'
19
+ gem.executables << 'svgsprite'
20
+
21
+ gem.add_dependency 'thor', '~> 0.14'
22
+ gem.add_dependency 'nokogiri', '~> 1.6.2.1'
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: svgsprite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Etienne Lemay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.2.1
41
+ description:
42
+ email:
43
+ - etienne@heliom.ca
44
+ executables:
45
+ - svgsprite
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - MIT-LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - bin/svgsprite
55
+ - lib/svgsprite.rb
56
+ - lib/svgsprite/base.rb
57
+ - lib/svgsprite/cli.rb
58
+ - lib/svgsprite/exporter.rb
59
+ - lib/svgsprite/extractor.rb
60
+ - lib/svgsprite/version.rb
61
+ - svgsprite.gemspec
62
+ homepage: https://github.com/EtienneLem/svgsprite
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Merge SVGs from a folder
86
+ test_files: []