paggio 0.2.4 → 0.2.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03850a7f3bf3978f419ccc6e7189ef8377f43780
4
- data.tar.gz: 04c931b87504e60e8716e8e99871141242c7a3fa
3
+ metadata.gz: 1d1920260c7987e407745d55bee4b68cb3863fc7
4
+ data.tar.gz: 85e07d23af662cea97458b190900a147d174525c
5
5
  SHA512:
6
- metadata.gz: bf6b9403e176a1cfc3cbbc106d129592b2ca98049dc2b0263cb96f22b005bbaf6e8558e1a7d539ef8162d25712c421fceae5dee06fa48c44c2c68786a946d639
7
- data.tar.gz: 277e56800dbd8144c90701e5bb0f1bb6de6b9548edb76efc768af2f48d64ea0d3abaa78dde069703b14ecd7a5becc508abb697b3406ac15c849d9e5dd4682791
6
+ metadata.gz: c7004ebc7443c84654f9c38c2331220d1a2687f9af9508e5288046a64aa39b54cef8bff3654207a97a4367d965d6f49bca2aed65a6788410523c20e207cb247f
7
+ data.tar.gz: 9c5d4da6163c49968c00889c2ee919d0515604ce1a314ccafbc0462189d34b398d4bf366cfe3bcdbec1ef4fd21a1562a4d2332cf8898f3392bec3a09679d9e7c
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'rake'
5
+ gem 'rspec'
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ paggio (0.2.4)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.1.1)
11
+ rspec (2.14.1)
12
+ rspec-core (~> 2.14.0)
13
+ rspec-expectations (~> 2.14.0)
14
+ rspec-mocks (~> 2.14.0)
15
+ rspec-core (2.14.8)
16
+ rspec-expectations (2.14.5)
17
+ diff-lcs (>= 1.1.3, < 2.0)
18
+ rspec-mocks (2.14.6)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ paggio!
25
+ rake
26
+ rspec
data/Rakefile CHANGED
@@ -1,16 +1,10 @@
1
1
  #! /usr/bin/env ruby
2
2
  require 'rake'
3
3
 
4
- task :default => [:install, :test]
5
-
6
- task :install do
7
- sh 'gem install --no-force rspec'
8
- sh 'gem build *.gemspec'
9
- sh 'gem install *.gem'
10
- end
4
+ task :default => :test
11
5
 
12
6
  task :test do
13
7
  FileUtils.cd 'spec' do
14
- sh 'rspec css_spec.rb --backtrace --color --format doc'
8
+ sh 'rspec css_spec.rb html_spec.rb --backtrace --color --format doc'
15
9
  end
16
10
  end
@@ -11,12 +11,13 @@
11
11
  require 'paggio/css/unit'
12
12
  require 'paggio/css/color'
13
13
  require 'paggio/css/definition'
14
+ require 'paggio/css/rule'
15
+ require 'paggio/css/font'
16
+ require 'paggio/css/animation'
14
17
 
15
18
  class Paggio
16
19
 
17
20
  class CSS < BasicObject
18
- Rule = ::Struct.new(:selector, :definition)
19
-
20
21
  def self.selector(list)
21
22
  result = ''
22
23
 
@@ -35,14 +36,16 @@ class CSS < BasicObject
35
36
  end
36
37
  end
37
38
 
38
- attr_reader :rules
39
+ attr_reader :rules, :media, :fonts, :animations
39
40
 
40
41
  def initialize(&block)
41
42
  ::Kernel.raise ::ArgumentError, 'no block given' unless block
42
43
 
43
- @selector = []
44
- @current = []
45
- @rules = []
44
+ @selector = []
45
+ @current = []
46
+ @rules = []
47
+ @fonts = []
48
+ @animations = []
46
49
 
47
50
  if block.arity == 0
48
51
  instance_exec(&block)
@@ -60,19 +63,49 @@ class CSS < BasicObject
60
63
 
61
64
  names.each {|name|
62
65
  @selector << name
63
- @current << Rule.new(CSS.selector(@selector), Definition.new)
66
+ @current << Rule.new(CSS.selector(@selector), @media)
64
67
 
65
- block.call(self)
68
+ block.call
66
69
 
67
70
  @selector.pop
68
71
  @rules << @current.pop
69
72
  }
70
73
  end
71
74
 
75
+ def media(query, *args, &block)
76
+ if block
77
+ old, @media = @media, query
78
+ block.call
79
+ @media = old
80
+ else
81
+ method_missing(:media, query, *args)
82
+ end
83
+ end
84
+
85
+ def font(name, *args, &block)
86
+ if block
87
+ @current << Font.new(name)
88
+ block.call
89
+ @fonts << @current.pop
90
+ else
91
+ method_missing(:font, name, *args)
92
+ end
93
+ end
94
+
95
+ def animation(name, *args, &block)
96
+ if block
97
+ @current << Animation.new(name)
98
+ block.call
99
+ @animations << @current.pop
100
+ else
101
+ method_missing(:animation, name, *args)
102
+ end
103
+ end
104
+
72
105
  # this is needed because the methods inside the rule blocks are actually
73
106
  # called on the CSS object
74
- def method_missing(name, *args, &block)
75
- @current.last.definition.__send__(name, *args, &block)
107
+ def method_missing(*args, &block)
108
+ @current.last.__send__(*args, &block)
76
109
  end
77
110
  end
78
111
 
@@ -0,0 +1,54 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ class Paggio; class CSS < BasicObject
12
+
13
+ class Animation < BasicObject
14
+ class Step < BasicObject
15
+ attr_reader :value
16
+
17
+ def initialize(value)
18
+ @value = value
19
+ @definition = Definition.new
20
+ end
21
+
22
+ def method_missing(*args, &block)
23
+ @definition.__send__(*args, &block)
24
+ end
25
+ end
26
+
27
+ attr_reader :name, :steps
28
+
29
+ def initialize(name)
30
+ @name = name
31
+ @steps = []
32
+ end
33
+
34
+ def step(value, &block)
35
+ @steps << Step.new(value)
36
+ block.call
37
+ end
38
+
39
+ def from(value, &block)
40
+ @steps << Step.new(0.%)
41
+ block.call
42
+ end
43
+
44
+ def to(value, &block)
45
+ @steps << Step.new(100.%)
46
+ block.call
47
+ end
48
+
49
+ def method_missing(*args, &block)
50
+ @steps.last.__send__(*args, &block)
51
+ end
52
+ end
53
+
54
+ end; end
@@ -35,10 +35,40 @@ class Definition < BasicObject
35
35
  Gradient.new(*args)
36
36
  end
37
37
 
38
- def url(arg)
39
- "url(#{arg.inspect})"
38
+ def url(value)
39
+ "url(#{value.to_s.inspect})"
40
40
  end
41
41
 
42
+ %w[url blur brightness rotate contrast grayscale invert opacity saturate sepia].each {|name|
43
+ define_method name do |value|
44
+ "#{name}(#{value})"
45
+ end
46
+ }
47
+
48
+ def rgb(r, g, b)
49
+ "rgb(#{r}, #{g}, #{b}, #{a})"
50
+ end
51
+
52
+ def rgba(r, g, b, a)
53
+ "rgba(#{r}, #{g}, #{b}, #{a})"
54
+ end
55
+
56
+ %w[scale skew translate].each {|name|
57
+ define_method name do |a, b = nil|
58
+ if b
59
+ "#{name}(#{a}, #{b})"
60
+ else
61
+ "#{name}(#{a})"
62
+ end
63
+ end
64
+ }
65
+
66
+ %w[translateX translateY translateZ rotateX rotateY rotateZ skewX skewY scaleX scaleY].each {|name|
67
+ define_method name do |value|
68
+ "#{name}(#{value})"
69
+ end
70
+ }
71
+
42
72
  def background(*args)
43
73
  if Gradient === args.first
44
74
  if args.length > 1
@@ -67,6 +97,15 @@ class Definition < BasicObject
67
97
 
68
98
  options.each {|name, value|
69
99
  case name
100
+ when :top, :bottom, :left, :right
101
+ if ::Hash === value
102
+ value.each {|n, v|
103
+ style "border-#{name}-#{n}", v
104
+ }
105
+ else
106
+ style "border-#{name}", value
107
+ end
108
+
70
109
  when :radius
71
110
  if ::Hash === value
72
111
  value.each {|horizontal, value|
@@ -135,8 +174,19 @@ class Definition < BasicObject
135
174
  end
136
175
 
137
176
  def animation(*args)
138
- style 'animation', args
139
- style '-webkit-animation', args
177
+ if Hash === args.first
178
+ if args.length == 1
179
+ options = args.first
180
+ end
181
+
182
+ options.each {|name, value|
183
+ style "-webkit-animation-#{name}", value
184
+ style "animation-#{name}", value
185
+ }
186
+ else
187
+ style 'animation', args
188
+ style '-webkit-animation', args
189
+ end
140
190
  end
141
191
 
142
192
  def transition(*args)
@@ -145,14 +195,36 @@ class Definition < BasicObject
145
195
  style '-moz-transition', args
146
196
  end
147
197
 
198
+ def user_select(*args)
199
+ style 'user-select', args
200
+ style '-webkit-user-select', args
201
+ style '-moz-user-select', args
202
+ style '-ms-user-select', args
203
+ end
204
+
205
+ def transform(*args)
206
+ style 'transform', args
207
+ style '-webkit-transform', args
208
+ style '-moz-transform', args
209
+ style '-ms-transform', args
210
+ style '-o-transform', args
211
+ end
212
+
213
+ def filter(*args)
214
+ style 'filter', args
215
+ style '-webkit-filter', args
216
+ style '-moz-filter', args
217
+ style '-ms-filter', args
218
+ style '-o-filter', args
219
+ end
220
+
148
221
  def method_missing(name, *args, &block)
149
- name = name.to_s
150
- important = name.end_with? ?!
151
- name = name[0 .. -2] if important
222
+ name = name.to_s
152
223
 
153
- @important = true if important
224
+ if name.end_with? ?!
225
+ name = name[0 .. -2]
154
226
 
155
- if important && respond_to?(name)
227
+ @important = true
156
228
  __send__ name, *args, &block
157
229
  @important = false
158
230
 
@@ -0,0 +1,28 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ class Paggio; class CSS < BasicObject
12
+
13
+ class Font < BasicObject
14
+ attr_reader :name
15
+
16
+ def initialize(name)
17
+ @name = name
18
+ @definition = Definition.new
19
+
20
+ font family: name
21
+ end
22
+
23
+ def method_missing(*args, &block)
24
+ @definition.__send__(*args, &block)
25
+ end
26
+ end
27
+
28
+ end; end
@@ -0,0 +1,27 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ class Paggio; class CSS < BasicObject
12
+
13
+ class Rule < BasicObject
14
+ attr_reader :selector, :media
15
+
16
+ def initialize(selector, media)
17
+ @selector = selector
18
+ @media = media
19
+ @definition = Definition.new
20
+ end
21
+
22
+ def method_missing(*args, &block)
23
+ @definition.__send__(*args, &block)
24
+ end
25
+ end
26
+
27
+ end; end
@@ -78,11 +78,21 @@ class Formatter
78
78
 
79
79
  def indent(&block)
80
80
  if indent?
81
- @options[:indent][:level] += 1
82
- block.call
83
- @options[:indent][:level] -= 1
81
+ if block
82
+ @options[:indent][:level] += 1
83
+ block.call
84
+ @options[:indent][:level] -= 1
85
+ else
86
+ @options[:indent][:level] += 1
87
+ end
84
88
  else
85
- block.call
89
+ block.call if block
90
+ end
91
+ end
92
+
93
+ def deindent
94
+ if indent?
95
+ @options[:indent][:level] -= 1
86
96
  end
87
97
  end
88
98
 
@@ -140,6 +150,11 @@ Formatter.for HTML::Element do |f, item|
140
150
  f.print "<#{name} #{attrs.join(' ')}>"
141
151
  end
142
152
 
153
+ next if %w[
154
+ area base br col embed hr img input keygen link
155
+ menuitem meta param source track wbr
156
+ ].include?(name.to_s.downcase)
157
+
143
158
  f.indent {
144
159
  if inner = item.instance_eval { @inner_html }
145
160
  f.print inner
@@ -166,17 +181,55 @@ Formatter.for HTML::Element do |f, item|
166
181
  f.print "</#{name}>"
167
182
  end
168
183
 
184
+ Formatter.for CSS::Definition::Style do |f, style|
185
+ f.print "#{style.name}: #{style.value}#{' !important' if style.important};"
186
+ end
187
+
169
188
  Formatter.for CSS do |f, item|
189
+ item.fonts.each {|font|
190
+ f.print '@font-face {'
191
+ f.indent {
192
+ font.each {|style|
193
+ f.format style
194
+ }
195
+ }
196
+ f.print '}'
197
+ }
198
+
199
+ item.animations.each {|animation|
200
+ ['', '-webkit-', '-moz-', '-o-'].each {|platform|
201
+ f.print "@#{platform}keyframes #{animation.name} {"
202
+ animation.steps.each {|step|
203
+ f.print "#{step.value} {"
204
+ step.each {|style|
205
+ f.format style
206
+ }
207
+ f.print '}'
208
+ }
209
+ f.print '}'
210
+ }
211
+ }
212
+
170
213
  item.rules.reverse.each {|rule|
171
- next if rule.definition.empty?
214
+ next if rule.empty?
215
+
216
+ if m = rule.media
217
+ f.print "@media #{m} {"
218
+ f.indent
219
+ end
172
220
 
173
221
  f.print "#{rule.selector} {"
174
222
  f.indent {
175
- rule.definition.each {|style|
176
- f.print "#{style.name}: #{style.value}#{' !important' if style.important};"
223
+ rule.each {|style|
224
+ f.format style
177
225
  }
178
226
  }
179
227
  f.print '}'
228
+
229
+ if rule.media
230
+ f.print '}'
231
+ f.deindent
232
+ end
180
233
  }
181
234
  end
182
235
 
@@ -13,9 +13,13 @@ require 'paggio/html/element/base'
13
13
  require 'paggio/html/element/blockquote'
14
14
  require 'paggio/html/element/button'
15
15
  require 'paggio/html/element/canvas'
16
+ require 'paggio/html/element/embed'
16
17
  require 'paggio/html/element/img'
17
18
  require 'paggio/html/element/input'
18
19
  require 'paggio/html/element/object'
20
+ require 'paggio/html/element/option'
21
+ require 'paggio/html/element/optgroup'
22
+ require 'paggio/html/element/select'
19
23
  require 'paggio/html/element/td'
20
24
 
21
25
  class Paggio; class HTML < BasicObject
@@ -52,15 +56,20 @@ class Element < BasicObject
52
56
  end
53
57
 
54
58
  def method_missing(name, content = nil, &block)
55
- if content
56
- self << ::Paggio::Utils.heredoc(content.to_s)
57
- end
58
-
59
59
  if name.to_s.end_with? ?!
60
60
  @attributes[:id] = name[0 .. -2]
61
61
  else
62
- @last = name
63
- @class_names.push(name)
62
+ @class_names << name
63
+ end
64
+
65
+ if ::Hash === content
66
+ if content.has_key?(:class) || content.has_key?(:classes)
67
+ @class_names.unshift(*(content.delete(:class).to_s.split | content.delete(:classes).to_a))
68
+ end
69
+
70
+ ::Paggio::Utils.deep_merge!(@attributes, content)
71
+ elsif content
72
+ self >> content
64
73
  end
65
74
 
66
75
  @owner.extend!(self, &block) if block
@@ -69,10 +78,9 @@ class Element < BasicObject
69
78
  end
70
79
 
71
80
  def [](*names)
72
- return unless @last
73
-
74
- @class_names.pop
75
- @class_names.push([@last, *names].join('-'))
81
+ if last = @class_names.pop
82
+ @class_names << [last, *names].join('-')
83
+ end
76
84
 
77
85
  self
78
86
  end
@@ -83,6 +91,11 @@ class Element < BasicObject
83
91
  self
84
92
  end
85
93
 
94
+ def >>(content)
95
+ self << ::Paggio::Utils.heredoc(content.to_s)
96
+ self
97
+ end
98
+
86
99
  defhelper :style do |hash|
87
100
  @attributes[:style] = hash.map {|name, value|
88
101
  "#{name}: #{value}"
@@ -27,7 +27,7 @@ class A < self
27
27
  media: :media,
28
28
  }.each {|name, attribute|
29
29
  defhelper name do |value|
30
- @attributes[attribute] = value.to_s
30
+ @attributes[name] = value.to_s
31
31
  end
32
32
  }
33
33
 
@@ -17,7 +17,7 @@ class Base < self
17
17
  target: :target,
18
18
  }.each {|name, attribute|
19
19
  defhelper name do |value|
20
- @attributes[attribute] = value.to_s
20
+ @attributes[name] = value.to_s
21
21
  end
22
22
  }
23
23
  end
@@ -22,7 +22,7 @@ class Button < self
22
22
  target: :formtarget,
23
23
  }.each {|name, attributes|
24
24
  defhelper name do |value|
25
- @attributes[attribute] = value.to_s
25
+ @attributes[name] = value.to_s
26
26
  end
27
27
  }
28
28
 
@@ -15,7 +15,7 @@ class Canvas < self
15
15
  height: :height
16
16
  }.each {|name, attribute|
17
17
  defhelper name do |value|
18
- @attributes[attribute] = value.to_s
18
+ @attributes[name] = value.to_s
19
19
  end
20
20
  }
21
21
  end
@@ -0,0 +1,24 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ class Paggio; class HTML < BasicObject; class Element < BasicObject
12
+
13
+ class Embed < self
14
+ { type: :type,
15
+ height: :height,
16
+ width: :width
17
+ }.each {|name, attribute|
18
+ defhelper name do |value|
19
+ @attributes[name] = value
20
+ end
21
+ }
22
+ end
23
+
24
+ end; end; end
@@ -23,7 +23,7 @@ class Img < self
23
23
  map: :usemap,
24
24
  }.each {|name, attribute|
25
25
  defhelper name do |value|
26
- @attributes[attribute] = value.to_s
26
+ @attributes[name] = value.to_s
27
27
  end
28
28
  }
29
29
 
@@ -18,9 +18,10 @@ class Input < self
18
18
  place_holder: :placeholder,
19
19
  read_only: :readonly,
20
20
  required: :required,
21
+ limit: :maxlength
21
22
  }.each {|name, attribute|
22
23
  defhelper name do |value|
23
- @attributes[attribute] = value
24
+ @attributes[name] = value
24
25
  end
25
26
  }
26
27
  end
@@ -19,7 +19,7 @@ class Object < self
19
19
  width: :width
20
20
  }.each {|name, attribute|
21
21
  defhelper name do |value|
22
- @attributes[attribute] = value
22
+ @attributes[name] = value
23
23
  end
24
24
  }
25
25
  end
@@ -0,0 +1,24 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ class Paggio; class HTML < BasicObject; class Element < BasicObject
12
+
13
+ class Optgroup < self
14
+ %w[label value].each {|name|
15
+ defhelper name do |value|
16
+ @attributes[name] = value
17
+ end
18
+ }
19
+
20
+ defhelper! :disabled
21
+ defhelper! :selected
22
+ end
23
+
24
+ end; end; end
@@ -0,0 +1,24 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ class Paggio; class HTML < BasicObject; class Element < BasicObject
12
+
13
+ class Option < self
14
+ %w[label value].each {|name|
15
+ defhelper name do |value|
16
+ @attributes[name] = value
17
+ end
18
+ }
19
+
20
+ defhelper! :disabled
21
+ defhelper! :selected
22
+ end
23
+
24
+ end; end; end
@@ -0,0 +1,25 @@
1
+ #--
2
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
+ # Version 2, December 2004
4
+ #
5
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
+ #
8
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
+ #++
10
+
11
+ class Paggio; class HTML < BasicObject; class Element < BasicObject
12
+
13
+ class Select < self
14
+ %w[form name size].each {|name|
15
+ defhelper name do |value|
16
+ @attributes[name] = value
17
+ end
18
+ }
19
+
20
+ defhelper! :auto_focus, :autofocus
21
+ defhelper! :disabled
22
+ defhelper! :required
23
+ end
24
+
25
+ end; end; end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new {|s|
2
2
  s.name = 'paggio'
3
- s.version = '0.2.4'
3
+ s.version = '0.2.5'
4
4
  s.author = 'meh.'
5
5
  s.email = 'meh@schizofreni.co'
6
6
  s.homepage = 'http://github.com/meh/paggio'
@@ -8,7 +8,7 @@ describe Paggio::CSS do
8
8
  end
9
9
  end
10
10
 
11
- css.to_s.should == "#lol {\n\tcolor: black;\n}\n"
11
+ expect(css.to_s).to eq("#lol {\n\tcolor: black;\n}\n")
12
12
  end
13
13
 
14
14
  it 'builds border-radius correctly' do
@@ -18,7 +18,7 @@ describe Paggio::CSS do
18
18
  end
19
19
  end
20
20
 
21
- css.to_s.should == "#lol {\n\t-moz-border-radius: 5px;\n\t-webkit-border-radius: 5px;\n\tborder-radius: 5px;\n}\n"
21
+ expect(css.to_s).to eq("#lol {\n\t-moz-border-radius: 5px;\n\t-webkit-border-radius: 5px;\n\tborder-radius: 5px;\n}\n")
22
22
 
23
23
  css = Paggio.css do
24
24
  rule '#lol' do
@@ -26,7 +26,7 @@ describe Paggio::CSS do
26
26
  end
27
27
  end
28
28
 
29
- css.to_s.should == "#lol {\n\t-moz-border-radius-topleft: 5px;\n\t-webkit-border-top-left-radius: 5px;\n\tborder-top-left-radius: 5px;\n}\n"
29
+ expect(css.to_s).to eq("#lol {\n\t-moz-border-radius-topleft: 5px;\n\t-webkit-border-top-left-radius: 5px;\n\tborder-top-left-radius: 5px;\n}\n")
30
30
  end
31
31
 
32
32
  it 'builds box-shadow correctly' do
@@ -36,6 +36,20 @@ describe Paggio::CSS do
36
36
  end
37
37
  end
38
38
 
39
- css.to_s.should == "#lol {\n\t-moz-box-shadow: 0 0 5px black;\n\t-webkit-box-shadow: 0 0 5px black;\n\tbox-shadow: 0 0 5px black;\n}\n"
39
+ expect(css.to_s).to eq("#lol {\n\t-moz-box-shadow: 0 0 5px black;\n\t-webkit-box-shadow: 0 0 5px black;\n\tbox-shadow: 0 0 5px black;\n}\n")
40
+ end
41
+
42
+ it 'builds @font-face' do
43
+ css = Paggio.css do
44
+ font 'hue' do
45
+ src url('test')
46
+ end
47
+ end
48
+
49
+ expect(css.to_s).to eq("@font-face {\n\tfont-family: hue;\n\tsrc: url(\"test\");\n}\n")
50
+ end
51
+
52
+ it 'builds @keyframes' do
53
+
40
54
  end
41
55
  end
@@ -0,0 +1,153 @@
1
+ require 'paggio'
2
+
3
+ describe Paggio::HTML do
4
+ it 'builds an element' do
5
+ html = Paggio.html! do
6
+ div
7
+ end
8
+
9
+ expect(html.to_s).to eq("<div>\n</div>\n")
10
+ end
11
+
12
+ it 'builds an element with text content' do
13
+ html = Paggio.html! do
14
+ div "foo bar"
15
+ end
16
+
17
+ expect(html.to_s).to eq("<div>\n\tfoo bar\n</div>\n")
18
+
19
+ html = Paggio.html! do
20
+ div do
21
+ "foo bar"
22
+ end
23
+ end
24
+
25
+ expect(html.to_s).to eq("<div>\n\tfoo bar\n</div>\n")
26
+ end
27
+
28
+ it 'builds an element with attributes' do
29
+ html = Paggio.html! do
30
+ div class: :wut
31
+ end
32
+
33
+ expect(html.to_s).to eq("<div class=\"wut\">\n</div>\n")
34
+ end
35
+
36
+ it 'builds deeper trees' do
37
+ html = Paggio.html! do
38
+ div do
39
+ span do
40
+ "wut"
41
+ end
42
+ end
43
+ end
44
+
45
+ expect(html.to_s).to eq("<div>\n\t<span>\n\t\twut\n\t</span>\n</div>\n")
46
+ end
47
+
48
+ it 'sets classes with methods' do
49
+ html = Paggio.html! do
50
+ div.nice.element
51
+ end
52
+
53
+ expect(html.to_s).to eq("<div class=\"nice element\">\n</div>\n")
54
+ end
55
+
56
+ it 'nests when setting classes' do
57
+ html = Paggio.html! do
58
+ div.nice.element do
59
+ span.nicer 'lol'
60
+ end
61
+ end
62
+
63
+ expect(html.to_s).to eq("<div class=\"nice element\">\n\t<span class=\"nicer\">\n\t\tlol\n\t</span>\n</div>\n")
64
+ end
65
+
66
+ it 'joins class name properly' do
67
+ html = Paggio.html! do
68
+ i.icon[:legal]
69
+ end
70
+
71
+ expect(html.to_s).to eq("<i class=\"icon-legal\">\n</i>\n")
72
+
73
+ html = Paggio.html! do
74
+ i.icon.icon[:legal, :shmegal]
75
+ end
76
+
77
+ expect(html.to_s).to eq("<i class=\"icon icon-legal-shmegal\">\n</i>\n")
78
+ end
79
+
80
+ it 'sets the id' do
81
+ html = Paggio.html! do
82
+ div.omg!
83
+ end
84
+
85
+ expect(html.to_s).to eq("<div id=\"omg\">\n</div>\n")
86
+ end
87
+
88
+ it 'chains ids and classes' do
89
+ html = Paggio.html! do
90
+ div.omg!.wut
91
+ end
92
+
93
+ expect(html.to_s).to eq("<div id=\"omg\" class=\"wut\">\n</div>\n")
94
+ end
95
+
96
+ it 'chains ids and attributes' do
97
+ html = Paggio.html! do
98
+ div.omg! class: :wut
99
+ end
100
+
101
+ expect(html.to_s).to eq("<div id=\"omg\" class=\"wut\">\n</div>\n")
102
+ end
103
+
104
+ it 'chains classes and attributes' do
105
+ html = Paggio.html! do
106
+ div.wut width: 80
107
+ end
108
+
109
+ expect(html.to_s).to eq("<div width=\"80\" class=\"wut\">\n</div>\n")
110
+ end
111
+
112
+ it 'overrides with id from attributes' do
113
+ html = Paggio.html! do
114
+ div.omg! id: 'ikr'
115
+ end
116
+
117
+ expect(html.to_s).to eq("<div id=\"ikr\">\n</div>\n")
118
+ expect(html.to_s).not_to eq("<div id=\"omg\">\n</div>\n")
119
+ end
120
+
121
+ it 'coalesces classes from attributes' do
122
+ html = Paggio.html! do
123
+ div.wut class: 'rofl'
124
+ end
125
+
126
+ expect(html.to_s).to eq("<div class=\"rofl wut\">\n</div>\n")
127
+ expect(html.to_s).not_to eq("<div class=\"wut\" class=\"rofl\">n")
128
+
129
+ html = Paggio.html! do
130
+ div.wut class: 'rofl idk'
131
+ end
132
+
133
+ expect(html.to_s).to eq("<div class=\"rofl idk wut\">\n</div>\n")
134
+ expect(html.to_s).not_to eq("<div class=\"wut\" class=\"rofl idk\">n")
135
+ end
136
+
137
+ it 'coalesces multiple classes from attributes' do
138
+ html = Paggio.html! do
139
+ div.wut classes: %w[rofl idk]
140
+ end
141
+
142
+ expect(html.to_s).to eq("<div class=\"rofl idk wut\">\n</div>\n")
143
+ expect(html.to_s).not_to eq("<div class=\"wut\" classes=\"[&quot;rofl&quot;, &quot;idk&quot;]\">\n</div>\n")
144
+ end
145
+
146
+ it 'joins class name properly with class attributes' do
147
+ html = Paggio.html! do
148
+ i.icon(class: 'illegal')[:legal]
149
+ end
150
+
151
+ expect(html.to_s).to eq("<i class=\"illegal icon-legal\">\n</i>\n")
152
+ end
153
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paggio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - meh.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-28 00:00:00.000000000 Z
11
+ date: 2015-09-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: meh@schizofreni.co
@@ -17,12 +17,17 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - ".travis.yml"
20
+ - Gemfile
21
+ - Gemfile.lock
20
22
  - README.md
21
23
  - Rakefile
22
24
  - lib/paggio.rb
23
25
  - lib/paggio/css.rb
26
+ - lib/paggio/css/animation.rb
24
27
  - lib/paggio/css/color.rb
25
28
  - lib/paggio/css/definition.rb
29
+ - lib/paggio/css/font.rb
30
+ - lib/paggio/css/rule.rb
26
31
  - lib/paggio/css/unit.rb
27
32
  - lib/paggio/formatter.rb
28
33
  - lib/paggio/html.rb
@@ -32,9 +37,13 @@ files:
32
37
  - lib/paggio/html/element/blockquote.rb
33
38
  - lib/paggio/html/element/button.rb
34
39
  - lib/paggio/html/element/canvas.rb
40
+ - lib/paggio/html/element/embed.rb
35
41
  - lib/paggio/html/element/img.rb
36
42
  - lib/paggio/html/element/input.rb
37
43
  - lib/paggio/html/element/object.rb
44
+ - lib/paggio/html/element/optgroup.rb
45
+ - lib/paggio/html/element/option.rb
46
+ - lib/paggio/html/element/select.rb
38
47
  - lib/paggio/html/element/td.rb
39
48
  - lib/paggio/html/helpers.rb
40
49
  - lib/paggio/markdown.rb
@@ -43,6 +52,7 @@ files:
43
52
  - lib/paggio/utils.rb
44
53
  - paggio.gemspec
45
54
  - spec/css_spec.rb
55
+ - spec/html_spec.rb
46
56
  homepage: http://github.com/meh/paggio
47
57
  licenses:
48
58
  - WTFPL
@@ -63,10 +73,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
73
  version: '0'
64
74
  requirements: []
65
75
  rubyforge_project:
66
- rubygems_version: 2.2.0
76
+ rubygems_version: 2.4.5.1
67
77
  signing_key:
68
78
  specification_version: 4
69
79
  summary: Ruby, HTML and CSS at war.
70
80
  test_files:
71
81
  - spec/css_spec.rb
72
- has_rdoc:
82
+ - spec/html_spec.rb