Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- remove errstr stuff, use exception instead.
- do not pass template path at creating new instance.
- Loading branch information
Showing
19 changed files
with
193 additions
and
158 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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package Tfall::HTML::Template; | ||
use strict; | ||
use warnings; | ||
use parent qw/Tfall::Base/; | ||
use HTML::Template; | ||
use Try::Tiny; | ||
|
||
sub new { | ||
my $class = shift; | ||
my %args = @_ == 1 ? %{$_[0]} : @_; | ||
bless {%args}, $class; | ||
} | ||
|
||
sub render { | ||
my ($self, $args) = @_; | ||
try { | ||
my $type = ref $self->{stuff} ? 'scalarref' : 'filename'; | ||
my $ht = HTML::Template->new($type => $self->{stuff}, @{$self->{args}}); | ||
while (my ($k, $v) = each %$args) { | ||
$ht->param($k => $v); | ||
} | ||
return $ht->output(); | ||
} catch { | ||
$self->errstr($_); | ||
return undef; | ||
}; | ||
my ($self, $stuff, $args) = @_; | ||
|
||
my $type = ref $stuff ? 'scalarref' : 'filename'; | ||
my $ht = HTML::Template->new($type => $stuff, %$self); | ||
while (my ($k, $v) = each %$args) { | ||
$ht->param($k => $v); | ||
} | ||
return $ht->output(); | ||
} | ||
|
||
1; |
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
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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package Tfall::Template::Semantic; | ||
use strict; | ||
use warnings; | ||
use parent qw/Tfall::Base/; | ||
use Template::Semantic; | ||
use Try::Tiny; | ||
|
||
sub new { | ||
my $class = shift; | ||
my $ts = Template::Semantic->new(@_); | ||
bless { | ||
ts => $ts, | ||
}, $class; | ||
} | ||
|
||
sub render { | ||
my ($self, @args) = @_; | ||
try { | ||
my $ts = Template::Semantic->new(@{$self->{args}}); | ||
$ts->process( $self->{stuff}, @args); | ||
} catch { | ||
$self->errstr($_); | ||
return undef; | ||
}; | ||
my ($self, $stuff, @args) = @_; | ||
$self->{ts}->process( $stuff, @args); | ||
} | ||
|
||
1; |
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 |
---|---|---|
@@ -1,16 +1,21 @@ | ||
package Tfall::Text::Markdown; | ||
use strict; | ||
use warnings; | ||
use parent qw/Tfall::Base/; | ||
use Text::Markdown; | ||
use Tfall::Util qw/slurp/; | ||
|
||
sub new { | ||
my $class = shift; | ||
my $mkdn = Text::Markdown->new(@_); | ||
bless { | ||
mkdn => $mkdn, | ||
}, $class; | ||
} | ||
|
||
sub render { | ||
my ($self, @args) = @_; | ||
if (defined (my $src = $self->slurp)) { | ||
return Text::Markdown->new(@{ $self->args })->markdown($src); | ||
} else { | ||
return undef; | ||
} | ||
my ($self, $stuff, @args) = @_; | ||
my $src = slurp($stuff); | ||
return $self->{mkdn}->markdown($src); | ||
} | ||
|
||
1; |
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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package Tfall::Text::MicroMason; | ||
use strict; | ||
use warnings; | ||
use parent 'Tfall::Base'; | ||
use Text::MicroMason; | ||
use Try::Tiny; | ||
|
||
sub new { | ||
my $class = shift; | ||
my $mason = Text::MicroMason->new(@_); | ||
bless { | ||
mason => $mason, | ||
}, $class; | ||
} | ||
|
||
sub render { | ||
my ($self, @args) = @_; | ||
my ($self, $stuff, @args) = @_; | ||
|
||
try { | ||
my $mason = Text::MicroMason->new(@{$self->args}); | ||
$mason->execute( | ||
(ref $self->stuff ? ('text' => ${$self->stuff}) : ('file' => $self->stuff)), | ||
@args | ||
); | ||
} catch { | ||
$self->errstr($_); | ||
return undef; | ||
} | ||
$self->{mason}->execute( | ||
(ref $stuff ? ('text' => ${$stuff}) : ('file' => $stuff)), | ||
@args | ||
); | ||
} | ||
|
||
1; |
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
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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
package Tfall::Text::Sass; | ||
use strict; | ||
use warnings; | ||
use parent qw/Tfall::Base/; | ||
use Text::Sass; | ||
use Tfall::Util qw/slurp/; | ||
|
||
sub new { | ||
my $class = shift; | ||
my $sass = Text::Sass->new(); | ||
bless { | ||
sass => $sass, | ||
}, $class; | ||
} | ||
|
||
sub render { | ||
my ($self, @args) = @_; | ||
if (defined (my $src = $self->slurp)) { | ||
my $sass = Text::Sass->new(); | ||
return $sass->sass2css($src); | ||
} else { | ||
return undef; | ||
} | ||
my ($self, $stuff, @args) = @_; | ||
my $sass = $self->{sass}; | ||
my $src = slurp($stuff); | ||
return $sass->sass2css($src); | ||
} | ||
|
||
1; |
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
package Tfall::Text::Xslate; | ||
use strict; | ||
use warnings; | ||
use parent qw/Tfall::Base/; | ||
use Text::Xslate; | ||
use Try::Tiny; | ||
|
||
sub new { | ||
my $class = shift; | ||
|
||
my $xslate = Text::Xslate->new(@_); | ||
bless { | ||
xslate => $xslate, | ||
}, $class; | ||
} | ||
|
||
sub render { | ||
my ($self, @args) = @_; | ||
|
||
my $tt = Text::Xslate->new(@{$self->{args}}); | ||
my $out; | ||
try { | ||
my $out = $tt->process( $self->{stuff}, @args ); | ||
} catch { | ||
$self->errstr( $_ ); | ||
}; | ||
$out; | ||
return $self->{xslate}->render(@args); | ||
} | ||
|
||
1; |
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,18 @@ | ||
package Tfall::Util; | ||
use strict; | ||
use warnings; | ||
use Exporter 'import'; | ||
|
||
our @EXPORT = qw/slurp/; | ||
|
||
sub slurp { | ||
my $stuff = shift; | ||
return ${$stuff} if ref $stuff; | ||
|
||
open my $fh, '<', $stuff or do { | ||
die "Cannot open file '@{[ $stuff ]}': $!"; | ||
}; | ||
do { local $/; <$fh> }; | ||
} | ||
|
||
1; |
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
Oops, something went wrong.