Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 1 | package Mojolicious::Plugin::AssetPack::LibSass; |
| 2 | use Mojo::Base 'Mojolicious::Plugin'; |
| 3 | use CSS::Sass; |
| 4 | use CSS::Minifier::XS; |
| 5 | |
| 6 | sub register { |
| 7 | my ($plugin, $mojo) = @_; |
| 8 | |
| 9 | my $sass = CSS::Sass->new; |
| 10 | |
| 11 | # Todo: Check if AssetPack is loaded |
| 12 | # Todo: Only minify if necessary |
| 13 | |
| 14 | my $proc = $mojo->asset->preprocessors; |
| 15 | |
| 16 | $proc->remove('scss'); |
| 17 | $proc->add( |
| 18 | scss => sub { |
| 19 | my ($as, $text, $file) = @_; |
| 20 | $$text = CSS::Minifier::XS::minify($sass->compile($$text)); |
| 21 | }); |
| 22 | $proc->map_type(scss => 'css'); |
| 23 | }; |
| 24 | |
| 25 | 1; |
| 26 | |
| 27 | __END__ |