All Projects → fiatjaf → Tempreites

fiatjaf / Tempreites

Licence: mit
One-file semantic DSL-free templates direto da roça for the browser and server.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Tempreites

Laravel Tabler
Laravel Package for integrating Tabler template and this package is Laravel Mix friendly.
Stars: ✭ 20 (-35.48%)
Mutual labels:  template
Traingenerator
🧙 A web app to generate template code for machine learning
Stars: ✭ 948 (+2958.06%)
Mutual labels:  template
Medium Clone
🎉 Mediumm WordPress theme, very inspired by medium.com
Stars: ✭ 29 (-6.45%)
Mutual labels:  template
Unityfx
DocFX template to create Unity-esque documentation
Stars: ✭ 21 (-32.26%)
Mutual labels:  template
Exgen
A templating library for generating reusable Elixir projects
Stars: ✭ 27 (-12.9%)
Mutual labels:  template
Regexanalyzer
Regular Expression Analyzer and Composer for Node.js / XPCOM / Browser Javascript, PHP, Python
Stars: ✭ 29 (-6.45%)
Mutual labels:  regular-expression
Bcf Skeleton
BigClown Firmware Skeleton (Empty Application)
Stars: ✭ 14 (-54.84%)
Mutual labels:  template
Quick Free Bootstrap Theme
Free Bootstrap 4 Theme perfect for building responsive, mobile-first projects on the web suitable for businesses, startups, and agencies.
Stars: ✭ 31 (+0%)
Mutual labels:  template
React Saas Template
🌊 Template for building an SaaS / admin website using React + Material-UI
Stars: ✭ 942 (+2938.71%)
Mutual labels:  template
Freemo
A free resume,portfolio and CV HTML template
Stars: ✭ 30 (-3.23%)
Mutual labels:  template
Zstemplatedlistscene
列表类应用场景模板化
Stars: ✭ 20 (-35.48%)
Mutual labels:  template
Swiftproject
🏆 Generate Swift project with necessary toolings
Stars: ✭ 27 (-12.9%)
Mutual labels:  template
Flutter easy rich text
The EasyRichText widget provides an easy way to use RichText.
Stars: ✭ 30 (-3.23%)
Mutual labels:  regular-expression
Regex
A sane interface for php's built in preg_* functions
Stars: ✭ 909 (+2832.26%)
Mutual labels:  regular-expression
Flixel Templates
Project templates for HaxeFlixel
Stars: ✭ 30 (-3.23%)
Mutual labels:  template
Heroku Aiohttp Web
A project starter template for deploying an aiohttp app to Heroku
Stars: ✭ 14 (-54.84%)
Mutual labels:  template
Bootstrap Blog Template
An awesome blog template constructed using Twitter Bootstrap 3
Stars: ✭ 29 (-6.45%)
Mutual labels:  template
Vue Blog Template
vue-blog 基础模板
Stars: ✭ 31 (+0%)
Mutual labels:  template
Suicrux
🚀 Ultimate universal starter with lazy-loading, SSR and i18n. [not maintained]
Stars: ✭ 958 (+2990.32%)
Mutual labels:  template
Place2live
Analysis of the characteristics of different countries
Stars: ✭ 30 (-3.23%)
Mutual labels:  regular-expression

DEMO

Comparison with Mustache

Tempreites

Crude string templating without any syntax, just semantic HTML.

Disclaimer: This is old, slow, buggy and not recommended. It's here just for historical reasons. It was my first public library and published on http://microjs.com/.

Usage

Get this as a string,

<div id="austrianeconomics">
  <h1 class="title"></h1>
  <ul id="theories">
    <li>
      <span class="author"></span>
      <span>
        <a class="theory"
           data-bind-here="href"
           data-bind-there="url">
        </a>
      </span>
    </li>
  </ul>
</div>

attach data to it,

var data = {
  title: 'Austrian economists and their theories',
  theories: [
    { author: 'Menger', theory: 'Subjective value', url: '/subj' },
    { author: 'Hayek', theory: 'Austrian Business Cycle Theory', url: '/abct' },
    { author: 'Kirzner', theory: 'Sheer ignorance and entrepreneurship', url: '/entre' },
  ]
}

tempreites.render(template, data)

get this back:

<div id="austrianeconomics">
  <h1 class="title"></h1>
  <ul id="theories">
    <li>
      <span class="author">Menger</span>
      <span>
        <a class="theory"
           data-bind-here="href"
           data-bind-there="url"
           href="/subj">
          Subjective value
        </a>
      </span>
    </li>
    <li>
      <span class="author">Hayek</span>
      <span>
        <a class="theory"
           data-bind-here="href"
           data-bind-there="url"
           href="/abct">
          Austrian Business Cycle Theory
        </a>
      </span>
    </li>
    <li>
      <span class="author">Kirzner</span>
      <span>
        <a class="theory"
           data-bind-here="href"
           data-bind-there="url"
           href="/entre">
          Sheer ignorance and entrepreneurship
        </a>
      </span>
    </li>
  </ul>
</div>

Features

  • Semantic data binding - No need for <%=foo%> or {{foo}} assignments
  • Collection rendering - No need for hand-written loops
  • Valid HTML templates - Write templates as a part of the HTML, in plain HTML
  • View logic in JavaScript - No crippled micro-template language, just plain JavaScript functions

TODOs:

  • Basic optmization
  • Read some data- attr to see in which element arrays of data will duplicate

Installation

npm install tempreites

Or download the file and include it anywhere.


Documentation

Considering a data object like this:

var data = {
  name: 'Miyamoto',
  link: '/miyamoto',
  completeName: {
    first: 'Shigeru'
    last: 'Miyamoto'
  },
  sons: [{ name: 'Mario', show: true }, { name: 'Luigi', show: false }]
  show: true
}
Tempreites.render(template, data)

Binding values

Use a class or an id at the target element with the value of the key in your data object.

<h1 class="name"></h1>

Nested objects

Use a class or an id at some element with the value of the parent key in your data object, then use a class or id with the child key anywhere inside the parent element.

<div id="name">
  <h1>
    <span class="last"></span>, <span class="first"></span></h1>
  </h1>
</div>

Nested lists

Use a class or an id at the element immediattely before the element you want to be repeated with the list values, then use a class or id with the child key anywhere inside it.

<div id="sons">
  <p class="name"></p>
</div>

Binding values to attributes

Use the data-bind attribute with the special syntax "javascriptObjectAttrName - > htmlElementAttrNameToBindTo". If you want to bind to more than one attr, write the other bindings at the same data-bind, separated by a |:

<header>
  <h1 id="name"></h1>
  <img data-bind="url -> src | name -> alt">
</header>

Conditional showing of elements

Use the data-show-if attr naming a key at the data object which will be tested for deciding if the element will be shown or not.

<div id="miyamoto" data-show-if="show">
  <ul class="sons">
    <li class="name" data-show-if="show"></li>
  </ul>
</div>

Pre-compiling templates

Call the compile function to get a pre-compiled template to which you can just pass the data later.

var tpr = Tempreites.compile('<div class="u"></div>')
tpr.render({u: 'a'})
tpr.render({u: 'b'})

Inspired by Plates and Transparency, but simplified and more useful.


Written with regular expressions, como se fazia antigamente lá na roça.

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].