rbss 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,12 +1,2 @@
1
1
  source "http://rubygems.org"
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem "jquery-rails"
7
- gem "shoulda", ">= 0"
8
- gem "rdoc", "~> 3.12"
9
- gem "bundler"
10
- gem "jeweler", "~> 1.8.4"
11
- gem "simplecov"
12
- end
2
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,83 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbss (0.2.2)
4
+ rbss (0.2.3)
5
+ rbss
5
6
 
6
7
  GEM
7
8
  remote: http://rubygems.org/
8
9
  specs:
9
- actionpack (3.2.13)
10
- activemodel (= 3.2.13)
11
- activesupport (= 3.2.13)
12
- builder (~> 3.0.0)
13
- erubis (~> 2.7.0)
14
- journey (~> 1.0.4)
15
- rack (~> 1.4.5)
16
- rack-cache (~> 1.2)
17
- rack-test (~> 0.6.1)
18
- sprockets (~> 2.2.1)
19
- activemodel (3.2.13)
20
- activesupport (= 3.2.13)
21
- builder (~> 3.0.0)
22
- activesupport (3.2.13)
23
- i18n (= 0.6.1)
24
- multi_json (~> 1.0)
25
- bourne (1.4.0)
26
- mocha (~> 0.13.2)
27
- builder (3.0.4)
28
- erubis (2.7.0)
10
+ diff-lcs (1.2.4)
29
11
  git (1.2.5)
30
- hike (1.2.2)
31
- i18n (0.6.1)
32
12
  jeweler (1.8.4)
33
13
  bundler (~> 1.0)
34
14
  git (>= 1.2.5)
35
15
  rake
36
16
  rdoc
37
- journey (1.0.4)
38
- jquery-rails (2.2.1)
39
- railties (>= 3.0, < 5.0)
40
- thor (>= 0.14, < 2.0)
41
17
  json (1.7.7)
42
- metaclass (0.0.1)
43
- mocha (0.13.3)
44
- metaclass (~> 0.0.1)
45
18
  multi_json (1.7.2)
46
- rack (1.4.5)
47
- rack-cache (1.2)
48
- rack (>= 0.4)
49
- rack-ssl (1.3.3)
50
- rack
51
- rack-test (0.6.2)
52
- rack (>= 1.0)
53
- railties (3.2.13)
54
- actionpack (= 3.2.13)
55
- activesupport (= 3.2.13)
56
- rack-ssl (~> 1.3.2)
57
- rake (>= 0.8.7)
58
- rdoc (~> 3.4)
59
- thor (>= 0.14.6, < 2.0)
60
19
  rake (10.0.4)
61
20
  rdoc (3.12.2)
62
21
  json (~> 1.4)
63
- shoulda (3.4.0)
64
- shoulda-context (~> 1.0, >= 1.0.1)
65
- shoulda-matchers (~> 1.0, >= 1.4.1)
66
- shoulda-context (1.1.1)
67
- shoulda-matchers (1.5.6)
68
- activesupport (>= 3.0.0)
69
- bourne (~> 1.3)
22
+ rspec (2.13.0)
23
+ rspec-core (~> 2.13.0)
24
+ rspec-expectations (~> 2.13.0)
25
+ rspec-mocks (~> 2.13.0)
26
+ rspec-core (2.13.1)
27
+ rspec-expectations (2.13.0)
28
+ diff-lcs (>= 1.1.3, < 2.0)
29
+ rspec-mocks (2.13.1)
70
30
  simplecov (0.7.1)
71
31
  multi_json (~> 1.0)
72
32
  simplecov-html (~> 0.7.1)
73
33
  simplecov-html (0.7.1)
74
- sprockets (2.2.2)
75
- hike (~> 1.2)
76
- multi_json (~> 1.0)
77
- rack (~> 1.0)
78
- tilt (~> 1.1, != 1.3.0)
79
- thor (0.18.1)
80
- tilt (1.3.7)
34
+ sqlite3 (1.3.7)
81
35
 
82
36
  PLATFORMS
83
37
  ruby
@@ -85,8 +39,8 @@ PLATFORMS
85
39
  DEPENDENCIES
86
40
  bundler
87
41
  jeweler (~> 1.8.4)
88
- jquery-rails
89
42
  rbss!
90
43
  rdoc (~> 3.12)
91
- shoulda
44
+ rspec
92
45
  simplecov
46
+ sqlite3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/lib/rbss/base.rb CHANGED
@@ -2,79 +2,49 @@ module Rbss
2
2
  class Base
3
3
  def initialize(files)
4
4
  if files.is_a?(Array)
5
- @files = files
5
+ @@files = files
6
6
  elsif files.is_a?(String)
7
- @files = files.split(',')
7
+ @@files = files.split(',')
8
8
  elsif files.is_a?(Symbol)
9
- @files = [files.to_s]
9
+ @@files = [files.to_s]
10
+ elsif files.is_a?(NilClass)
11
+ @@files = nil
10
12
  else
11
13
  raise 'List of files must be either an Array of Strings or a String of files seperated by commas'
12
14
  end
13
15
 
14
- @top_stack_level = caller.size - 1
15
- @stack = [[@top_stack_level, nil, Selector.new(nil,nil)]] # stack level, name, object
16
- @fake_stack = nil
17
- end
18
-
19
- def read(root = defined?(Rails) ? "#{Rails.root.join('app', 'assets', 'stylesheets')}/" : nil)
20
- @files.each do |file|
21
- finder = "#{root}#{file}.rbss"
22
- eval File.open(finder).read
23
- end
24
- end
25
-
26
- def parse
27
- css = ''
28
- @stack.last(@stack.size-1).each do |pancake|
29
- css << "#{pancake[1]}{"
30
- pancake[2].properties.each do |property|
31
- css << "#{property.name.gsub('_','-')}:#{property.value};"
32
- end
33
- css << "}"
34
- end
35
- "<style>" + css + "</style>"
36
- end
37
-
38
- def evaluate(options = {})
39
- read
40
- parse
16
+ @@top_stack_level = caller.size - 1
17
+ @@stack = [[@@top_stack_level, nil, Selector.new(nil,nil)]] # stack level, name, object
18
+ @@fake_stack = nil
41
19
  end
42
20
 
43
21
  def method_missing(method_name, *args, &block)
44
- if !@fake_stack.nil?
45
- stack_level = @fake_stack
46
- @fake_stack = nil
22
+ if !@@fake_stack.nil?
23
+ stack_level = @@fake_stack
24
+ @@fake_stack = nil
47
25
  else
48
- stack_level = caller.size
26
+ stack_level = caller.size - (@offset || 0)
49
27
  end
50
28
 
51
- reverse_stack = @stack.reverse
29
+ reverse_stack = @@stack.reverse
52
30
  parent = reverse_stack[0]
53
31
  i = 0
54
- until parent[0] < stack_level || parent[0] == @top_stack_level
32
+ until parent[0] < stack_level || parent[0] == @@top_stack_level
55
33
  i += 1
56
34
  parent = reverse_stack[i]
57
35
  end
58
-
36
+
59
37
  if block_given?
60
38
  selector = Selector.new(method_name.to_s, args)
61
- if stack_level != @top_stack_level
39
+ if stack_level != @@top_stack_level
62
40
  selector.identify_parent(parent[1])
63
41
  end
64
- @stack = @stack << [stack_level, selector.name, selector]
42
+ @@stack = @@stack << [stack_level, selector.name, selector]
65
43
  yield
66
44
  else
67
45
  property = Property.new(method_name.to_s, args.first)
68
46
  parent[2].add_to_properties(property)
69
47
  end
70
48
  end
71
-
72
- def p(*args, &block)
73
- @fake_stack = caller.size
74
- method_missing('p', *args) do
75
- yield
76
- end
77
- end
78
-
79
49
  end
80
50
  end
@@ -0,0 +1,7 @@
1
+ module Rbss
2
+ class Custom < Base
3
+ def initialize
4
+ @offset = 1
5
+ end
6
+ end
7
+ end
data/lib/rbss/helper.rb CHANGED
@@ -2,7 +2,7 @@ module Rbss
2
2
  module ApplicationHelper
3
3
 
4
4
  def rbss(files, options = {})
5
- Rbss::Base.new(files).evaluate(options).html_safe
5
+ Rbss::Parser.new(files).evaluate(options).html_safe
6
6
  end
7
7
 
8
8
  end
@@ -0,0 +1,35 @@
1
+ module Rbss
2
+ class Parser < Base
3
+ def read(root = defined?(Rails) ? "#{Rails.root.join('app', 'assets', 'stylesheets')}/" : nil)
4
+ @@files.each do |file|
5
+ finder = "#{root}#{file}.rbss"
6
+ eval File.open(finder).read
7
+ end
8
+ end
9
+
10
+ def parse
11
+ css = ''
12
+ @@stack.last(@@stack.size-1).each do |pancake|
13
+ css << "#{pancake[1]}{"
14
+ pancake[2].properties.each do |property|
15
+ css << "#{property.name.gsub('_','-')}:#{property.value};"
16
+ end
17
+ css << "}"
18
+ end
19
+ "<style>" + css + "</style>"
20
+ end
21
+
22
+ def evaluate(options = {})
23
+ read
24
+ parse
25
+ end
26
+
27
+ def p(*args, &block)
28
+ @@fake_stack = caller.size
29
+ method_missing('p', *args) do
30
+ yield
31
+ end
32
+ end
33
+
34
+ end
35
+ end
data/lib/rbss/railtie.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  module Rbss
2
2
  class RbssRailtie < Rails::Railtie
3
- # initializer "rbss_railtie.configure_rails_initialization" do
4
- # ActionView::Base.send :include, Rbss::ApplicationHelper
5
- # end
6
3
  config.to_prepare do
7
4
  ActionView::Base.send :include, Rbss::ApplicationHelper
8
5
  end
data/lib/rbss/rbss.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require_relative 'base'
2
+ require_relative 'parser'
3
+ require_relative 'custom'
2
4
  require_relative 'property'
3
5
  require_relative 'selector'
4
6
  if defined?(Rails)
data/rbss.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rbss"
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gabriel Scholz"]
12
- s.date = "2013-04-28"
12
+ s.date = "2013-05-02"
13
13
  s.description = "Generates minified CSS by reading the stack level through method missing calls."
14
14
  s.email = "gabe.scholz@zozi.com"
15
15
  s.extra_rdoc_files = [
@@ -25,7 +25,9 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "lib/rbss.rb",
27
27
  "lib/rbss/base.rb",
28
+ "lib/rbss/custom.rb",
28
29
  "lib/rbss/helper.rb",
30
+ "lib/rbss/parser.rb",
29
31
  "lib/rbss/property.rb",
30
32
  "lib/rbss/railtie.rb",
31
33
  "lib/rbss/rbss.rb",
@@ -33,9 +35,10 @@ Gem::Specification.new do |s|
33
35
  "lib/rbss/version.rb",
34
36
  "lib/tasks/rbss-tasks.rake",
35
37
  "rbss.gemspec",
36
- "spec/rbss_base_spec.rb",
38
+ "spec/rbss_parser_spec.rb",
37
39
  "spec/spec_helper.rb",
38
40
  "spec/test/complex.rbss",
41
+ "spec/test/css_class.rbss",
39
42
  "spec/test/simple.rbss",
40
43
  "test/dummy/README.rdoc",
41
44
  "test/dummy/Rakefile",
@@ -79,4 +82,34 @@ Gem::Specification.new do |s|
79
82
  s.rubygems_version = "1.8.23"
80
83
  s.summary = "Generate minified CSS in Ruby on Rails."
81
84
 
85
+ if s.respond_to? :specification_version then
86
+ s.specification_version = 3
87
+
88
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
89
+ s.add_runtime_dependency(%q<rbss>, [">= 0"])
90
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
91
+ s.add_development_dependency(%q<rspec>, [">= 0"])
92
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
93
+ s.add_development_dependency(%q<bundler>, [">= 0"])
94
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
95
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
96
+ else
97
+ s.add_dependency(%q<rbss>, [">= 0"])
98
+ s.add_dependency(%q<sqlite3>, [">= 0"])
99
+ s.add_dependency(%q<rspec>, [">= 0"])
100
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
101
+ s.add_dependency(%q<bundler>, [">= 0"])
102
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
103
+ s.add_dependency(%q<simplecov>, [">= 0"])
104
+ end
105
+ else
106
+ s.add_dependency(%q<rbss>, [">= 0"])
107
+ s.add_dependency(%q<sqlite3>, [">= 0"])
108
+ s.add_dependency(%q<rspec>, [">= 0"])
109
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
110
+ s.add_dependency(%q<bundler>, [">= 0"])
111
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
112
+ s.add_dependency(%q<simplecov>, [">= 0"])
113
+ end
82
114
  end
115
+
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Rbss::Parser do
4
+
5
+ subject { described_class.new(file) }
6
+
7
+ context "when evaluating a simple file" do
8
+ let(:file) { "spec/test/simple" }
9
+ 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;}" }
10
+
11
+ its(:evaluate) { should == wrap_in_style { expected_result } }
12
+
13
+ context "when evaluating a simple file twice" do
14
+ subject { described_class.new([file, file]) }
15
+ its(:evaluate) { should == wrap_in_style { expected_result + expected_result } }
16
+ end
17
+ end
18
+
19
+ context "when evaluating a complex file" do
20
+ let(:file) { "spec/test/complex" }
21
+ let(:expected_result) { "body#okay.goodbye{width:95px;color:white;}body#okay.goodbye a.success{margin:1px 1px;}" }
22
+
23
+ its(:evaluate) { should == wrap_in_style { expected_result } }
24
+ end
25
+
26
+ context "When evaluating methods of a css class file" do
27
+ let(:file) { "spec/test/css_class" }
28
+ let(:expected_result) { "canvas{height:50px;width:100px;}" }
29
+
30
+ its(:evaluate) { should == "<style>" + expected_result + "</style>" }
31
+
32
+ context "Where there is a css class file and a simple" do
33
+ let(:another_file) { "spec/test/complex" }
34
+ let(:another_expected_result) { "body#okay.goodbye{width:95px;color:white;}body#okay.goodbye a.success{margin:1px 1px;}" }
35
+ subject { described_class.new([file, another_file]) }
36
+
37
+ its(:evaluate) { should == wrap_in_style { expected_result + another_expected_result } }
38
+ end
39
+ end
40
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,3 +10,8 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
10
  RSpec.configure do |config|
11
11
 
12
12
  end
13
+
14
+ #helper methods
15
+ def wrap_in_style
16
+ "<style>" + yield + "</style>"
17
+ end
@@ -0,0 +1,10 @@
1
+ class SomeCSSClass < Rbss::Custom
2
+ def build_it
3
+ canvas do
4
+ height '50px'
5
+ width '100px'
6
+ end
7
+ end
8
+ end
9
+
10
+ SomeCSSClass.new.build_it
@@ -10,6 +10,4 @@
10
10
  // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
11
  // GO AFTER THE REQUIRES BELOW.
12
12
  //
13
- //= require jquery
14
- //= require jquery_ujs
15
- //= require_tree .
13
+ //= require_tree .
@@ -1,3 +1,19 @@
1
+ class SomeCSSClass < Rbss::Custom
2
+ def build_it
3
+ canvas do
4
+ height '50px'
5
+ width '100px'
6
+ dance_dance
7
+ end
8
+ end
9
+
10
+ def dance_dance
11
+ a '.submit' do
12
+ color 'blue'
13
+ end
14
+ end
15
+ end
16
+
1
17
  html do
2
18
  font_size '500%'
3
19
  end
@@ -11,4 +27,9 @@ div do
11
27
  p '#blue' do
12
28
  color 'blue'
13
29
  end
30
+ end
31
+
32
+ div '#catface' do
33
+ text_align 'right'
34
+ SomeCSSClass.new.build_it
14
35
  end
@@ -1,3 +1,2 @@
1
1
  module ApplicationHelper
2
-
3
2
  end
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- Dummy::Application.config.secret_token = 'acd73408689b491d81d928d39791212e95da687e1bf0ea92f6dd1ddbe3a6bd67bf18d2e771fe42b7a6a276185a80f8bb8d1169346df4f2773c10586465a5f953'
7
+ Dummy::Application.config.secret_token = 'd80d597ad490fdaf25f4f1c62aa6823f5e6e8dd8f7f74da299300ef609bdf90dbfec5c1360b63f2213d85325cf08ef24be584f3777a15dbe1936ff01033c52fa'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-28 00:00:00.000000000 Z
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rbss
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: jquery-rails
31
+ name: sqlite3
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
@@ -44,7 +44,7 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: shoulda
47
+ name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -140,7 +140,9 @@ files:
140
140
  - VERSION
141
141
  - lib/rbss.rb
142
142
  - lib/rbss/base.rb
143
+ - lib/rbss/custom.rb
143
144
  - lib/rbss/helper.rb
145
+ - lib/rbss/parser.rb
144
146
  - lib/rbss/property.rb
145
147
  - lib/rbss/railtie.rb
146
148
  - lib/rbss/rbss.rb
@@ -148,9 +150,10 @@ files:
148
150
  - lib/rbss/version.rb
149
151
  - lib/tasks/rbss-tasks.rake
150
152
  - rbss.gemspec
151
- - spec/rbss_base_spec.rb
153
+ - spec/rbss_parser_spec.rb
152
154
  - spec/spec_helper.rb
153
155
  - spec/test/complex.rbss
156
+ - spec/test/css_class.rbss
154
157
  - spec/test/simple.rbss
155
158
  - test/dummy/README.rdoc
156
159
  - test/dummy/Rakefile
@@ -202,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
205
  version: '0'
203
206
  segments:
204
207
  - 0
205
- hash: -2285444922700302913
208
+ hash: 3491439648690247056
206
209
  required_rubygems_version: !ruby/object:Gem::Requirement
207
210
  none: false
208
211
  requirements:
@@ -1,25 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe Rbss::Base do
4
-
5
- context "when evaluating a simple file" do
6
- let(:simple_file) { "spec/test/simple" }
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 { described_class.new(simple_file) }
9
-
10
- its(:evaluate) { should == "<style>" + expected_result + "</style>" }
11
-
12
- context "when evaluating a simple file twice" do
13
- subject { described_class.new([simple_file, simple_file]) }
14
- its(:evaluate) { should == "<style>" + expected_result + expected_result + "</style>" }
15
- end
16
- end
17
-
18
- context "when evaluating a complex file" do
19
- let(:complex_file) { "spec/test/complex" }
20
- let(:expected_result) { "body#okay.goodbye{width:95px;color:white;}body#okay.goodbye a.success{margin:1px 1px;}" }
21
- subject { described_class.new(complex_file) }
22
-
23
- its(:evaluate) { should == "<style>" + expected_result + "</style>" }
24
- end
25
- end