All Projects → soveran → Mote

soveran / Mote

Licence: mit
Minimum Operational Template

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Mote

Ng Polymorpheus
Polymorpheus is a tiny library for polymorphic templates in Angular.
Stars: ✭ 191 (-8.17%)
Mutual labels:  template
Stisla
Free Bootstrap Admin Template
Stars: ✭ 2,772 (+1232.69%)
Mutual labels:  template
Remco
remco is a lightweight configuration management tool
Stars: ✭ 200 (-3.85%)
Mutual labels:  template
Hermes
Golang package that generates clean, responsive HTML e-mails for sending transactional mail
Stars: ✭ 2,379 (+1043.75%)
Mutual labels:  template
Dokuwiki Template Bootstrap3
Bootstrap-based template for DokuWiki
Stars: ✭ 197 (-5.29%)
Mutual labels:  template
A Good Readme Template
A template to make good README.md
Stars: ✭ 196 (-5.77%)
Mutual labels:  template
Cgx
💻🔥CLI to generate the recommended documentation/files to improve contribution (Github, Gitlab, CodeCommit and Bitbucket)
Stars: ✭ 190 (-8.65%)
Mutual labels:  template
Ionic Starter Template
Reinventing the wheel, again! Sorry Ionic Team... but there are many newbies learning on Youtube!
Stars: ✭ 208 (+0%)
Mutual labels:  template
Sprig
Useful template functions for Go templates.
Stars: ✭ 2,701 (+1198.56%)
Mutual labels:  template
Koa Vue Notes Web
🤓 This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Features MySQL integration, user authentication, CRUD note actions, and Vuex store modules.
Stars: ✭ 200 (-3.85%)
Mutual labels:  template
Expo Native Firebase
🔥 Native Firebase Expo App (iOS, Android) Demo for Firestore, Notifications, Analytics, Storage, Messaging, Database 🚨
Stars: ✭ 197 (-5.29%)
Mutual labels:  template
Rails Api Base
Rails 5 RESTful api template
Stars: ✭ 197 (-5.29%)
Mutual labels:  template
Yadm
Yet Another Dotfiles Manager
Stars: ✭ 2,982 (+1333.65%)
Mutual labels:  template
Markdown Pdf
📄 Markdown to PDF converter
Stars: ✭ 2,365 (+1037.02%)
Mutual labels:  template
Framework
ThinkPHP Framework
Stars: ✭ 2,399 (+1053.37%)
Mutual labels:  template
Pandoc Markdown Book Template
A template for creating epub books from markdown using pandoc.
Stars: ✭ 191 (-8.17%)
Mutual labels:  template
Wordpress Heroku
This project is a template for installing and running WordPress 5.x on Heroku.
Stars: ✭ 198 (-4.81%)
Mutual labels:  template
Lncs
Improved Lecture Notes in Computer Science (LNCS) template
Stars: ✭ 208 (+0%)
Mutual labels:  template
Mobile App Landingpage Template
📱 Free to use static generated website template for your mobile app
Stars: ✭ 208 (+0%)
Mutual labels:  template
Mazer
Free and Open-source Bootstrap 5 Admin Dashboard Template and Landing Page
Stars: ✭ 195 (-6.25%)
Mutual labels:  template

Mote

Minimum Operational Template.

Description

Mote is a very simple and fast template engine.

Usage

Usage is very similar to that of ERB:

template = Mote.parse("This is a template")
template.call #=> "This is a template"

Silly example, you may say, and I would agree. What follows is a short list of the different use cases you may face:

% # This is a comment
% if user == "Bruno"
  {{user}} rhymes with Piano
% elsif user == "Brutus"
  {{user}} rhymes with Opus
% end

<?
  # Multiline code evaluation
  lucky = [1, 3, 7, 9, 13, 15]
  prime = [2, 3, 5, 7, 11, 13]
?>

{{ lucky & prime }}

Control flow

Lines that start with % are evaluated as Ruby code. Anything between <? and ?>, including new lines, is also evaluated as Ruby code.

Assignment

Whatever it is between {{ and }} gets printed in the template.

Comments

There's nothing special about comments, it's just a # inside your Ruby code:

% # This is a comment.

Block evaluation

As with control instructions, it happens naturally:

% 3.times do |i|
  {{i}}
% end

Parameters

The values passed to the template are available as local variables:

example = Mote.parse("Hello {{name}}", self, [:name])
assert_equal "Hello world", example.call(name: "world")
assert_equal "Hello Bruno", example.call(name: "Bruno")

Please note that the keys in the parameters hash must be symbols.

Helpers

There's a helper available in the Mote::Helpers module, and you are free to include it in your code. To do it, just type:

include Mote::Helpers

Using the mote helper

The mote helper receives a file name and a hash and returns the rendered version of its content. The compiled template is cached for subsequent calls.

assert_equal "***\n", mote("test/basic.mote", n: 3)

Template caching

When the mote helper is first called with a template name, the file is read and parsed, and a proc is created and stored in the current thread. The parameters passed are defined as local variables in the template. If you want to provide more parameters once the template was cached, you won't be able to access the values as local variables, but you can always access the params hash.

For example:

# First call
mote("foo.mote", a: 1, b: 2)

Command line tool

Mote ships with a command line tool to render mote templates. The result is redirected to standard output.

mote FILE [param1 value1 ... paramN valueN]

The extra parameters supplied will be passed to the template. Note that all the parameter values will be treated as strings.

Example usage

If your template is called foo.mote, you can render it with the following command:

mote foo.mote

To write the result to a new file, just redirect the output:

mote foo.mote > foo.html

If the template uses a local variable bar, you can pass a value from the command line:

mote foo.mote bar 42

Installation

You can install it using rubygems.

$ gem install mote
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].