rbss 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/Gemfile +8 -9
  2. data/Gemfile.lock +69 -12
  3. data/{LICENSE.txt → MIT-LICENSE} +1 -1
  4. data/README.md +15 -1
  5. data/Rakefile +26 -40
  6. data/VERSION +1 -1
  7. data/lib/rbss.rb +1 -1
  8. data/lib/rbss/base.rb +80 -0
  9. data/lib/rbss/helper.rb +9 -0
  10. data/lib/rbss/property.rb +3 -2
  11. data/lib/rbss/railtie.rb +10 -0
  12. data/lib/rbss/rbss.rb +6 -58
  13. data/lib/rbss/selector.rb +18 -16
  14. data/lib/rbss/version.rb +3 -0
  15. data/lib/tasks/rbss-tasks.rake +4 -0
  16. data/rbss.gemspec +85 -21
  17. data/spec/{rbss_spec.rb → rbss_base_spec.rb} +9 -9
  18. data/test/dummy/README.rdoc +261 -0
  19. data/test/dummy/Rakefile +7 -0
  20. data/test/dummy/app/assets/javascripts/application.js +15 -0
  21. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  22. data/test/dummy/app/assets/stylesheets/my_file.rbss +14 -0
  23. data/test/dummy/app/controllers/application_controller.rb +3 -0
  24. data/test/dummy/app/controllers/home_controller.rb +7 -0
  25. data/test/dummy/app/helpers/application_helper.rb +3 -0
  26. data/test/dummy/app/mailers/.gitkeep +0 -0
  27. data/test/dummy/app/models/.gitkeep +0 -0
  28. data/test/dummy/app/views/home/index.html.erb +1 -0
  29. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  30. data/test/dummy/config.ru +4 -0
  31. data/test/dummy/config/application.rb +59 -0
  32. data/test/dummy/config/boot.rb +10 -0
  33. data/test/dummy/config/database.yml +25 -0
  34. data/test/dummy/config/environment.rb +5 -0
  35. data/test/dummy/config/environments/development.rb +37 -0
  36. data/test/dummy/config/environments/production.rb +67 -0
  37. data/test/dummy/config/environments/test.rb +37 -0
  38. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/test/dummy/config/initializers/inflections.rb +15 -0
  40. data/test/dummy/config/initializers/mime_types.rb +5 -0
  41. data/test/dummy/config/initializers/secret_token.rb +7 -0
  42. data/test/dummy/config/initializers/session_store.rb +8 -0
  43. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  44. data/test/dummy/config/locales/en.yml +5 -0
  45. data/test/dummy/config/routes.rb +59 -0
  46. data/test/dummy/lib/assets/.gitkeep +0 -0
  47. data/test/dummy/log/.gitkeep +0 -0
  48. data/test/dummy/public/404.html +26 -0
  49. data/test/dummy/public/422.html +26 -0
  50. data/test/dummy/public/500.html +25 -0
  51. data/test/dummy/public/favicon.ico +0 -0
  52. data/test/dummy/script/rails +6 -0
  53. metadata +295 -17
  54. data/.document +0 -5
  55. data/lib/rbss/require.rb +0 -3
data/Gemfile CHANGED
@@ -1,13 +1,12 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
3
+ gemspec
4
+
8
5
  group :development do
9
- gem "rspec", "= 2.13.0"
10
- gem "rdoc"
11
- gem "jeweler"
6
+ gem "jquery-rails"
7
+ gem "shoulda", ">= 0"
8
+ gem "rdoc", "~> 3.12"
9
+ gem "bundler"
10
+ gem "jeweler", "~> 1.8.4"
12
11
  gem "simplecov"
13
- end
12
+ end
data/Gemfile.lock CHANGED
@@ -1,36 +1,93 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rbss (0.2.0)
5
+ rbss
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
4
- diff-lcs (1.2.1)
10
+ actionpack (3.2.13)
11
+ activemodel (= 3.2.13)
12
+ activesupport (= 3.2.13)
13
+ builder (~> 3.0.0)
14
+ erubis (~> 2.7.0)
15
+ journey (~> 1.0.4)
16
+ rack (~> 1.4.5)
17
+ rack-cache (~> 1.2)
18
+ rack-test (~> 0.6.1)
19
+ sprockets (~> 2.2.1)
20
+ activemodel (3.2.13)
21
+ activesupport (= 3.2.13)
22
+ builder (~> 3.0.0)
23
+ activesupport (3.2.13)
24
+ i18n (= 0.6.1)
25
+ multi_json (~> 1.0)
26
+ bourne (1.4.0)
27
+ mocha (~> 0.13.2)
28
+ builder (3.0.4)
29
+ erubis (2.7.0)
5
30
  git (1.2.5)
31
+ hike (1.2.2)
32
+ i18n (0.6.1)
6
33
  jeweler (1.8.4)
7
34
  bundler (~> 1.0)
8
35
  git (>= 1.2.5)
9
36
  rake
10
37
  rdoc
38
+ journey (1.0.4)
39
+ jquery-rails (2.2.1)
40
+ railties (>= 3.0, < 5.0)
41
+ thor (>= 0.14, < 2.0)
11
42
  json (1.7.7)
43
+ metaclass (0.0.1)
44
+ mocha (0.13.3)
45
+ metaclass (~> 0.0.1)
12
46
  multi_json (1.7.2)
47
+ rack (1.4.5)
48
+ rack-cache (1.2)
49
+ rack (>= 0.4)
50
+ rack-ssl (1.3.3)
51
+ rack
52
+ rack-test (0.6.2)
53
+ rack (>= 1.0)
54
+ railties (3.2.13)
55
+ actionpack (= 3.2.13)
56
+ activesupport (= 3.2.13)
57
+ rack-ssl (~> 1.3.2)
58
+ rake (>= 0.8.7)
59
+ rdoc (~> 3.4)
60
+ thor (>= 0.14.6, < 2.0)
13
61
  rake (10.0.4)
14
62
  rdoc (3.12.2)
15
63
  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)
64
+ shoulda (3.4.0)
65
+ shoulda-context (~> 1.0, >= 1.0.1)
66
+ shoulda-matchers (~> 1.0, >= 1.4.1)
67
+ shoulda-context (1.1.1)
68
+ shoulda-matchers (1.5.6)
69
+ activesupport (>= 3.0.0)
70
+ bourne (~> 1.3)
24
71
  simplecov (0.7.1)
25
72
  multi_json (~> 1.0)
26
73
  simplecov-html (~> 0.7.1)
27
74
  simplecov-html (0.7.1)
75
+ sprockets (2.2.2)
76
+ hike (~> 1.2)
77
+ multi_json (~> 1.0)
78
+ rack (~> 1.0)
79
+ tilt (~> 1.1, != 1.3.0)
80
+ thor (0.18.1)
81
+ tilt (1.3.7)
28
82
 
29
83
  PLATFORMS
30
84
  ruby
31
85
 
32
86
  DEPENDENCIES
33
- jeweler
34
- rdoc
35
- rspec (= 2.13.0)
87
+ bundler
88
+ jeweler (~> 1.8.4)
89
+ jquery-rails
90
+ rbss!
91
+ rdoc (~> 3.12)
92
+ shoulda
36
93
  simplecov
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 garbles
1
+ Copyright 2013 Gabriel Scholz
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,11 +2,25 @@
2
2
 
3
3
  Ruby Styling Sheets. Turn Ruby code into valid, minified CSS.
4
4
 
5
+ ## Installation
6
+
7
+ In your Gemfile
8
+
9
+ ```gem rbss```
10
+
5
11
  ## Usage
6
12
 
13
+ Currently, all rbss files are not cached and evaluated on run time.
14
+
15
+ In `layouts/application.html.erb` (or otherwise), include the line
7
16
  ```ruby
8
- Rbss.new('file,names,go,here').evaluate
17
+ <%= rbss('file,names,here') %>
9
18
  ```
19
+ Do not include the .rbss file extension with each name.
20
+
21
+ In `app/assets/stylesheets`, create some files: `file.rbss`, `names.rbss`, `here.rbss` or whatever.
22
+
23
+ The files will be evaluated and minified CSS (in style tags) will replace `<%= rbss('file,names,here') %>`.
10
24
 
11
25
  ## Example
12
26
 
data/Rakefile CHANGED
@@ -1,49 +1,35 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
5
7
  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
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
11
13
  end
12
- require 'rake'
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'rbss'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
13
24
 
14
25
  require 'jeweler'
15
26
  Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
27
  gem.name = "rbss"
18
28
  gem.homepage = "http://github.com/garbles/rbss"
19
29
  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')
30
+ gem.summary = %Q{Generate minified CSS in Ruby on Rails.}
31
+ gem.description = %Q{Generates minified CSS by reading the stack level through method missing calls.}
32
+ gem.email = "gabe.scholz@zozi.com"
33
+ gem.authors = ["Gabriel Scholz"]
49
34
  end
35
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/rbss.rb CHANGED
@@ -1 +1 @@
1
- require_relative 'rbss/require'
1
+ require 'rbss/rbss'
data/lib/rbss/base.rb ADDED
@@ -0,0 +1,80 @@
1
+ module Rbss
2
+ class Base
3
+ def initialize(files)
4
+ if files.is_a?(Array)
5
+ @files = files
6
+ elsif files.is_a?(String)
7
+ @files = files.split(',')
8
+ elsif files.is_a?(Symbol)
9
+ @files = [files.to_s]
10
+ else
11
+ raise 'List of files must be either an Array of Strings or a String of files seperated by commas'
12
+ end
13
+
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
41
+ end
42
+
43
+ def method_missing(method_name, *args, &block)
44
+ if !@fake_stack.nil?
45
+ stack_level = @fake_stack
46
+ @fake_stack = nil
47
+ else
48
+ stack_level = caller.size
49
+ end
50
+
51
+ reverse_stack = @stack.reverse
52
+ parent = reverse_stack[0]
53
+ i = 0
54
+ until parent[0] < stack_level || parent[0] == @top_stack_level
55
+ i += 1
56
+ parent = reverse_stack[i]
57
+ end
58
+
59
+ if block_given?
60
+ selector = Selector.new(method_name.to_s, args)
61
+ if stack_level != @top_stack_level
62
+ selector.identify_parent(parent[1])
63
+ end
64
+ @stack = @stack << [stack_level, selector.name, selector]
65
+ yield
66
+ else
67
+ property = Property.new(method_name.to_s, args.first)
68
+ parent[2].add_to_properties(property)
69
+ end
70
+ 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
+ end
80
+ end
@@ -0,0 +1,9 @@
1
+ module Rbss
2
+ module ApplicationHelper
3
+
4
+ def rbss(files, options = {})
5
+ Rbss::Base.new(files).evaluate(options).html_safe
6
+ end
7
+
8
+ end
9
+ end
data/lib/rbss/property.rb CHANGED
@@ -1,3 +1,4 @@
1
- Property = Struct.new(:name, :value) do
2
-
1
+ module Rbss
2
+ Property = Struct.new(:name, :value) do
3
+ end
3
4
  end
@@ -0,0 +1,10 @@
1
+ module Rbss
2
+ class RbssRailtie < Rails::Railtie
3
+ # initializer "rbss_railtie.configure_rails_initialization" do
4
+ # ActionView::Base.send :include, Rbss::ApplicationHelper
5
+ # end
6
+ config.to_prepare do
7
+ ActionView::Base.send :include, Rbss::ApplicationHelper
8
+ end
9
+ end
10
+ end
data/lib/rbss/rbss.rb CHANGED
@@ -1,59 +1,7 @@
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
1
+ require_relative 'base'
2
+ require_relative 'property'
3
+ require_relative 'selector'
4
+ if defined?(Rails)
5
+ require_relative 'railtie'
6
+ require_relative 'helper'
59
7
  end
data/lib/rbss/selector.rb CHANGED
@@ -1,22 +1,24 @@
1
- Selector = Struct.new(:div, :classes_ids) do
2
- def name
3
- "#{"#{parent} " unless parent.nil?}#{div unless div == '_'}#{classes_ids.join}"
4
- end
1
+ module Rbss
2
+ Selector = Struct.new(:div, :classes_ids) do
3
+ def name
4
+ "#{"#{parent} " unless parent.nil?}#{div unless div == '_'}#{classes_ids.join}"
5
+ end
5
6
 
6
- def identify_parent(name)
7
- @parent = name
8
- end
7
+ def identify_parent(name)
8
+ @parent = name
9
+ end
9
10
 
10
- def parent
11
- @parent
12
- end
11
+ def parent
12
+ @parent
13
+ end
13
14
 
14
- def add_to_properties(property)
15
- properties
16
- @properties << property
17
- end
15
+ def add_to_properties(property)
16
+ properties
17
+ @properties << property
18
+ end
18
19
 
19
- def properties
20
- @properties ||= []
20
+ def properties
21
+ @properties ||= []
22
+ end
21
23
  end
22
24
  end