[Bps-public-commit] CSS-Squish branch, master, updated. v0.09-4-g0d09a4a
Ruslan Zakirov
ruz at bestpractical.com
Thu Sep 8 10:01:52 EDT 2011
The branch, master has been updated
via 0d09a4adcc0b1c3545e212798bd22f4851546c99 (commit)
via 04fbdccc6a2eae46262f069a82cff36fa9acb94b (commit)
from b2c6667c4363905ed798b4c9ec890a50cf99c85e (commit)
Summary of changes:
.gitignore | 13 +++++++++++++
MANIFEST | 2 ++
lib/CSS/Squish.pm | 32 +++++++++++++++++++++++++-------
t/{01-basic.t => 08-comments.t} | 17 +++++++++++++++--
t/css/08-comments.css | 17 +++++++++++++++++
5 files changed, 72 insertions(+), 9 deletions(-)
create mode 100644 .gitignore
copy t/{01-basic.t => 08-comments.t} (54%)
create mode 100644 t/css/08-comments.css
- Log -----------------------------------------------------------------
commit 04fbdccc6a2eae46262f069a82cff36fa9acb94b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Sep 8 17:35:59 2011 +0400
.gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0a12b71
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+Makefile
+Makefile.bak
+Makefile.old
+Makefile.new
+pm_to_blib
+blib/
+MANIFEST.bak
+MANIFEST.new
+MANIFEST.old
+cover_db/
+nytprof/
+*.tar.gz
+*.sw[po]
commit 0d09a4adcc0b1c3545e212798bd22f4851546c99
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Sep 8 18:00:52 2011 +0400
ignore leading comments
diff --git a/MANIFEST b/MANIFEST
index b11e255..56388d3 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -11,6 +11,7 @@ t/04-recursion.t
t/05-basic-loop-prevention.t
t/06-server-relative-urls.t
t/07-basic-extra-roots.t
+t/08-comments.t
t/99-pod-coverage.t
t/99-pod.t
t/css/01-basic-import.css
@@ -24,6 +25,7 @@ t/css/05-loop-prevention.css
t/css/07-basic-extra-roots.css
t/css/07-basic-extra-roots3.css
t/css/07-basic-extra-roots4.css
+t/css/08-comments.css
t/css/blam.css
t/css/foo.css
t/css/foo/04-recursion-2.css
diff --git a/lib/CSS/Squish.pm b/lib/CSS/Squish.pm
index 30c29cf..fb26498 100644
--- a/lib/CSS/Squish.pm
+++ b/lib/CSS/Squish.pm
@@ -80,6 +80,8 @@ my $AT_IMPORT = qr/^\s* # leading whitespace
\s*$ # trailing whitespace
/x;
+my $COMMENT = qr{/\*[^*]*\*+([^/*][^*]*\*+)*/}ms;
+
=head1 COMMON METHODS
=head2 new( [roots=>[...]] )
@@ -153,7 +155,21 @@ sub _concatenate_to {
my $seen = shift || {};
while ( my $line = <$fh> ) {
- if ( $line =~ /$AT_IMPORT/o ) {
+ REDO:
+ # skip empty lines and one line comments
+ if ( $line =~ /^\s*(?:$COMMENT\s*)*$/o ) {
+ print $dest $line;
+ }
+ elsif ( $line =~ m{^\s*/\*} ) {
+ while ( my $tmp = <$fh> ) {
+ $line .= $tmp;
+ next unless $line =~ s/^(\s*$COMMENT)//o;
+
+ print $dest $1; last;
+ }
+ goto REDO;
+ }
+ elsif ( $line =~ /$AT_IMPORT/o ) {
my $import = $1;
my $media = $2;
@@ -213,7 +229,7 @@ sub _concatenate_to {
}
else {
print $dest $line;
- last if not $line =~ /^\s*$/;
+ last;
}
}
$self->_debug("Printing the rest");
@@ -417,11 +433,13 @@ sub _debug {
=head1 BUGS AND SHORTCOMINGS
-At the current time, comments are not skipped. This means comments happening
-before @import statements at the top of a file will cause the @import rules
-to not be parsed. Make sure the @import rules are the very first thing in
-the file (and only one per line). Processing of @import rules stops as soon
-as the first line that doesn't match an @import rule is encountered.
+Comments are ignored. Make sure the @import rules are the very first
+thing in the file (and only one per line). Processing of @import rules
+stops as soon as the first line that doesn't match an @import rule is
+encountered.
+
+ at charset rule stops processing. Media queries are not supported.
+Patches are welcome.
All other bugs should be reported via
L<http://rt.cpan.org/Public/Dist/Display.html?Name=CSS-Squish>
diff --git a/t/08-comments.t b/t/08-comments.t
new file mode 100644
index 0000000..0094f93
--- /dev/null
+++ b/t/08-comments.t
@@ -0,0 +1,40 @@
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+use_ok("CSS::Squish");
+
+my $expected_result = <<'EOT';
+
+/* comment */
+
+/* comment with * inside */
+
+/* multiline
+comment */
+
+/*
+ * shiny
+ * multiline
+ * comment
+ */
+
+
+/**
+ * From t/css/08-comments.css: @import "01-basic-import.css";
+ */
+
+inside 01-basic-import.css
+
+/** End of 01-basic-import.css */
+
+body { color: blue; }
+
+EOT
+
+my $result = CSS::Squish->concatenate('t/css/08-comments.css');
+
+is($result, $expected_result, "Basic import");
+
diff --git a/t/css/08-comments.css b/t/css/08-comments.css
new file mode 100644
index 0000000..bc40d51
--- /dev/null
+++ b/t/css/08-comments.css
@@ -0,0 +1,17 @@
+
+/* comment */
+
+/* comment with * inside */
+
+/* multiline
+comment */
+
+/*
+ * shiny
+ * multiline
+ * comment
+ */
+
+ at import "01-basic-import.css";
+body { color: blue; }
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list