compass-svg-polyfill 1.0.6 → 1.0.7

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: b92ea0cc7dff77a975068ea1c51c7db694f5a6c8
4
- data.tar.gz: 96f275eb0e40c3b63d4cbf0e69b3d92cdbcd6499
3
+ metadata.gz: fc2ba58d9987f92353653ad9ded9d156d942a48b
4
+ data.tar.gz: ff2d2f173900f5dff4f146387297cb447b815d9f
5
5
  SHA512:
6
- metadata.gz: 0e182d09d9f5e41618cc8de79daf86fc5c2b0ab82ec3ef1a8495536b59dfbaf734eee6e7cd653a2ecd4865ebd1230e10e2333e329f0f333a6254035606f7526a
7
- data.tar.gz: 80378d9d4abe24b3faba9d73586f7aa9f8974a8d10b55610db76cf0f9c2ff3c4a7edef1418e16fce8db01715748f1b81ec7399cb9ba75bdade687df2f8445b3e
6
+ metadata.gz: f440fa50551bd792a30ff27fa4ac5d6ade880a6b315c5e331b89aaef51f394aa0265ee9249c79c421bead1a4d89897b07d3f1f5d8a1fdd8542ff2d76449fcda9
7
+ data.tar.gz: 3f1d41f801cfe19de9a61169966b84080a0de3baf0a5708551a6ac2e852d167c81ca3a601179107a70d7b1db1c5969093ca40777391e8e9a68949c03bb67ec26
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Compass SVG polyfill
2
2
 
3
- Version 1.0.6
4
-
5
3
  A compass plugin which serves SVG background images to new browsers and
6
4
  provides a PNG fallback to old browsers.
7
5
 
@@ -1,4 +1,4 @@
1
- require 'compass-svg-polyfill/sass_functions.rb'
1
+ require 'compass-svg-polyfill/sass_functions'
2
2
 
3
3
  Compass::Frameworks.register(
4
4
  'compass-svg-polyfill',
@@ -1,3 +1,6 @@
1
+ require 'tempfile'
2
+ require 'fileutils'
3
+ require 'digest'
1
4
  require 'RMagick' unless Object.const_defined?("Magick")
2
5
 
3
6
  module Sass::Script::Functions
@@ -8,43 +11,74 @@ module Sass::Script::Functions
8
11
  assert_type pngName, :String
9
12
  assert_type imageConverter, :String
10
13
 
14
+ # Normalise values
15
+ svgFilepath = File.join Compass.configuration.images_path, svgName.value.to_s
16
+ pngFilepath = File.join Compass.configuration.images_path, pngName.value.to_s
11
17
  imageConverter = imageConverter.value.to_sym
12
18
 
19
+ # Helper objects
13
20
  logger = Compass::Logger.new
21
+ cache_store = environment.options[:cache_store]
14
22
 
15
- svgName = svgName.value.to_s
16
- svgPath = File.join Compass.configuration.images_path, svgName
17
-
18
- pngName = pngName.value.to_s
19
- pngPath = File.join Compass.configuration.images_path, pngName
20
-
21
- if !File.exists? svgPath
22
- raise Sass::SyntaxError, "svg does not exist #{svgName}"
23
+ # Check if file exists
24
+ if !File.exists? svgFilepath
25
+ raise Sass::SyntaxError, "SVG file does not exist #{svgName.value.to_s}"
23
26
  end
24
27
 
25
- if File.exists? pngPath
26
- logger.record :overwrite, pngName
27
- else
28
- logger.record :create, pngName
29
- end
28
+ # Create a temporary output file
29
+ tmpFile = Tempfile.new(['compass-svg-polyfill', '.png'])
30
+ tmpFile.close false
30
31
 
31
32
  case imageConverter
32
33
  when :imagemagick
33
- img = Magick::Image.read(svgPath).first
34
+ img = Magick::Image.read(svgFilepath).first
34
35
  img.resize!(width.value.to_i, height.value.to_i)
35
- img.write pngPath
36
+ img.write tmpFile.path
36
37
  when :librsvg
37
38
  system(
38
- "rsvg-convert", # Process
39
- "-w", "#{width.value}", # Width
40
- "-h", "#{height.value}", # Height
41
- "#{svgPath}", # Input
42
- "-o", "#{pngPath}" # Output
39
+ "rsvg-convert", # Process
40
+ "-w", width.value, # Width
41
+ "-h", height.value, # Height
42
+ svgFilepath, # Input
43
+ "-o", tmpFile.path # Output
43
44
  )
44
45
  else
45
46
  raise Sass::SyntaxError, "Unknown image converter #{imageConverter}"
46
47
  end
47
48
 
49
+ # Setup cache values
50
+ cacheKey = cache_store.key(File.dirname(pngFilepath), File.basename(pngFilepath))
51
+ cacheSHA = Digest::SHA1.hexdigest(pngFilepath)
52
+ cacheVal = "#{width} #{height} #{Digest::SHA1.file(svgFilepath).hexdigest}"
53
+
54
+ action = nil
55
+
56
+ if File.exists? pngFilepath
57
+ action = :overwrite
58
+
59
+ if (cachedSHA = cache_store.retrieve(cacheKey, cacheSHA)) then
60
+ if cachedSHA.eql? cacheVal then
61
+ action = :unchanged
62
+ end
63
+ end
64
+ else
65
+ action = :create
66
+ end
67
+
68
+ logger.record action, pngName.value
69
+
70
+ case action
71
+ when :overwrite, :create
72
+ # Save the file
73
+ FileUtils.mv(tmpFile.path, pngFilepath)
74
+ end
75
+
76
+ # Save the cache key
77
+ cache_store.store(cacheKey, cacheSHA, cacheVal)
78
+
79
+ # Remove temp file
80
+ tmpFile.unlink
81
+
48
82
  Sass::Script::Bool.new true
49
83
  end
50
84
 
@@ -1,5 +1,5 @@
1
1
  module Compass
2
2
  module SVGPolyfill
3
- VERSION = "1.0.6"
3
+ VERSION = "1.0.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compass-svg-polyfill
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bashkim Isai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-19 00:00:00.000000000 Z
11
+ date: 2015-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
@@ -60,11 +60,11 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - README.md
64
+ - lib/compass-svg-polyfill.rb
63
65
  - lib/compass-svg-polyfill/sass_functions.rb
64
- - lib/compass-svg-polyfill/stylesheets/compass-svg-polyfill/svg.scss
66
+ - lib/compass-svg-polyfill/stylesheets/compass-svg-polyfill/_svg.scss
65
67
  - lib/compass-svg-polyfill/version.rb
66
- - lib/compass-svg-polyfill.rb
67
- - README.md
68
68
  homepage: http://github.com/bashaus/compass-svg-polyfill
69
69
  licenses:
70
70
  - MIT
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 2.0.6
88
+ rubygems_version: 2.4.4
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Converts SVG images to PNG for use in older browsers