CSS-Prepare
view release on metacpan or search on metacpan
bin/cssprepare view on Meta::CPAN
foreach my $block ( @structure ) {
foreach my $error ( @{$block->{'errors'}} ) {
my $selector = defined $block->{'selectors'}
? join ', ', @{$block->{'selectors'}}
: '';
my( $level, $text ) = each %$error;
status(
" [${level}] '${selector}' - ${text}",
0,
'bold red'
);
$cache->{'error_count'}++;
}
}
if ( !defined $options{'warnings-only'} ) {
@structure = $preparer->optimise( @structure )
if defined $options{'optimise'};
$cache->{'output'}
lib/CSS/Prepare/Property/Values.pm view on Meta::CPAN
| xx-large | smaller | larger | inherit
| $length_value | $percentage_value
)
}x;
my $font_size_line_height_value
= qr{ $font_size_value / $line_height_value }x;
our $font_style_value = qr{ (?: italic | oblique | normal | inherit ) }x;
our $font_variant_value = qr{ (?: normal | small-caps | inherit ) }x;
our $font_weight_value = qr{
(?:
normal | bold | bolder | lighter
| 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
| inherit
)
}x;
my $height_value
= qr{ (?: $length_value | $percentage_value | auto | inherit ) }x;
my $letter_spacing_value = qr{ (?: normal | $length_value | inherit ) }x;
our $list_style_image_value = qr{ (?: $url_value | none | inherit ) }x;
our $list_style_position_value = qr{ (?: inside | outside | inherit ) }x;
t/01.values.t view on Meta::CPAN
foreach my $value qw( normal small-caps inherit ) {
ok( is_font_variant_value( $value ),
"font-variant: '$value'" );
}
ok( ! is_font_variant_value( 'drop-cap' ),
"not font-variant: 'drop-cap'" );
my @font_weight_values = qw(
normal bold bolder lighter inherit
100 200 300 400 500
600 700 800 900
);
foreach my $value ( @font_weight_values ) {
ok( is_font_weight_value( $value ),
"font-weight: '$value'" );
}
ok( ! is_font_weight_value( 'light' ),
"not font-weight: 'light'" );
t/02.font.t view on Meta::CPAN
);
@parsed = $preparer->parse_string( $css );
is_deeply( \@structure, \@parsed )
or say "font-weight was:\n" . Dumper \@parsed;
}
# shorthand works
{
$css = <<CSS;
div { font: italic small-caps bold 13px/16px "Palatino"; }
CSS
@structure = (
{
original => ' font: italic small-caps'
. ' bold 13px/16px "Palatino"; ',
errors => [],
selectors => [ 'div' ],
block => {
'font-style' => 'italic',
'font-variant' => 'small-caps',
'font-weight' => 'bold',
'font-size' => '13px',
'line-height' => '16px',
'font-family' => '"Palatino"',
},
},
);
@parsed = $preparer->parse_string( $css );
is_deeply( \@structure, \@parsed )
or say "full font shorthand was:\n" . Dumper \@parsed;
}
{
$css = <<CSS;
div { font: italic small-caps bold 13px/16px "Palatino" !important; }
CSS
@structure = (
{
original => ' font: italic small-caps'
. ' bold 13px/16px "Palatino" !important; ',
errors => [],
selectors => [ 'div' ],
block => {
'important-font-style' => 'italic',
'important-font-variant' => 'small-caps',
'important-font-weight' => 'bold',
'important-font-size' => '13px',
'important-line-height' => '16px',
'important-font-family' => '"Palatino"',
},
},
);
@parsed = $preparer->parse_string( $css );
is_deeply( \@structure, \@parsed )
or say "important full font shorthand was:\n" . Dumper \@parsed;
t/02.font.t view on Meta::CPAN
);
@parsed = $preparer->parse_string( $css );
is_deeply( \@structure, \@parsed )
or say "different order font shorthand was:\n" . Dumper \@parsed;
}
# need a minimum of size and family for it to be a valid shorthand
{
$css = <<CSS;
div { font: bold italic; }
CSS
@structure = (
{
original => ' font: bold italic; ',
errors => [
{
error => 'invalid font property: bold italic',
}
],
selectors => [ 'div' ],
block => {},
},
);
@parsed = $preparer->parse_string( $css );
is_deeply( \@structure, \@parsed )
or say "important full font shorthand was:\n" . Dumper \@parsed;
t/04.font.t view on Meta::CPAN
}
# shorthand works
{
@structure = (
{
selectors => [ 'div' ],
block => {
'font-style' => 'italic',
'font-variant' => 'small-caps',
'font-weight' => 'bold',
'font-size' => '13px',
'font-family' => '"Palatino"',
},
},
);
$css = <<CSS;
div{font:italic small-caps bold 13px "Palatino";}
CSS
$output = $preparer_concise->output_as_string( @structure );
ok( $output eq $css )
or say "full font shorthand was:\n" . $output;
$css = <<CSS;
div {
font: italic
small-caps
bold
13px
"Palatino";
}
CSS
$output = $preparer_pretty->output_as_string( @structure );
ok( $output eq $css )
or say "full font shorthand was:\n" . $output;
}
{
t/04.font.t view on Meta::CPAN
}
# shorthand is not invoked for only some font values
{
@structure = (
{
selectors => [ 'p' ],
block => {
'font-style' => 'normal',
'font-variant' => 'small-caps',
'font-weight' => 'bold',
},
},
);
$css = <<CSS;
p{font-style:normal;font-variant:small-caps;font-weight:bold;}
CSS
$output = $preparer_concise->output_as_string( @structure );
ok( $output eq $css )
or say "no partial font shorthand was:\n" . $output;
$css = <<CSS;
p {
font-style: normal;
font-variant: small-caps;
font-weight: bold;
}
CSS
$output = $preparer_pretty->output_as_string( @structure );
ok( $output eq $css )
or say "no partial font shorthand was:\n" . $output;
}
# line-height is separate when there is no font-size in the shorthand
{
@structure = (
{
selectors => [ 'p' ],
block => {
'font-style' => '',
'font-variant' => '',
'font-weight' => 'bold',
'font-size' => '',
'line-height' => '16px',
'font-family' => '"Palatino"',
},
},
);
$css = <<CSS;
p{font:bold "Palatino";line-height:16px;}
CSS
$output = $preparer_concise->output_as_string( @structure );
ok( $output eq $css )
or say "no partial font shorthand was:\n" . $output;
$css = <<CSS;
p {
font: bold
"Palatino";
line-height: 16px;
}
CSS
$output = $preparer_pretty->output_as_string( @structure );
ok( $output eq $css )
or say "no partial font shorthand was:\n" . $output;
}
{
( run in 2.160 seconds using v1.01-cache-2.11-cpan-5dc5da66d9d )