File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed
Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 2121require "csscss/parser/list_style"
2222require "csscss/parser/margin"
2323require "csscss/parser/padding"
24+ require "csscss/parser/border_width"
25+
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments