| 1 | package Template::Plugin::Filter::Scss; | ||
| 2 | 2 | ▶ | use 5.008001; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 2 | ▶ | use Template::Plugin::Filter; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 2 | ▶ | use base qw( Template::Plugin::Filter ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 2 | ▶ | use CSS::Sass; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | |||
| 11 | our $VERSION = "0.01"; | ||
| 12 | |||
| 13 | sub init { | ||
| 14 | my ($self) = @_; | ||
| 15 | $self->install_filter('scss'); | ||
| 16 | return $self; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub filter { | ||
| 20 | my ($self, $text) = @_; | ||
| 21 | |||
| 22 | my %options = (); | ||
| 23 | if ($self->{ _CONFIG } && (ref($self->{ _CONFIG }) eq 'HASH')) { | ||
| 24 | if ($self->{ _CONFIG }->{include_paths}) { | ||
| 25 | $options{include_paths} = [$self->{ _CONFIG }->{include_paths}]; | ||
| 26 | } | ||
| 27 | elsif ($self->{ _CONFIG }->{include_path}) { | ||
| 28 | $options{include_paths} = [$self->{ _CONFIG }->{include_path}]; | ||
| 29 | } | ||
| 30 | |||
| 31 | if ($self->{ _CONFIG }->{output_style}) { | ||
| 32 | $options{output_style} = SASS_STYLE_NESTED if uc($self->{ _CONFIG }->{output_style}) eq 'NESTED'; | ||
| 33 | $options{output_style} = SASS_STYLE_COMPACT if uc($self->{ _CONFIG }->{output_style}) eq 'COMPACT'; | ||
| 34 | $options{output_style} = SASS_STYLE_EXPANDED if uc($self->{ _CONFIG }->{output_style}) eq 'EXPANDED'; | ||
| 35 | $options{output_style} = SASS_STYLE_COMPRESSED if uc($self->{ _CONFIG }->{output_style}) eq 'COMPRESSED'; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | my $sass = CSS::Sass->new(%options); | ||
| 40 | |||
| 41 | my ($css, $stats) = $sass->compile($text); | ||
| 42 | return $css; | ||
| 43 | } | ||
| 44 | |||
| 45 | |||
| 46 | 1; | ||
| 47 | __END__ | ||