remi-css3-now 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ = CSS3Now
2
+
3
+ I'm sick and tired of writing CSS like this ...
4
+
5
+ -moz-border-radius: 5px;
6
+ -webkit-border-radius: 5px;
7
+ -khtml-border-radius: 5px;
8
+ border-radius: 5px;
9
+
10
+ opacity: 0.7;
11
+ filter:alpha(opacity=70);
12
+
13
+ It's gross.
14
+
15
+ So ... I'm making a little gem for post-procssing CSS so I can write my CSS like:
16
+
17
+ border-radius: 5px;
18
+
19
+ And I'll end up with:
20
+
21
+ -moz-border-radius: 5px;
22
+ -webkit-border-radius: 5px;
23
+ -khtml-border-radius: 5px;
24
+ border-radius: 5px;
25
+
26
+ I'll keep track of which browsers support what.
27
+
28
+ == Installation
29
+
30
+ sudo gem install remi-css3-now --source http://gems.github.com
31
+
32
+ == Usage
33
+
34
+ require 'css3-now'
35
+
36
+ CSS3Now.new("original CSS").to_css
37
+
38
+ # Reading from a file
39
+ CSS3Now.new( File.read('my/stylesheet.css') ).to_css
40
+
41
+ # Sinatra example
42
+ CSS3Now.new( sass(:stylesheet) ).to_css
data/Rakefile ADDED
@@ -0,0 +1,68 @@
1
+ require 'rake'
2
+ require 'rubygems'
3
+ require 'rake/rdoctask'
4
+ require 'spec/rake/spectask'
5
+
6
+ puts "\nGem: css3-now\n\n"
7
+
8
+ begin
9
+ require 'jeweler'
10
+ Jeweler::Tasks.new do |s|
11
+ s.name = 'css3-now'
12
+ s.summary = ''
13
+ s.email = 'remi@remitaylor.com'
14
+ s.homepage = 'http://github.com/remi/css3-now'
15
+ s.description = ''
16
+ s.authors = %w( remi )
17
+ s.files = FileList['[A-Z]*', '{lib,spec,bin,examples}/**/*']
18
+ # s.add_dependency 'person-gemname'
19
+ # s.executables << 'script'
20
+ # s.rubyforge_project = 'gemname'
21
+ # s.extra_rdoc_files = %w( README.rdoc )
22
+ end
23
+ rescue LoadError
24
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new do |t|
28
+ t.spec_files = FileList['spec/**/*_spec.rb']
29
+ end
30
+
31
+ desc "Run all examples with RCov"
32
+ Spec::Rake::SpecTask.new('rcov') do |t|
33
+ t.spec_files = FileList['spec/**/*_spec.rb']
34
+ t.rcov = true
35
+ end
36
+
37
+ # require 'hanna'
38
+ # require 'darkfish-rdoc'
39
+
40
+ Rake::RDocTask.new do |rdoc|
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = 'css3-now'
43
+ rdoc.options << '--line-numbers' << '--inline-source'
44
+ # rdoc.options += ["--template=#{`allison --path`}"] # sudo gem install allison
45
+ # rdoc.options += %w( -f darkfish ) # sudo gem install darkfish-rdoc
46
+ # rdoc.options += %w( -T hanna ) # sudo gem install mislav-hanna
47
+ rdoc.options += %w( -m README.rdoc ) # the initial page displayed
48
+ rdoc.rdoc_files.include('README.rdoc')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
51
+
52
+ desc 'Confirm that gemspec is $SAFE'
53
+ task :safe do
54
+ require 'yaml'
55
+ require 'rubygems/specification'
56
+ data = File.read('css3-now.gemspec')
57
+ spec = nil
58
+ if data !~ %r{!ruby/object:Gem::Specification}
59
+ Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
60
+ else
61
+ spec = YAML.load(data)
62
+ end
63
+ spec.validate
64
+ puts spec
65
+ puts "OK"
66
+ end
67
+
68
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/css3-now.rb ADDED
@@ -0,0 +1,34 @@
1
+ # ...
2
+ class CSS3Now
3
+
4
+ Substitutions = [
5
+ lambda {|css| replace_browser_specific css, 'border-radius' },
6
+ lambda {|css| replace_browser_specific css, 'box-shadow' },
7
+ lambda {|css| css.gsub(/opacity: ([\w\.]+);/){ "filter:alpha(opacity=#{ ($1.to_f * 100).to_i }); opacity: #{ $1 };" } }
8
+ ]
9
+
10
+ def initialize original_css
11
+ @original_css = original_css
12
+ end
13
+
14
+ def to_css
15
+ Substitutions.inject(@original_css) do |css, substitution|
16
+ css = substitution.call css
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def self.browser_specific attribute, value, browsers = nil
23
+ browsers = [ :moz, :webkit, :khtml ] if browsers.nil?
24
+ browsers.inject("") do |all, browser|
25
+ all << "-#{ browser }-#{ attribute }: #{ value }; "
26
+ all
27
+ end + "#{ attribute }: #{ value };"
28
+ end
29
+
30
+ def self.replace_browser_specific css, attribute, browsers = nil
31
+ css.gsub /#{ attribute }: ([-\.\w ]+);/, browser_specific(attribute, '\1', browsers)
32
+ end
33
+
34
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe CSS3Now do
4
+
5
+ it 'should replace border-radius' do
6
+ css = CSS3Now.new("#header {\n border-radius: 5em;\n }").to_css
7
+ css.should == "#header {\n -moz-border-radius: 5em; -webkit-border-radius: 5em; " +
8
+ "-khtml-border-radius: 5em; border-radius: 5em;\n }"
9
+ end
10
+
11
+ it 'should work with spaces in value' do
12
+ css = CSS3Now.new("#header {\n border-radius: 5em 10px -3.4em;\n }").to_css
13
+ css.should == "#header {\n -moz-border-radius: 5em 10px -3.4em; -webkit-border-radius: 5em 10px -3.4em; " +
14
+ "-khtml-border-radius: 5em 10px -3.4em; border-radius: 5em 10px -3.4em;\n }"
15
+ end
16
+
17
+ it 'should work with multiple instances of an attibute'
18
+
19
+ it 'should replace box-shadow' do
20
+ css = CSS3Now.new("#header {\n box-shadow: 5em;\n }").to_css
21
+ css.should == "#header {\n -moz-box-shadow: 5em; -webkit-box-shadow: 5em; " +
22
+ "-khtml-box-shadow: 5em; box-shadow: 5em;\n }"
23
+ end
24
+
25
+ it 'should replace opacity' do
26
+ CSS3Now.new("#x {\n opacity: 0.5;\n }").to_css.should == "#x {\n filter:alpha(opacity=50); opacity: 0.5;\n }"
27
+ end
28
+
29
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.dirname(__FILE__) + '/../lib/css3-now'
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remi-css3-now
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - remi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ""
17
+ email: remi@remitaylor.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - README.rdoc
26
+ - Rakefile
27
+ - VERSION
28
+ - lib/css3-now.rb
29
+ - spec/css3-now_spec.rb
30
+ - spec/spec.opts
31
+ - spec/spec_helper.rb
32
+ has_rdoc: false
33
+ homepage: http://github.com/remi/css3-now
34
+ licenses:
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --charset=UTF-8
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.3.5
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: ""
59
+ test_files:
60
+ - spec/css3-now_spec.rb
61
+ - spec/spec_helper.rb