automatthew-casuistry 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,14 @@
1
+ casuistry.gemspec
2
+ lib/casuistry.rb
3
+ lib/properties.rb
4
+ lib/tags.rb
5
+ Manifest
6
+ README.rdoc
7
+ test/basics.rb
8
+ test/dan.css
9
+ test/experiment.cssy
10
+ test/fiddle.cssy
11
+ test/helper.rb
12
+ test/nesting.cssy
13
+ test/test.css
14
+ test/test.cssy
data/README.rdoc ADDED
@@ -0,0 +1,24 @@
1
+ A CSS companion to Markaby. Would be nice if you could interpolate variables.
2
+
3
+ css = Casuistry.new
4
+ css.instance_eval do
5
+ my_favorite_color = :green
6
+ ul do
7
+ background('red')
8
+ li.ugly do
9
+ color(my_favorite_color)
10
+ end
11
+ smurf.house do
12
+ height('256px')
13
+ end
14
+ asrael! do
15
+ padding("10px")
16
+ end
17
+ end
18
+ outer.middle.inner do
19
+ top("34px")
20
+ end
21
+ end
22
+
23
+ css.data #=> array of arrays
24
+ css.output #=> string of css
data/casuistry.gemspec ADDED
@@ -0,0 +1,60 @@
1
+
2
+ # Gem::Specification for Casuistry-0.1.1
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{casuistry}
7
+ s.version = "0.1.1"
8
+
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.authors = ["Matthew King"]
11
+ s.date = %q{2008-07-07}
12
+ s.description = %q{Generates CSS using Ruby, like Markaby}
13
+ s.email = %q{automatthew@gmail.com}
14
+ s.extra_rdoc_files = ["lib/casuistry.rb", "lib/properties.rb", "lib/tags.rb", "README.rdoc"]
15
+ s.files = ["casuistry.gemspec", "lib/casuistry.rb", "lib/properties.rb", "lib/tags.rb", "Manifest", "README.rdoc", "test/basics.rb", "test/dan.css", "test/experiment.cssy", "test/fiddle.cssy", "test/helper.rb", "test/nesting.cssy", "test/test.css", "test/test.cssy"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Casuistry", "--main", "README.rdoc"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{casuistry}
21
+ s.rubygems_version = %q{1.2.0}
22
+ s.summary = %q{Generates CSS using Ruby, like Markaby}
23
+ s.test_files = ["test/basics.rb", "test/helper.rb"]
24
+
25
+ if s.respond_to? :specification_version then
26
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
+ s.specification_version = 2
28
+
29
+ if current_version >= 3 then
30
+ else
31
+ end
32
+ else
33
+ end
34
+ end
35
+
36
+
37
+ # # Original Rakefile source (requires the Echoe gem):
38
+ #
39
+ # %w{rubygems}.each do |dep|
40
+ # require dep
41
+ # end
42
+ #
43
+ # Version = '0.1.1'
44
+ #
45
+ # task :default => [:test]
46
+ #
47
+ # begin
48
+ # gem 'echoe', '>=2.7'
49
+ # require 'echoe'
50
+ # Echoe.new('casuistry', Version) do |p|
51
+ # p.project = 'casuistry'
52
+ # p.summary = "Generates CSS using Ruby, like Markaby"
53
+ # p.author = "Matthew King"
54
+ # p.email = "automatthew@gmail.com"
55
+ # p.ignore_pattern = /^(\.git).+/
56
+ # p.test_pattern = "test/*.rb"
57
+ # end
58
+ # rescue
59
+ # "(ignored echoe gemification, as you don't have the Right Stuff)"
60
+ # end
data/lib/casuistry.rb ADDED
@@ -0,0 +1,115 @@
1
+ require 'properties'
2
+ require 'tags'
3
+
4
+ # Markaby-ish way to declare CSS
5
+ class Casuistry
6
+
7
+ include Tags
8
+
9
+ attr_reader :data, :assigns
10
+
11
+ def self.process(file)
12
+ cssy = File.read(file)
13
+ c = self.new
14
+ c.process(cssy)
15
+ c
16
+ end
17
+
18
+ def process(string)
19
+ self.instance_eval(string)
20
+ end
21
+
22
+ def initialize(selector=nil)
23
+ @selector = selector
24
+ @data = []
25
+ end
26
+
27
+ def output
28
+ output = ""
29
+ @data.each do |selector|
30
+ output << selector.first
31
+ properties = selector.last.map { |s| " #{s}" }.join("\n")
32
+ output << "\n{\n#{properties}\n}\n"
33
+ end
34
+ output
35
+ end
36
+
37
+ def selector_eval(*args, &block)
38
+ selector = args.compact.join(" ")
39
+ Selector.new(selector, self).instance_eval(&block)
40
+ end
41
+
42
+
43
+ def selectify(method_name)
44
+ matches = method_name.to_s.match( /([\w_]+)!$/)
45
+ matches ? "##{matches[1]}" : ".#{method_name}"
46
+ end
47
+
48
+ def method_missing(name, &block)
49
+ selector = selectify(name)
50
+ if block
51
+ selector_eval(@selector, selector, &block)
52
+ else
53
+ x = [@selector, selector].compact.join(' ')
54
+ Selector.new(x, self)
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ class Selector
61
+ include Tags
62
+ def initialize(base_selector, casuist)
63
+ @selector = base_selector
64
+ @casuist = casuist
65
+ end
66
+
67
+
68
+ def selector_eval(*args, &block)
69
+ selector = args.compact.join(" ")
70
+ if block
71
+ Selector.new(selector, @casuist).instance_eval(&block)
72
+ else
73
+ Selector.new(selector, @casuist)
74
+ end
75
+ end
76
+
77
+ CSS_PROPERTIES.each do |method_name|
78
+ define_method method_name do |*args|
79
+ css_attr = method_name.gsub('_', '-')
80
+ property(css_attr, args)
81
+ end
82
+ end
83
+
84
+ def properties
85
+ if @properties
86
+ return @properties
87
+ else
88
+ @properties ||= []
89
+ @casuist.data << [@selector, @properties]
90
+ @properties
91
+ end
92
+ end
93
+
94
+ def property(css_attr, *args)
95
+ properties << "#{css_attr}: #{args.join(' ')};"
96
+ end
97
+
98
+ def selectify(method_name)
99
+ matches = method_name.to_s.match( /([\w_]+)!$/)
100
+ matches ? "##{matches[1]}" : ".#{method_name}"
101
+ end
102
+
103
+ def method_missing(name, &block)
104
+ selector = selectify(name)
105
+ if block
106
+ selector_eval(@selector, selector, &block)
107
+ else
108
+ x = [@selector, selector].join(' ')
109
+ Selector.new(x, @casuist)
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+ Cssy = Casuistry
data/lib/properties.rb ADDED
@@ -0,0 +1,106 @@
1
+ CSS_PROPERTIES = %w{
2
+ azimuth
3
+ background
4
+ background_attachment
5
+ background_color
6
+ background_image
7
+ background_position
8
+ background_repeat
9
+ border
10
+ border_collapse
11
+ border_color
12
+ border_spacing
13
+ border_style
14
+ border_top
15
+ border_top_color
16
+ border_top_style
17
+ border_top_width
18
+ border_width
19
+ bottom
20
+ caption_side
21
+ clear
22
+ clip
23
+ color
24
+ content
25
+ counter_increment
26
+ counter_reset
27
+ cue
28
+ cue_after
29
+ cue_before
30
+ cursor
31
+ direction
32
+ display
33
+ elevation
34
+ empty_cells
35
+ float
36
+ font
37
+ font_family
38
+ font_size
39
+ font_size_adjust
40
+ font_stretch
41
+ font_style
42
+ font_variant
43
+ font_weight
44
+ height
45
+ left
46
+ letter_spacing
47
+ line_height
48
+ list_style
49
+ list_style_image
50
+ list_style_position
51
+ list_style_type
52
+ margin
53
+ margin_top
54
+ marker_offset
55
+ marks
56
+ max_height
57
+ max_width
58
+ min_height
59
+ min_width
60
+ orphans
61
+ outline
62
+ outline_color
63
+ outline_style
64
+ outline_width
65
+ overflow
66
+ padding
67
+ padding_top
68
+ page
69
+ page_break_after
70
+ page_break_before
71
+ page_break_inside
72
+ pause
73
+ pause_after
74
+ pause_before
75
+ pitch
76
+ pitch_range
77
+ play_during
78
+ position
79
+ quotes
80
+ richness
81
+ right
82
+ size
83
+ speak
84
+ speak_header
85
+ speak_numeral
86
+ speak_punctuation
87
+ speech_rate
88
+ stress
89
+ table_layout
90
+ text_align
91
+ text_decoration
92
+ text_indent
93
+ text_shadow
94
+ text_transform
95
+ top
96
+ unicode_bidi
97
+ vertical_align
98
+ visibility
99
+ voice_family
100
+ volume
101
+ white_space
102
+ widows
103
+ width
104
+ word_spacing
105
+ z_index
106
+ }
data/lib/tags.rb ADDED
@@ -0,0 +1,89 @@
1
+ module Tags
2
+ HTML_TAGS = [
3
+ :a,
4
+ :abbr,
5
+ :acronym,
6
+ :address,
7
+ :area,
8
+ :b,
9
+ :base,
10
+ :bdo,
11
+ :big,
12
+ :blockquote,
13
+ :body,
14
+ :br,
15
+ :button,
16
+ :caption,
17
+ :cite,
18
+ :code,
19
+ :col,
20
+ :colgroup,
21
+ :dd,
22
+ :del,
23
+ :dfn,
24
+ :div,
25
+ :dl,
26
+ :dt,
27
+ :em,
28
+ :fieldset,
29
+ :form,
30
+ :h1,
31
+ :h2,
32
+ :h3,
33
+ :h4,
34
+ :h5,
35
+ :h6,
36
+ :head,
37
+ :hr,
38
+ :html,
39
+ :i,
40
+ :img,
41
+ :input,
42
+ :ins,
43
+ :kbd,
44
+ :label,
45
+ :legend,
46
+ :li,
47
+ :link,
48
+ :map,
49
+ :meta,
50
+ :noscript,
51
+ :object,
52
+ :ol,
53
+ :optgroup,
54
+ :option,
55
+ :p,
56
+ :param,
57
+ :pre,
58
+ :q,
59
+ :samp,
60
+ :script,
61
+ :select,
62
+ :small,
63
+ :span,
64
+ :strong,
65
+ :style,
66
+ :sub,
67
+ :sup,
68
+ :table,
69
+ :tbody,
70
+ :td,
71
+ :textarea,
72
+ :tfoot,
73
+ :th,
74
+ :thead,
75
+ :title,
76
+ :tr,
77
+ :tt,
78
+ :ul,
79
+ :var,
80
+ ]
81
+
82
+ # define tag methods to delegate to selector_eval
83
+ methods = HTML_TAGS.map do |tag|
84
+ "def #{tag}(&block); selector_eval(@selector, '#{tag}', &block);end\n"
85
+ end.join
86
+
87
+ module_eval methods
88
+
89
+ end
data/test/basics.rb ADDED
@@ -0,0 +1,75 @@
1
+ here = File.dirname(__FILE__)
2
+ require "#{here}/helper"
3
+
4
+ describe "Casuistry" do
5
+
6
+ before do
7
+ @string = File.read("test.css")
8
+ @data = [
9
+ [ '.class_name1 .class_name2 .class_name3',
10
+ [ 'font-size: 2em;', 'line-height: 3em;', 'border: 1px solid blue;']],
11
+ [ '#milk',
12
+ ['background-color: blue;', 'border: 1px solid red']]
13
+ ]
14
+ @data2 = [
15
+ [ '#header', ['width: 500px;'] ],
16
+ [ '#header #menu', ['background: gray;']]
17
+ ]
18
+
19
+ @data3 = [
20
+ ["ul", ["background: red;", "width: 134px;"]],
21
+ ["ul li .ugly", ["color: green;"]],
22
+ ["ul .smurf .house", ["height: 256px;"]],
23
+ ["ul #asrael", ["padding: 10px;"]],
24
+ [".gargamel", ["margin: 0px;"]],
25
+ [".outer .middle .inner", ["top: 34px;"]]
26
+ ]
27
+
28
+ @css1 = <<-CSS
29
+ ul
30
+ {
31
+ background: red;
32
+ width: 134px;
33
+ }
34
+ ul li .ugly
35
+ {
36
+ color: green;
37
+ }
38
+ ul .smurf .house
39
+ {
40
+ height: 256px;
41
+ }
42
+ ul #asrael
43
+ {
44
+ padding: 10px;
45
+ }
46
+ .gargamel
47
+ {
48
+ margin: 0px;
49
+ }
50
+ .outer .middle .inner
51
+ {
52
+ top: 34px;
53
+ }
54
+ CSS
55
+ end
56
+
57
+
58
+ it "interprets unknown ! methods as ids and others as classes" do
59
+ c = Casuistry.new
60
+ c.selectify("smurf!").should == "#smurf"
61
+ c.selectify("smurf").should == ".smurf"
62
+ end
63
+
64
+ it "processes cssy code" do
65
+ c = Casuistry.new
66
+ c.instance_eval do
67
+ @background = "red"
68
+ end
69
+ c.process(File.read( "#{here}/fiddle.cssy"))
70
+ c.data.should == @data3
71
+ c.output.should == @css1
72
+ end
73
+
74
+
75
+ end
data/test/dan.css ADDED
@@ -0,0 +1,58 @@
1
+ /* reset.css */
2
+ @import url( /stylesheets/main.css );
3
+ @import url( /stylesheets/products.css );
4
+
5
+ #intro_text a.back {
6
+ padding: 0 0 2px 25px;
7
+ font-weight: bold;
8
+ background: url("/images/icons-back.gif") 0 0 no-repeat;
9
+ }
10
+ div.wizard { margin-right: 8px; float: left; }
11
+
12
+ form ul.properties { display: block; margin: 0; padding: 0; clear: both; }
13
+ li.property { display: block; list-style-type: none; clear: both; padding-bottom: 40px; }
14
+ #content form ul.properties li.property hr { display: block; clear: left; float: none; height: 0; visibility: hidden; margin: -0.66em; padding: 0; }
15
+ form label { float: left; display: block; width: 80px; text-align: right; padding-right: 14px; color: gray; font-weight: bold; font-size: 13px; }
16
+ form div.value { float: left; color: gray; }
17
+ div.radio div.option, div.checkbox div.option { cursor: pointer; }
18
+ li.size div.option { background: url( /images/bt_radio_off.gif) no-repeat; padding-left: 17px; height: 21px; font-size: 13px; }
19
+ li.size div.option.selected { background: url( /images/bt_radio_on.gif) no-repeat; padding-left: 17px; height: 21px; font-size: 13px; }
20
+ li.style div.option { float: left; border: 1px solid silver; padding: 1px; margin-left: 4px; opacity: 0.5; }
21
+ li.style div.option.hover, li.style div.option.selected { border: 1px solid gray; }
22
+ li.style div.option.selected { opacity: 1.0; }
23
+ li.tos div.option { background: url( /images/checkbox.gif ) no-repeat; padding-left: 17px; }
24
+ li.code.property { display: none; }
25
+ div.text.value { margin-top: -4px; }
26
+ div.text.value input { height: 23px; width: 220px; border: none; background: url( /images/textfield_bg.gif) no-repeat;
27
+ padding: 4px; font-size: 11px; font-weight: bold; color: gray; }
28
+ div.text.value textarea { width: 280px; height: 184px; font-size: 11px; color: gray; }
29
+ div.preview { float: left ; height: 400px; }
30
+ div.preview iframe { border: none; display: block; position: relative; width: 490px; height: 340px; border: 1px solid silver; margin: 4px; padding: 30px 0; }
31
+
32
+ div.ac_results { border: 1px solid silver; text-align: left; background-color: white; color: gray; padding: 5px; margin-top: -8px; }
33
+
34
+ img.title { padding-bottom: 8px; }
35
+
36
+ ul.steps { display: block; margin: 0; padding: 0; clear: both; }
37
+
38
+ ul.steps li.step {
39
+ display: none; width: 403px; height: 335px;
40
+ margin-left: 2px; padding: 16px;
41
+ list-style-type: none;
42
+ border: 1px solid silver;
43
+ }
44
+ u.steps li.step.selected { display: block; }
45
+
46
+ div.tab-selector span {
47
+ color: gray;
48
+ font-size: 11px; text-align: center;
49
+ display: block; float: left; height: 26px; width: 129px; padding: 12px 8px 0px 8px;
50
+ background: url( /images/tab/unselected.gif ) repeat-x; cursor: pointer;
51
+ }
52
+
53
+ div.tab-selector span.selected {
54
+ /* border-right: 1px solid gray; border-left: 1px solid gray; border-top: 1px solid silver; */
55
+ font-weight: bold; color: black;
56
+ background: url( /images/tab/selected.gif ) repeat-x;
57
+ }
58
+
@@ -0,0 +1,19 @@
1
+ selector "div.foo > ul.bar" do
2
+
3
+ width "137px"
4
+ color :blue
5
+
6
+ selector "a:hover" do
7
+ color :red
8
+ background :gray
9
+ end
10
+
11
+ child "li.monkey" do
12
+ list_style :none
13
+ end
14
+
15
+ sibling "p" do
16
+ margin "10px"
17
+ end
18
+
19
+ end
data/test/fiddle.cssy ADDED
@@ -0,0 +1,29 @@
1
+ favorite = 'green'
2
+
3
+ ul do
4
+
5
+ background('red')
6
+
7
+ li.ugly do
8
+ color(favorite)
9
+ end
10
+
11
+ smurf.house do
12
+ height('256px')
13
+ end
14
+
15
+ asrael! do
16
+ padding("10px")
17
+ end
18
+
19
+ width('134px')
20
+
21
+ end
22
+
23
+ gargamel do
24
+ margin("0px")
25
+ end
26
+
27
+ outer.middle.inner do
28
+ top("34px")
29
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,8 @@
1
+ %w{ rubygems bacon facon }.each { |dep| require dep }
2
+
3
+ Bacon.extend Bacon::TestUnitOutput
4
+ Bacon.summary_on_exit
5
+
6
+ $:.unshift "#{File.dirname(__FILE__)}/../lib"
7
+ require 'casuistry'
8
+
data/test/nesting.cssy ADDED
@@ -0,0 +1,13 @@
1
+ div.header! do
2
+ width('500px')
3
+
4
+ ul.menu! do
5
+ background(:gray)
6
+ end
7
+
8
+ end
9
+
10
+ data2 = [
11
+ [ '#header', ['width: 500px;'] ],
12
+ [ '#header #menu', ['background: gray;']]
13
+ ]
data/test/test.css ADDED
@@ -0,0 +1,11 @@
1
+ .class_name1 .class_name2 .class_name3
2
+ {
3
+ font-size: 2em;
4
+ line-height: 3em;
5
+ border: 1px solid blue;
6
+ }
7
+ #milk
8
+ {
9
+ background-color: blue;
10
+ border: 1px solid red;
11
+ }
data/test/test.cssy ADDED
@@ -0,0 +1,11 @@
1
+ # test.cssy
2
+
3
+ # anonymous selector
4
+ selector 'ul > li' do
5
+
6
+ end
7
+
8
+ # named selector
9
+ menu_header 'div#header h3' do
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: automatthew-casuistry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew King
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-07 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Generates CSS using Ruby, like Markaby
17
+ email: automatthew@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - lib/casuistry.rb
24
+ - lib/properties.rb
25
+ - lib/tags.rb
26
+ - README.rdoc
27
+ files:
28
+ - casuistry.gemspec
29
+ - lib/casuistry.rb
30
+ - lib/properties.rb
31
+ - lib/tags.rb
32
+ - Manifest
33
+ - README.rdoc
34
+ - test/basics.rb
35
+ - test/dan.css
36
+ - test/experiment.cssy
37
+ - test/fiddle.cssy
38
+ - test/helper.rb
39
+ - test/nesting.cssy
40
+ - test/test.css
41
+ - test/test.cssy
42
+ has_rdoc: true
43
+ homepage: ""
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --line-numbers
47
+ - --inline-source
48
+ - --title
49
+ - Casuistry
50
+ - --main
51
+ - README.rdoc
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: casuistry
69
+ rubygems_version: 1.2.0
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: Generates CSS using Ruby, like Markaby
73
+ test_files:
74
+ - test/basics.rb
75
+ - test/helper.rb