Coder Social home page Coder Social logo

exeex's Introduction

ExEEx

ExEEx is an Elixir template engine with macro and template import and inheritance capabilities.

Usage

  iex> ExEEx.render_string("foo <%= bar %>", bar: "baz")
  "foo baz"

  iex> ExEEx.render("template_file.eex", bar: "baz")
  "foo baz"

Include directive

The include directive is used to include another template file.

main.eex:

  <%= include "header.eex" %>
  Hello world

header.eex:

  This is header

The rendering output of main.eex is as follows:

  This is header
  Hello world

Block directive

The block directive is used to override part of the included text.

super.eex:

  Hello world
  <%= block "body" do %>In super<% end %>

sub.eex:

  <%= include "super.eex" do %>
  <%= block "body" do %>In sub<%= block "subbody" %><% end %>
  <% end %>

subsub.eex:

  <%= include "sub.eex" do %>
  <%= block "subbody" do %>(In subsub)<% end %>
  <% end %>

The rendering output of super.eex is as follows:

  Hello World
  In super

The rendering output of sub.eex is as follows:

  Hello World
  In sub

The rendering output of subsub.eex is as follows:

  Hello World
  In sub(In subsub)

Super directive

The super directive is used to refer to an included template block.

super.eex:

  Hello world
  <%= block "body" do %>In super<% end %>

sub.eex:

  <%= include "super.eex" do %>
  <%= block "body" do %><%= super %>(In sub)<% end %>
  <% end %>

The rendering output of sub.eex is as follows:

  Hello World
  In super(In sub)

Macro directive

The macro directive defines a macro.

<% def @checkbox_input(name, checked, disabled) do %>
<input type="checkbox" name="<%= @name %>" id="id_<%= @name %>" <%= if @checked do %>checked<% end %> <%= if @disabled do %>disabled<% end %>>
<% end %>

Using macros:

<%= @input("checkbox", true, true) %>

Import macros

Import macros:

<% import "macro_defs.txt" %>
<%= @input("check_box", true, true) %>

or import macros into specified namespace.

<% import "macro_defs.txt", as: view %>
<%= view::@input("check_box", true, true) %>

exeex's People

Contributors

eight-birds avatar khattori 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.