All Projects → softmoth → raku-Template-Mustache

softmoth / raku-Template-Mustache

Licence: Artistic-2.0 license
Raku library for the Mustache template format

Programming Languages

Raku
181 projects
Mustache
554 projects

Projects that are alternatives of or similar to raku-Template-Mustache

Statik
Multi-purpose static web site generator aimed at developers.
Stars: ✭ 249 (+1456.25%)
Mutual labels:  mustache
gogoAST
The simplest tool to parse/transform/generate code on ast
Stars: ✭ 29 (+81.25%)
Mutual labels:  mustache
crustache
{{Mustache}} for Crystal 💎
Stars: ✭ 76 (+375%)
Mutual labels:  mustache
dssg
A static site generator with a different approach
Stars: ✭ 15 (-6.25%)
Mutual labels:  mustache
ocaml-mustache
mustache.js logic-less templates in OCaml
Stars: ✭ 74 (+362.5%)
Mutual labels:  mustache
HandlebarsCookbook
A cookbook of handlebars and mustache, focus on handlebars.js , mustache.js and lightncandy usage
Stars: ✭ 20 (+25%)
Mutual labels:  mustache
Stubble
Trimmed down {{mustache}} templates in .NET
Stars: ✭ 247 (+1443.75%)
Mutual labels:  mustache
gci-leaders
A website showing Google Code-in information 🏆
Stars: ✭ 40 (+150%)
Mutual labels:  mustache
samples
A collection of sample dashboards, custom labels, mustaches, SQL scripts and PowerShell scripts to help you get the most out of SquaredUp. #community-powered
Stars: ✭ 17 (+6.25%)
Mutual labels:  mustache
hyperstache
👨‍🦰 Handlebars just got a trim, alternative JS template engine, 2kb gzip
Stars: ✭ 36 (+125%)
Mutual labels:  mustache
abap mustache
Mustache template engine for ABAP
Stars: ✭ 14 (-12.5%)
Mutual labels:  mustache
php-mustache
Mustache PHP Extension
Stars: ✭ 55 (+243.75%)
Mutual labels:  mustache
Mustache
A simple Mustache parser/evaluator for Swift
Stars: ✭ 23 (+43.75%)
Mutual labels:  mustache
VueXcode
Syntax highlighting for .Vue components and .mustache templates in Xcode
Stars: ✭ 25 (+56.25%)
Mutual labels:  mustache
nimib
nimib 🐳 - nim 👑 driven ⛵ publishing ✍
Stars: ✭ 89 (+456.25%)
Mutual labels:  mustache
Mustache
Mustache text templates for modern C++
Stars: ✭ 248 (+1450%)
Mutual labels:  mustache
mustache-cli
Command line interface to mustache template engine in Go.
Stars: ✭ 40 (+150%)
Mutual labels:  mustache
chimera
🐍 A CLI tool for generating Boost.Python/pybind11 bindings from C/C++
Stars: ✭ 12 (-25%)
Mutual labels:  mustache
pogonos
Another Clojure(Script) implementation of Mustache templating language
Stars: ✭ 56 (+250%)
Mutual labels:  mustache
morestachio
Lightweight, powerful, flavorful, template engine.
Stars: ✭ 45 (+181.25%)
Mutual labels:  mustache

Build Status Windows Status

Raku implementation of Mustache templates, http://mustache.github.io/.

Synopsis

use Template::Mustache;

# Call .render as a class method
Template::Mustache.render('Hello, {{planet}}!', { planet => 'world' }).say;

# Or instantiate an instance
my $stache = Template::Mustache.new: :from<./views>;

# Subroutines are called
say $stache.render('The time is {{time}}', {
    time => { ~DateTime.new(now).local }
});

my @people =
    { :name('James T. Kirk'), :title<Captain> },
    { :name('Wesley'), :title('Dread Pirate'), :emcee },
    { :name('Dana Scully'), :title('Special Agent') },
    ;

# See this template in ./t/views/roster.mustache
$stache.render('roster', { :@people }).say;

my %context =
    event => 'Masters of the Universe Convention',
    :@people,
    ;
my %partials =
    welcome =>
        qq:b{Welcome to the {{event}}! We’re pleased to have you here.\n\n},
    ;

# See this result in ./t/50-readme.t
Template::Mustache.render(q:to/EOF/,
        {{> welcome}}
        {{> roster}}

            Dinner at 7PM in the Grand Ballroom. Bring a chair!
        EOF
    %context,
    :from([%partials, './views'])
).say;

Description

Logging

Log levels

Messages are logged with varying severity levels (from most to least severe): Fatal, Error, Warn, Info, Verbose, Audit, Debug, Trace, Trace2

By default, only messages of Error or worse are logged. That default can be changed with the TEMPLATE_MUSTACHE_LOGLEVEL environment variable.

TEMPLATE_MUSTACHE_LOGLEVEL=Debug

The default is overridden with the :log-level option to Template::Mustache.new, or a Template::Mustache::Logger object can be passed via the :logger option.

my $stache = Template::Mustache.new: :log-level<Trace>;

my $logger = Template::Mustache::Logger.new: :level<Debug>;
my $stache = Template::Mustache.new: :$logger;

Either method can be used with the .render method, as well.

my %data = hello => 'world';

Template::Mustache.render: 'Hello, {{hello}}!', %data, :log-level<Trace>;

my $logger = Template::Mustache::Logger.new: :level<Debug>;
Template::Mustache.render: 'Hello, {{hello}}!', %data, :$logger;

Log routine

By default, any messages at level Warn or worse are logged with the warn routine. A CONTROL block can handle such warnings if needed; see Language/phasers for details. Less severe messages (Info and up) are logged with the note routine.

The routine can be set per log level, in the Template::Mustache::Logger.routines hash.

# Use say instead of note for Info and up; the more severe
# levels (C<Warn> down to C<Fatal>) still use the warn routine
my $stache = Template::Mustache.new: :log-routine(&say);

# But even those can be set explicitly
$stache.logger.routines{$_} = &die for <Warn Error Fatal>;

$stache.render: '{{missing}}', {};  # dies

method log

  • multi method log(Exception $exception, LogLevel :$level)

  • multi method log(LogLevel :$level, *@msgs)

Emit a message at $level (Info by default).

Extra features

Template inheritence

Support for hogan.js-style template inheritence is available.

Pragma: KEEP-UNUSED-VARIABLES

Specify :pragma<KEEP-UNUSED-VARIABLES> to either Template::Mustache.new or .render, and any variables which are not defined in the data context will be kept in the rendered text. See t/13-pragmas.t for examples.

More Examples and Tests

The Mustache spec provides a wealth of examples to demonstrate exactly how the format behaves.

https://github.com/mustache/spec/tree/master/specs/

All of the official Mustache spec tests pass. A copy of the tests is distributed in t/specs.

To check against the official specs repository, clone it into ../mustache-spec:

git clone --depth=1 https://github.com/mustache/spec.git ../mustache-spec
prove -v -e 'raku -Ilib' t/

Extra Specifications

The test file t/specs/inheritable_partials.json is taken from groue/GRMustache.

Other Mustache Implementations

There are many, many Mustache implementations in various languages. Some of note are:

TODO

  • full object support (with method calls; currently the object is just stringified)

  • global helpers (context items that float at the top of the stack)

  • database loader

  • pragmas (FILTERS?)

License

Artistic License 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].