middleman-svg-fallback 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in middleman-svg-fallback.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # middleman-svg-fallback
2
+
3
+ Generate nice JPEG and PNG files from any SVG files in your `images/` folder.
4
+
5
+ Also, generate gzipped SVGZ files.
6
+
7
+ *Attention:* This requires [Inkscape](http://inkscape.org/).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your `Gemfile`:
12
+
13
+ ```ruby
14
+ gem 'middleman-svg-fallback'
15
+ ```
16
+
17
+ And something like this to your `config.rb`:
18
+
19
+ ```ruby
20
+ require "middleman-svg-fallback"
21
+ activate :svg_fallback,
22
+ :inkscape_bin => '/Applications/Inkscape.app/Contents/Resources/bin/inkscape',
23
+ :inkscape_options => '--export-dpi=100 --export-background-opacity=0'
24
+ ```
25
+
26
+ (supposed you're working on a Mac)
27
+
28
+ Then, during build, middleman-svg-fallback will generate the fallbacks as you would expect and you can use them with a [modernizr](http://modernizr.com/) based CSS rule, like this for example:
29
+
30
+ ```css
31
+ .illustration {
32
+ background: url('illustration.svg') 0 0 no-repeat;
33
+ }
34
+
35
+ .no-svg .illustration {
36
+ background: url('illustration.png') 0 0 no-repeat;
37
+ }
38
+ ```
39
+
40
+ The JPEG files are intended for use with [OpenGraph](http://ogp.me/). Facebook doesn't like PNGs in `og:image` properties, so the JPG versions will come in handy.
41
+
42
+ ## License
43
+
44
+ MIT; Copyright (c) 2012 Jan Schulz-Hofen
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,42 @@
1
+ require 'rake'
2
+ module Middleman
3
+ module SVGFallback
4
+ class << self
5
+ def registered(app, options={})
6
+
7
+ options[:inkscape_bin] ||= 'inkscape'
8
+
9
+ app.after_configuration do
10
+
11
+ dir = File.join(build_dir, images_dir)
12
+ prefix = build_dir + File::SEPARATOR
13
+
14
+ after_build do |builder|
15
+ files = FileList["#{dir}/**/*.svg*"]
16
+
17
+ files.each do |file|
18
+ # make sure we have both an svg and an svgz version
19
+ basename = file.sub(/\.svgz?$/,'')
20
+
21
+ unless File.exists? "#{basename}.svg"
22
+ `gunzip --to-stdout --suffix .svgz #{basename}.svgz > #{basename}.svg`
23
+ builder.say_status :svg, "#{basename}.svg"
24
+ end
25
+ unless File.exists? "#{basename}.svgz"
26
+ `gzip --to-stdout #{basename}.svg > #{basename}.svgz`
27
+ builder.say_status :svgz, "#{basename}.svgz"
28
+ end
29
+
30
+ # generate fallbacks
31
+ %w(jpg png).each do |ext|
32
+ `#{options[:inkscape_bin]} --export-png=#{basename}.#{ext} #{options[:inkscape_options]} --without-gui #{basename}.svg > /dev/null 2>&1`
33
+ builder.say_status :svg_fallback, "#{basename}.#{ext}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ alias :included :registered
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module SVGFallback
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "middleman-core"
2
+
3
+ require "middleman-svg-fallback/version"
4
+
5
+ ::Middleman::Extensions.register(:svg_fallback) do
6
+ require "middleman-svg-fallback/extension"
7
+ ::Middleman::SVGFallback
8
+ end
@@ -0,0 +1 @@
1
+ require "middleman-svg-fallback"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "middleman-svg-fallback/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "middleman-svg-fallback"
7
+ s.version = Middleman::SVGFallback::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jan Schulz-Hofen"]
10
+ s.email = ["jan@launchco.com"]
11
+ s.homepage = "https://github.com/yeah/middleman-svg-fallback"
12
+ s.summary = %q{Generate nice JPEG and PNG files from any SVG files.}
13
+ s.description = s.summary
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency("middleman", [">= 3.0.0"])
20
+ s.add_runtime_dependency("rake", [">= 0"])
21
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-svg-fallback
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jan Schulz-Hofen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-12-18 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: middleman
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: Generate nice JPEG and PNG files from any SVG files.
52
+ email:
53
+ - jan@launchco.com
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - .gitignore
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - lib/middleman-svg-fallback.rb
66
+ - lib/middleman-svg-fallback/extension.rb
67
+ - lib/middleman-svg-fallback/version.rb
68
+ - lib/middleman_extension.rb
69
+ - middleman-svg-fallback.gemspec
70
+ has_rdoc: true
71
+ homepage: https://github.com/yeah/middleman-svg-fallback
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.4.2
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Generate nice JPEG and PNG files from any SVG files.
104
+ test_files: []
105
+