X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate%2FPlugin%2FJavaScript.pm;h=241ea0ea3cdb738d079ff4d1c8559d2f0efc4965;hb=d08c706c8c3790ff09c5c9c97541c7936e74e6c9;hp=467c59111a1cae3f6635594e54e8943ba2075a83;hpb=518ed6b5bd287b66ea4d8495d319640541878dea;p=kivitendo-erp.git diff --git a/SL/Template/Plugin/JavaScript.pm b/SL/Template/Plugin/JavaScript.pm index 467c59111..241ea0ea3 100644 --- a/SL/Template/Plugin/JavaScript.pm +++ b/SL/Template/Plugin/JavaScript.pm @@ -3,22 +3,142 @@ package SL::Template::Plugin::JavaScript; use base qw( Template::Plugin ); use Template::Plugin; +use strict; + sub new { - my $class = shift; - my $context = shift; + my ($class, $context, @args) = @_; - bless { }, $class; + return bless { + CONTEXT => $context, + }, $class; } +# +# public interface +# + sub escape { my $self = shift; my $text = shift; + $text =~ s|\\|\\\\|g; $text =~ s|\"|\\\"|g; + $text =~ s|\n|\\n|g; return $text; } +sub replace_with { + return _replace_helper('replaceWith', @_); +} + +sub replace_html_with { + return _replace_helper('html', @_); +} + +# +# private methods +# + +sub _context { + die 'not an accessor' if @_ > 1; + return $_[0]->{CONTEXT}; +} + +sub _replace_helper { + my ($method, $self, $selector, $template, $locals) = @_; + + $template .= '.html' unless $template =~ m/\.html$/; + my $html = $self->escape($self->_context->process($template, %{ $locals || { } })); + my $code = < + +Returns C<$value> escaped for inclusion in a JavaScript string. The +value is not wrapped in quotes. Example: + + + +=item C + +Returns code replacing the DOM elements matched by C<$selector> with +the content rendered by Template's I directive applied to +C<$template>. C<%locals> are passed as local parameters to I. + +Uses jQuery's C function. Requires jQuery to be loaded. + +Example: + +
TODO:
+
    +
  • First item
  • +
  • Second item
  • +
  • Another item
  • +
+ + + + + +=item C + +Returns code replacing the inner HTML of the DOM elements matched by +C<$selector> with the content rendered by Template's I +directive applied to C<$template>. C<%locals> are passed as local +parameters to I. + +Uses jQuery's C function. Requires jQuery to be loaded. + +
TODO:
+
    +
  • First item
  • +
  • Second item
  • +
  • Another item
  • +
+ + + + + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut