NAME
JavaScript::V8::Handlebars - Compile and execute Handlebars templates via the actual JS library
SYNOPSIS
use JavaScript::V8::Handlebars;
#use JavaScript::V8::Handlebars ( library_path => "/path/to/handlebars.js" );
my $hbjs = JavaScript::V8::Handlebars->new;
print $hbjs->render_string( "Hello {{var}}", { var => "world" } );
my $template = $hbjs->compile_file( "template.hbs" );
print $template->({ var => "world" });
$hbjs->add_template_dir( './templates' );
open my $oh, ">", "template.bundle.js" or die $!;
print $oh $hbjs->bundle;
close $oh;
METHODS
For now the majority of these methods work as described in http://handlebarsjs.com/
- $hbjs->new(%opts)
-
Arguments:
- $hbjs->c()
-
Returns the internal JavaScript::V8 object, useful for executing javascript code in the context of the module.
- $hbjs->eval_file($javascript_filename)
- $hbjs->eval($javascript_string)
-
Wrapper function for
$hbjs-
c->eval> that checks for errors and throws an exception. - $hbjs->precompile_file($template_filename)
- $hbjs->precompile($template_string)
-
Takes a template and translates it into the javascript code suitable for passing to the
template
method. - $hbjs->compile_file($template_filename)
- $hbjs->compile($template_string)
-
Takes a template and returns a subref that takes a hashref containing variables as an argument and returns the text of the executed template.
- $hbjs->register_helper
-
TBD
- $hbjs->template( $compiled_javascript_string | $compiled_perl_object )
-
Takes a precompiled template datastructure and returns a subref ready to be executed.
- $hbjs->render_string( $template_string, \%context_vars )
-
Wrapper method for compiling and then executing a template passed as a string.
- $hbjs->add_template_dir( $directory, [$extension] )
- $hbjs->add_template_file( $filename, [$base_path] )
- $hbjs->add_template( $name, $template_string )
-
Takes a template, compiles it and adds it to the internal store of cached templates for
execute_template
to use. - $hbjs->execute_template( $name, \%context_vars )
-
Executes a cached template.
- $hbjs->bundle()
-
Returns a string of javascript consisting of all the templates in the cache ready for execution by the browser.
- $hbjs->safeString($string)
-
Whatever the original Handlebar function does.
- $hbjs->escapeString ($string)
-
Whatever the original Handlebar function does.
- $hbjs->register_partial($name, $template_string)
-
Registers a partial named '$name' with the code in '$template_string' so later templates can access it.
AUTHOR
Robert Grimes, <rmzgrimes at gmail.com>
BUGS
Please report and bugs or feature requests through the interfaces at https://github.com/rmzg/JavaScript-V8-Handlebars
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc JavaScript::V8::Handlebars
LICENSE AND COPYRIGHT
Copyright 2015 Robert Grimes.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
https://github.com/rmzg/JavaScript-V8-Handlebars, http://handlebarsjs.com/