| 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 | 30 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 30 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 30 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 30 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 30 | ▶ | use Text::Sass::Expr; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 30 | ▶ | use Text::Sass::Functions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 30 | ▶ | use Text::Sass::Token; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 30 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 30 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 30 | our $VERSION = q[1.0.4]; | |||||||||||||||||||||||||||
| 25 | 30 | our $DEBUG = 0; | |||||||||||||||||||||||||||
| 26 | 30 | our $FUNCTIONS = [qw(Text::Sass::Functions)]; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 30 | Readonly::Scalar our $DEBUG_SEPARATOR => 30; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub import { | ||||||||||||||||||||||||||||
| 31 | 29 | ▶ | my ($class, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 29 | ▶ | if(!scalar @args % 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 26 | my $args = {@args}; | |||||||||||||||||||||||||||
| 35 | 26 | ▶ | 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 | 29 | return 1; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub new { | ||||||||||||||||||||||||||||
| 48 | 53 | ▶ | my ($class, $ref) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 53 | ▶ | if(!$ref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 53 | $ref = {}; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 53 | bless $ref, $class; | |||||||||||||||||||||||||||
| 55 | 53 | return $ref; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub css2sass { | ||||||||||||||||||||||||||||
| 59 | 3 | ▶ | my ($self, $str) = @_; | ||||||||||||||||||||||||||
|
Subroutine
css2sass: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | sub sass2css { | ||||||||||||||||||||||||||||
| 72 | 28 | ▶ | my ($self, $str) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sass2css: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 28 | ▶ | if(!ref $self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | $self = $self->new; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 28 | my $symbols = {}; | |||||||||||||||||||||||||||
| 79 | 28 | my $stash = []; | |||||||||||||||||||||||||||
| 80 | 28 | my $chain = []; | |||||||||||||||||||||||||||
| 81 | 28 | $self->{_sass_indent} = 0; | |||||||||||||||||||||||||||
| 82 | 28 | $self->_parse_sass($str, $stash, $symbols, $chain); | |||||||||||||||||||||||||||
| 83 | 27 | return $self->_stash2css($stash, $symbols); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub scss2css { | ||||||||||||||||||||||||||||
| 87 | 24 | ▶ | my ($self, $str) = @_; | ||||||||||||||||||||||||||
|
Subroutine
scss2css: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 24 | ▶ | if(!ref $self) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $self = $self->new; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 24 | my $symbols = {}; | |||||||||||||||||||||||||||
| 94 | 24 | my $stash = []; | |||||||||||||||||||||||||||
| 95 | 24 | $self->_parse_css($str, $stash, $symbols); | |||||||||||||||||||||||||||
| 96 | 24 | return $self->_stash2css($stash, $symbols); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub _parse_sass { | ||||||||||||||||||||||||||||
| 100 | 169 | ▶ | my ($self, $str, $substash, $symbols, $chain) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse_sass: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 101 | 169 | ▶ | $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 | 169 | $str =~ s/\n(\S)/\n\n$1/smxg; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | ######### | ||||||||||||||||||||||||||||
| 113 | # strip blank lines from: | ||||||||||||||||||||||||||||
| 114 | # <blank line> | ||||||||||||||||||||||||||||
| 115 | # code | ||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||
| 117 | 169 | $str =~ s/^\s*\n(\s+)/$1/smxg; | |||||||||||||||||||||||||||
| 118 | 169 | my $groups = [split /\n\s*?\n/smx, $str]; | |||||||||||||||||||||||||||
| 119 | 169 | for my $g (@{$groups}) { | |||||||||||||||||||||||||||
| 120 | 239 | $self->_parse_sass_group($substash, $symbols, $chain, $g); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 166 | ▶ | $DEBUG and print {*STDERR} q[=]x$DEBUG_SEPARATOR, q[ end _parse_sass ], q[=]x$DEBUG_SEPARATOR, "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 166 | return 1; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub _parse_sass_group { | ||||||||||||||||||||||||||||
| 129 | 239 | ▶ | my ($self, $substash, $symbols, $chain, $group) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse_sass_group: called CC=28 SCAR=33.7
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 239 | my @lines = split /\n/smx, $group; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 239 | ▶ | while(my $line = shift @lines) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | ######### | ||||||||||||||||||||||||||||
| 135 | # /* comment */ | ||||||||||||||||||||||||||||
| 136 | # /* comment | ||||||||||||||||||||||||||||
| 137 | # | ||||||||||||||||||||||||||||
| 138 | 240 | $line =~ s{/[*].*?[*]/\s*}{}smx; | |||||||||||||||||||||||||||
| 139 | 240 | $line =~ s{/[*].*$}{}smx; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | ######### | ||||||||||||||||||||||||||||
| 142 | # !x = y variable declarations | ||||||||||||||||||||||||||||
| 143 | # | ||||||||||||||||||||||||||||
| 144 | 240 | $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 | 240 | $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 | 240 | $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 | 240 | $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 | 240 | $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 | 240 | $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 | 240 | $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 | 240 | $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 | 240 | $line =~ s{^(\S+)\s*[:=]\s*(.*?)$}{ | |||||||||||||||||||||||||||
| 289 | 86 | my $key = $1; | |||||||||||||||||||||||||||
| 290 | 86 | my $val = $2; | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 86 | ▶ | $DEBUG and carp qq[ATTR $key = $val]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 86 | ▶ | 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 | 84 | push @{$substash}, { $key => $val }; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | 86 | q[]; | |||||||||||||||||||||||||||
| 304 | }smxegi; | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | ######### | ||||||||||||||||||||||||||||
| 307 | # <x-space indented sub-content> | ||||||||||||||||||||||||||||
| 308 | # | ||||||||||||||||||||||||||||
| 309 | 240 | ▶ | if ($line =~ /^([ ]+)(\S.*)$/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 71 | my $indent = $1; | |||||||||||||||||||||||||||
| 311 | # Indented | ||||||||||||||||||||||||||||
| 312 | 71 | ▶ | if (!$self->{_sass_indent}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 28 | $self->{_sass_indent} = length $1; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 71 | ▶ | if ($line =~ /^[ ]{$self->{_sass_indent}}(\S.*)$/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 70 | my $process = []; | |||||||||||||||||||||||||||
| 318 | 70 | ▶ | while (my $l = shift @lines) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | 92 | ▶ | if($l =~ /^[ ]{$self->{_sass_indent}}(.*)$/smx) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 320 | 92 | 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 | 70 | my $remaining = join "\n", $1, @{$process}; | |||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 70 | ▶ | $DEBUG and carp qq[INDENTED $line CALLING DOWN REMAINING=$remaining ].Dumper($substash); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 70 | $self->_parse_sass($remaining, $substash, $symbols, [@{$chain}]); | |||||||||||||||||||||||||||
| 334 | 69 | $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 | 238 | $line =~ s{^(\S+.*?)$}{ | |||||||||||||||||||||||||||
| 349 | 62 | my $one = $1; | |||||||||||||||||||||||||||
| 350 | 62 | $one =~ s/\s+/ /smxg; | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 62 | my $remaining = join "\n", @lines; | |||||||||||||||||||||||||||
| 353 | 62 | @lines = (); | |||||||||||||||||||||||||||
| 354 | 62 | my $subsubstash = []; | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 62 | ▶ | $DEBUG and carp qq[ELEMENT $one descending with REMAINING=$remaining]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | 62 | ▶ | $DEBUG and carp Dumper($substash); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | 62 | $self->_parse_sass($remaining, $subsubstash, $symbols, [@{$chain}, $one]); | |||||||||||||||||||||||||||
| 359 | 61 | push @{$substash}, { $one => $subsubstash }; | |||||||||||||||||||||||||||
| 360 | 61 | ▶ | $DEBUG and carp qq[ELEMENT $one returned]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | 61 | ▶ | $DEBUG and carp Dumper($substash); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | 61 | q[]; | |||||||||||||||||||||||||||
| 363 | }smxegi; | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 237 | ▶ | $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 | 236 | return 1; | |||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | sub _parse_sass_parentref { ## no critic (ProhibitManyArgs) # todo: tidy this up! | ||||||||||||||||||||||||||||
| 372 | 3 | ▶ | my ($self, $substash, $symbols, $chain, $lines, $pseudo) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse_sass_parentref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 3 | my $remaining = join "\n", @{$lines}; | |||||||||||||||||||||||||||
| 375 | 3 | @{$lines} = (); | |||||||||||||||||||||||||||
| 376 | 3 | my $newkey = join q[ ], @{$chain}; | |||||||||||||||||||||||||||
| 377 | 3 | $pseudo =~ s/&/&$newkey/smx; | |||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 3 | my $subsubstash = []; | |||||||||||||||||||||||||||
| 380 | 3 | $self->_parse_sass($remaining, $subsubstash, $symbols, ['TBD']); | |||||||||||||||||||||||||||
| 381 | 3 | push @{$substash}, {$pseudo => $subsubstash}; | |||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 3 | return q[]; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | sub _css_nestedgroups { | ||||||||||||||||||||||||||||
| 387 | 42 | ▶ | my ($self, $str) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_css_nestedgroups: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 42 | my $groups = []; | |||||||||||||||||||||||||||
| 390 | 42 | my $groupstr = q[]; | |||||||||||||||||||||||||||
| 391 | 42 | my $indent = 0; | |||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | 42 | for my $i (0..length $str ) { | |||||||||||||||||||||||||||
| 394 | 2826 | my $char = substr $str, $i, 1; | |||||||||||||||||||||||||||
| 395 | 2826 | $groupstr .= $char; | |||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 2826 | ▶ | if ($char eq '{') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | 66 | $indent++; | |||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 2826 | ▶ | if ($char eq '}') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | 66 | $indent--; | |||||||||||||||||||||||||||
| 403 | 66 | ▶ | if ($indent == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 52 | push @{$groups}, $groupstr; | |||||||||||||||||||||||||||
| 405 | 52 | $groupstr = q[]; | |||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 42 | return $groups; | |||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | sub _css_kvs { | ||||||||||||||||||||||||||||
| 414 | 49 | ▶ | my ($self, $str) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_css_kvs: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 49 | my $groups = []; | |||||||||||||||||||||||||||
| 417 | 49 | my $groupstr = q[]; | |||||||||||||||||||||||||||
| 418 | 49 | my $indent = 0; | |||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 49 | for my $i (0..length $str) { | |||||||||||||||||||||||||||
| 421 | 2101 | my $char = substr $str, $i, 1; | |||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 2101 | ▶ | 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 | 59 | push @{$groups}, $groupstr; | |||||||||||||||||||||||||||
| 425 | 59 | $groupstr = q[]; | |||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | } else { | ||||||||||||||||||||||||||||
| 428 | 2042 | $groupstr .= $char; | |||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 2101 | ▶ | if ($char eq '{') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | 12 | $indent++; | |||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 2101 | ▶ | if ($char eq '}') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | 12 | $indent--; | |||||||||||||||||||||||||||
| 437 | 12 | ▶ | if ($indent == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | 11 | push @{$groups}, $groupstr; | |||||||||||||||||||||||||||
| 439 | 11 | $groupstr = q[]; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 49 | return $groups; | |||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | sub _parse_css { | ||||||||||||||||||||||||||||
| 448 | 42 | ▶ | my ($self, $str, $substash, $symbols) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse_css: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | ######### | ||||||||||||||||||||||||||||
| 451 | # /* comment */ | ||||||||||||||||||||||||||||
| 452 | # // comment | ||||||||||||||||||||||||||||
| 453 | # | ||||||||||||||||||||||||||||
| 454 | 42 | $str =~ s{$Text::Sass::Token::COMMENT}{}smxg; | |||||||||||||||||||||||||||
| 455 | 42 | $str =~ s{$Text::Sass::Token::SINGLE_LINE_COMMENT}{}smxg; | |||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | # Normalize line breaks | ||||||||||||||||||||||||||||
| 458 | 42 | $str =~ s/\n//sg; ## no critic (RegularExpressions) | |||||||||||||||||||||||||||
| 459 | 42 | $str =~ s/;/;\n/sg; ## no critic (RegularExpressions) | |||||||||||||||||||||||||||
| 460 | 42 | $str =~ s/{/{\n/sg; ## no critic (RegularExpressions) | |||||||||||||||||||||||||||
| 461 | 42 | $str =~ s/}/}\n/sg; ## no critic (RegularExpressions) | |||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | ######### | ||||||||||||||||||||||||||||
| 464 | # scss definitions | ||||||||||||||||||||||||||||
| 465 | # | ||||||||||||||||||||||||||||
| 466 | 42 | $str =~ s{^\s*\$(\S+)\s*:\s*(.*?)\s*\;}{ | |||||||||||||||||||||||||||
| 467 | 11 | $symbols->{variables}->{$1} = $2; | |||||||||||||||||||||||||||
| 468 | 11 | ▶ | $DEBUG and carp qq[VARIABLE $1 = $2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 469 | 11 | q[]; | |||||||||||||||||||||||||||
| 470 | }smxegi; | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 42 | my $groups = $self->_css_nestedgroups($str); | |||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | 42 | for my $g (@{$groups}) { | |||||||||||||||||||||||||||
| 475 | 52 | my ($tokens, $block) = $g =~ m/([^{]*)[{](.*)[}]/smxg; | |||||||||||||||||||||||||||
| 476 | 52 | $tokens =~ s/^\s+//smx; | |||||||||||||||||||||||||||
| 477 | 52 | $tokens =~ s/\s+$//smx; | |||||||||||||||||||||||||||
| 478 | 52 | $tokens =~ s/\n\s+/\n/smx; | |||||||||||||||||||||||||||
| 479 | 52 | $tokens =~ s/\s+\n/\n/smx; | |||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 52 | ▶ | if ($tokens =~ /^\s*\@mixin\s+(.*)$/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 482 | 3 | my $proto = $1; | |||||||||||||||||||||||||||
| 483 | 3 | my ($func) = $1 =~ /^([^(]+)/smx; | |||||||||||||||||||||||||||
| 484 | 3 | $symbols->{mixins}->{$func} = "$proto {\n$block\n}\n"; | |||||||||||||||||||||||||||
| 485 | 3 | ▶ | $DEBUG and carp qq[MIXIN $func]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | 3 | next; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 49 | my $kvs = $self->_css_kvs($block); | |||||||||||||||||||||||||||
| 490 | 49 | my $ssubstash = []; | |||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | 49 | for my $kv (@{$kvs}) { | |||||||||||||||||||||||||||
| 493 | 70 | $kv =~ s/^\s+//smx; | |||||||||||||||||||||||||||
| 494 | 70 | $kv =~ s/\s+$//smx; | |||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | 70 | ▶ | if(!$kv) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 497 | 0 | next; | |||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 70 | ▶ | if ($kv =~ /[{].*[}]/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 501 | 11 | $self->_parse_css( $kv, $ssubstash, $symbols ); | |||||||||||||||||||||||||||
| 502 | 11 | next; | |||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 59 | ▶ | if ($kv =~ /^\s*\@include\s+(.*?)(?:[(](.*?)[)])?$/xms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 506 | 4 | my ($func, $argstr) = ($1, $2); | |||||||||||||||||||||||||||
| 507 | 4 | my $mixin_str = $symbols->{mixins}->{$func}; | |||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 4 | my $subsymbols = $symbols; # todo: correct scoping - is better as {%{$symbols}} | |||||||||||||||||||||||||||
| 510 | 4 | ▶ | my $values = $argstr ? [split /\s*,\s*/smx, $argstr] : []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 511 | 4 | my ($varstr) = $mixin_str =~ /^.*?[(](.*?)[)]/smx; | |||||||||||||||||||||||||||
| 512 | 4 | my ($proto) = $mixin_str =~ /^\s*([^{]*\S)\s*[{]/smx; | |||||||||||||||||||||||||||
| 513 | 4 | ▶ | my $vars = $varstr ? [split /\s*,\s*/smx, $varstr] : []; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 4 | for my $var (@{$vars}) { | |||||||||||||||||||||||||||
| 516 | 1 | $var =~ s/^[\!\$]//smx; | |||||||||||||||||||||||||||
| 517 | 1 | $subsymbols->{variables}->{$var} = shift @{$values}; | |||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | 4 | my $result = []; | |||||||||||||||||||||||||||
| 521 | 4 | $self->_parse_css($mixin_str, $result, $subsymbols); | |||||||||||||||||||||||||||
| 522 | 4 | push @{$ssubstash}, @{$result->[0]->{$proto}}; | |||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | 4 | ▶ | $DEBUG and carp qq[DYNAMIC MIXIN $func]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 525 | 4 | next; | |||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | 55 | ▶ | if ($kv =~ /^\s*\@extend\s+(.*?)$/xms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 529 | 1 | my ($selector) = ($1, $2); | |||||||||||||||||||||||||||
| 530 | 1 | carp q[@extend not yet implemented]; ## no critic (RequireInterpolationOfMetachars) | |||||||||||||||||||||||||||
| 531 | 1 | next; | |||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | 54 | my ($key, $value) = split /:/smx, $kv, 2; | |||||||||||||||||||||||||||
| 535 | 54 | $key =~ s/^\s+//smx; | |||||||||||||||||||||||||||
| 536 | 54 | $key =~ s/\s+$//smx; | |||||||||||||||||||||||||||
| 537 | 54 | $value =~ s/^\s+//smx; | |||||||||||||||||||||||||||
| 538 | 54 | $value =~ s/\s+$//smx; | |||||||||||||||||||||||||||
| 539 | 54 | push @{$ssubstash}, { $key => $value }; | |||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | ######### | ||||||||||||||||||||||||||||
| 543 | # post-process parent references '&' | ||||||||||||||||||||||||||||
| 544 | # | ||||||||||||||||||||||||||||
| 545 | 49 | my $parent_processed = []; | |||||||||||||||||||||||||||
| 546 | #carp qq[SUBSTASH=].Dumper($substash); | ||||||||||||||||||||||||||||
| 547 | 49 | for my $child (@{$ssubstash}) { | |||||||||||||||||||||||||||
| 548 | #carp qq[CHILD=].Dumper($child); | ||||||||||||||||||||||||||||
| 549 | 71 | my ($k) = keys %{$child}; | |||||||||||||||||||||||||||
| 550 | 71 | my ($v) = $child->{$k}; | |||||||||||||||||||||||||||
| 551 | #carp qq[post-process k=$k v=$v tokens=$tokens]; | ||||||||||||||||||||||||||||
| 552 | 71 | $k =~ s{(.*)&}{&$1$tokens}smx; | |||||||||||||||||||||||||||
| 553 | #carp qq[post-process kafter=$k]; | ||||||||||||||||||||||||||||
| 554 | 71 | push @{$parent_processed}, { $k => $v }; | |||||||||||||||||||||||||||
| 555 | #carp Dumper($substash); | ||||||||||||||||||||||||||||
| 556 | #carp Dumper({$tokens => $parent_processed}); | ||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | 49 | push @{$substash}, { $tokens => $parent_processed }; | |||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||
| 561 | 42 | return 1; | |||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | sub _stash2css { | ||||||||||||||||||||||||||||
| 565 | 89 | ▶ | my ($self, $stash, $symbols) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_stash2css: called CC=17 SCAR=28.3
| |||||||||||||||||||||||||||||
| 566 | 89 | my $groups = []; | |||||||||||||||||||||||||||
| 567 | 89 | my $delayed = []; | |||||||||||||||||||||||||||
| 568 | #carp qq[STASH2CSS: ].Dumper($stash); | ||||||||||||||||||||||||||||
| 569 | 89 | for my $stash_line (@{$stash}) { | |||||||||||||||||||||||||||
| 570 | 107 | for my $k (keys %{$stash_line}) { | |||||||||||||||||||||||||||
| 571 | 107 | my $vk = $k; | |||||||||||||||||||||||||||
| 572 | 107 | $vk =~ s/\s+/ /smx; | |||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | 107 | ▶ | if($k =~ /&/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 575 | 6 | ($vk) = $k =~ /&(.*)$/smx; | |||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | 6 | $stash_line->{$vk} = $stash_line->{$k}; | |||||||||||||||||||||||||||
| 578 | 6 | delete $stash_line->{$k}; | |||||||||||||||||||||||||||
| 579 | 6 | $k = $vk; | |||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | 107 | my $str = "$vk {\n"; | |||||||||||||||||||||||||||
| 583 | 107 | ▶ | if(!ref $stash_line->{$k}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 584 | 0 | $str .= sprintf q[ %s: %s], $vk, $stash_line->{$k}; | |||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | } else { | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | 107 | for my $attr_line (@{$stash_line->{$k}}) { | |||||||||||||||||||||||||||
| 589 | 163 | for my $attr (sort keys %{$attr_line}) { | |||||||||||||||||||||||||||
| 590 | 163 | my $val = $attr_line->{$attr}; | |||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | 163 | ▶ | if($attr =~ /^[+]/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 593 | 3 | $attr = q[]; | |||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | 163 | ▶ | if($attr =~ /:$/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 597 | ######### | ||||||||||||||||||||||||||||
| 598 | # font: | ||||||||||||||||||||||||||||
| 599 | # family: foo; | ||||||||||||||||||||||||||||
| 600 | # size: bar; | ||||||||||||||||||||||||||||
| 601 | # | ||||||||||||||||||||||||||||
| 602 | 3 | my $rattr = $attr; | |||||||||||||||||||||||||||
| 603 | 3 | $rattr =~ s/:$//smx; | |||||||||||||||||||||||||||
| 604 | 3 | for my $val_line (@{$val}) { | |||||||||||||||||||||||||||
| 605 | 9 | for my $k2 (sort keys %{$val_line}) { | |||||||||||||||||||||||||||
| 606 | 9 | $str .= sprintf qq[ %s-%s: %s;\n], $rattr, $k2, $self->_expr($stash, $symbols, $val_line->{$k2}); | |||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||
| 609 | 3 | next; | |||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | 160 | ▶ | if(ref $val) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 613 | 38 | ▶ | if($attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 614 | 35 | $attr = sprintf q[ %s], $attr; | |||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||
| 616 | 38 | ▶ | my $rattr = $k . ($attr ? $attr : q[]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | 38 | ▶ | if($k =~ /,/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 619 | 1 | $rattr = join q[, ], map { "$_$attr" } split /\s*,\s*/smx, $k; | |||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | 38 | ▶ | if($attr =~ /,/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 623 | 3 | $attr =~ s/^\s//smx; | |||||||||||||||||||||||||||
| 624 | 3 | $rattr = join q[, ], map { "$k $_" } split /\s*,\s*/smx, $attr; | |||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | # TODO: What if both have ,? | ||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | 38 | push @{$delayed}, $self->_stash2css([{$rattr => $val}], $symbols); | |||||||||||||||||||||||||||
| 630 | 38 | next; | |||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | 122 | $str .= sprintf qq[ %s: %s;\n], $attr, $self->_expr($stash, $symbols, $val); | |||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | 107 | $str .= "}\n"; | |||||||||||||||||||||||||||
| 639 | 107 | ▶ | if($str !~ /[{]\s*[}]/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 640 | 97 | push @{$groups}, $str; | |||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||
| 643 | 107 | push @{$groups}, @{$delayed}; | |||||||||||||||||||||||||||
| 644 | 107 | $delayed = []; | |||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | 89 | return join "\n", @{$groups}; | |||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||
| 651 | sub _expr { | ||||||||||||||||||||||||||||
| 652 | 159 | ▶ | my ($self, $stash, $symbols, $expr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_expr: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||
| 653 | 159 | ▶ | 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'}
| |||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||
| 655 | ######### | ||||||||||||||||||||||||||||
| 656 | # Do variable expansion | ||||||||||||||||||||||||||||
| 657 | # | ||||||||||||||||||||||||||||
| 658 | 159 | ▶ | $expr =~ s/\!($Text::Sass::Token::IDENT)/{$vars->{$1}||"\!$1"}/smxeg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 659 | 159 | ▶ | $expr =~ s/\$($Text::Sass::Token::IDENT)/{$vars->{$1}||"\$$1"}/smxeg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | # TODO: should have lwp, so that url() will work | ||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | { | ||||||||||||||||||||||||||||
| 664 | # Functions | ||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | 159 | ▶ | while ($expr =~ /^(.*?)((\S+)\s*[(]([^)]+)[)](.*)$)/smx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 667 | 16 | my $start = $1; | |||||||||||||||||||||||||||
| 668 | 16 | my $mstr = $2; | |||||||||||||||||||||||||||
| 669 | 16 | my $func = $3; | |||||||||||||||||||||||||||
| 670 | 16 | my $varstr = $4; | |||||||||||||||||||||||||||
| 671 | 16 | my $end = $5; | |||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||
| 673 | ######### | ||||||||||||||||||||||||||||
| 674 | # We want hyphenated 'adjust-hue' to work | ||||||||||||||||||||||||||||
| 675 | # | ||||||||||||||||||||||||||||
| 676 | 16 | $func =~ s/\-/_/gsmx; | |||||||||||||||||||||||||||
| 677 | 16 | my ($implementor) = [grep { $_->can($func); } @{$FUNCTIONS}]->[0]; | |||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||
| 679 | 16 | ▶ | if (!$implementor) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 680 | 7 | $start = $self->_expr($stash, $symbols, $start); | |||||||||||||||||||||||||||
| 681 | 7 | $end = $self->_expr($stash, $symbols, $end); | |||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | ######### | ||||||||||||||||||||||||||||
| 684 | # not happy with this here. It probably at least belongs in Expr | ||||||||||||||||||||||||||||
| 685 | # - and should include any other CSS stop-words | ||||||||||||||||||||||||||||
| 686 | # | ||||||||||||||||||||||||||||
| 687 | 7 | ▶ | if($end =~ /repeat|left|top|right|bottom/smx) { ## no-repeat, repeat-x, repeat-y | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 688 | 6 | $end = q[]; | |||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | 7 | $expr = $start . $mstr . $end; | |||||||||||||||||||||||||||
| 692 | 7 | last; | |||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||
| 695 | ######### | ||||||||||||||||||||||||||||
| 696 | # TODO: Should support darken(#323, something(4+5, 5)) | ||||||||||||||||||||||||||||
| 697 | # | ||||||||||||||||||||||||||||
| 698 | 9 | my @vars = split /,/smx, $varstr; | |||||||||||||||||||||||||||
| 699 | 9 | for my $var (@vars) { | |||||||||||||||||||||||||||
| 700 | 14 | $var =~ s/^\s//smx; | |||||||||||||||||||||||||||
| 701 | 14 | $var = $self->_expr($stash, $symbols, $var); | |||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||
| 704 | 9 | my $res = $implementor->$func(@vars); | |||||||||||||||||||||||||||
| 705 | 9 | $expr =~ s/\Q$mstr\E/$res/smx; | |||||||||||||||||||||||||||
| 706 | 9 | last; | |||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | 159 | my @parts = split /\s+/smx, $expr; | |||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||
| 712 | 159 | Readonly::Scalar my $BINARY_OP_PARTS => 3; | |||||||||||||||||||||||||||
| 713 | 159 | ▶ | if(scalar @parts == $BINARY_OP_PARTS) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 714 | 11 | my $ret = Text::Sass::Expr->expr(@parts); | |||||||||||||||||||||||||||
| 715 | 11 | ▶ | if (defined $ret) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 716 | 8 | return $ret; | |||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||
| 720 | 151 | return $expr; | |||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||
| 723 | sub _stash2sass { | ||||||||||||||||||||||||||||
| 724 | 3 | ▶ | my ($self, $stash, $symbols) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_stash2sass: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 725 | 3 | my $groups = []; | |||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | # TODO: Write symbols | ||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | 3 | for my $stashline (@{$stash}) { | |||||||||||||||||||||||||||
| 730 | 4 | for my $k (keys %{$stashline}) { | |||||||||||||||||||||||||||
| 731 | 4 | my $str = "$k\n"; | |||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||
| 733 | 4 | for my $attrline (@{$stashline->{$k}}){ | |||||||||||||||||||||||||||
| 734 | 6 | for my $attr (sort keys %{$attrline}) { | |||||||||||||||||||||||||||
| 735 | 6 | my $val = $attrline->{$attr}; | |||||||||||||||||||||||||||
| 736 | 6 | $str .= sprintf qq[ %s: %s\n], $attr, $val; | |||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||
| 739 | 4 | push @{$groups}, $str; | |||||||||||||||||||||||||||
| 740 | } | ||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||
| 743 | 3 | return join "\n", @{$groups}; | |||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||
| 746 | 30 | 1; | |||||||||||||||||||||||||||
| 747 | __END__ | ||||||||||||||||||||||||||||