ruby_css 0.0.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/bin/ruby-css ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "ruby_css/version"
4
+ puts RubyCss::VERSION
@@ -0,0 +1,4 @@
1
+
2
+ module RubyCss
3
+ VERSION = "0.0.0"
4
+ end
data/lib/ruby_css.rb ADDED
@@ -0,0 +1,108 @@
1
+
2
+ module RubyCss
3
+
4
+ class Selector
5
+
6
+ attr_accessor :name, :properties, :children
7
+
8
+ def initialize(name, &blk)
9
+ @properties = {}
10
+ @name = name.to_s
11
+ @children = []
12
+ instance_eval(&blk)
13
+ end
14
+
15
+ # Generates CSS for the given selector name.
16
+ #
17
+ # Example:
18
+ # s('h1.title') { font_size '2em' }
19
+ #
20
+ # Generates:
21
+ # h1.title {
22
+ # font-size: 2em;
23
+ # }
24
+ #
25
+ def s(selector_name, &blk)
26
+ @children << Selector.new("#{@name} #{selector_name}", &blk)
27
+ end
28
+
29
+ # Generates CSS for a given ID.
30
+ #
31
+ # Example:
32
+ # id('posts') { font_size '12px' }
33
+ #
34
+ # Generates:
35
+ # #posts {
36
+ # font-size: 12px;
37
+ # }
38
+ #
39
+ def id(id_name, &blk)
40
+ @children << Selector.new("#{@name} \##{id_name}", &blk)
41
+ end
42
+
43
+ # Generates CSS for a given class name.
44
+ #
45
+ # Example:
46
+ # c('post') { font_size '12px' }
47
+ #
48
+ # Generates:
49
+ # .post {
50
+ # font-size: 12px;
51
+ # }
52
+ #
53
+ def c(id_name, &blk)
54
+ @children << Selector.new("#{@name} .#{id_name}", &blk)
55
+ end
56
+
57
+ # Handles generation of CSS for any HTML tag.
58
+ #
59
+ # Example:
60
+ # nav { float 'right' }
61
+ #
62
+ # Generates:
63
+ # nav {
64
+ # float: right;
65
+ # }
66
+ #
67
+ # TODO: Create selectors only for valid HTML tags.
68
+ #
69
+ def method_missing(method_name, *args, &blk)
70
+ if block_given?
71
+ @children << Selector.new([@name, method_name].join(' '), &blk)
72
+ else
73
+ @properties[method_name.to_s.sub('_', '-')] = args[0]
74
+ end
75
+ end
76
+
77
+ # Generates the formatted output CSS as a string.
78
+ #
79
+ def to_s
80
+ css = "#{@name} {\n"
81
+ @properties.each_pair { |k, v| css += " #{k}: #{v};\n" }
82
+ css += "}\n\n"
83
+ @children.each { |c| css += c.to_s }
84
+ css
85
+ end
86
+
87
+ end
88
+
89
+ class Stylesheet
90
+
91
+ def initialize(file)
92
+ @__selectors = []
93
+ instance_eval( File.read(file) )
94
+ end
95
+
96
+ def method_missing(method_name, *args, &blk)
97
+ @__selectors << Selector.new(method_name, &blk) if block_given?
98
+ end
99
+
100
+ def to_css
101
+ puts "\n\n"
102
+ @__selectors.each do |s|
103
+ puts s.to_s
104
+ end
105
+ end
106
+
107
+ end
108
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_css
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nithin Bekal
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-22 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Generate CSS through Ruby code.
15
+ email:
16
+ - nithinbekal@gmail.com
17
+ executables:
18
+ - ruby-css
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/ruby_css.rb
23
+ - lib/ruby_css/version.rb
24
+ - bin/ruby-css
25
+ homepage: http://github.com/nithinbekal/ruby_css
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.5
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Generate CSS through Ruby code
49
+ test_files: []