| 1 | # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- | ||||||||||||||||||||||||||||
| 2 | # vim:ts=8:sw=2:et:sta:sts=2 | ||||||||||||||||||||||||||||
| 3 | ######### | ||||||||||||||||||||||||||||
| 4 | # Author: rmp | ||||||||||||||||||||||||||||
| 5 | # Last Modified: $Date: 2012-11-10 16:33:37 +0000 (Sat, 10 Nov 2012) $ | ||||||||||||||||||||||||||||
| 6 | # Id: $Id: Sass.pm 75 2012-11-10 16:33:37Z zerojinx $ | ||||||||||||||||||||||||||||
| 7 | # $HeadURL: https://text-sass.svn.sourceforge.net/svnroot/text-sass/trunk/lib/Text/Sass.pm $ | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # Note to reader: | ||||||||||||||||||||||||||||
| 10 | # Recursive regex processing can be very bad for your health. | ||||||||||||||||||||||||||||
| 11 | # Sass & SCSS are both pretty cool. This module is not. | ||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||
| 13 | package Text::Sass; | ||||||||||||||||||||||||||||
| 14 | 34 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 34 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 34 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 34 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 34 | ▶ | use Text::Sass::Expr; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 34 | ▶ | use Text::Sass::Functions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 34 | ▶ | use Text::Sass::Token; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 34 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 34 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 34 | our $VERSION = q[1.1.0]; | |||||||||||||||||||||||||||
| 25 | 34 | our $DEBUG = 0; | |||||||||||||||||||||||||||
| 26 | 34 | our $FUNCTIONS = [qw(Text::Sass::Functions)]; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 34 | Readonly::Scalar our $DEBUG_SEPARATOR => 30; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 33 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 31 | 33 | my ($class, @args) = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 33 | ▶ | if(!scalar @args % 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 30 | my $args = {@args}; | |||||||||||||||||||||||||||
| 35 | 30 | ▶ | if($args->{Functions}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 1 | for my $functions (@{$args->{Functions}}) { | |||||||||||||||||||||||||||
| 37 | 1 | ▶ | eval "require $functions" or carp qq[Could not require $functions: $EVAL_ERROR]; ## no critic (ProhibitStringyEval) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | push @{$FUNCTIONS}, $functions; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 33 | return 1; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 64 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 64 | my ($class, $ref) = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 64 | ▶ | if(!$ref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 64 | $ref = {}; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 64 | bless $ref, $class; | |||||||||||||||||||||||||||
| 55 | 64 | return $ref; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 3 | ▶ | sub css2sass { | ||||||||||||||||||||||||||
|
Subroutine
css2sass: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 3 | my ($self, $str) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 3 | ▶ | if(!ref $self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | $self = $self->new; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | my $symbols = {}; | |||||||||||||||||||||||||||
| 66 | 3 | my $stash = []; | |||||||||||||||||||||||||||
| 67 | 3 | $self->_parse_css($str, $stash, $symbols); | |||||||||||||||||||||||||||
| 68 | 3 | return $self->_stash2sass($stash, $symbols); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 29 | ▶ | sub sass2css { | ||||||||||||||||||||||||||
|
Subroutine
sass2css: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 29 | my ($self, $str) = @_; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 29 | ▶ | if(!ref $self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | $self = $self->new; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 29 | my $symbols = {}; | |||||||||||||||||||||||||||
| 79 | 29 | my $stash = []; | |||||||||||||||||||||||||||
| 80 | 29 | my $chain = []; | |||||||||||||||||||||||||||
| 81 | 29 | $self->{_sass_indent} = 0; | |||||||||||||||||||||||||||
| 82 | 29 | $self->_parse_sass($str, $stash, $symbols, $chain); | |||||||||||||||||||||||||||
| 83 | 28 | return $self->_stash2css($stash, $symbols); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 34 | ▶ | sub scss2css { | ||||||||||||||||||||||||||
|
Subroutine
scss2css: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 34 | my ($self, $str) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 34 | ▶ | if(!ref $self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $self = $self->new; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 34 | my $symbols = {}; | |||||||||||||||||||||||||||
| 94 | 34 | my $stash = []; | |||||||||||||||||||||||||||
| 95 | 34 | $self->_parse_css($str, $stash, $symbols); | |||||||||||||||||||||||||||
| 96 | 34 | return $self->_stash2css($stash, $symbols); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 178 | ▶ | sub _parse_sass { | ||||||||||||||||||||||||||
|
Subroutine
_parse_sass: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 100 | 178 | my ($self, $str, $substash, $symbols, $chain) = @_; | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | $DEBUG and print {*STDERR} q[=]x$DEBUG_SEPARATOR, q[begin _parse_sass], q[=]x$DEBUG_SEPARATOR, "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | ######### | ||||||||||||||||||||||||||||
| 104 | # insert blank links after code2: | ||||||||||||||||||||||||||||
| 105 | # code1 | ||||||||||||||||||||||||||||
| 106 | # code2 | ||||||||||||||||||||||||||||
| 107 | # code3 | ||||||||||||||||||||||||||||
| 108 | # code4 | ||||||||||||||||||||||||||||
| 109 | # | ||||||||||||||||||||||||||||
| 110 | 178 | $str =~ s/\n(\S)/\n\n$1/smxg; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | ######### | ||||||||||||||||||||||||||||
| 113 | # strip blank lines from: | ||||||||||||||||||||||||||||
| 114 | # <blank line> | ||||||||||||||||||||||||||||
| 115 | # code | ||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||
| 117 | 178 | $str =~ s/^\s*\n(\s+)/$1/smxg; | |||||||||||||||||||||||||||
| 118 | 178 | my $groups = [split /\n\s*?\n/smx, $str]; | |||||||||||||||||||||||||||
| 119 | 178 | for my $g (@{$groups}) { | |||||||||||||||||||||||||||
| 120 | 252 | $self->_parse_sass_group($substash, $symbols, $chain, $g); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $DEBUG and print {*STDERR} q[=]x$DEBUG_SEPARATOR, q[ end _parse_sass ], q[=]x$DEBUG_SEPARATOR, "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 175 | return 1; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 252 | ▶ | sub _parse_sass_group { | ||||||||||||||||||||||||||
|
Subroutine
_parse_sass_group: called CC=28 SCAR=33.7
| |||||||||||||||||||||||||||||
| 129 | 252 | my ($self, $substash, $symbols, $chain, $group) = @_; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 252 | my @lines = split /\n/smx, $group; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 252 | ▶ | while(my $line = shift @lines) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | ######### | ||||||||||||||||||||||||||||
| 135 | # /* comment */ | ||||||||||||||||||||||||||||
| 136 | # /* comment | ||||||||||||||||||||||||||||
| 137 | # | ||||||||||||||||||||||||||||
| 138 | 253 | $line =~ s{/[*].*?[*]/\s*}{}smx; | |||||||||||||||||||||||||||
| 139 | 253 | $line =~ s{/[*].*$}{}smx; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | ######### | ||||||||||||||||||||||||||||
| 142 | # !x = y variable declarations | ||||||||||||||||||||||||||||
| 143 | # | ||||||||||||||||||||||||||||
| 144 | 253 | $line =~ s{^\!(\S+)\s*=\s*(.*?)$}{ | |||||||||||||||||||||||||||
| 145 | 3 | $symbols->{variables}->{$1} = $2; | |||||||||||||||||||||||||||
| 146 | 3 | ▶ | $DEBUG and carp qq[VARIABLE $1 = $2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 3 | q[]; | |||||||||||||||||||||||||||
| 148 | }smxegi; | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | ######### | ||||||||||||||||||||||||||||
| 151 | # $x : y variable declarations | ||||||||||||||||||||||||||||
| 152 | # | ||||||||||||||||||||||||||||
| 153 | 253 | $line =~ s{^\$(\S+)\s*:\s*(.*?)$}{ | |||||||||||||||||||||||||||
| 154 | 4 | $symbols->{variables}->{$1} = $2; | |||||||||||||||||||||||||||
| 155 | 4 | ▶ | $DEBUG and carp qq[VARIABLE $1 = $2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 4 | q[]; | |||||||||||||||||||||||||||
| 157 | }smxegi; | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | ######### | ||||||||||||||||||||||||||||
| 160 | # =x | =x(!var) | ||||||||||||||||||||||||||||
| 161 | # bla | bla | ||||||||||||||||||||||||||||
| 162 | # | ||||||||||||||||||||||||||||
| 163 | # mixin declaration | ||||||||||||||||||||||||||||
| 164 | # | ||||||||||||||||||||||||||||
| 165 | 253 | $line =~ s{^=(.*?)$}{ | |||||||||||||||||||||||||||
| 166 | 2 | my $mixin_stash = {}; | |||||||||||||||||||||||||||
| 167 | 2 | my $remaining = join "\n", @lines; | |||||||||||||||||||||||||||
| 168 | 2 | @lines = (); | |||||||||||||||||||||||||||
| 169 | 2 | my $proto = $1; | |||||||||||||||||||||||||||
| 170 | 2 | my ($func) = $1 =~ /^([^(]+)/smx; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | ######### | ||||||||||||||||||||||||||||
| 173 | # mixins are interpolated later, so we just store the string here | ||||||||||||||||||||||||||||
| 174 | # | ||||||||||||||||||||||||||||
| 175 | 2 | $symbols->{mixins}->{$func} = "$proto\n$remaining\n"; | |||||||||||||||||||||||||||
| 176 | 2 | ▶ | $DEBUG and carp qq[MIXIN $func]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 2 | q[]; | |||||||||||||||||||||||||||
| 178 | }smxegi; | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | ######### | ||||||||||||||||||||||||||||
| 181 | # @include | ||||||||||||||||||||||||||||
| 182 | # | ||||||||||||||||||||||||||||
| 183 | # mixin usage | ||||||||||||||||||||||||||||
| 184 | # | ||||||||||||||||||||||||||||
| 185 | 253 | $line =~ s{^\@include\s*(.*?)(?:[(](.*?)[)])?$}{ | |||||||||||||||||||||||||||
| 186 | 2 | my ($func, $argstr) = ($1, $2); | |||||||||||||||||||||||||||
| 187 | 2 | my $mixin_str = $symbols->{mixins}->{$func}; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 2 | my $subsymbols = $symbols; # todo: correct scoping - is better as {%{$symbols}} | |||||||||||||||||||||||||||
| 190 | 2 | ▶ | my $values = $argstr ? [split /\s*,\s*/smx, $argstr] : []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 2 | my ($varstr) = $mixin_str =~ /^.*?[(](.*?)[)]/smx; | |||||||||||||||||||||||||||
| 192 | 2 | ▶ | my $vars = $varstr ? [split /\s*,\s*/smx, $varstr] : []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 2 | for my $var (@{$vars}) { | |||||||||||||||||||||||||||
| 195 | 1 | $var =~ s/^[\!\$]//smx; | |||||||||||||||||||||||||||
| 196 | 1 | $subsymbols->{variables}->{$var} = shift @{$values}; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 2 | $mixin_str =~ s/^.*?\n//smx; | |||||||||||||||||||||||||||
| 200 | 2 | my $result = []; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 2 | $self->_parse_sass($mixin_str, $result, $subsymbols, [@{$chain}]); | |||||||||||||||||||||||||||
| 203 | 2 | push @{$substash}, {"+$func" => $result}; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 2 | ▶ | $DEBUG and carp qq[DYNAMIC MIXIN $func]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 2 | q[]; | |||||||||||||||||||||||||||
| 207 | }smxegi; | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | ######### | ||||||||||||||||||||||||||||
| 210 | # @mixin name | ||||||||||||||||||||||||||||
| 211 | # bla | ||||||||||||||||||||||||||||
| 212 | # | ||||||||||||||||||||||||||||
| 213 | # mixin declaration | ||||||||||||||||||||||||||||
| 214 | # | ||||||||||||||||||||||||||||
| 215 | 253 | $line =~ s{^\@mixin\s+(.*?)$}{ | |||||||||||||||||||||||||||
| 216 | 2 | my $mixin_stash = {}; | |||||||||||||||||||||||||||
| 217 | 2 | my $remaining = join "\n", @lines; | |||||||||||||||||||||||||||
| 218 | 2 | @lines = (); | |||||||||||||||||||||||||||
| 219 | 2 | my $proto = $1; | |||||||||||||||||||||||||||
| 220 | 2 | my ($func) = $1 =~ /^([^(]+)/smx; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | ######### | ||||||||||||||||||||||||||||
| 223 | # mixins are interpolated later, so we just store the string here | ||||||||||||||||||||||||||||
| 224 | # | ||||||||||||||||||||||||||||
| 225 | 2 | $symbols->{mixins}->{$func} = "$proto\n$remaining\n"; | |||||||||||||||||||||||||||
| 226 | 2 | ▶ | $DEBUG and carp qq[MIXIN $func]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 2 | q[]; | |||||||||||||||||||||||||||
| 228 | }smxegi; | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | ######### | ||||||||||||||||||||||||||||
| 231 | # static +mixin | ||||||||||||||||||||||||||||
| 232 | # | ||||||||||||||||||||||||||||
| 233 | 253 | $line =~ s{^[+]([^(]+)$}{ | |||||||||||||||||||||||||||
| 234 | 1 | my $func = $1; | |||||||||||||||||||||||||||
| 235 | 1 | my $mixin_str = $symbols->{mixins}->{$func}; | |||||||||||||||||||||||||||
| 236 | 1 | $mixin_str =~ s/^.*?\n//smx; | |||||||||||||||||||||||||||
| 237 | 1 | my $result = []; | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 1 | $self->_parse_sass($mixin_str, $result, $symbols, [@{$chain}]); | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 1 | my $mixin_tag = (keys %{$result->[0]})[0]; | |||||||||||||||||||||||||||
| 242 | 1 | push @{$substash}, {$mixin_tag => (values %{$result->[0]})[0]}; | |||||||||||||||||||||||||||
| 243 | 1 | ▶ | $DEBUG and carp qq[STATIC MIXIN $func / $mixin_tag]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 1 | q[]; | |||||||||||||||||||||||||||
| 245 | }smxegi; | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | ######### | ||||||||||||||||||||||||||||
| 248 | # interpolated +mixin(value) | ||||||||||||||||||||||||||||
| 249 | # | ||||||||||||||||||||||||||||
| 250 | 253 | $line =~ s{^[+](.*?)[(](.*?)[)]$}{ | |||||||||||||||||||||||||||
| 251 | 1 | my ($func, $argstr) = ($1, $2); | |||||||||||||||||||||||||||
| 252 | 1 | my $mixin_str = $symbols->{mixins}->{$func}; | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 1 | my $subsymbols = $symbols; # todo: correct scoping - is better as {%{$symbols}} | |||||||||||||||||||||||||||
| 255 | 1 | my $values = [split /\s*,\s*/smx, $argstr]; | |||||||||||||||||||||||||||
| 256 | 1 | my ($varstr) = $mixin_str =~ /^.*?[(](.*?)[)]/smx; | |||||||||||||||||||||||||||
| 257 | 1 | my $vars = [split /\s*,\s*/smx, $varstr]; | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 1 | for my $var (@{$vars}) { | |||||||||||||||||||||||||||
| 260 | 1 | $var =~ s/^[\!\$]//smx; | |||||||||||||||||||||||||||
| 261 | 1 | $subsymbols->{variables}->{$var} = shift @{$values}; | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 1 | $mixin_str =~ s/^.*?\n//smx; | |||||||||||||||||||||||||||
| 265 | 1 | my $result = []; | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 1 | $self->_parse_sass($mixin_str, $result, $subsymbols, [@{$chain}]); | |||||||||||||||||||||||||||
| 268 | 1 | push @{$substash}, {"+$func" => $result}; | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 1 | ▶ | $DEBUG and carp qq[DYNAMIC MIXIN $func]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | 1 | q[]; | |||||||||||||||||||||||||||
| 272 | }smxegi; | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | ######### | ||||||||||||||||||||||||||||
| 275 | # parent ref | ||||||||||||||||||||||||||||
| 276 | # | ||||||||||||||||||||||||||||
| 277 | # tag | ||||||||||||||||||||||||||||
| 278 | # attribute: value | ||||||||||||||||||||||||||||
| 279 | # &:pseudoclass | ||||||||||||||||||||||||||||
| 280 | # attribute: value2 | ||||||||||||||||||||||||||||
| 281 | # | ||||||||||||||||||||||||||||
| 282 | 253 | $line =~ s{^(&\s*.*?)$}{$self->_parse_sass_parentref($substash, $symbols, $chain, \@lines, $1)}smxegi; | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | ######### | ||||||||||||||||||||||||||||
| 285 | # static and dynamic attr: value | ||||||||||||||||||||||||||||
| 286 | # color: #aaa | ||||||||||||||||||||||||||||
| 287 | # | ||||||||||||||||||||||||||||
| 288 | 253 | $line =~ s{^(\S+)\s*[:=]\s*(.*?)$}{ | |||||||||||||||||||||||||||
| 289 | 90 | my $key = $1; | |||||||||||||||||||||||||||
| 290 | 90 | my $val = $2; | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 90 | ▶ | $DEBUG and carp qq[ATTR $key = $val]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 90 | ▶ | if($val =~ /^\s*$/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 2 | my $remaining = join "\n", @lines; | |||||||||||||||||||||||||||
| 296 | 2 | @lines = (); | |||||||||||||||||||||||||||
| 297 | 2 | my $ssubstash = []; | |||||||||||||||||||||||||||
| 298 | 2 | $self->_parse_sass($remaining, $ssubstash, $symbols, [@{$chain}]); | |||||||||||||||||||||||||||
| 299 | 2 | push @{$substash}, { "$key:" => $ssubstash }; | |||||||||||||||||||||||||||
| 300 | } else { | ||||||||||||||||||||||||||||
| 301 | 88 | push @{$substash}, { $key => $val }; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | 90 | q[]; | |||||||||||||||||||||||||||
| 304 | }smxegi; | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | ######### | ||||||||||||||||||||||||||||
| 307 | # <x-space indented sub-content> | ||||||||||||||||||||||||||||
| 308 | # | ||||||||||||||||||||||||||||
| 309 | 253 | ▶ | if ($line =~ /^([ ]+)(\S.*)$/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 75 | my $indent = $1; | |||||||||||||||||||||||||||
| 311 | # Indented | ||||||||||||||||||||||||||||
| 312 | 75 | ▶ | if (!$self->{_sass_indent}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 29 | $self->{_sass_indent} = length $1; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 75 | ▶ | if ($line =~ /^[ ]{$self->{_sass_indent}}(\S.*)$/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 74 | my $process = []; | |||||||||||||||||||||||||||
| 318 | 74 | ▶ | while (my $l = shift @lines) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | 101 | ▶ | if($l =~ /^[ ]{$self->{_sass_indent}}(.*)$/smx) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 320 | 101 | push @{$process}, $1; | |||||||||||||||||||||||||||
| 321 | } elsif ($l !~ /^\s*$/xms) { | ||||||||||||||||||||||||||||
| 322 | ######### | ||||||||||||||||||||||||||||
| 323 | # put it back where it came from | ||||||||||||||||||||||||||||
| 324 | # | ||||||||||||||||||||||||||||
| 325 | 0 | unshift @lines, $l; | |||||||||||||||||||||||||||
| 326 | 0 | last; | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 74 | my $remaining = join "\n", $1, @{$process}; | |||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 74 | ▶ | $DEBUG and carp qq[INDENTED $line CALLING DOWN REMAINING=$remaining ].Dumper($substash); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 74 | $self->_parse_sass($remaining, $substash, $symbols, [@{$chain}]); | |||||||||||||||||||||||||||
| 334 | 73 | $line = q[]; | |||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | } else { | ||||||||||||||||||||||||||||
| 337 | 1 | croak qq[Illegal indent @{[length $indent]} we're using @{[$self->{_sass_indent}]} ($line)]; | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | ######### | ||||||||||||||||||||||||||||
| 342 | # .class | ||||||||||||||||||||||||||||
| 343 | # #id | ||||||||||||||||||||||||||||
| 344 | # element | ||||||||||||||||||||||||||||
| 345 | # element2, element2 | ||||||||||||||||||||||||||||
| 346 | # <following content> | ||||||||||||||||||||||||||||
| 347 | # | ||||||||||||||||||||||||||||
| 348 | 251 | $line =~ s{^(\S+.*?)$}{ | |||||||||||||||||||||||||||
| 349 | 65 | my $one = $1; | |||||||||||||||||||||||||||
| 350 | 65 | $one =~ s/\s+/ /smxg; | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 65 | my $remaining = join "\n", @lines; | |||||||||||||||||||||||||||
| 353 | 65 | @lines = (); | |||||||||||||||||||||||||||
| 354 | 65 | my $subsubstash = []; | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 65 | ▶ | $DEBUG and carp qq[ELEMENT $one descending with REMAINING=$remaining]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | 65 | ▶ | $DEBUG and carp Dumper($substash); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | 65 | $self->_parse_sass($remaining, $subsubstash, $symbols, [@{$chain}, $one]); | |||||||||||||||||||||||||||
| 359 | 64 | push @{$substash}, { $one => $subsubstash }; | |||||||||||||||||||||||||||
| 360 | 64 | ▶ | $DEBUG and carp qq[ELEMENT $one returned]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | 64 | ▶ | $DEBUG and carp Dumper($substash); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | 64 | q[]; | |||||||||||||||||||||||||||
| 363 | }smxegi; | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 250 | ▶ | $DEBUG and $line and carp qq[REMAINING $line]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$Text::Sass::DEBUG and $line
MC/DC0%0/2
$Text::Sass::DEBUG and $line
$Text::Sass::DEBUG
$line
Truth table33%1/3
A and B
A= $Text::Sass::DEBUGB= $line
| |||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 249 | return 1; | |||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | 4 | ▶ | sub _parse_sass_parentref { ## no critic (ProhibitManyArgs) # todo: tidy this up! | ||||||||||||||||||||||||||
|
Subroutine
_parse_sass_parentref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 372 | 4 | my ($self, $substash, $symbols, $chain, $lines, $pseudo) = @_; | |||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 4 | my $remaining = join "\n", @{$lines}; | |||||||||||||||||||||||||||
| 375 | 4 | @{$lines} = (); | |||||||||||||||||||||||||||
| 376 | 4 | my $newkey = join q[ ], @{$chain}; | |||||||||||||||||||||||||||
| 377 | 4 | $pseudo =~ s/&/&$newkey/smx; | |||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 4 | my $subsubstash = []; | |||||||||||||||||||||||||||
| 380 | 4 | $self->_parse_sass($remaining, $subsubstash, $symbols, ['TBD']); | |||||||||||||||||||||||||||
| 381 | 4 | push @{$substash}, {$pseudo => $subsubstash}; | |||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 4 | return q[]; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 72 | ▶ | sub _css_nestedgroups { | ||||||||||||||||||||||||||
|
Subroutine
_css_nestedgroups: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 387 | 72 | my ($self, $str) = @_; | |||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 72 | my $groups = []; | |||||||||||||||||||||||||||
| 390 | 72 | my $groupstr = q[]; | |||||||||||||||||||||||||||
| 391 | 72 | my $indent = 0; | |||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 72 | for my $i (0..length $str ) { | |||||||||||||||||||||||||||
| 394 | 4283 | my $char = substr $str, $i, 1; | |||||||||||||||||||||||||||
| 395 | 4283 | $groupstr .= $char; | |||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 4283 | ▶ | if ($char eq '{') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | 120 | $indent++; | |||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 4283 | ▶ | if ($char eq '}') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | 120 | $indent--; | |||||||||||||||||||||||||||
| 403 | 120 | ▶ | if ($indent == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 87 | push @{$groups}, $groupstr; | |||||||||||||||||||||||||||
| 405 | 87 | $groupstr = q[]; | |||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 72 | return $groups; | |||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 80 | ▶ | sub _css_kvs { | ||||||||||||||||||||||||||
|
Subroutine
_css_kvs: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 414 | 80 | my ($self, $str) = @_; | |||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 80 | my $groups = []; | |||||||||||||||||||||||||||
| 417 | 80 | my $groupstr = q[]; | |||||||||||||||||||||||||||
| 418 | 80 | my $indent = 0; | |||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 80 | for my $i (0..length $str) { | |||||||||||||||||||||||||||
| 421 | 3092 | my $char = substr $str, $i, 1; | |||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 3092 | ▶ | if ($char eq q[;] and $indent == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$char eq ";" and $indent == 0
MC/DC100%2/2
$char eq ";" and $indent == 0
$char eq ";"
$indent == 0
Truth table100%3/3
A and B
A= $char eq ";"B= $indent == 0
| |||||||||||||||||||||||||||||
| 424 | 78 | push @{$groups}, $groupstr; | |||||||||||||||||||||||||||
| 425 | 78 | $groupstr = q[]; | |||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | } else { | ||||||||||||||||||||||||||||
| 428 | 3014 | $groupstr .= $char; | |||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 3092 | ▶ | if ($char eq '{') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | 31 | $indent++; | |||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 3092 | ▶ | if ($char eq '}') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | 31 | $indent--; | |||||||||||||||||||||||||||
| 437 | 31 | ▶ | if ($indent == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | 25 | push @{$groups}, $groupstr; | |||||||||||||||||||||||||||
| 439 | 25 | $groupstr = q[]; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 80 | return $groups; | |||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | 72 | ▶ | sub _parse_css { | ||||||||||||||||||||||||||
|
Subroutine
_parse_css: called CC=16 SCAR=27.7
| |||||||||||||||||||||||||||||
| 448 | 72 | my ($self, $str, $substash, $symbols, $chain) = @_; | |||||||||||||||||||||||||||
| 449 | 72 | ▶ | $chain ||= []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$chain ||= []
MC/DC100%1/1
$chain ||= []
$chain
Truth table100%2/2
A
A= $chain
| |||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | ######### | ||||||||||||||||||||||||||||
| 452 | # /* comment */ | ||||||||||||||||||||||||||||
| 453 | # // comment | ||||||||||||||||||||||||||||
| 454 | # | ||||||||||||||||||||||||||||
| 455 | 72 | $str =~ s{$Text::Sass::Token::COMMENT}{}smxg; | |||||||||||||||||||||||||||
| 456 | 72 | $str =~ s{$Text::Sass::Token::SINGLE_LINE_COMMENT}{}smxg; | |||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | # Normalize line breaks | ||||||||||||||||||||||||||||
| 459 | 72 | $str =~ s/\n//sg; ## no critic (RegularExpressions) | |||||||||||||||||||||||||||
| 460 | 72 | $str =~ s/;/;\n/sg; ## no critic (RegularExpressions) | |||||||||||||||||||||||||||
| 461 | 72 | $str =~ s/{/{\n/sg; ## no critic (RegularExpressions) | |||||||||||||||||||||||||||
| 462 | 72 | $str =~ s/}/}\n/sg; ## no critic (RegularExpressions) | |||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | ######### | ||||||||||||||||||||||||||||
| 465 | # scss definitions | ||||||||||||||||||||||||||||
| 466 | # | ||||||||||||||||||||||||||||
| 467 | 72 | $str =~ s{^\s*\$(\S+)\s*:\s*(.*?)\s*\;}{ | |||||||||||||||||||||||||||
| 468 | 13 | $symbols->{variables}->{$1} = $2; | |||||||||||||||||||||||||||
| 469 | 13 | ▶ | $DEBUG and carp qq[VARIABLE $1 = $2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 470 | 13 | q[]; | |||||||||||||||||||||||||||
| 471 | }smxegi; | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 72 | my $groups = $self->_css_nestedgroups($str); | |||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | 72 | for my $g (@{$groups}) { | |||||||||||||||||||||||||||
| 476 | 87 | my ($tokens, $block) = $g =~ m/([^{]*)[{](.*)[}]/smxg; | |||||||||||||||||||||||||||
| 477 | 87 | $tokens =~ s/^\s+//smx; | |||||||||||||||||||||||||||
| 478 | 87 | $tokens =~ s/\s+$//smx; | |||||||||||||||||||||||||||
| 479 | 87 | $tokens =~ s/\n\s+/\n/smx; | |||||||||||||||||||||||||||
| 480 | 87 | $tokens =~ s/\s+\n/\n/smx; | |||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 87 | ▶ | if ($tokens =~ /^\s*\@mixin\s+(.*)$/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 483 | 7 | my $proto = $1; | |||||||||||||||||||||||||||
| 484 | 7 | my ($func) = $1 =~ /^([^(]+)/smx; | |||||||||||||||||||||||||||
| 485 | 7 | $symbols->{mixins}->{$func} = "$proto {\n$block\n}\n"; | |||||||||||||||||||||||||||
| 486 | 7 | ▶ | $DEBUG and carp qq[MIXIN $func]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 487 | 7 | next; | |||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 80 | my $kvs = $self->_css_kvs($block); | |||||||||||||||||||||||||||
| 491 | 80 | my $ssubstash = []; | |||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 80 | for my $kv (@{$kvs}) { | |||||||||||||||||||||||||||
| 494 | 103 | $kv =~ s/^\s+//smx; | |||||||||||||||||||||||||||
| 495 | 103 | $kv =~ s/\s+$//smx; | |||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | 103 | ▶ | if(!$kv) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 498 | 0 | next; | |||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 103 | ▶ | if ($kv =~ /[{].*[}]/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 502 | # Nested group - process recursively with parent chain | ||||||||||||||||||||||||||||
| 503 | 25 | my $newchain = [@{$chain}, $tokens]; | |||||||||||||||||||||||||||
| 504 | 25 | $self->_parse_css( $kv, $ssubstash, $symbols, $newchain ); | |||||||||||||||||||||||||||
| 505 | 25 | next; | |||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | 78 | ▶ | if ($kv =~ /^\s*\@include\s+(.*?)(?:[(](.*?)[)])?$/xms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 509 | 10 | my ($func, $argstr) = ($1, $2); | |||||||||||||||||||||||||||
| 510 | 10 | my $mixin_str = $symbols->{mixins}->{$func}; | |||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||
| 512 | 10 | my $subsymbols = $symbols; # todo: correct scoping - is better as {%{$symbols}} | |||||||||||||||||||||||||||
| 513 | 10 | ▶ | my $values = $argstr ? [split /\s*,\s*/smx, $argstr] : []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 514 | 10 | my ($varstr) = $mixin_str =~ /^.*?[(](.*?)[)]/smx; | |||||||||||||||||||||||||||
| 515 | 10 | my ($proto) = $mixin_str =~ /^\s*([^{]*\S)\s*[{]/smx; | |||||||||||||||||||||||||||
| 516 | 10 | ▶ | my $vars = $varstr ? [split /\s*,\s*/smx, $varstr] : []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 10 | for my $var (@{$vars}) { | |||||||||||||||||||||||||||
| 519 | 5 | $var =~ s/^[\!\$]//smx; | |||||||||||||||||||||||||||
| 520 | 5 | $subsymbols->{variables}->{$var} = shift @{$values}; | |||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | 10 | my $result = []; | |||||||||||||||||||||||||||
| 524 | 10 | $self->_parse_css($mixin_str, $result, $subsymbols, $chain); | |||||||||||||||||||||||||||
| 525 | 10 | push @{$ssubstash}, @{$result->[0]->{$proto}}; | |||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | 10 | ▶ | $DEBUG and carp qq[DYNAMIC MIXIN $func]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 528 | 10 | next; | |||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 68 | ▶ | if ($kv =~ /^\s*\@extend\s+(.*?)$/xms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 532 | 1 | my ($selector) = ($1, $2); | |||||||||||||||||||||||||||
| 533 | 1 | carp q[@extend not yet implemented]; ## no critic (RequireInterpolationOfMetachars) | |||||||||||||||||||||||||||
| 534 | 1 | next; | |||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | 67 | my ($key, $value) = split /:/smx, $kv, 2; | |||||||||||||||||||||||||||
| 538 | 67 | $key =~ s/^\s+//smx; | |||||||||||||||||||||||||||
| 539 | 67 | $key =~ s/\s+$//smx; | |||||||||||||||||||||||||||
| 540 | 67 | $value =~ s/^\s+//smx; | |||||||||||||||||||||||||||
| 541 | 67 | $value =~ s/\s+$//smx; | |||||||||||||||||||||||||||
| 542 | 67 | push @{$ssubstash}, { $key => $value }; | |||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | ######### | ||||||||||||||||||||||||||||
| 546 | # post-process parent references '&' | ||||||||||||||||||||||||||||
| 547 | # | ||||||||||||||||||||||||||||
| 548 | 80 | my $parent_processed = []; | |||||||||||||||||||||||||||
| 549 | #carp qq[SUBSTASH=].Dumper($substash); | ||||||||||||||||||||||||||||
| 550 | 80 | for my $child (@{$ssubstash}) { | |||||||||||||||||||||||||||
| 551 | #carp qq[CHILD=].Dumper($child); | ||||||||||||||||||||||||||||
| 552 | 104 | my ($k) = keys %{$child}; | |||||||||||||||||||||||||||
| 553 | 104 | my ($v) = $child->{$k}; | |||||||||||||||||||||||||||
| 554 | #carp qq[post-process k=$k v=$v tokens=$tokens]; | ||||||||||||||||||||||||||||
| 555 | # Prepend parent chain + tokens to selectors with & | ||||||||||||||||||||||||||||
| 556 | 104 | my $parent_selector = join q[ ], @{$chain}, $tokens; | |||||||||||||||||||||||||||
| 557 | 104 | $k =~ s{(.*)&}{&$1$parent_selector}smx; | |||||||||||||||||||||||||||
| 558 | #carp qq[post-process kafter=$k]; | ||||||||||||||||||||||||||||
| 559 | 104 | push @{$parent_processed}, { $k => $v }; | |||||||||||||||||||||||||||
| 560 | #carp Dumper($substash); | ||||||||||||||||||||||||||||
| 561 | #carp Dumper({$tokens => $parent_processed}); | ||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 80 | push @{$substash}, { $tokens => $parent_processed }; | |||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||
| 566 | 72 | return 1; | |||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | 117 | ▶ | sub _stash2css { | ||||||||||||||||||||||||||
|
Subroutine
_stash2css: called CC=17 SCAR=28.3
| |||||||||||||||||||||||||||||
| 570 | 117 | my ($self, $stash, $symbols) = @_; | |||||||||||||||||||||||||||
| 571 | 117 | my $groups = []; | |||||||||||||||||||||||||||
| 572 | 117 | my $delayed = []; | |||||||||||||||||||||||||||
| 573 | #carp qq[STASH2CSS: ].Dumper($stash); | ||||||||||||||||||||||||||||
| 574 | 117 | for my $stash_line (@{$stash}) { | |||||||||||||||||||||||||||
| 575 | 136 | for my $k (keys %{$stash_line}) { | |||||||||||||||||||||||||||
| 576 | 136 | my $vk = $k; | |||||||||||||||||||||||||||
| 577 | 136 | $vk =~ s/\s+/ /smx; | |||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | 136 | ▶ | if($k =~ /&/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 580 | 10 | ($vk) = $k =~ /&(.*)$/smx; | |||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | 10 | $stash_line->{$vk} = $stash_line->{$k}; | |||||||||||||||||||||||||||
| 583 | 10 | delete $stash_line->{$k}; | |||||||||||||||||||||||||||
| 584 | 10 | $k = $vk; | |||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | 136 | my $str = "$vk {\n"; | |||||||||||||||||||||||||||
| 588 | 136 | ▶ | if(!ref $stash_line->{$k}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 589 | 0 | $str .= sprintf q[ %s: %s], $vk, $stash_line->{$k}; | |||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | } else { | ||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | 136 | for my $attr_line (@{$stash_line->{$k}}) { | |||||||||||||||||||||||||||
| 594 | 197 | for my $attr (sort keys %{$attr_line}) { | |||||||||||||||||||||||||||
| 595 | 197 | my $val = $attr_line->{$attr}; | |||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | 197 | ▶ | if($attr =~ /^[+]/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 598 | 3 | $attr = q[]; | |||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | 197 | ▶ | if($attr =~ /:$/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 602 | ######### | ||||||||||||||||||||||||||||
| 603 | # font: | ||||||||||||||||||||||||||||
| 604 | # family: foo; | ||||||||||||||||||||||||||||
| 605 | # size: bar; | ||||||||||||||||||||||||||||
| 606 | # | ||||||||||||||||||||||||||||
| 607 | 3 | my $rattr = $attr; | |||||||||||||||||||||||||||
| 608 | 3 | $rattr =~ s/:$//smx; | |||||||||||||||||||||||||||
| 609 | 3 | for my $val_line (@{$val}) { | |||||||||||||||||||||||||||
| 610 | 9 | for my $k2 (sort keys %{$val_line}) { | |||||||||||||||||||||||||||
| 611 | 9 | $str .= sprintf qq[ %s-%s: %s;\n], $rattr, $k2, $self->_expr($stash, $symbols, $val_line->{$k2}); | |||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||
| 614 | 3 | next; | |||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||
| 617 | 194 | ▶ | if(ref $val) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 618 | 55 | ▶ | if($attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 619 | 52 | $attr = sprintf q[ %s], $attr; | |||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||
| 621 | 55 | ▶ | my $rattr = $k . ($attr ? $attr : q[]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | 55 | ▶ | if($k =~ /,/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 624 | 3 | $rattr = join q[, ], map { "$_$attr" } split /\s*,\s*/smx, $k; | |||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | 55 | ▶ | if($attr =~ /,/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 628 | 9 | $attr =~ s/^\s//smx; | |||||||||||||||||||||||||||
| 629 | 9 | $rattr = join q[, ], map { "$k $_" } split /\s*,\s*/smx, $attr; | |||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | # TODO: What if both have ,? | ||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | 55 | push @{$delayed}, $self->_stash2css([{$rattr => $val}], $symbols); | |||||||||||||||||||||||||||
| 635 | 55 | next; | |||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | 139 | $str .= sprintf qq[ %s: %s;\n], $attr, $self->_expr($stash, $symbols, $val); | |||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||
| 643 | 136 | $str .= "}\n"; | |||||||||||||||||||||||||||
| 644 | 136 | ▶ | if($str !~ /[{]\s*[}]/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 645 | 114 | push @{$groups}, $str; | |||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | 136 | push @{$groups}, @{$delayed}; | |||||||||||||||||||||||||||
| 649 | 136 | $delayed = []; | |||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | 117 | return join "\n", @{$groups}; | |||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | 176 | ▶ | sub _expr { | ||||||||||||||||||||||||||
|
Subroutine
_expr: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||
| 657 | 176 | my ($self, $stash, $symbols, $expr) = @_; | |||||||||||||||||||||||||||
| 658 | 176 | ▶ | my $vars = $symbols->{variables} || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$symbols->{'variables'} || {}
MC/DC100%1/1
$symbols->{'variables'} || {}
$symbols->{'variables'}
Truth table100%2/2
A
A= $symbols->{'variables'}
| |||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | ######### | ||||||||||||||||||||||||||||
| 661 | # Do variable expansion | ||||||||||||||||||||||||||||
| 662 | # | ||||||||||||||||||||||||||||
| 663 | 176 | ▶ | $expr =~ s/\!($Text::Sass::Token::IDENT)/{$vars->{$1}||"\!$1"}/smxeg; | ||||||||||||||||||||||||||
|
Condition50%1/2
$vars->{$1} || "!$1"
MC/DC0%0/1
$vars->{$1} || "!$1"
$vars->{$1}
Truth table50%1/2
A
A= $vars->{$1}
| |||||||||||||||||||||||||||||
| 664 | 176 | ▶ | $expr =~ s/\$($Text::Sass::Token::IDENT)/{$vars->{$1}||"\$$1"}/smxeg; | ||||||||||||||||||||||||||
|
Condition100%2/2
$vars->{$1} || "\$$1"
MC/DC100%1/1
$vars->{$1} || "\$$1"
$vars->{$1}
Truth table100%2/2
A
A= $vars->{$1}
| |||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | # TODO: should have lwp, so that url() will work | ||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | { | ||||||||||||||||||||||||||||
| 669 | # Functions | ||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||
| 671 | 176 | ▶ | while ($expr =~ /^(.*?)((\S+)\s*[(]([^)]+)[)](.*)$)/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 672 | 16 | my $start = $1; | |||||||||||||||||||||||||||
| 673 | 16 | my $mstr = $2; | |||||||||||||||||||||||||||
| 674 | 16 | my $func = $3; | |||||||||||||||||||||||||||
| 675 | 16 | my $varstr = $4; | |||||||||||||||||||||||||||
| 676 | 16 | my $end = $5; | |||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||
| 678 | ######### | ||||||||||||||||||||||||||||
| 679 | # We want hyphenated 'adjust-hue' to work | ||||||||||||||||||||||||||||
| 680 | # | ||||||||||||||||||||||||||||
| 681 | 16 | $func =~ s/\-/_/gsmx; | |||||||||||||||||||||||||||
| 682 | 16 | my ($implementor) = [grep { $_->can($func); } @{$FUNCTIONS}]->[0]; | |||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||
| 684 | 16 | ▶ | if (!$implementor) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 685 | 7 | $start = $self->_expr($stash, $symbols, $start); | |||||||||||||||||||||||||||
| 686 | 7 | $end = $self->_expr($stash, $symbols, $end); | |||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | ######### | ||||||||||||||||||||||||||||
| 689 | # not happy with this here. It probably at least belongs in Expr | ||||||||||||||||||||||||||||
| 690 | # - and should include any other CSS stop-words | ||||||||||||||||||||||||||||
| 691 | # | ||||||||||||||||||||||||||||
| 692 | 7 | ▶ | if($end =~ /repeat|left|top|right|bottom/smx) { ## no-repeat, repeat-x, repeat-y | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 693 | 6 | $end = q[]; | |||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | 7 | $expr = $start . $mstr . $end; | |||||||||||||||||||||||||||
| 697 | 7 | last; | |||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||
| 700 | ######### | ||||||||||||||||||||||||||||
| 701 | # TODO: Should support darken(#323, something(4+5, 5)) | ||||||||||||||||||||||||||||
| 702 | # | ||||||||||||||||||||||||||||
| 703 | 9 | my @vars = split /,/smx, $varstr; | |||||||||||||||||||||||||||
| 704 | 9 | for my $var (@vars) { | |||||||||||||||||||||||||||
| 705 | 14 | $var =~ s/^\s//smx; | |||||||||||||||||||||||||||
| 706 | 14 | $var = $self->_expr($stash, $symbols, $var); | |||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||
| 709 | 9 | my $res = $implementor->$func(@vars); | |||||||||||||||||||||||||||
| 710 | 9 | $expr =~ s/\Q$mstr\E/$res/smx; | |||||||||||||||||||||||||||
| 711 | 9 | last; | |||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | 176 | my @parts = split /\s+/smx, $expr; | |||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | 176 | Readonly::Scalar my $BINARY_OP_PARTS => 3; | |||||||||||||||||||||||||||
| 718 | 176 | ▶ | if(scalar @parts == $BINARY_OP_PARTS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 719 | 13 | my $ret = Text::Sass::Expr->expr(@parts); | |||||||||||||||||||||||||||
| 720 | 13 | ▶ | if (defined $ret) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 721 | 8 | return $ret; | |||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||
| 725 | 168 | return $expr; | |||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | 3 | ▶ | sub _stash2sass { | ||||||||||||||||||||||||||
|
Subroutine
_stash2sass: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 729 | 3 | my ($self, $stash, $symbols) = @_; | |||||||||||||||||||||||||||
| 730 | 3 | my $groups = []; | |||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||
| 732 | # TODO: Write symbols | ||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||
| 734 | 3 | for my $stashline (@{$stash}) { | |||||||||||||||||||||||||||
| 735 | 4 | for my $k (keys %{$stashline}) { | |||||||||||||||||||||||||||
| 736 | 4 | my $str = "$k\n"; | |||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||
| 738 | 4 | for my $attrline (@{$stashline->{$k}}){ | |||||||||||||||||||||||||||
| 739 | 6 | for my $attr (sort keys %{$attrline}) { | |||||||||||||||||||||||||||
| 740 | 6 | my $val = $attrline->{$attr}; | |||||||||||||||||||||||||||
| 741 | 6 | $str .= sprintf qq[ %s: %s\n], $attr, $val; | |||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||
| 744 | 4 | push @{$groups}, $str; | |||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||
| 748 | 3 | return join "\n", @{$groups}; | |||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | 34 | 1; | |||||||||||||||||||||||||||
| 752 | __END__ | ||||||||||||||||||||||||||||