Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mephist/Dancer-Template-Ctpp2
base: e3d0e61cae
...
head fork: mephist/Dancer-Template-Ctpp2
compare: cf0c48690b
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 31, 2011
@knutov knutov 0.03 version decb6ce
Commits on Feb 16, 2012
Maxim Nikolenko Merge pull request #1 from knutov/master cf0c486
Showing with 80 additions and 58 deletions.
  1. +5 −0 Changes
  2. +16 −15 Makefile.PL
  3. +59 −43 lib/Dancer/Template/Ctpp2.pm
View
5 Changes
@@ -1,5 +1,10 @@
Revision history for Dancer-Template-HtmlTemplate
+0.03 2011-12-31
+ Bug fixes
+ Small improvements
+ Changes in config format
+
0.02 2011-03-23
Bug fixes
View
31 Makefile.PL
@@ -3,20 +3,21 @@ use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
- NAME => 'Dancer::Template::Ctpp2',
- AUTHOR => q{Maxim Nikolenko <mnikolenko@agava.com>},
- VERSION_FROM => 'lib/Dancer/Template/Ctpp2.pm',
- ABSTRACT_FROM => 'lib/Dancer/Template/Ctpp2.pm',
- ($ExtUtils::MakeMaker::VERSION >= 6.3002
- ? ('LICENSE'=> 'perl')
- : ()),
- PL_FILES => {},
- PREREQ_PM => {
- 'Dancer' => 1.175,
- 'HTML::CTPP2' => 0,
- 'Test::More' => 0,
- },
- dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
- clean => { FILES => 'Dancer-Template-Ctpp2-*' },
+ NAME => 'Dancer::Template::Ctpp2',
+ AUTHOR => q{Maxim Nikolenko <mnikolenko@agava.com>},
+ VERSION_FROM => 'lib/Dancer/Template/Ctpp2.pm',
+ ABSTRACT_FROM => 'lib/Dancer/Template/Ctpp2.pm',
+ ($ExtUtils::MakeMaker::VERSION >= 6.3002
+ ? ('LICENSE'=> 'perl')
+ : ()),
+ PL_FILES => {},
+ PREREQ_PM => {
+ 'Dancer' => 1.175,
+ 'HTML::CTPP2' => 0,
+ 'Test::More' => 0,
+ 'String::SetUTF8' => 0,
+ },
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'Dancer-Template-Ctpp2-*' },
);
View
102 lib/Dancer/Template/Ctpp2.pm
@@ -5,64 +5,77 @@ use warnings;
use Dancer::Config 'setting';
use Dancer::ModuleLoader;
use Dancer::FileUtils 'path';
+use String::SetUTF8;
use base 'Dancer::Template::Abstract';
-our $VERSION = '0.02';
+our $VERSION = '0.03';
our $_ctpp2;
our %_cfg;
+our %ctpp2_cfg;
sub default_tmpl_ext {
- return ($_cfg{'use_bytecode'}) ? 'ct2' : 'tmpl';
+ return ($_cfg{'use_bytecode'}) ? 'ct2' : 'tmpl';
}
sub init {
- my ($self) = @_;
-
- die "HTML::CTPP2 is needed by Dancer::Template::Ctpp2"
- unless Dancer::ModuleLoader->load('HTML::CTPP2');
-
- %_cfg=%{$self->config};
- my $use_bytecode = (defined $_cfg{'compiled'}) ? delete $_cfg{'compiled'} : 0;
-
- $_ctpp2 = new HTML::CTPP2(
- arg_stack_size => 1024,
- code_stack_size => 1024,
- steps_limit => 1024*1024,
- max_functions => 1024,
- %_cfg,
- );
-
- $_cfg{'use_bytecode'} = $use_bytecode;
+ my ($self) = @_;
+
+ die "HTML::CTPP2 is needed by Dancer::Template::Ctpp2"
+ unless Dancer::ModuleLoader->load('HTML::CTPP2');
+
+ %_cfg=%{$self->config};
+
+ $_cfg{use_bytecode} = (defined $_cfg{'compiled'}) ?
+ delete $_cfg{'compiled'} : 0;
+
+ %ctpp2_cfg = (%ctpp2_cfg, %{$self->config->{params}})
+ if $self->config->{params};
+
+ $_ctpp2 = new HTML::CTPP2(
+ arg_stack_size => 1024,
+ code_stack_size => 1024,
+ steps_limit => 1024*1024,
+ max_functions => 1024,
+ %ctpp2_cfg,
+ ) unless $_ctpp2;
}
sub render($$$) {
- my ($self, $template, $tokens) = @_;
-
- die "'$template' is not a regular file"
- if !ref($template) && (!-f $template);
-
- my $b;
-
- if ($_cfg{'use_bytecode'}) {
- $b = $_ctpp2->load_bytecode($template);
- } else {
- $b = $_ctpp2->parse_template($template);
- }
-
- $_ctpp2->reset();
- $_ctpp2->param($tokens);
-
- my $result = $_ctpp2->output($b);
-
- if(length(setting('charset')) && lc setting('charset') eq 'utf-8') {
- return pack "U0C*", unpack "C*", $result;
- } else {
- return $result;
- }
-
+ my ($self, $template, $tokens) = @_;
+
+ # in cases of different extensions we need to check
+ # samples: template 'index' vs template 'index.txt'
+ # template 'index' will be autoconverted to template 'index.tmpl' and
+ # template 'index.txt' to template 'index.txt.htm' without this fix.
+ $template =~ s/\.\w+?$// if !ref($template) and !-f $template;
+
+ die "'$template' is not a regular file"
+ if !ref($template) && (!-f $template);
+
+ my $b;
+ if ($_cfg{'use_bytecode'}) {
+ $b = $_ctpp2->load_bytecode($template);
+ } else {
+ $b = $_ctpp2->parse_template($template);
+ }
+
+ # $_ctpp2->reset(); # It's better to do this after
+ $_ctpp2->param($tokens);
+
+ my $result = $_ctpp2->output($b);
+
+ $_ctpp2->reset(); # we need to clear data for next cycles
+
+ return '<font color="red"><b>[template '.$template.' error]</b></font>'
+ if not $result and $_cfg{graceful_error};
+
+ setUTF8($result)
+ if length(setting('charset')) && lc setting('charset') eq 'utf-8';
+
+ return $result || '';
}
1;
@@ -104,6 +117,9 @@ This can be changed within your config file - for example:
template: ctpp2
engines:
ctpp2:
+ extension: 'htm'
+ graceful_error: 1
+ params:
compiled: 1
source_charset: 'CP1251'
destination_charset: 'utf-8'

No commit comments for this range

Something went wrong with that request. Please try again.