Code Monkey home page Code Monkey logo

p6-template-mustache's Introduction

Perl6 implementation of the Mustache template format, 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 %data =
             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
             %data,
             :from([%partials, './views'])
         ).say;



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/

To run tests,

        # NB Ensure you are using the default 'perl6' branch, not 'master'
         git clone [email protected]:softmoth/mustache-spec.git ../mustache-spec
         PERL6LIB=./lib prove -e perl6 -v


TODO

  * object support (not just hashes and arrays)

  * parsed template caching

  * .new(:helpers())

  * pragmas (FILTERS, inheritance)

  * database loader

  * inline loader (POD?)

p6-template-mustache's People

Contributors

softmoth avatar hoelzro avatar

Watchers

James Cloos avatar tony-o avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.