rbss 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "= 2.13.0"
10
+ gem "rdoc"
11
+ gem "jeweler"
12
+ gem "simplecov"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.1)
5
+ git (1.2.5)
6
+ jeweler (1.8.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.7.7)
12
+ multi_json (1.7.2)
13
+ rake (10.0.4)
14
+ rdoc (3.12.2)
15
+ json (~> 1.4)
16
+ rspec (2.13.0)
17
+ rspec-core (~> 2.13.0)
18
+ rspec-expectations (~> 2.13.0)
19
+ rspec-mocks (~> 2.13.0)
20
+ rspec-core (2.13.1)
21
+ rspec-expectations (2.13.0)
22
+ diff-lcs (>= 1.1.3, < 2.0)
23
+ rspec-mocks (2.13.0)
24
+ simplecov (0.7.1)
25
+ multi_json (~> 1.0)
26
+ simplecov-html (~> 0.7.1)
27
+ simplecov-html (0.7.1)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ jeweler
34
+ rdoc
35
+ rspec (= 2.13.0)
36
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 garbles
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,80 @@
1
+ # rbss
2
+
3
+ Ruby Styling Sheets. Turn Ruby code into valid, minified CSS.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ Rbss.new('file,names,go,here').evaluate
9
+ ```
10
+
11
+ ## Example
12
+
13
+ #### A simple example
14
+
15
+ ```ruby
16
+ body do
17
+ color 'black'
18
+ width '95px'
19
+ end
20
+
21
+ span '.bacon' do
22
+ padding '50px'
23
+ font_size '16px'
24
+ div '#div' do
25
+ color 'yellow'
26
+ div '.class' do
27
+ width '44px'
28
+ end
29
+ end
30
+
31
+ div '.potato' do
32
+ text_align 'right'
33
+ end
34
+ end
35
+
36
+ _ '#cats' do
37
+ height '100px'
38
+ end
39
+ ```
40
+
41
+ evaluates to
42
+
43
+ ```css
44
+ body{color:black;width:95px;}span.bacon{padding:50px;font-size:16px;}span.bacon div#div{color:yellow;}span.bacon div#div div.class{width:44px;}span.bacon div.potato{text-align:right;}#cats{height:100px;}
45
+ ```
46
+
47
+ #### A more sexy example
48
+
49
+ ```ruby
50
+ #custom logic
51
+ def fake_bacon
52
+ '95px'
53
+ end
54
+
55
+ def super_fake_bacon(value)
56
+ value.downcase
57
+ end
58
+
59
+ super_duper_fake_bacon = '1px 1px'
60
+
61
+ #rbss
62
+ body '#okay.goodbye' do
63
+ width fake_bacon
64
+ color super_fake_bacon("WHITE")
65
+ a '.success' do
66
+ margin super_duper_fake_bacon
67
+ end
68
+ end
69
+ ```
70
+
71
+ evaluates to
72
+
73
+ ```css
74
+ body#okay.goodbye{width:95px;color:white;}body#okay.goodbye a.success{margin:1px 1px;}
75
+ ```
76
+
77
+ ## Copyright
78
+
79
+ Copyright (c) 2013 Gabe Scholz. See LICENSE.txt for
80
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rbss"
18
+ gem.homepage = "http://github.com/garbles/rbss"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Generate minified CSS in Ruby}
21
+ gem.description = %Q{Generate minified CSS by exploiting Ruby's metaprogramming capabilities}
22
+ gem.email = "scholz.gabe@gmail.com"
23
+ gem.authors = ["garbles"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "rbss #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,3 @@
1
+ Property = Struct.new(:name, :value) do
2
+
3
+ end
data/lib/rbss/rbss.rb ADDED
@@ -0,0 +1,59 @@
1
+ class Rbss
2
+ def initialize(files)
3
+ if files.is_a?(Array)
4
+ @files = files
5
+ elsif files.is_a?(String)
6
+ @files = files.split(',')
7
+ else
8
+ raise 'List of files must be either an Array of Strings or a String of files seperated by commas'
9
+ end
10
+
11
+ @top_stack_level = caller.size - 1
12
+ @stack = [[@top_stack_level, nil, Selector.new(nil,nil)]] # stack level, name, object
13
+ end
14
+
15
+ def read
16
+ @files.each do |file|
17
+ eval File.open(file).read
18
+ end
19
+ end
20
+
21
+ def parse
22
+ css = ''
23
+ @stack.last(@stack.size-1).each do |pancake|
24
+ css << "#{pancake[1]}{"
25
+ pancake[2].properties.each do |property|
26
+ css << "#{property.name.gsub('_','-')}:#{property.value};"
27
+ end
28
+ css << "}"
29
+ end
30
+ css
31
+ end
32
+
33
+ def evaluate
34
+ read
35
+ parse
36
+ end
37
+
38
+ def method_missing(method_name, *args, &block)
39
+ parent = @stack.last
40
+ i = 0
41
+ until parent[0] < caller.size || parent[0] == @top_stack_level
42
+ parent = @stack.reverse[i]
43
+ i += 1
44
+ end
45
+
46
+ if block_given?
47
+ selector = Selector.new(method_name.to_s, args)
48
+ if caller.size != @top_stack_level
49
+ selector.identify_parent(parent[1])
50
+ end
51
+ @stack = @stack << [caller.size, selector.name, selector]
52
+ @parent_cell = @stack.size - 1
53
+ yield
54
+ else
55
+ property = Property.new(method_name.to_s, args.first)
56
+ parent[2].add_to_properties(property)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'rbss'
2
+ require_relative 'property'
3
+ require_relative 'selector'
@@ -0,0 +1,22 @@
1
+ Selector = Struct.new(:div, :classes_ids) do
2
+ def name
3
+ "#{"#{parent} " unless parent.nil?}#{div unless div == '_'}#{classes_ids.join}"
4
+ end
5
+
6
+ def identify_parent(name)
7
+ @parent = name
8
+ end
9
+
10
+ def parent
11
+ @parent
12
+ end
13
+
14
+ def add_to_properties(property)
15
+ properties
16
+ @properties << property
17
+ end
18
+
19
+ def properties
20
+ @properties ||= []
21
+ end
22
+ end
data/lib/rbss.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative 'rbss/require'
data/rbss.gemspec ADDED
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rbss"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["garbles"]
12
+ s.date = "2013-04-21"
13
+ s.description = "Generate minified CSS by exploiting Ruby's metaprogramming capabilities"
14
+ s.email = "scholz.gabe@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/rbss.rb",
29
+ "lib/rbss/property.rb",
30
+ "lib/rbss/rbss.rb",
31
+ "lib/rbss/require.rb",
32
+ "lib/rbss/selector.rb",
33
+ "rbss.gemspec",
34
+ "spec/rbss_spec.rb",
35
+ "spec/spec_helper.rb",
36
+ "spec/test/complex.rbss",
37
+ "spec/test/simple.rbss"
38
+ ]
39
+ s.homepage = "http://github.com/garbles/rbss"
40
+ s.licenses = ["MIT"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = "1.8.23"
43
+ s.summary = "Generate minified CSS in Ruby"
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, ["= 2.13.0"])
50
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
51
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
52
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<rspec>, ["= 2.13.0"])
55
+ s.add_dependency(%q<rdoc>, [">= 0"])
56
+ s.add_dependency(%q<jeweler>, [">= 0"])
57
+ s.add_dependency(%q<simplecov>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<rspec>, ["= 2.13.0"])
61
+ s.add_dependency(%q<rdoc>, [">= 0"])
62
+ s.add_dependency(%q<jeweler>, [">= 0"])
63
+ s.add_dependency(%q<simplecov>, [">= 0"])
64
+ end
65
+ end
66
+
data/spec/rbss_spec.rb ADDED
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Rbss" do
4
+
5
+ context "when evaluating a simple file" do
6
+ let(:simple_file) { File.dirname(__FILE__) + "/test/simple.rbss" }
7
+ let(:expected_result) { "body{color:black;width:95px;}span.bacon{padding:50px;font-size:16px;}span.bacon div#div{color:yellow;}span.bacon div#div div.class{width:44px;}span.bacon div.potato{text-align:right;}#cats{height:100px;}" }
8
+ subject { Rbss.new(simple_file) }
9
+
10
+ its(:evaluate) { should == expected_result }
11
+
12
+ context "when evaluating a simple file twice" do
13
+ subject { Rbss.new([simple_file, simple_file]) }
14
+ its(:evaluate) { should == expected_result + expected_result }
15
+ end
16
+ end
17
+
18
+ context "when evaluating a complex file" do
19
+ let(:complex_file) { File.dirname(__FILE__) + "/test/complex.rbss" }
20
+ let(:expected_result) { "body#okay.goodbye{width:95px;color:white;}body#okay.goodbye a.success{margin:1px 1px;}" }
21
+ subject { Rbss.new(complex_file) }
22
+
23
+ its(:evaluate) { should == expected_result }
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'rbss'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,20 @@
1
+ #custom logic
2
+ def fake_bacon
3
+ '95px'
4
+ end
5
+
6
+ def super_fake_bacon(value)
7
+ value.downcase
8
+ end
9
+
10
+ super_duper_fake_bacon = '1px 1px'
11
+
12
+
13
+ #rbss
14
+ body '#okay.goodbye' do
15
+ width fake_bacon
16
+ color super_fake_bacon("WHITE")
17
+ a '.success' do
18
+ margin super_duper_fake_bacon
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ body do
2
+ color 'black'
3
+ width '95px'
4
+ end
5
+
6
+ span '.bacon' do
7
+ padding '50px'
8
+ font_size '16px'
9
+ div '#div' do
10
+ color 'yellow'
11
+ div '.class' do
12
+ width '44px'
13
+ end
14
+ end
15
+
16
+ div '.potato' do
17
+ text_align 'right'
18
+ end
19
+ end
20
+
21
+ _ '#cats' do
22
+ height '100px'
23
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbss
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - garbles
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.13.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.13.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeweler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Generate minified CSS by exploiting Ruby's metaprogramming capabilities
79
+ email: scholz.gabe@gmail.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files:
83
+ - LICENSE.txt
84
+ - README.md
85
+ files:
86
+ - .document
87
+ - .rspec
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE.txt
91
+ - README.md
92
+ - Rakefile
93
+ - VERSION
94
+ - lib/rbss.rb
95
+ - lib/rbss/property.rb
96
+ - lib/rbss/rbss.rb
97
+ - lib/rbss/require.rb
98
+ - lib/rbss/selector.rb
99
+ - rbss.gemspec
100
+ - spec/rbss_spec.rb
101
+ - spec/spec_helper.rb
102
+ - spec/test/complex.rbss
103
+ - spec/test/simple.rbss
104
+ homepage: http://github.com/garbles/rbss
105
+ licenses:
106
+ - MIT
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ segments:
118
+ - 0
119
+ hash: 1290096207954111731
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.23
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Generate minified CSS in Ruby
132
+ test_files: []