Skip to content
Browse files

Start of component and controller

  • Loading branch information...
1 parent daccd82 commit 78c8fe20d328d1ea855e23858355283cf4b2ad8f @omega committed Feb 22, 2012
Showing with 39 additions and 0 deletions.
  1. +22 −0 lib/CatalystX/Less.pm
  2. +17 −0 lib/CatalystX/Less/Controller/LessCompiler.pm
View
22 lib/CatalystX/Less.pm
@@ -1,6 +1,28 @@
package CatalystX::Less;
use Moose::Role;
use namespace::autoclean;
+use CatalystX::InjectComponent;
+
+after 'setup_components' => sub {
+ my $class = shift;
+ CatalystX::InjectComponent->inject(
+ into => $class,
+ component => 'CatalystX::Less::Controller::LessCompiler',
+ as => 'Controller::Less',
+ );
+};
+sub uri_for_combined_less {
+ my $c = shift;
+ my $cfg = $c->config->{'CatalystX::Less'};
+ my $basepath = $cfg->{base_path} || '/less';
+
+ my @lesses = @_;
+
+ # We strip out .less and join by ; for now
+ my $encoded = join(";", (map { s/\.less$//; $_;} @lesses));
+ my $uri = $c->uri_for('/less', $encoded . ".css");
+ return $uri;
+}
1;
View
17 lib/CatalystX/Less/Controller/LessCompiler.pm
@@ -0,0 +1,17 @@
+package CatalystX::Less::Controller::LessCompiler;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller' };
+use CSS::LESSp;
+
+sub less : Path('') Args(1) {
+ my ($self, $c, $files) = @_;
+ $files =~ s/\.css$//;
+ my @files = map { $_ . '.less' } split(";", $files);
+ # compile and return
+ $c->res->body(join("\n", @files));
+}
+1;
+
+

0 comments on commit 78c8fe2

Please sign in to comment.
Something went wrong with that request. Please try again.