Git Product home page Git Product logo

erlydtl's Introduction

ErlyDTL

ErlyDTL implements most but not all of the Django Template Language.

Project homepage: http://code.google.com/p/erlydtl/

Compilation

To compile ErlyDTL, run

make

in this directory.

Template compilation

Four ways:

erlydtl:compile("/path/to/template.dtl", my_module_name)

erlydtl:compile("/path/to/template.dtl", my_module_name, Options)

erlydtl:compile(<<"<html>{{ foo }}</html>">>, my_module_name)

erlydtl:compile(<<"<html>{{ foo }}</html>">>, my_module_name, Options)

Options is a proplist possibly containing:

  • out_dir - Directory to store generated .beam files. If not specified, no .beam files will be created.

  • doc_root - Included template paths will be relative to this directory; defaults to the compiled template's directory.

  • custom_tags_dir - Directory of DTL files (no extension) includable as tags. E.g. if $custom_tags_dir/foo contains <b>{{ bar }}</b>, then {{ foo bar=100 }} will evaluate to <b>100</b>. Get it?

  • vars - Variables (and their values) to evaluate at compile-time rather than render-time.

  • reader - {module, function} tuple that takes a path to a template and returns a binary with the file contents. Defaults to {file, read_file}. Useful for reading templates from a network resource.

  • compiler_options - Proplist passed directly to compiler:forms/2

  • force_recompile - Recompile the module even if the source's checksum has not changed. Useful for debugging.

  • locale - The locale used for template compile. Requires erlang_gettext. It will ask gettext_server for the string value on the provided locale. For example, adding {locale, "en_US"} will call {key2str, Key, "en_US"} for all string marked as trans ({% trans "StringValue" %} on templates). See README_I18N.

Usage (of a compiled template)

my_compiled_template:render(Variables) -> {ok, IOList} | {error, Err}

Variables is a proplist, dict, gb_tree, or a parameterized module (whose method names correspond to variable names). The variable values can be atoms, strings, binaries, or (nested) variables.

IOList is the rendered template.

my_compiled_template:render(Variables, TranslationFun) -> 
        {ok, IOList} | {error, Err}

Same as render/1, but TranslationFun is a fun/1 that will be used to translate strings appearing inside {% trans %} tags. The simplest TranslationFun would be fun(Val) -> Val end

my_compiled_template:translatable_strings() -> [String]

List of strings appearing in {% trans %} tags that can be overridden with a dictionary passed to render/2.

my_compiled_template:source() -> {FileName, CheckSum}

Name and checksum of the original template file.

my_compiled_template:dependencies() -> [{FileName, CheckSum}]

List of names/checksums of templates included by the original template file. Useful for frameworks that recompile a template only when the template's dependencies change.

Tests

From a Unix shell, run:

make test

Note that the tests will create some output in examples/rendered_output.

erlydtl's People

Contributors

archaelus avatar asonge avatar evanmiller avatar gardenia avatar hdima avatar noss avatar rsaccon avatar

Stargazers

 avatar

Watchers

 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.