EZML
EZML is a templating engine for HTML. It's designed to make it both easier and
more pleasant to write HTML documents, by eliminating redundancy, reflecting the
underlying structure that the document represents, and providing an elegant syntax
that's both powerful and easy to understand.
Basic Usage
EZML is used from the command line to compile .ezml documents to .html
To install, ensure you have ruby installed and run
gem install ezml
After you write some EZML, you can run
ezml document.ezml
This will compile it to HTML, to specifiy an output do the following
ezml document.ezml document.html
For more information on the commands use the folowing
ezml --help
Formatting
The most basic element of EZML is a shorthand for creating HTML:
%tagname{:attr1 => 'value1', :attr2 => 'value2'} Contents
No end-tag is needed; EZML handles that automatically. If you prefer HTML-style
attributes, you can also use:
%tagname(attr1='value1' attr2='value2') Contents
Adding class
and id
attributes is even easier. EZML uses the same syntax as
the CSS that styles the document:
%tagname#id.class
In fact, when you're using the <div>
tag, it becomes even easier. Because
<div>
is such a common element, a tag without a name defaults to a div. So
#foo Hello!
becomes
<div id='foo'>Hello!</div>
EZML uses indentation to bring the individual elements to represent the HTML
structure. A tag's children are indented beneath than the parent tag. Again, a
closing tag is automatically added. For example:
%ul
%li Salt
%li Pepper
becomes:
<ul>
<li>Salt</li>
<li>Pepper</li>
</ul>
You can also put plain text as a child of an element:
%p
Hello,
World!
It's also possible to embed Ruby code into EZML documents. An equals sign, =
,
will output the result of the code. A hyphen, -
, will run the code but not
output the result. You can even use control statements like if
and while
:
%p
Date/Time:
- now = DateTime.now
%strong= now
- if now > DateTime.parse("December 31, 2006")
= "Happy new " + "year!"
Indentation
EZML's indentation can be made up of one or more tabs or spaces. However,
indentation must be consistent within a given document. Hard tabs and spaces
can't be mixed, and the same number of tabs or spaces must be used throughout.
Initial README.md for reference
Installation
Add this line to your application's Gemfile:
gem 'ezml'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ezml
Usage
TODO: Write usage instructions here
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.