-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b473453
Showing
17 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
META.yml | ||
Makefile | ||
inc/ | ||
pm_to_blib | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN | ||
git.push_to = origin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Revision history for Perl extension Plack::Middleware::File::Sass | ||
|
||
0.01 Sat Feb 6 01:33:23 2010 | ||
- original version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.gitignore | ||
Changes | ||
inc/Module/Install.pm | ||
inc/Module/Install/AuthorTests.pm | ||
inc/Module/Install/Base.pm | ||
inc/Module/Install/Can.pm | ||
inc/Module/Install/Fetch.pm | ||
inc/Module/Install/Include.pm | ||
inc/Module/Install/Makefile.pm | ||
inc/Module/Install/Metadata.pm | ||
inc/Module/Install/ReadmeFromPod.pm | ||
inc/Module/Install/Repository.pm | ||
inc/Module/Install/Win32.pm | ||
inc/Module/Install/WriteAll.pm | ||
inc/Test/Builder/Module.pm | ||
inc/Test/Requires.pm | ||
lib/Plack/Middleware/File/Sass.pm | ||
Makefile.PL | ||
MANIFEST This list of files | ||
META.yml | ||
README | ||
t/00_compile.t | ||
xt/perlcritic.t | ||
xt/pod.t | ||
xt/podspell.t | ||
xt/synopsis.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
\bRCS\b | ||
\bCVS\b | ||
\.svn/ | ||
\.git/ | ||
^MANIFEST\. | ||
^Makefile$ | ||
~$ | ||
\.old$ | ||
^blib/ | ||
^pm_to_blib | ||
^MakeMaker-\d | ||
\.gz$ | ||
\.cvsignore | ||
\.shipit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use inc::Module::Install; | ||
name 'Plack-Middleware-File-Sass'; | ||
all_from 'lib/Plack/Middleware/File/Sass.pm'; | ||
readme_from 'lib/Plack/Middleware/File/Sass.pm'; | ||
build_requires 'Test::More'; | ||
test_requires 'Test::Requires'; | ||
requires 'Plack::App::File'; | ||
requires 'Text::Sass'; | ||
auto_include_deps; | ||
author_tests('xt'); | ||
auto_set_repository; | ||
WriteAll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
NAME | ||
Plack::Middleware::File::Sass - | ||
|
||
SYNOPSIS | ||
use Plack::Middleware::File::Sass; | ||
|
||
DESCRIPTION | ||
Plack::Middleware::File::Sass is | ||
|
||
AUTHOR | ||
Tatsuhiko Miyagawa <miyagawa@bulknews.net> | ||
|
||
LICENSE | ||
This library is free software; you can redistribute it and/or modify it | ||
under the same terms as Perl itself. | ||
|
||
SEE ALSO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
!blue = #3bbfce | ||
!margin = 16px | ||
|
||
.content_navigation | ||
border-color = !blue | ||
color = !blue - #111 | ||
|
||
.border | ||
padding = !margin / 2 | ||
margin = !margin / 2 | ||
border-color = !blue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package Plack::Middleware::File::Sass; | ||
|
||
use strict; | ||
use 5.008_001; | ||
our $VERSION = '0.01'; | ||
|
||
use parent qw(Plack::Middleware); | ||
use Plack::Util::Accessor qw(sass); | ||
use Plack::Util; | ||
use Text::Sass; | ||
|
||
sub prepare_app { | ||
my $self = shift; | ||
$self->sass(Text::Sass->new); | ||
} | ||
|
||
sub call { | ||
my($self, $env) = @_; | ||
|
||
# Depends on how App::File works -- not really comfortable | ||
my $orig_path_info = $env->{PATH_INFO}; | ||
if ($env->{PATH_INFO} =~ s/\.css$/.sass/i) { | ||
my $res = $self->app->($env); | ||
|
||
return $res unless ref $res eq 'ARRAY'; | ||
|
||
if ($res->[0] == 200) { | ||
my $sass; Plack::Util::foreach($res->[2], sub { $sass .= $_[0] }); | ||
my $css = $self->sass->sass2css($sass); | ||
|
||
my $h = Plack::Util::headers($res->[1]); | ||
$h->set('Content-Type' => 'text/css'); | ||
$h->set('Content-Length' => length $css); | ||
|
||
$res->[2] = [ $css ]; | ||
} elsif ($res->[0] == 404) { | ||
$env->{PATH_INFO} = $orig_path_info; | ||
$res = $self->app->($env); | ||
} | ||
|
||
return $res; | ||
} | ||
|
||
return $self->app->($env); | ||
} | ||
|
||
1; | ||
__END__ | ||
=encoding utf-8 | ||
=for stopwords | ||
=head1 NAME | ||
Plack::Middleware::File::Sass - Sass support for all Plack frameworks | ||
=head1 SYNOPSIS | ||
use Plack::App::File; | ||
use Plack::Builder; | ||
builder { | ||
mount "/stylesheets" => builder { | ||
enable "File::Sass"; | ||
Plack::App::File->new(root => "./stylesheets"); | ||
}; | ||
}; | ||
# Or with Middleware::Static | ||
enable "File::Sass"; | ||
enable "Static", path => qr/\.css$/, root => "./static"; | ||
=head1 DESCRIPTION | ||
Plack::Middleware::File::Sass is a Plack middleware component that | ||
works with L<Plack::App::File> or L<Plack::Middleware::Static> to | ||
compile Sass templates into CSS stylesheet in every request. | ||
When a request comes in for I<.css> file, this middleware changes the | ||
internal path to I<.sass> in the same directory. If the Sass template | ||
is found, a new CSS stylesheet is built on memory and served to the | ||
browsers. Otherwise, it falls back to the original I<.css> file in | ||
the directory. | ||
=head1 AUTHOR | ||
Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt> | ||
=head1 LICENSE | ||
This library is free software; you can redistribute it and/or modify | ||
it under the same terms as Perl itself. | ||
=head1 SEE ALSO | ||
L<Plack::App::File> L<Text::Sass> | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
use strict; | ||
use Test::More tests => 1; | ||
|
||
BEGIN { use_ok 'Plack::Middleware::File::Sass' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#data { | ||
float: left; | ||
margin-left: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Sass | ||
!blue = #3bbfce | ||
!margin = 16px | ||
|
||
.content_navigation | ||
border-color = !blue | ||
color = !blue - #111 | ||
|
||
.border | ||
padding = !margin / 2 | ||
margin = !margin / 2 | ||
border-color = !blue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use strict; | ||
use Plack::App::File; | ||
use Plack::Middleware::File::Sass; | ||
use Test::More; | ||
use Plack::Test; | ||
use HTTP::Request::Common; | ||
|
||
my $app = Plack::App::File->new(root => "t"); | ||
$app = Plack::Middleware::File::Sass->wrap($app); | ||
|
||
test_psgi $app, sub { | ||
my $cb = shift; | ||
|
||
my $res = $cb->(GET "/"); | ||
is $res->code, 404; | ||
|
||
$res = $cb->(GET "/foo.css"); | ||
is $res->code, 200; | ||
is $res->content_type, 'text/css'; | ||
like $res->content, qr/border-color: \#3bbfce/; | ||
|
||
$res = $cb->(GET "/bar.css"); | ||
is $res->code, 200; | ||
is $res->content_type, 'text/css'; | ||
like $res->content, qr/float: left/; | ||
}; | ||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use strict; | ||
use Test::More; | ||
eval q{ use Test::Perl::Critic }; | ||
plan skip_all => "Test::Perl::Critic is not installed." if $@; | ||
all_critic_ok("lib"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
use Test::More; | ||
eval "use Test::Pod 1.00"; | ||
plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; | ||
all_pod_files_ok(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use Test::More; | ||
eval q{ use Test::Spelling }; | ||
plan skip_all => "Test::Spelling is not installed." if $@; | ||
add_stopwords(<DATA>); | ||
set_spell_cmd("aspell -l en list"); | ||
all_pod_files_spelling_ok('lib'); | ||
__DATA__ | ||
Tatsuhiko | ||
Miyagawa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
use Test::More; | ||
eval "use Test::Synopsis"; | ||
plan skip_all => "Test::Synopsis required" if $@; | ||
all_synopsis_ok(); |