diff --git a/template.php b/template.php
index c77e9f3..51bf125 100644
--- a/template.php
+++ b/template.php
@@ -776,7 +776,7 @@ class VMXTemplateOptions
$this->$k = $v;
}
}
- if ($this->strip_space)
+ if ($this->strip_space && array_search('strip_space', $this->filters) === false)
{
$this->filters[] = 'strip_space';
}
diff --git a/template.skel.pm b/template.skel.pm
index fc6bd16..d24c316 100644
--- a/template.skel.pm
+++ b/template.skel.pm
@@ -328,7 +328,7 @@ my @Wday = qw(Sun Mon Tue Wed Thu Fri Sat);
our $safe_tags = 'div|blockquote|span|a|b|i|u|p|h1|h2|h3|h4|h5|h6|strike|strong|small|big|blink|center|ol|pre|sub|sup|font|br|table|tr|td|th|tbody|tfoot|thead|tt|ul|li|em|img|marquee|cite';
-# ограниченная распознавалка дат
+# Date parser for some common formats
sub timestamp
{
my ($ts, $format) = @_;
@@ -552,6 +552,161 @@ sub encode_json
goto &JSON::encode_json;
}
+# Remove whitespace from the beginning and the end of the line
+sub trim
+{
+ local $_ = $_[0];
+ if ($_[1])
+ {
+ s/^$_[1]//s;
+ s/$_[1]$//s;
+ }
+ else
+ {
+ s/^\s+//so;
+ s/\s+$//so;
+ }
+ $_;
+}
+
+# htmlspecialchars + turn \n into
+sub html_pbr
+{
+ my ($s) = @_;
+ $s = htmlspecialchars($s);
+ $s =~ s/\n/
/gso;
+ return $s;
+}
+
+package VMXTemplate::Exception;
+
+VMXTemplate::Utils::import();
+
+sub new
+{
+ my $class = shift;
+ $class = ref($class) || $class;
+ my ($msg) = @_;
+ return bless { message => $msg }, $class;
+}
+
+package VMXTemplate::Options;
+
+sub new
+{
+ my $class = shift;
+ $class = ref($class) || $class;
+ my ($options) = @_;
+
+ my $self = bless {
+ begin_code => '', # instruction end
+ begin_subst => '{', # substitution start (may be turned off via false)
+ end_subst => '}', # substitution end (may be turned off via false)
+ no_code_subst => 0, # do not substitute expressions in instructions
+ eat_code_line => 1, # remove the "extra" lines which contain instructions only
+ root => '.', # directory with templates
+ cache_dir => undef, # compiled templates cache directory
+ reload => 1, # 0 means to not check for new versions of cached templates
+ filters => [], # filters to run on output of every template
+ use_utf8 => 1, # use UTF-8 for all string operations on template variables
+ raise_error => 0, # die() on fatal template errors
+ log_error => 0, # send errors to standard error output
+ print_error => 0, # print fatal template errors
+ strip_space => 0, # strip spaces from beginning and end of each line
+ auto_escape => undef, # "safe mode" (use 's' for HTML) - automatically escapes substituted
+ # values via this functions if not escaped explicitly
+ compiletime_functions => {},# custom compile-time functions (code generators)
+
+ input_filename => '',
+ errors => [],
+ }, $class;
+
+ $self->set($options);
+
+ return $self;
+}
+
+sub set
+{
+ my ($self, $options) = @_;
+ for (keys %$options)
+ {
+ if (exists $self->{$_} && $_ ne 'errors')
+ {
+ $self->{$_} = $options->{$_};
+ }
+ }
+ $self->{filters} = [] if ref $self->{filters} ne 'ARRAY';
+ if ($self->{strip_space} && !grep { $_ eq 'strip_space' } @{$self->{filters}})
+ {
+ push @{$self->{filters}}, 'strip_space';
+ }
+ if (!$self->{begin_subst} || !$self->{end_subst})
+ {
+ $self->{begin_subst} = undef;
+ $self->{end_subst} = undef;
+ $self->{no_code_subst} = 0;
+ }
+ $self->{cache_dir} =~ s!/*$!/!so;
+ if (!-w $self->{cache_dir})
+ {
+ die new VMXTemplate::Exception('VMXTemplate: cache_dir='.$self->{cache_dir}.' is not writable');
+ }
+ $self->{root} =~ s!/*$!/!so;
+}
+
+sub get_errors
+{
+ my ($self) = @_;
+ if ($self->{print_error} && @{$self->{errors}})
+ {
+ return '