Skip to content

Commit

Permalink
Make it always operate on a Bailador::App object
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed May 6, 2016
1 parent d439d0c commit 951de9f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"perl" : "6.c",
"name" : "Bailador::Plugin::AssetPack::SASS",
"version" : "1.001001",
"version" : "2.001001",
"description" : "Automatically preprocess and serve SASS files in Bailador apps",
"depends" : [
"Bailador"
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Bailador::Plugin::AssetPack::SASS - automatically serve static files
use Bailador;
use Bailador::Plugin::AssetPack::SASS;

Bailador::Plugin::AssetPack::SASS.install;
Bailador::Plugin::AssetPack::SASS.install: app;

```

Expand All @@ -27,9 +27,11 @@ http://sass-lang.com/install
## `.install`

```perl6
Bailador::Plugin::AssetPack::SASS.install;
Bailador::Plugin::AssetPack::SASS.install: $app;
```

Takes one argument: your `Bailador::App` object.

Starts `sass` watcher and creates a route for delivering CSS files from
`/assets/sass/*` URL, where the filename (and directory structure) from
`assets/sass` directory is preserved, except you'd refer to the file by
Expand All @@ -41,8 +43,8 @@ NOTE: if you're also using
be sure to include it AFTER `::AssetPack::SASS` or it'll shadow the created route:

```perl6
Bailador::Plugin::AssetPack::SASS.install;
Bailador::Plugin::Static.install;
Bailador::Plugin::AssetPack::SASS.install: $app;
Bailador::Plugin::Static.install: $app;
```

----
Expand Down
14 changes: 6 additions & 8 deletions lib/Bailador/Plugin/AssetPack/SASS.pm6
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
unit class Bailador::Plugin::AssetPack::SASS:ver<1.001001>;
unit class Bailador::Plugin::AssetPack::SASS:ver<2.001001>;

use Bailador;

method install {
method install ($app) {
my $sass = Proc::Async.new: 'sass', '--style', 'compressed',
'--watch', $*SPEC.catdir('assets', 'sass');

$sass.stdout.tap: -> $v { $*OUT.print: $v };
$sass.stderr.tap: -> $v { $*ERR.print: $v };
$sass.start;

get rx{ ^ '/assets/sass/' (.+) $ } => sub ($name) {
$app.get: rx{ ^ '/assets/sass/' (.+) $ } => sub ($name) {
my $file = $*SPEC.catdir('assets', 'sass', $name).IO;
return status 404 unless .extension eq 'css' and .f and .r given $file;
content_type 'text/css';
return $file.IO.slurp: :bin;
return $app.response.code: 404 unless .extension eq 'css' and .f and .r given $file;
$app.response.headers<Content-Type> = 'text/css';
$app.render: $file.IO.slurp: :bin;
};
}

0 comments on commit 951de9f

Please sign in to comment.