compass-rgbapng 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Aaron Russell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # rgbapng - Compass plugin
2
+
3
+ rgbapng is a Compass plugin for providing cross browser compatible RGBA support. It works by creating single pixel transparent PNGs on the fly for browsers that don't support RGBA. It uses the pure Ruby ChunkyPNG library resulting in hassle-free installation and deployment, and increased performance.
4
+
5
+ ## Installation
6
+
7
+ Installation is simple via Ruby Gems. [Compass](http://compass-style.org/) and [ChunkyPNG](http://github.com/wvanbergen/chunky_png) are required.
8
+
9
+ gem install compass-rgbapng
10
+
11
+ ## Using rgbapng with your Compass project
12
+
13
+ To use rgbapng with your project, require the plugin from your Compass configuration:
14
+
15
+ require "rgbapng"
16
+
17
+ And then import the mixins to your SASS/SCSS files:
18
+
19
+ @import "rgbapng";
20
+
21
+ ### Configurable variables
22
+
23
+ There is a single variable that defines the path to which your PNG images will be saved. This defaults to `rgbapng` inside your Compass images directory. Change the path globally with:
24
+
25
+ $rgbapng_path: 'my_pngs';
26
+
27
+ ### Mixins
28
+
29
+ There are two mixins available to you.
30
+
31
+ #### rgba-background($color, [$path])
32
+
33
+ Sets the background property to use the RGBA value, falling back to the compiled PNG.
34
+
35
+ @include rgba-background(rgba(0,0,0,0.75));
36
+
37
+ Compiles to:
38
+
39
+ background: url('/images/rgbapng/000000bf.png?1282127952');
40
+ background: rgba(0, 0, 0, 0.75);
41
+
42
+ #### rgba-background-inline($color)
43
+
44
+ Sets the background property to use the RGBA value, falling back to a base64 encoded image data.
45
+
46
+ @include rgba-background-inline(rgba(0,0,0,0.75));
47
+
48
+ Compiles to:
49
+
50
+ background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNh2A8AAM4AxOSyusMAAAAASUVORK5CYII=');
51
+ background: rgba(0, 0, 0, 0.75);
52
+
53
+ ### Functions
54
+
55
+ There are two `Sass::Script` functions which can be used in your SASS:
56
+
57
+ # Creates the single pixel PNG image
58
+ # Returns a String of the image path and filename
59
+ png_pixelate(color, [dir])
60
+
61
+ # Returns a String of the base64 encoded image data
62
+ png_base64(color)
63
+
64
+ ## Credit where it's due
65
+
66
+ * The CSS technique used was initially described by Lea Verou in [Bulletproof, cross-browser RGBA backgrounds, today](http://leaverou.me/2009/02/bulletproof-cross-browser-rgba-backgrounds/).
67
+ * The SASS functions were [first created by Benjamin Doherty](http://gist.github.com/377912) using the RMagick library.
68
+
69
+ ## Copyright
70
+
71
+ Copyright (c) 2010 [Aaron Russell](http://www.aaronrussell.co.uk/). See LICENSE for details.
data/lib/rgbapng.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "rgbapng/functions"
2
+
3
+ Compass::Frameworks.register("rgbapng",
4
+ :stylesheets_directory => File.join(File.dirname(__FILE__), "stylesheets"),
5
+ :templates_directory => File.join(File.dirname(__FILE__), "templates")
6
+ )
@@ -0,0 +1,33 @@
1
+ require "rubygems"
2
+ require "chunky_png"
3
+ require "base64"
4
+
5
+ module Sass::Script::Functions
6
+
7
+ def png_pixelate(c, dir = "rgbapng")
8
+ color = ChunkyPNG::Color.rgba(c.red, c.green, c.blue, (c.alpha * 100 * 2.55).round)
9
+ image = ChunkyPNG::Image.new(1,1, color)
10
+ dir = dir.is_a?(Sass::Script::String) ? dir.value : dir
11
+ file = File.join(dir, ChunkyPNG::Color.to_hex(color).gsub(/^#/, "") + ".png")
12
+ path = File.join(Compass.configuration.images_path, file)
13
+
14
+ if !File.exists?(path) || options[:force]
15
+ puts "Writing #{file}"
16
+ [Compass.configuration.images_path, File.join(Compass.configuration.images_path, dir)].each do |d|
17
+ Dir.mkdir(d) unless File.exists?(d)
18
+ end
19
+ image.save(path)
20
+ end
21
+
22
+ Sass::Script::String.new(file)
23
+ end
24
+
25
+ def png_base64(c)
26
+ color = ChunkyPNG::Color.rgba(c.red, c.green, c.blue, (c.alpha * 100 * 2.55).round)
27
+ image = ChunkyPNG::Image.new(1,1, color)
28
+ data = Base64.encode64(image.to_blob).gsub("\n", "")
29
+
30
+ Sass::Script::String.new("url('data:image/png;base64,#{data}')")
31
+ end
32
+
33
+ end
@@ -0,0 +1,12 @@
1
+ $rgbapng_path: 'rgbapng';
2
+
3
+ @mixin rgba-background($color, $dir:$rgbapng_path){
4
+ background: image_url(png_pixelate($color, $dir));
5
+ background: $color;
6
+ }
7
+
8
+ @mixin rgba-background-inline($color){
9
+ background: png_base64($color);
10
+ background: $color;
11
+ }
12
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compass-rgbapng
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Aaron Russell
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-18 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: compass
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 10
30
+ - 0
31
+ version: 0.10.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: chunky_png
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 8
44
+ - 0
45
+ version: 0.8.0
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: Compass plugin for providing cross-browser compatible RGBA support by creating transparent PNGs on the fly for browsers that don't support RGBA. Uses the pure Ruby ChunkyPNG library for hassle free install and deployment and increased performance.
49
+ email: aaron@gc4.co.uk
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - LICENSE
58
+ - README.md
59
+ - lib/rgbapng/functions.rb
60
+ - lib/rgbapng.rb
61
+ - lib/stylesheets/_rgbapng.scss
62
+ has_rdoc: false
63
+ homepage: http://github.com/aaronrussell/compass-rgbapng
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.6
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Compass plugin for providing cross-browser compatible RGBA support by creating transparent PNGs on the fly for browsers that don't support RGBA.
92
+ test_files: []
93
+