savagery 0.0.1 → 0.1.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: afdcbfb98ed3b794c4770fa6debd24e3889ef4f0
4
- data.tar.gz: a2084e5ff63b8c3b47daadb49360ec38e971baf5
3
+ metadata.gz: ee09c3c070917055eb7b817030e15f46f53d09a8
4
+ data.tar.gz: 8d68da05a447d63420b5bfe84df9f15c05063a38
5
5
  SHA512:
6
- metadata.gz: fb6e7e68739b3ff491d523a0c8b0e319d3e41f2d4f379d02aa5d5c26c572dd3bb7399623b79ba8fcc2dbbd69da2f3fe94888bfe8ffa6c395587c33c7d82a3a47
7
- data.tar.gz: d251faf0413e8129fd49dfd2bc802a756750e31bee1508e81dce42f13ff2ada7d4a66dfdf0433ede059bb408f5f74aca365810c1e3c0a7352d7762049210ad11
6
+ metadata.gz: 768b230c5568792fb1158e3c352149a26af9a07909a200a502d1f6310c10ceb21a8a59f9768a62b6aed0f51ead5ddb43e50f2b0fb95bc741f3216000718a0ede
7
+ data.tar.gz: 31b6973438164b642ec7a724e3c3a687a6c3e19ee88c9d34ac12929f47d170a9d7af5b57e081e17321f865e873aed44aa012cdbda1d0f07c4193a16804a88e33
data/README.md CHANGED
@@ -12,23 +12,40 @@ gem "savagery"
12
12
 
13
13
  ## Usage
14
14
 
15
- Give savagery the name of a directory in app/assets/images to sprite:
15
+ Given the following directory structure:
16
16
 
17
- ```ruby
18
- # app/views/layouts/application.html.erb
19
- <%= svg_sprite_include "svgs" %>
17
+ ```
18
+ app/assets/images/
19
+ └── dogs
20
+    ├── chihuahua.svg
21
+    ├── golden.svg
22
+    └── lab.svg
20
23
  ```
21
24
 
22
- And then any images within that directory will be available later on in the view:
25
+ Use the `svg_sprite_use` helper in your view:
23
26
 
24
27
  ```ruby
25
28
  # app/views/dogs/show.html.erb
26
- <%= svg_sprite_use "svgs/chihuahua" %>
29
+ <%= svg_sprite_use "dogs/chihuahua" %>
27
30
  ```
28
31
 
32
+ And Savagery will do all the hard work of spriting and embedding. A new .svg
33
+ sprite file will appear in the images directory, named after the directory
34
+ containing the sprites:
35
+
36
+ ```
37
+ app/assets/images/
38
+ ├── dogs
39
+ │   ├── chilhuahua.svg
40
+ │   ├── golden.svg
41
+ │   └── lab.svg
42
+ └── dogs.svg
43
+ ```
44
+
45
+ Make sure you check this file into version control.
46
+
29
47
  ## TODO
30
48
 
31
- * remove necessity of `svg_sprite_include`
32
49
  * add handlebars helpers for ember apps
33
50
 
34
51
  ## Contributing
@@ -1,17 +1,28 @@
1
+ require "set"
2
+
1
3
  module Savagery
2
4
  module Helpers
3
5
  def svg_sprite_include path
6
+ return raw("") if svg_sprites_included.include?(path)
4
7
  sprite_file_path = Savagery.sprite!("app/assets/images/#{path}")
8
+ svg_sprites_included.add path
5
9
  raw File.read(sprite_file_path)
6
10
  end
7
11
 
8
12
  def svg_sprite_use name, options={}
13
+ dirname = File.dirname(name)
14
+ sprite = svg_sprite_include(dirname)
15
+
9
16
  basename = File.basename(name)
10
17
  options[:class] ||= basename
11
- content_tag :svg, options do
18
+ sprite + content_tag(:svg, options) do
12
19
  content_tag :use, nil, "xlink:href" => "##{basename}"
13
20
  end
14
21
  end
22
+
23
+ def svg_sprites_included
24
+ @svg_sprites_included ||= Set.new
25
+ end
15
26
  end
16
27
  end
17
28
 
@@ -1,3 +1,3 @@
1
1
  module Savagery
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: savagery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel