CSS-Prepare

 view release on metacpan or  search on metacpan

lib/CSS/Prepare.pm  view on Meta::CPAN

    
    my $base = $self->get_base_directory();
    return undef
        unless defined $base && -d $base;
    
    my $stylesheet = basename( $file );
    my $directory  = dirname( $file );
    my @blocks;
    my $path;
    
    foreach my $section ( split m{/}, $directory ) {
           $path  .= "${section}/";
        my $target = "${base}${path}${stylesheet}";
        
        my @file_blocks = $self->parse_file( $target );
        push @blocks, @file_blocks
            if @file_blocks;    # non-existent file is not an error
    }
    
    return @blocks;
}

lib/CSS/Prepare.pm  view on Meta::CPAN

    
    my $base = $self->get_base_url();
    return undef
        unless defined $base && $base =~ m{https?://};
    
    my $stylesheet = basename( $file );
    my $directory  = dirname( $file );
    my @blocks;
    my $path;
    
    foreach my $section ( split m{/}, $directory ) {
           $path  .= "${section}/";
        my $target = "${base}${path}${stylesheet}";
        
        my @file_blocks = $self->parse_url( $target );
        push @blocks, @file_blocks
            if @file_blocks;    # non-existent url is not an error
    }
    
    return @blocks;
}

t/06.basic.t  view on Meta::CPAN

CSS
    $css = <<CSS;
body,div,li{margin:0;}
div,li{padding:0;}
CSS
    
    @structure = $preparer->parse_string( $input );
    @structure = $preparer->optimise( @structure );
    $output    = $preparer->output_as_string( @structure );
    ok( $output eq $css )
        or say "split multiple properties was:\n" . $output;
}

# matching selectors and properties can be split if smaller output
{
    $input = <<CSS;
div, li { padding: 0; }
div, li { margin: 0; }
li, fieldset { border: none; }
CSS
    $css = <<CSS;
div,li{margin:0;padding:0;}
fieldset,li{border:none;}
CSS
    
    @structure = $preparer->parse_string( $input );
    @structure = $preparer->optimise( @structure );
    $output    = $preparer->output_as_string( @structure );
    ok( $output eq $css )
        or say "split multiple properties was:\n" . $output;
}

# multiple choices of combinations result in the shortest string
{
    $input = <<CSS;
li { padding: 0; }
div { margin: 0; }
li { margin: 0; }
CSS
    $css = <<CSS;



( run in 0.405 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )