rbcss 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34613909c22009956e41b30702bf8b59891dbbf6
4
- data.tar.gz: 648787ac4d7dbb4652c99fa820473702f466ecec
3
+ metadata.gz: c8f0b828893535a4825691f879d38dbb81c8e742
4
+ data.tar.gz: 20ef37044748c197e9f89d0520aa9ddca550e20b
5
5
  SHA512:
6
- metadata.gz: 4936a3196561ef88fcdb6329bf546d0978d786dc898f9b0db5ccb5c6c2fe4ee4c4b801ed728b55e8fb4452e62a5ba32f977366c6827eb909c9954a4993d524bc
7
- data.tar.gz: accf51e73db20a9a0b4ac36dad22f533a9f7381bf40e127c2136d0a138b8cfcddd87966557d2f0e16d9fba0b4ac78e920559fa060b8e613dce445b4668cce4d5
6
+ metadata.gz: d6f971cff23c305b0c61ad0c524b1041339c6cf3681d660a5de9b4332d6bc1e8d2de04b5003d9c5079fc563fd051dba5a84913dfab38e8bd879cfc2f37ffb86b
7
+ data.tar.gz: 98ea24e00b3239c62a1c3f8a06d3e4bc0fed8efd9b5a4ac82a119954d0835f81303c9db7513fc5585b3eea3dc6aaec12b4b92a144c0f4e588844f39ef38dc17e
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # Rbcss
1
+ # RBCSS
2
2
 
3
- TODO: Write a gem description
3
+ This is a Ruby DSL library to express the CSS structure as Ruby code. Expressing CSS using a DSL permits the use of all the capabilities of the host language like: functions, classes, modules, variables, hashes, array etc.
4
+
5
+ This library does not intend to make CSS property or value validations, this was left to CSS itself. The purpose here is add dynamic capabilities while writing CSS code.
4
6
 
5
7
  ## Installation
6
8
 
@@ -20,11 +22,71 @@ Or install it yourself as:
20
22
 
21
23
  ## Usage
22
24
 
23
- TODO: Write usage instructions here
25
+ ### Basic Usage
26
+ In a ruby file, require css and pass a block to CSS.style function:
27
+
28
+ ```ruby
29
+ require 'css'
30
+
31
+ CSS.style do
32
+ to("body"){
33
+ background_color "green"
34
+ }
35
+ to("section.main div:nth-of-type(1)"){
36
+ width "100%"
37
+ height "64px"
38
+ }
39
+ end
40
+ ```
41
+ Run your file with Ruby and the output will be echoed to $stdout.
42
+
43
+ ### Writing to a file
44
+
45
+ You can add a $stdout.reopen above CSS.style call to change the $stdout to a file with the same name as your Ruby file but with .css extension:
46
+
47
+ ```ruby
48
+ require 'css'
49
+
50
+ $stdout.reopen("#{$0.gsub('rb', 'css')}")
51
+ CSS.style do
52
+ #...
53
+ end
54
+ ```
55
+ or you can use shell:
56
+
57
+ $ ruby mycss.rb > mycss.css
58
+
59
+ ### Adding functionality
60
+
61
+ You can create mixins with modules:
62
+
63
+ ```ruby
64
+ require 'css'
65
+
66
+ module Shadow
67
+ def shadow(color: "grey")
68
+ box_shadow "0px 0px 7px 1px #{color}"
69
+ _webkit_shadow "0px 0px 7px 1px #{color}"
70
+ end
71
+ end
72
+
73
+ CSS.style do
74
+ extend Shadow
75
+
76
+ to("body"){
77
+ background_color "green"
78
+ }
79
+ to("section.main div:nth-of-type(1)"){
80
+ width "100%"
81
+ height "64px"
82
+ shadow "rgba(0, 0, 0, 0.12)"
83
+ }
84
+ end
85
+ ```
24
86
 
25
87
  ## Contributing
26
88
 
27
- 1. Fork it ( https://github.com/[my-github-username]/rbcss/fork )
89
+ 1. Fork it ( https://github.com/IvanOM/rbcss/fork )
28
90
  2. Create your feature branch (`git checkout -b my-new-feature`)
29
91
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
92
  4. Push to the branch (`git push origin my-new-feature`)
@@ -0,0 +1,41 @@
1
+ Feature: Converting Ruby DSL code to CSS
2
+
3
+ In order to have flexibility to write CSS
4
+ As an user
5
+ I want to write CSS in Ruby DSL and execute the file
6
+
7
+ Scenario: A simple block of code
8
+ Given a file named "mycss.rb" with:
9
+ """
10
+ require 'css'
11
+
12
+ CSS.style do
13
+ to('body'){
14
+ _webkit_animation "expand 1s linear"
15
+ }
16
+ end
17
+ """
18
+ When I run `ruby mycss.rb`
19
+ Then the output should contain:
20
+ """
21
+ body{-webkit-animation:expand 1s linear;}
22
+ """
23
+
24
+ Scenario: A nested block of code
25
+ Given a file named "mycss.rb" with:
26
+ """
27
+ require 'css'
28
+
29
+ CSS.style do
30
+ to('@media (max-width: 800px)'){
31
+ to('body'){
32
+ _webkit_animation "expand 1s linear"
33
+ }
34
+ }
35
+ end
36
+ """
37
+ When I run `ruby mycss.rb`
38
+ Then the output should contain:
39
+ """
40
+ @media (max-width: 800px){body{-webkit-animation:expand 1s linear;}}
41
+ """
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
data/lib/css.rb CHANGED
@@ -1,21 +1,28 @@
1
- $stdout.reopen("#{$0.gsub('rb', 'css')}")
2
1
  module CSS
3
2
 
3
+ # Send a message to the module_eval method of CSS module. It is just an Alias.
4
+ # @param &block [Proc] the code block to be executed in the CSS context
4
5
  def self.style &block
5
6
  send :module_eval, &block
6
7
  end
7
8
 
9
+ # Write a css selector declaration to $stdout
10
+ # @param selector [String] the selector name or string
8
11
  def self.selector selector, &block
9
12
  $stdout.write "#{selector}{"; yield; $stdout.write "}"
10
13
  end
11
14
 
15
+ # Write a css property declaration with the name of the called method
16
+ # @param method [Symbol] the called method name as a symbol
12
17
  def self.property method, *args, &block
13
18
  $stdout.write "#{method.to_s.gsub('_', '-')}:#{args[0]};"
14
19
  end
15
20
 
21
+ private
22
+
16
23
  def self.method_missing name, *args, &block
17
- send(:selector, *args, &block) if args[0] and block
18
- send(:property, name, *args, &block) if args[0] and !block
24
+ send(:selector, *args, &block) if block
25
+ send(:property, name, *args, &block) if args[0] and !block
19
26
  end
20
27
 
21
28
  end
data/lib/rbcss/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rbcss
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/rbcss.rb CHANGED
@@ -2,7 +2,4 @@ require "rbcss/version"
2
2
 
3
3
  module Rbcss
4
4
 
5
- class RubyCSS
6
-
7
- end
8
5
  end
data/rbcss.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Rbcss::VERSION
9
9
  spec.authors = ["Ivan"]
10
10
  spec.email = ["ivan.eng.controle@gmail.com"]
11
- spec.summary = %q{A Ruy DSL to generate css.}
11
+ spec.summary = %q{A Ruby DSL to generate css.}
12
12
  spec.description = %q{This command line application generates css stylesheets from a Ruby DSL code.}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
@@ -20,4 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "cucumber", "~> 1.0"
24
+ spec.add_development_dependency "aruba", "~> 0.6"
25
+ spec.add_development_dependency "rspec", "~> 3.1"
23
26
  end
data/spec/css_spec.rb ADDED
@@ -0,0 +1,63 @@
1
+ require "css"
2
+
3
+ RSpec.describe CSS, :type => :module do
4
+ describe "#style" do
5
+ it "calls module_eval method" do
6
+ expect(CSS).to receive(:module_eval)
7
+ CSS.style do
8
+ end
9
+ end
10
+ end
11
+
12
+ describe "#property" do
13
+ it "prints a css property declaration to $stdout" do
14
+ expect{
15
+ CSS.style do
16
+ property "color", "green"
17
+ end
18
+ }.to output("color:green;").to_stdout
19
+ end
20
+ end
21
+
22
+ describe "#selector" do
23
+ it "prints a css selector declaration to $stdout" do
24
+ expect{
25
+ CSS.style do
26
+ selector("body"){}
27
+ end
28
+ }.to output("body{}").to_stdout
29
+ end
30
+
31
+ it "yields to a block with properties declarations" do
32
+ expect{
33
+ CSS.style do
34
+ selector("body"){
35
+ color "green"
36
+ }
37
+ end
38
+ }.to output("body{color:green;}").to_stdout
39
+ end
40
+ end
41
+
42
+ describe "calls to the inexistent method to" do
43
+ context "with an argument and a block" do
44
+ it "prints a css selector declaration to $stdout" do
45
+ expect{
46
+ CSS.style do
47
+ to("body"){}
48
+ end
49
+ }.to output("body{}").to_stdout
50
+ end
51
+ end
52
+
53
+ context "with just an argument" do
54
+ it "prints a css property declaration to $stdout" do
55
+ expect{
56
+ CSS.style do
57
+ to "body"
58
+ end
59
+ }.to output("to:body;").to_stdout
60
+ end
61
+ end
62
+ end
63
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbcss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-21 00:00:00.000000000 Z
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,12 +38,53 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: cucumber
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.1'
41
83
  description: This command line application generates css stylesheets from a Ruby DSL
42
84
  code.
43
85
  email:
44
86
  - ivan.eng.controle@gmail.com
45
- executables:
46
- - rbcss
87
+ executables: []
47
88
  extensions: []
48
89
  extra_rdoc_files: []
49
90
  files:
@@ -52,11 +93,13 @@ files:
52
93
  - LICENSE.txt
53
94
  - README.md
54
95
  - Rakefile
55
- - bin/rbcss
96
+ - features/convert_ruby_to_css.feature
97
+ - features/support/env.rb
56
98
  - lib/css.rb
57
99
  - lib/rbcss.rb
58
100
  - lib/rbcss/version.rb
59
101
  - rbcss.gemspec
102
+ - spec/css_spec.rb
60
103
  homepage: ''
61
104
  licenses:
62
105
  - MIT
@@ -77,8 +120,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
120
  version: '0'
78
121
  requirements: []
79
122
  rubyforge_project:
80
- rubygems_version: 2.4.3
123
+ rubygems_version: 2.4.2
81
124
  signing_key:
82
125
  specification_version: 4
83
- summary: A Ruy DSL to generate css.
84
- test_files: []
126
+ summary: A Ruby DSL to generate css.
127
+ test_files:
128
+ - features/convert_ruby_to_css.feature
129
+ - features/support/env.rb
130
+ - spec/css_spec.rb
data/bin/rbcss DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "rbcss"
4
- require "css"
5
-
6
- rubycss = Rbcss::RubyCSS.new
7
-
8
- file = ARGV[0]
9
- $stdout.reopen("#{file}.css", "w")
10
- require "#{file}"