-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added imagemagick as converter option
- Loading branch information
Bashkim Isai
committed
Oct 10, 2013
1 parent
0a5ce0d
commit 4058ae8
Showing
11 changed files
with
113 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in compass-baseline.gemspec | ||
gemspec | ||
gemspec | ||
|
||
gem "rmagick" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
@import "svg-polyfill/svg"; | ||
@import "compass-svg-polyfill/svg"; | ||
|
||
.map { | ||
@include background-svg( | ||
$width: 856px, | ||
$height: 433px, | ||
$svg: "world-map.svg", | ||
$png: "world-map-856x433.png", | ||
$inline: false | ||
$inline: true | ||
); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
require 'compass-svg-polyfill/sass_functions.rb' | ||
|
||
Compass::Frameworks.register( | ||
'svg-polyfill', | ||
'compass-svg-polyfill', | ||
:stylesheets_directory => File.join(File.dirname(__FILE__), 'compass-svg-polyfill', 'stylesheets') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,52 @@ | ||
require 'RMagick' | ||
|
||
module Sass::Script::Functions | ||
def svg_polyfill(width, height, svgIn, pngOut) | ||
def svg_polyfill(width, height, svgName, pngName, imageConverter) | ||
assert_type width, :Number | ||
assert_type height, :Number | ||
assert_type svgIn, :String | ||
assert_type pngOut, :String | ||
assert_type svgName, :String | ||
assert_type pngName, :String | ||
assert_type imageConverter, :String | ||
|
||
imageConverter = imageConverter.value.to_sym | ||
|
||
svgPath = File.join Compass.configuration.images_path, svgIn.value | ||
pngPath = File.join Compass.configuration.images_path, pngOut.value | ||
logger = Compass::Logger.new | ||
|
||
begin | ||
if !File.exists? svgPath | ||
Compass::Logger.new.record :error, File.join(Compass.configuration.images_dir, svgIn.value) | ||
raise "SVG does not exist" | ||
end | ||
svgName = svgName.value.to_s | ||
svgPath = File.join Compass.configuration.images_path, svgName | ||
|
||
if File.exists? File.join(Compass.configuration.images_path, pngOut.value) | ||
Compass::Logger.new.record :overwrite, File.join(Compass.configuration.images_dir, pngOut.value) | ||
else | ||
Compass::Logger.new.record :create, File.join(Compass.configuration.images_dir, pngOut.value) | ||
end | ||
pngName = pngName.value.to_s | ||
pngPath = File.join Compass.configuration.images_path, pngName | ||
|
||
if !File.exists? svgPath | ||
raise Sass::SyntaxError, "svg does not exist #{svgName}" | ||
end | ||
|
||
if File.exists? pngPath | ||
logger.record :overwrite, pngName | ||
else | ||
logger.record :create, pngName | ||
end | ||
|
||
case imageConverter | ||
when :imagemagick | ||
img = Magick::Image.read(svgPath).first | ||
img.resize!(width.value.to_i, height.value.to_i) | ||
img.write pngPath | ||
when :librsvg | ||
system( | ||
"rsvg-convert", # Process | ||
"-w", width.value.to_s, # Width | ||
"-h", height.value.to_s, # Height | ||
"-w", "#{width.value}", # Width | ||
"-h", "#{height.value}", # Height | ||
"#{svgPath}", # Input | ||
"-o", "#{pngPath}" # Output | ||
) | ||
|
||
Sass::Script::Bool.new true | ||
rescue | ||
Sass::Script::Bool.new false | ||
else | ||
raise Sass::SyntaxError, "Unknown image converter #{imageConverter}" | ||
end | ||
|
||
Sass::Script::Bool.new true | ||
end | ||
|
||
declare :svg_polyfill, :args => [:Number, :Number, :String, :String] | ||
end |
11 changes: 8 additions & 3 deletions
11
...olyfill/stylesheets/svg-polyfill/svg.scss → ...stylesheets/compass-svg-polyfill/svg.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Compass | ||
module SVGPolyfill | ||
VERSION = "1.0.4" | ||
VERSION = "1.0.5" | ||
end | ||
end |