Skip to content

Commit

Permalink
more work-arounds for issue #8 - background-position
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Feb 23, 2017
1 parent 989e3ce commit 03e108c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@
0.4.7 - remove Panda dependency from make-properties.pl
- work-around for issue #6 - background-position
- work-around for issue #8 - background-position
0.4.6 $module.parse-property now returns explicit Nil and warns
on parse failure. New :!warn option to silence warnings.
0.4.5 Fix make-modules.pl for latest Rakudo
Expand Down
6 changes: 4 additions & 2 deletions etc/css1-properties.txt
Expand Up @@ -15,14 +15,16 @@
'background-image' <uri> | none none all elements no N/A 5.3.3
'background-repeat' repeat | repeat-x | repeat-y | no-repeat repeat all elements no N/A 5.3.4
'background-attachment' scroll | fixed scroll all elements no N/A 5.3.5
'background-position' [<percentage> | <length>]{1,2} | [top | center | bottom] || [left | center | right] 0% 0% block-level and replaced elements no refer to the size of the element itself 5.3.6
'background-position' [<percentage> | <length> | <align> ] [ <percentage> | <length> | <valign> ]? | [ <valign> || <align> ] 0% 0% block-level and replaced elements no refer to the size of the element itself 5.3.6
<align> := left | center | right
<valign> := top | center | bottom
'background' 'background-color' || 'background-image' || 'background-repeat' || 'background-attachment' || 'background-position' not defined for shorthand properties all elements no allowed on <background-position> 5.3.7
'word-spacing' normal | <length> normal all elements yes N/A 5.4.1
'letter-spacing' normal | <length> normal all elements yes N/A 5.4.2
'text-decoration' none | [ underline || overline || line-through || blink ] none all elements no ** N/A 5.4.3
'vertical-align' baseline | sub | super | top | text-top | middle | bottom | text-bottom | <percentage> baseline inline elements no refer to the 'line-height' of the element itself 5.4.4
'text-transform' capitalize | uppercase | lowercase | none none all elements yes N/A 5.4.5
'text-align' left | right | center | justify UA specific block-level elements yes N/A 5.4.6
'text-align' <align> | justify UA specific block-level elements yes N/A 5.4.6
'text-indent' <length> | <percentage> 0 block-level elements yes refer to parent element's width 5.4.7
'line-height' normal | <number> | <length> | <percentage> normal all elements yes relative to the font size of the element itself 5.4.8
'margin-top' <length> | <percentage> | auto 0 all elements no refer to parent element's width 5.5.1
Expand Down
2 changes: 1 addition & 1 deletion lib/CSS/Module/CSS1/Metadata.pm

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/CSS/Module/CSS1/Spec/Actions.pm
Expand Up @@ -17,6 +17,8 @@ class CSS::Module::CSS1::Spec::Actions {
method expr-background-repeat($/) { make $.list($/) }
method expr-background-attachment($/) { make $.list($/) }
method expr-background-position($/) { make $.list($/) }
method align($/) { make $.rule($/) }
method valign($/) { make $.rule($/) }
method expr-line-height($/) { make $.list($/) }
method expr-border-top-width($/) { make $.list($/) }
method expr-border-right-width($/) { make $.list($/) }
Expand Down
14 changes: 10 additions & 4 deletions lib/CSS/Module/CSS1/Spec/Grammar.pm
Expand Up @@ -60,9 +60,15 @@ grammar CSS::Module::CSS1::Spec::Grammar {
rule decl:sym<background-attachment> {:i (background\-attachment) ':' <val( rx{ <expr=.expr-background-attachment> }, &?ROUTINE.WHY)> }
rule expr-background-attachment {:i [ scroll | fixed ] & <keyw> }

#| background-position: [<percentage> | <length>]{1,2} | [top | center | bottom] || [left | center | right]
#| background-position: [<percentage> | <length> | <align> ] [ <percentage> | <length> | <valign> ]? | [ <valign> || <align> ]
rule decl:sym<background-position> {:i (background\-position) ':' <val( rx{ <expr=.expr-background-position> }, &?ROUTINE.WHY)> }
rule expr-background-position {:i :my @*SEEN; [ [ [ <percentage> || <length> ] ] ** 1..2 || [ [ [ top | center | bottom ] & <keyw> ] <!seen(0)> | [ [ left | center | right ] & <keyw> ] <!seen(1)> ]+ ] }
rule expr-background-position {:i :my @*SEEN; [ [ [ <percentage> || <length> || <align> ] ] [ [ <percentage> || <length> || <valign> ] ]? || [ [ <valign> <!seen(0)> | <align> <!seen(1)> ]+ ] ] }

#| align: left | center | right
rule align {:i [ left | center | right ] & <keyw> }

#| valign: top | center | bottom
rule valign {:i [ top | center | bottom ] & <keyw> }

#| background: 'background-color' || 'background-image' || 'background-repeat' || 'background-attachment' || 'background-position'
rule decl:sym<background> {:i (background) ':' <val( rx{ <expr=.expr-background> }, &?ROUTINE.WHY)> }
Expand All @@ -88,9 +94,9 @@ grammar CSS::Module::CSS1::Spec::Grammar {
rule decl:sym<text-transform> {:i (text\-transform) ':' <val( rx{ <expr=.expr-text-transform> }, &?ROUTINE.WHY)> }
rule expr-text-transform {:i [ capitalize | uppercase | lowercase | none ] & <keyw> }

#| text-align: left | right | center | justify
#| text-align: <align> | justify
rule decl:sym<text-align> {:i (text\-align) ':' <val( rx{ <expr=.expr-text-align> }, &?ROUTINE.WHY)> }
rule expr-text-align {:i [ left | right | center | justify ] & <keyw> }
rule expr-text-align {:i [ <align> || justify & <keyw> ] }

#| text-indent: <length> | <percentage>
rule decl:sym<text-indent> {:i (text\-indent) ':' <val( rx{ <expr=.expr-text-indent> }, &?ROUTINE.WHY)> }
Expand Down
2 changes: 2 additions & 0 deletions lib/CSS/Module/CSS1/Spec/Interface.pm
Expand Up @@ -3,6 +3,7 @@ use v6;
# generated by: make-modules.pl
role CSS::Module::CSS1::Spec::Interface {
method absolute-size($/) { ... }
method align($/) { ... }
method color($/) { ... }
method family-name($/) { ... }
method generic-family($/) { ... }
Expand All @@ -14,4 +15,5 @@ role CSS::Module::CSS1::Spec::Interface {
method relative-size($/) { ... }
method string($/) { ... }
method uri($/) { ... }
method valign($/) { ... }
}
4 changes: 3 additions & 1 deletion t/css1-properties.t
Expand Up @@ -21,10 +21,11 @@ for 't/css1-properties.json'.IO.lines {

next if .substr(0,2) eq '//';

my %expected = %( from-json($_) );
my %expected = from-json($_);
my $prop = %expected<prop>.lc;
my $input = sprintf '{%s: %s}', $prop, %expected<decl>;
my $expr = %expected<expr>;
warn $input;

%expected<ast> = $expr ?? { :declarations[{ :property{ :ident($prop), :$expr } }] } !! Any;

Expand Down Expand Up @@ -60,6 +61,7 @@ for 't/css1-properties.json'.IO.lines {

for @$proforma -> $misc {
my $decl = sprintf '{%s: %s}', $prop, $misc;
warn $decl;

my $ast = { :declarations[{ :property{ :ident($prop), :expr[ { :keyw($misc)} ] } }] };

Expand Down

0 comments on commit 03e108c

Please sign in to comment.