Skip to content

Commit 686ba71

Browse files
committed
1 parent 927b037 commit 686ba71

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

lib/csscss.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
require "csscss/parser/list_style"
2222
require "csscss/parser/margin"
2323
require "csscss/parser/padding"
24+
require "csscss/parser/border_width"
25+

lib/csscss/parser/border_width.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module Csscss
2+
module Parser
3+
module BorderWidth
4+
extend Parser::Base
5+
6+
class Parser < Parslet::Parser
7+
include Color
8+
9+
rule(:border_width_side) {
10+
symbol_list(%w(thin medium thick inherit)) | length
11+
}
12+
13+
rule(:border_width) {
14+
(
15+
symbol("inherit") >> eof | (
16+
border_width_side.maybe.as(:top) >>
17+
border_width_side.maybe.as(:right) >>
18+
border_width_side.maybe.as(:bottom) >>
19+
border_width_side.maybe.as(:left)
20+
)
21+
).as(:border_width)
22+
}
23+
24+
root(:border_width)
25+
end
26+
27+
class Transformer < Parslet::Transform
28+
@property = :border_width
29+
extend MultiWidthTransformer
30+
31+
def self.side_declaration(side, value)
32+
Declaration.from_parser("border-#{side}-width", value)
33+
end
34+
end
35+
end
36+
end
37+
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require "test_helper"
2+
3+
module Csscss::Parser
4+
module BorderWidth
5+
describe BorderWidth do
6+
include CommonParserTests
7+
8+
before do
9+
@parser = Parser.new
10+
@trans = Transformer.new
11+
end
12+
13+
it "converts shorthand rules to longhand" do
14+
trans("thin thick inherit 10em").must_equal([
15+
dec("border-top-width", "thin"),
16+
dec("border-right-width", "thick"),
17+
dec("border-bottom-width", "inherit"),
18+
dec("border-left-width", "10em")
19+
])
20+
21+
trans("thin thick").must_equal([
22+
dec("border-top-width", "thin"),
23+
dec("border-right-width", "thick"),
24+
dec("border-bottom-width", "thin"),
25+
dec("border-left-width", "thick")
26+
])
27+
end
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)