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 +4 -4
- data/README.md +24 -7
- data/lib/savagery/helpers.rb +12 -1
- data/lib/savagery/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee09c3c070917055eb7b817030e15f46f53d09a8
|
4
|
+
data.tar.gz: 8d68da05a447d63420b5bfe84df9f15c05063a38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
15
|
+
Given the following directory structure:
|
16
16
|
|
17
|
-
```
|
18
|
-
|
19
|
-
|
17
|
+
```
|
18
|
+
app/assets/images/
|
19
|
+
└── dogs
|
20
|
+
├── chihuahua.svg
|
21
|
+
├── golden.svg
|
22
|
+
└── lab.svg
|
20
23
|
```
|
21
24
|
|
22
|
-
|
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 "
|
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
|
data/lib/savagery/helpers.rb
CHANGED
@@ -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
|
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
|
|
data/lib/savagery/version.rb
CHANGED