2006-12-03 19:06:39 -05:00
|
|
|
dir = File.dirname(__FILE__)
|
|
|
|
$LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
2006-12-18 21:56:49 -05:00
|
|
|
|
|
|
|
# = Haml (XHTML Abstraction Markup Language)
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# Haml is a markup language
|
|
|
|
# that's used to cleanly and simply describe the XHTML of any web document,
|
|
|
|
# without the use of inline code.
|
|
|
|
# Haml functions as a replacement
|
2008-04-08 02:09:17 -04:00
|
|
|
# for inline page templating systems such as PHP, ERB, and ASP.
|
|
|
|
# However, Haml avoids the need for explicitly coding XHTML into the template,
|
2006-12-18 21:56:49 -05:00
|
|
|
# because it is actually an abstract description of the XHTML,
|
|
|
|
# with some code to generate dynamic content.
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# == Features
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# * Whitespace active
|
|
|
|
# * Well-formatted markup
|
|
|
|
# * DRY
|
|
|
|
# * Follows CSS conventions
|
2007-02-28 05:44:12 -05:00
|
|
|
# * Integrates Ruby code
|
2006-12-18 21:56:49 -05:00
|
|
|
# * Implements Rails templates with the .haml extension
|
2007-02-28 05:44:12 -05:00
|
|
|
#
|
|
|
|
# == Using Haml
|
|
|
|
#
|
2007-03-01 00:52:47 -05:00
|
|
|
# Haml can be used in two ways:
|
|
|
|
# as a plugin for Ruby on Rails,
|
2007-11-18 22:36:21 -05:00
|
|
|
# and as a standalone Ruby module.
|
2007-03-01 00:52:47 -05:00
|
|
|
#
|
2007-11-18 04:19:21 -05:00
|
|
|
# Sass can be used in several ways:
|
|
|
|
# As a template engine for Ruby on Rails or Merb,
|
|
|
|
# or as a standalone engine.
|
|
|
|
# The first step for all of these is to install the Haml gem:
|
|
|
|
#
|
|
|
|
# gem install haml
|
|
|
|
#
|
|
|
|
# To enable it as a Rails plugin,
|
|
|
|
# then run
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-11-18 04:19:21 -05:00
|
|
|
# haml --rails path/to/rails/app
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-11-18 04:19:21 -05:00
|
|
|
# Haml is enabled in Merb by default,
|
|
|
|
# so Merb users don't have to do anything more.
|
2007-02-28 05:44:12 -05:00
|
|
|
#
|
|
|
|
# Once it's installed, all view files with the ".haml" extension
|
2007-11-18 04:19:21 -05:00
|
|
|
# (or ".html.haml" for Merb or edge Rails)
|
2007-02-28 05:44:12 -05:00
|
|
|
# will be compiled using Haml.
|
|
|
|
#
|
2007-03-01 00:52:47 -05:00
|
|
|
# You can access instance variables in Haml templates
|
|
|
|
# the same way you do in ERb templates.
|
|
|
|
# Helper methods are also available in Haml templates.
|
2007-11-18 04:19:21 -05:00
|
|
|
# For example (this example uses Rails, but the principle for Merb is the same):
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-03-01 00:52:47 -05:00
|
|
|
# # file: app/controllers/movies_controller.rb
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-03-01 00:52:47 -05:00
|
|
|
# class MoviesController < ApplicationController
|
|
|
|
# def index
|
|
|
|
# @title = "Teen Wolf"
|
|
|
|
# end
|
|
|
|
# end
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-11-18 22:36:21 -05:00
|
|
|
# -# file: app/views/movies/index.haml
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-03-01 00:52:47 -05:00
|
|
|
# #content
|
|
|
|
# .title
|
|
|
|
# %h1= @title
|
|
|
|
# = link_to 'Home', home_url
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-03-01 00:52:47 -05:00
|
|
|
# may be compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-03-01 00:52:47 -05:00
|
|
|
# <div id='content'>
|
|
|
|
# <div class='title'>
|
|
|
|
# <h1>Teen Wolf</h1>
|
|
|
|
# <a href='/'>Home</a>
|
|
|
|
# </div>
|
|
|
|
# </div>
|
|
|
|
#
|
|
|
|
# === Ruby Module
|
|
|
|
#
|
2007-02-28 05:44:12 -05:00
|
|
|
# Haml can also be used completely separately from Rails and ActionView.
|
|
|
|
# To do this, install the gem with RubyGems:
|
|
|
|
#
|
|
|
|
# gem install haml
|
|
|
|
#
|
|
|
|
# You can then use it by including the "haml" gem in Ruby code,
|
|
|
|
# and using Haml::Engine like so:
|
|
|
|
#
|
|
|
|
# engine = Haml::Engine.new("%p Haml code!")
|
|
|
|
# engine.render #=> "<p>Haml code!</p>\n"
|
2007-05-28 03:55:08 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# == Characters with meaning to Haml
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# Various characters, when placed at a certain point in a line,
|
|
|
|
# instruct Haml to render different types of things.
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# === XHTML Tags
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# These characters render XHTML tags.
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== %
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
|
|
|
#
|
2007-02-28 05:44:12 -05:00
|
|
|
# The percent character is placed at the beginning of a line.
|
2006-12-18 21:56:49 -05:00
|
|
|
# It's followed immediately by the name of an element,
|
|
|
|
# then optionally by modifiers (see below), a space,
|
|
|
|
# and text to be rendered inside the element.
|
|
|
|
# It creates an element in the form of <tt><element></element></tt>.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %one
|
|
|
|
# %two
|
|
|
|
# %three Hey there
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <one>
|
|
|
|
# <two>
|
|
|
|
# <three>Hey there</three>
|
|
|
|
# </two>
|
|
|
|
# </one>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# Any string is a valid element name;
|
|
|
|
# Haml will automatically generate opening and closing tags for any element.
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== {}
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# Brackets represent a Ruby hash
|
|
|
|
# that is used for specifying the attributes of an element.
|
|
|
|
# It is literally evaluated as a Ruby hash,
|
|
|
|
# so logic will work in it and local variables may be used.
|
|
|
|
# Quote characters within the attribute
|
|
|
|
# will be replaced by appropriate escape sequences.
|
|
|
|
# The hash is placed after the tag is defined.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %head{ :name => "doc_head" }
|
|
|
|
# %script{ 'type' => "text/" + "javascript",
|
|
|
|
# :src => "javascripts/script_#{2 + 7}" }
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <head name="doc_head">
|
|
|
|
# <script src='javascripts/script_9' type='text/javascript'>
|
|
|
|
# </script>
|
|
|
|
# </head>
|
2007-12-19 06:53:19 -05:00
|
|
|
#
|
2008-02-29 20:56:38 -05:00
|
|
|
# ===== Attribute Methods
|
|
|
|
#
|
2007-12-19 06:53:19 -05:00
|
|
|
# A Ruby method call that returns a hash
|
|
|
|
# can be substituted for the hash contents.
|
|
|
|
# For example, Haml::Helpers defines the following method:
|
|
|
|
#
|
|
|
|
# def html_attrs(lang = 'en-US')
|
|
|
|
# {:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => lang, :lang => lang}
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# This can then be used in Haml, like so:
|
|
|
|
#
|
|
|
|
# %html{html_attrs('fr-fr')}
|
|
|
|
#
|
|
|
|
# This is compiled to:
|
|
|
|
#
|
|
|
|
# <html lang='fr-fr' xml:lang='fr=fr' xmlns='http://www.w3.org/1999/xhtml'>
|
|
|
|
# </html>
|
|
|
|
#
|
|
|
|
# You can use as many such attribute methods as you want
|
|
|
|
# by separating them with commas,
|
|
|
|
# like a Ruby argument list.
|
|
|
|
# All the hashes will me merged together, from left to right.
|
|
|
|
# For example, if you defined
|
|
|
|
#
|
|
|
|
# def hash1
|
|
|
|
# {:bread => 'white', :filling => 'peanut butter and jelly'}
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# def hash2
|
|
|
|
# {:bread => 'whole wheat'}
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# then
|
|
|
|
#
|
|
|
|
# %sandwich{hash1, hash2, :delicious => true}/
|
|
|
|
#
|
|
|
|
# would compile to:
|
|
|
|
#
|
|
|
|
# <sandwich bread='whole wheat' delicious='true' filling='peanut butter and jelly' />
|
2008-02-29 20:56:38 -05:00
|
|
|
#
|
|
|
|
# ===== Boolean Attributes
|
|
|
|
#
|
|
|
|
# Some attributes, such as "checked" for <tt>input</tt> tags or "selected" for <tt>option</tt> tags,
|
|
|
|
# are "boolean" in the sense that their values don't matter -
|
|
|
|
# it only matters whether or not they're present.
|
|
|
|
# In HTML (but not XHTML), these attributes can be written as
|
|
|
|
#
|
|
|
|
# <input selected>
|
|
|
|
#
|
|
|
|
# To do this in Haml, just assign a Ruby true value to the attribute:
|
|
|
|
#
|
|
|
|
# %input{:selected => true}
|
|
|
|
#
|
2008-03-02 20:20:43 -05:00
|
|
|
# In XHTML, the only valid value for these attributes is the name of the attribute.
|
|
|
|
# Thus this will render in XHTML as
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2008-03-02 20:20:43 -05:00
|
|
|
# <input selected="selected">
|
2008-02-29 20:56:38 -05:00
|
|
|
#
|
2008-03-02 20:20:43 -05:00
|
|
|
# To set these attributes to false, simply assign them to a Ruby false value.
|
|
|
|
# In both XHTML and HTML
|
2008-02-29 20:56:38 -05:00
|
|
|
#
|
2008-03-02 20:20:43 -05:00
|
|
|
# %input{:selected => false}
|
2008-02-29 20:56:38 -05:00
|
|
|
#
|
2008-03-02 20:20:43 -05:00
|
|
|
# will just render as
|
2008-02-29 20:56:38 -05:00
|
|
|
#
|
2008-03-02 20:20:43 -05:00
|
|
|
# <input>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== []
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# Square brackets follow a tag definition and contain a Ruby object
|
|
|
|
# that is used to set the class and id of that tag.
|
|
|
|
# The class is set to the object's class
|
|
|
|
# (transformed to use underlines rather than camel case)
|
|
|
|
# and the id is set to the object's class, followed by its id.
|
|
|
|
# Because the id of an object is normally an obscure implementation detail,
|
|
|
|
# this is most useful for elements that represent instances of Models.
|
2008-04-10 06:37:22 -04:00
|
|
|
# Additionally, the second argument (if present) will be used as a prefix for
|
|
|
|
# both the id and class attributes.
|
2006-12-18 21:56:49 -05:00
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# # file: app/controllers/users_controller.rb
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# def show
|
|
|
|
# @user = CrazyUser.find(15)
|
|
|
|
# end
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-11-18 22:36:21 -05:00
|
|
|
# -# file: app/views/users/show.haml
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2008-04-10 06:37:22 -04:00
|
|
|
# %div[@user, :greeting]
|
2006-12-18 21:56:49 -05:00
|
|
|
# %bar[290]/
|
|
|
|
# Hello!
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2008-04-10 06:37:22 -04:00
|
|
|
# <div class="greeting_crazy_user" id="greeting_crazy_user_15">
|
2006-12-18 21:56:49 -05:00
|
|
|
# <bar class="fixnum" id="fixnum_581" />
|
|
|
|
# Hello!
|
|
|
|
# </div>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== /
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# The forward slash character, when placed at the end of a tag definition,
|
|
|
|
# causes the tag to be self-closed.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %br/
|
2008-03-16 22:17:12 -04:00
|
|
|
# %meta{'http-equiv' => 'Content-Type', :content => 'text/html'}/
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <br />
|
|
|
|
# <meta http-equiv='Content-Type' content='text/html' />
|
2007-03-26 02:03:29 -04:00
|
|
|
#
|
|
|
|
# Some tags are automatically closed, as long as they have no content.
|
|
|
|
# +meta+, +img+, +link+, +script+, +br+, and +hr+ tags are closed by default.
|
|
|
|
# This list can be customized by setting the <tt>:autoclose</tt> option (see below).
|
|
|
|
# For example:
|
|
|
|
#
|
|
|
|
# %br
|
|
|
|
# %meta{'http-equiv' => 'Content-Type', :content => 'text/html'}
|
|
|
|
#
|
|
|
|
# is also compiled to:
|
|
|
|
#
|
|
|
|
# <br />
|
|
|
|
# <meta http-equiv='Content-Type' content='text/html' />
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== . and #
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# The period and pound sign are borrowed from CSS.
|
|
|
|
# They are used as shortcuts to specify the <tt>class</tt>
|
|
|
|
# and <tt>id</tt> attributes of an element, respectively.
|
|
|
|
# Multiple class names can be specified in a similar way to CSS,
|
|
|
|
# by chaining the class names together with periods.
|
|
|
|
# They are placed immediately after the tag and before an attributes hash.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-01-20 02:16:28 -05:00
|
|
|
# %div#things
|
2006-12-18 21:56:49 -05:00
|
|
|
# %span#rice Chicken Fried
|
|
|
|
# %p.beans{ :food => 'true' } The magical fruit
|
|
|
|
# %h1.class.otherclass#id La La La
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <div id='things'>
|
|
|
|
# <span id='rice'>Chicken Fried</span>
|
|
|
|
# <p class='beans' food='true'>The magical fruit</p>
|
2007-01-20 15:40:37 -05:00
|
|
|
# <h1 class='class otherclass' id='id'>La La La</h1>
|
2006-12-18 21:56:49 -05:00
|
|
|
# </div>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# And,
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# #content
|
|
|
|
# .articles
|
|
|
|
# .article.title
|
|
|
|
# Doogie Howser Comes Out
|
|
|
|
# .article.date
|
|
|
|
# 2006-11-05
|
|
|
|
# .article.entry
|
|
|
|
# Neil Patrick Harris would like to dispel any rumors that he is straight
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <div id="content">
|
|
|
|
# <div class="articles">
|
|
|
|
# <div class="article title">Doogie Howser Comes Out</div>
|
|
|
|
# <div class="article date">2006-11-05</div>
|
|
|
|
# <div class="article entry">
|
|
|
|
# Neil Patrick Harris would like to dispel any rumors that he is straight
|
|
|
|
# </div>
|
|
|
|
# </div>
|
|
|
|
# </div>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== Implicit Div Elements
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# Because the div element is used so often, it is the default element.
|
|
|
|
# If you only define a class and/or id using the <tt>.</tt> or <tt>#</tt> syntax,
|
|
|
|
# a div element is automatically used.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# #collection
|
|
|
|
# .item
|
|
|
|
# .description What a cool item!
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is the same as:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %div{:id => collection}
|
|
|
|
# %div{:class => 'item'}
|
|
|
|
# %div{:class => 'description'} What a cool item!
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# and is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <div id='collection'>
|
2007-09-02 13:11:19 -04:00
|
|
|
# <div class='item'>
|
|
|
|
# <div class='description'>What a cool item!</div>
|
|
|
|
# </div>
|
2006-12-18 21:56:49 -05:00
|
|
|
# </div>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-02-06 03:08:32 -05:00
|
|
|
# ==== =
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-02-06 03:08:32 -05:00
|
|
|
# <tt>=</tt> is placed at the end of a tag definition,
|
2006-12-18 21:56:49 -05:00
|
|
|
# after class, id, and attribute declarations.
|
2007-02-06 03:08:32 -05:00
|
|
|
# It's just a shortcut for inserting Ruby code into an element.
|
|
|
|
# It works the same as <tt>=</tt> without a tag:
|
|
|
|
# it inserts the result of the Ruby code into the template.
|
2006-12-18 21:56:49 -05:00
|
|
|
# However, if the result is short enough,
|
|
|
|
# it is displayed entirely on one line.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %p= "hello"
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is not quite the same as:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %p
|
|
|
|
# = "hello"
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# It's compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <p>hello</p>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2008-04-24 15:35:42 -04:00
|
|
|
# ==== ~
|
|
|
|
#
|
|
|
|
# ~ works just like =, except that it runs Haml::Helpers#find_and_preserve on its input.
|
|
|
|
# For example,
|
|
|
|
#
|
|
|
|
# ~ "Foo\n<pre>Bar\nBaz</pre>"
|
|
|
|
#
|
|
|
|
# is the same as:
|
|
|
|
#
|
|
|
|
# = find_and_preserve("Foo\n<pre>Bar\nBaz</pre>")
|
|
|
|
#
|
|
|
|
# and is compiled to:
|
|
|
|
#
|
|
|
|
# Foo
|
|
|
|
# <pre>Bar
Baz</pre>
|
|
|
|
#
|
|
|
|
# See also Whitespace Preservation, below.
|
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# === XHTML Helpers
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== No Special Character
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# If no special character appears at the beginning of a line,
|
|
|
|
# the line is rendered as plain text.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %gee
|
|
|
|
# %whiz
|
|
|
|
# Wow this is cool!
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <gee>
|
|
|
|
# <whiz>
|
|
|
|
# Wow this is cool!
|
|
|
|
# </whiz>
|
|
|
|
# </gee>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== !!!
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# When describing XHTML documents with Haml,
|
|
|
|
# you can have a document type or XML prolog generated automatically
|
|
|
|
# by including the characters <tt>!!!</tt>.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# !!! XML
|
|
|
|
# !!!
|
|
|
|
# %html
|
|
|
|
# %head
|
|
|
|
# %title Myspace
|
|
|
|
# %body
|
|
|
|
# %h1 I am the international space station
|
|
|
|
# %p Sign my guestbook
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <?xml version="1.0" encoding="utf-8" ?>
|
|
|
|
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
# <html>
|
|
|
|
# <head>
|
|
|
|
# <title>Myspace</title>
|
|
|
|
# </head>
|
|
|
|
# <body>
|
|
|
|
# <h1>I am the international space station</h1>
|
|
|
|
# <p>Sign my guestbook</p>
|
|
|
|
# </body>
|
|
|
|
# </html>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# You can also specify the version and type of XHTML after the <tt>!!!</tt>.
|
|
|
|
# XHTML 1.0 Strict, Transitional, and Frameset and XHTML 1.1 are supported.
|
|
|
|
# The default version is 1.0 and the default type is Transitional.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# !!! 1.1
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# and
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# !!! Strict
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-11-18 22:36:21 -05:00
|
|
|
# If you're not using the UTF-8 character set for your document,
|
2006-12-18 21:56:49 -05:00
|
|
|
# you can specify which encoding should appear
|
|
|
|
# in the XML prolog in a similar way.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# !!! XML iso-8859-1
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <?xml version="1.0" encoding="iso-8859-1" ?>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== /
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# The forward slash character, when placed at the beginning of a line,
|
|
|
|
# wraps all text after it in an HTML comment.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-11-18 22:36:21 -05:00
|
|
|
# %peanutbutterjelly
|
|
|
|
# / This is the peanutbutterjelly element
|
|
|
|
# I like sandwiches!
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-11-18 22:36:21 -05:00
|
|
|
# <peanutbutterjelly>
|
|
|
|
# <!-- This is the peanutbutterjelly element -->
|
|
|
|
# I like sandwiches!
|
|
|
|
# </peanutbutterjelly>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# The forward slash can also wrap indented sections of code. For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# /
|
|
|
|
# %p This doesn't render...
|
|
|
|
# %div
|
|
|
|
# %h1 Because it's commented out!
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <!--
|
|
|
|
# <p>This doesn't render...</p>
|
|
|
|
# <div>
|
|
|
|
# <h1>Because it's commented out!</h1>
|
|
|
|
# </div>
|
|
|
|
# -->
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# You can also use Internet Explorer conditional comments
|
|
|
|
# (about)[http://www.quirksmode.org/css/condcom.html]
|
|
|
|
# by enclosing the condition in square brackets after the <tt>/</tt>.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# /[if IE]
|
|
|
|
# %a{ :href => 'http://www.mozilla.com/en-US/firefox/' }
|
|
|
|
# %h1 Get Firefox
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <!--[if IE]>
|
|
|
|
# <a href='http://www.mozilla.com/en-US/firefox/'>
|
|
|
|
# <h1>Get Firefox</h1>
|
|
|
|
# </a>
|
|
|
|
# <![endif]-->
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== \
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# The backslash character escapes the first character of a line,
|
|
|
|
# allowing use of otherwise interpreted characters as plain text.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %title
|
|
|
|
# = @title
|
|
|
|
# \- MySite
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <title>
|
|
|
|
# MyPage
|
|
|
|
# - MySite
|
|
|
|
# </title>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== |
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# The pipe character designates a multiline string.
|
|
|
|
# It's placed at the end of a line
|
|
|
|
# and means that all following lines that end with <tt>|</tt>
|
|
|
|
# will be evaluated as though they were on the same line.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %whoo
|
|
|
|
# %hoo I think this might get |
|
|
|
|
# pretty long so I should |
|
|
|
|
# probably make it |
|
|
|
|
# multiline so it doesn't |
|
|
|
|
# look awful. |
|
|
|
|
# %p This is short.
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-02-27 13:57:17 -05:00
|
|
|
# <whoo>
|
|
|
|
# <hoo>
|
|
|
|
# I think this might get pretty long so I should probably make it multiline so it doesn't look awful.
|
|
|
|
# </hoo>
|
|
|
|
# </whoo>
|
2007-01-19 12:03:47 -05:00
|
|
|
#
|
|
|
|
# ==== :
|
|
|
|
#
|
|
|
|
# The colon character designates a filter.
|
|
|
|
# This allows you to pass an indented block of text as input
|
|
|
|
# to another filtering program and add the result to the output of Haml.
|
|
|
|
# The syntax is simply a colon followed by the name of the filter.
|
|
|
|
# For example,
|
|
|
|
#
|
|
|
|
# %p
|
|
|
|
# :markdown
|
|
|
|
# Textile
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# Hello, *World*
|
|
|
|
#
|
|
|
|
# is compiled to
|
|
|
|
#
|
|
|
|
# <p>
|
|
|
|
# <h1>Textile</h1>
|
|
|
|
#
|
|
|
|
# <p>Hello, <em>World</em></p>
|
|
|
|
# </p>
|
|
|
|
#
|
2008-02-23 02:27:35 -05:00
|
|
|
# Filters can have Ruby code interpolated, like with ==.
|
|
|
|
# For example,
|
|
|
|
#
|
|
|
|
# - flavor = "raspberry"
|
|
|
|
# #content
|
|
|
|
# :textile
|
|
|
|
# I *really* prefer _#{h flavor}_ jam.
|
|
|
|
#
|
|
|
|
# is compiled to
|
|
|
|
#
|
|
|
|
# <div id='content'>
|
|
|
|
# <p>I <strong>really</strong> prefer <em>raspberry</em> jam.</p>
|
|
|
|
# </div>
|
|
|
|
#
|
2007-01-19 12:03:47 -05:00
|
|
|
# Haml has the following filters defined:
|
|
|
|
#
|
2008-02-23 04:56:16 -05:00
|
|
|
# [plain] Does not parse the filtered text.
|
|
|
|
# This is useful for large blocks of text without HTML tags,
|
|
|
|
# when you don't want lines starting with <tt>.</tt> or <tt>-</tt>
|
|
|
|
# to be parsed.
|
|
|
|
#
|
|
|
|
# [javascript] Surrounds the filtered text with <script> and CDATA tags.
|
|
|
|
# Useful for including inline Javascript.
|
|
|
|
#
|
|
|
|
# [ruby] Parses the filtered text with the normal Ruby interpreter.
|
|
|
|
# All output sent to <tt>$stdout</tt>, like with +puts+,
|
|
|
|
# is output into the Haml document.
|
|
|
|
# Not available if the <tt>suppress_eval</tt> option is set to true.
|
|
|
|
# The Ruby code is evaluated in the same context as the Haml template.
|
|
|
|
#
|
|
|
|
# [preserve] Inserts the filtered text into the template with whitespace preserved.
|
|
|
|
# <tt>preserve</tt>d blocks of text aren't indented,
|
|
|
|
# and newlines are replaced with the HTML escape code for newlines,
|
|
|
|
# to preserve nice-looking output.
|
2008-04-24 15:35:42 -04:00
|
|
|
# See also Whitespace Preservation, below.
|
2008-02-23 04:56:16 -05:00
|
|
|
#
|
|
|
|
# [erb] Parses the filtered text with ERB, like an RHTML template.
|
|
|
|
# Not available if the <tt>suppress_eval</tt> option is set to true.
|
|
|
|
# Embedded Ruby code is evaluated in the same context as the Haml template.
|
|
|
|
#
|
|
|
|
# [sass] Parses the filtered text with Sass to produce CSS output.
|
|
|
|
#
|
|
|
|
# [redcloth] Parses the filtered text with RedCloth (http://whytheluckystiff.net/ruby/redcloth),
|
|
|
|
# which uses both Textile and Markdown syntax.
|
|
|
|
# Only works if RedCloth is installed.
|
|
|
|
#
|
|
|
|
# [textile] Parses the filtered text with Textile (http://www.textism.com/tools/textile).
|
|
|
|
# Only works if RedCloth is installed.
|
|
|
|
#
|
|
|
|
# [markdown] Parses the filtered text with Markdown (http://daringfireball.net/projects/markdown).
|
|
|
|
# Only works if RedCloth or BlueCloth (http://www.deveiate.org/projects/BlueCloth)
|
|
|
|
# is installed
|
|
|
|
# (BlueCloth takes precedence if both are installed).
|
2007-01-19 12:03:47 -05:00
|
|
|
#
|
|
|
|
# You can also define your own filters (see Setting Options, below).
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# === Ruby evaluators
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== =
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# The equals character is followed by Ruby code,
|
|
|
|
# which is evaluated and the output inserted into the document as plain text.
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %p
|
|
|
|
# = ['hi', 'there', 'reader!'].join " "
|
|
|
|
# = "yo"
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <p>
|
|
|
|
# hi there reader!
|
|
|
|
# yo
|
|
|
|
# </p>
|
2007-04-15 21:21:16 -04:00
|
|
|
#
|
2008-03-16 18:40:53 -04:00
|
|
|
# If the <tt>:escape_html</tt> option is set,
|
|
|
|
# = will sanitize any HTML-sensitive characters generated by the script.
|
|
|
|
# For example:
|
|
|
|
#
|
|
|
|
# = '<script>alert("I\'m evil!");</script>'
|
|
|
|
#
|
|
|
|
# would be compiled to
|
|
|
|
#
|
|
|
|
# <script>alert("I'm evil!");</script>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ==== -
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# The hyphen character makes the text following it into "silent script":
|
|
|
|
# Ruby script that is evaluated, but not output.
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <b>It is not recommended that you use this widely;
|
|
|
|
# almost all processing code and logic should be restricted
|
|
|
|
# to the Controller, the Helper, or partials.</b>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# - foo = "hello"
|
|
|
|
# - foo << " there"
|
|
|
|
# - foo << " you!"
|
|
|
|
# %p= foo
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <p>
|
|
|
|
# hello there you!
|
|
|
|
# </p>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2008-02-23 04:08:47 -05:00
|
|
|
# ==== ==
|
|
|
|
#
|
|
|
|
# Two equals characters interpolates Ruby code into plain text,
|
|
|
|
# similarly to Ruby string interpolation.
|
|
|
|
# For example,
|
|
|
|
#
|
|
|
|
# %p== This is #{h quality} cake!
|
|
|
|
#
|
|
|
|
# is the same as
|
|
|
|
#
|
|
|
|
# %p= "This is #{h quality} cake!"
|
|
|
|
#
|
|
|
|
# and might compile to
|
|
|
|
#
|
|
|
|
# <p>This is scrumptious cake!</p>
|
|
|
|
#
|
2008-02-23 04:09:23 -05:00
|
|
|
# Backslashes can be used to escape "#{" strings,
|
|
|
|
# but they don't act as escapes anywhere else in the string.
|
|
|
|
# For example:
|
|
|
|
#
|
|
|
|
# %p
|
|
|
|
# == \\ Look at \\#{h word} lack of backslash: \#{foo}
|
|
|
|
#
|
|
|
|
# might compile to
|
|
|
|
#
|
|
|
|
# <p>
|
|
|
|
# \\ Look at \yon lack of backslash: #{foo}
|
|
|
|
# </p>
|
|
|
|
#
|
2008-03-16 18:40:53 -04:00
|
|
|
# ==== &=
|
|
|
|
#
|
2008-03-18 05:19:41 -04:00
|
|
|
# An ampersand followed by one or two equals characters
|
|
|
|
# evaluates Ruby code just like the equals without the ampersand,
|
2008-03-16 18:40:53 -04:00
|
|
|
# but sanitizes any HTML-sensitive characters in the result of the code.
|
|
|
|
# For example:
|
|
|
|
#
|
|
|
|
# &= "I like cheese & crackers"
|
|
|
|
#
|
|
|
|
# compiles to
|
|
|
|
#
|
|
|
|
# I like cheese & crackers
|
|
|
|
#
|
|
|
|
# If the <tt>:escape_html</tt> option is set,
|
|
|
|
# &= behaves identically to =.
|
|
|
|
#
|
|
|
|
# ==== !=
|
|
|
|
#
|
2008-03-18 05:19:41 -04:00
|
|
|
# An exclamation mark followed by one or two equals characters
|
|
|
|
# evaluates Ruby code just like the equals would,
|
2008-03-16 18:40:53 -04:00
|
|
|
# but never sanitizes the HTML.
|
|
|
|
#
|
|
|
|
# By default, the single equals doesn't sanitize HTML either.
|
|
|
|
# However, if the <tt>:escape_html</tt> option is set, = will sanitize the HTML, but != still won't.
|
|
|
|
# For example, if <tt>:escape_html</tt> is set:
|
|
|
|
#
|
|
|
|
# = "I feel <strong>!"
|
|
|
|
# != "I feel <strong>!"
|
|
|
|
#
|
|
|
|
# compiles to
|
|
|
|
#
|
|
|
|
# I feel <strong>!
|
|
|
|
# I feel <strong>!
|
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# ===== Blocks
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# Ruby blocks, like XHTML tags, don't need to be explicitly closed in Haml.
|
|
|
|
# Rather, they're automatically closed, based on indentation.
|
|
|
|
# A block begins whenever the indentation is increased
|
|
|
|
# after a silent script command.
|
|
|
|
# It ends when the indentation decreases
|
|
|
|
# (as long as it's not an +else+ clause or something similar).
|
|
|
|
# For example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# - (42...47).each do |i|
|
|
|
|
# %p= i
|
|
|
|
# %p See, I can count!
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <p>
|
|
|
|
# 42
|
|
|
|
# </p>
|
|
|
|
# <p>
|
|
|
|
# 43
|
|
|
|
# </p>
|
|
|
|
# <p>
|
|
|
|
# 44
|
|
|
|
# </p>
|
|
|
|
# <p>
|
|
|
|
# 45
|
|
|
|
# </p>
|
|
|
|
# <p>
|
|
|
|
# 46
|
|
|
|
# </p>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# Another example:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# %p
|
|
|
|
# - case 2
|
|
|
|
# - when 1
|
|
|
|
# = "1!"
|
|
|
|
# - when 2
|
|
|
|
# = "2?"
|
|
|
|
# - when 3
|
|
|
|
# = "3."
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# is compiled to:
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# <p>
|
|
|
|
# 2?
|
|
|
|
# </p>
|
2007-05-28 03:55:08 -04:00
|
|
|
#
|
2007-08-29 11:12:49 -04:00
|
|
|
# ==== -#
|
|
|
|
#
|
|
|
|
# The hyphen followed immediately by the pound sign
|
|
|
|
# signifies a silent comment.
|
|
|
|
# Any text following this isn't rendered in the resulting document
|
|
|
|
# at all.
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-08-29 11:12:49 -04:00
|
|
|
# For example:
|
|
|
|
#
|
|
|
|
# %p foo
|
|
|
|
# -# This is a comment
|
|
|
|
# %p bar
|
|
|
|
#
|
|
|
|
# is compiled to:
|
|
|
|
#
|
|
|
|
# <p>foo</p>
|
|
|
|
# <p>bar</p>
|
2007-12-10 15:54:49 -05:00
|
|
|
#
|
|
|
|
# You can also nest text beneath a silent comment.
|
|
|
|
# None of this text will be rendered.
|
|
|
|
# For example:
|
|
|
|
#
|
|
|
|
# %p foo
|
|
|
|
# -#
|
|
|
|
# This won't be displayed
|
|
|
|
# Nor will this
|
|
|
|
# %p bar
|
|
|
|
#
|
|
|
|
# is compiled to:
|
|
|
|
#
|
|
|
|
# <p>foo</p>
|
|
|
|
# <p>bar</p>
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-05-28 03:55:08 -04:00
|
|
|
# == Other Useful Things
|
|
|
|
#
|
2008-04-24 15:35:42 -04:00
|
|
|
# === Whitespace Preservation
|
|
|
|
#
|
|
|
|
# Sometimes you don't want Haml to indent all your text.
|
|
|
|
# For example, tags like +pre+ and +textarea+ are whitespace-sensitive;
|
|
|
|
# indenting the text makes them render wrong.
|
|
|
|
#
|
|
|
|
# Haml deals with this by "preserving" newlines before they're put into the document --
|
|
|
|
# converting them to the XHTML whitespace escape code, <tt>
</tt>.
|
|
|
|
# Then Haml won't try to re-format the indentation.
|
|
|
|
#
|
|
|
|
# Literal +textarea+ and +pre+ tags automatically preserve their content.
|
|
|
|
# Dynamically can't be caught automatically,
|
|
|
|
# and so should be passed through Haml::Helpers#find_and_preserve or the <tt>~</tt> command,
|
|
|
|
# which has the same effect (see above).
|
|
|
|
#
|
|
|
|
# Blocks of literal text can be preserved using the :preserve filter (see above).
|
|
|
|
#
|
2007-05-28 03:55:08 -04:00
|
|
|
# === Helpers
|
|
|
|
#
|
|
|
|
# Haml offers a bunch of helpers that are useful
|
|
|
|
# for doing stuff like preserving whitespace,
|
|
|
|
# creating nicely indented output for user-defined helpers,
|
|
|
|
# and other useful things.
|
|
|
|
# The helpers are all documented in the Haml::Helpers and Haml::Helpers::ActionViewExtensions modules.
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2007-05-28 03:55:08 -04:00
|
|
|
# === Haml Options
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# Options can be set by setting the hash <tt>Haml::Template.options</tt>
|
2007-03-01 00:52:47 -05:00
|
|
|
# from <tt>environment.rb</tt> in Rails,
|
|
|
|
# or by passing an options hash to Haml::Engine.
|
2006-12-18 21:56:49 -05:00
|
|
|
# Available options are:
|
2008-02-26 13:57:45 -05:00
|
|
|
#
|
|
|
|
# [<tt>:output</tt>] Determines the output format. The default is :xhtml.
|
2008-02-27 16:33:50 -05:00
|
|
|
# Other options are :html4 and :html5, which are
|
|
|
|
# identical to :xhtml except there are no self-closing tags,
|
|
|
|
# XML prolog is ignored and correct DOCTYPEs are generated.
|
2008-02-26 13:57:45 -05:00
|
|
|
#
|
2008-03-16 18:40:53 -04:00
|
|
|
# [<tt>:escape_html</tt>] Sets whether or not to escape HTML-sensitive characters in script.
|
|
|
|
# If this is true, = behaves like &=;
|
|
|
|
# otherwise, it behaves like !=.
|
2008-03-18 05:19:41 -04:00
|
|
|
# <b>Note that this escapes tag attributes.</b>
|
2008-03-16 18:40:53 -04:00
|
|
|
# Defaults to false.
|
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# [<tt>:suppress_eval</tt>] Whether or not attribute hashes and Ruby scripts
|
|
|
|
# designated by <tt>=</tt> or <tt>~</tt> should be
|
|
|
|
# evaluated. If this is true, said scripts are
|
|
|
|
# rendered as empty strings. Defaults to false.
|
2008-04-08 02:09:17 -04:00
|
|
|
#
|
2006-12-18 21:56:49 -05:00
|
|
|
# [<tt>:attr_wrapper</tt>] The character that should wrap element attributes.
|
|
|
|
# This defaults to <tt>'</tt> (an apostrophe). Characters
|
|
|
|
# of this type within the attributes will be escaped
|
|
|
|
# (e.g. by replacing them with <tt>'</tt>) if
|
|
|
|
# the character is an apostrophe or a quotation mark.
|
2007-01-19 12:03:47 -05:00
|
|
|
#
|
2007-01-28 02:59:44 -05:00
|
|
|
# [<tt>:filename</tt>] The name of the Haml file being parsed.
|
|
|
|
# This is only used as information when exceptions are raised.
|
|
|
|
# This is automatically assigned when working through ActionView,
|
|
|
|
# so it's really only useful for the user to assign
|
|
|
|
# when dealing with Haml programatically.
|
|
|
|
#
|
2007-01-19 12:03:47 -05:00
|
|
|
# [<tt>:filters</tt>] A hash of filters that can be applied to Haml code.
|
|
|
|
# The keys are the string names of the filters;
|
|
|
|
# the values are references to the classes of the filters.
|
|
|
|
# User-defined filters should always have lowercase keys,
|
2008-03-02 19:26:20 -05:00
|
|
|
# and should have the interface described in Haml::Filters::Base.
|
2006-12-18 21:56:49 -05:00
|
|
|
#
|
2007-03-26 02:03:29 -04:00
|
|
|
# [<tt>:autoclose</tt>] A list of tag names that should be automatically self-closed
|
|
|
|
# if they have no content.
|
2008-02-26 13:57:45 -05:00
|
|
|
# Defaults to <tt>['meta', 'img', 'link', 'br', 'hr', 'input', 'area', 'param', 'col', 'base']</tt>.
|
2007-03-26 02:03:29 -04:00
|
|
|
#
|
2008-03-02 19:24:47 -05:00
|
|
|
# [<tt>:preserve</tt>] A list of tag names that should automatically have their newlines preserved
|
|
|
|
# using the Haml::Helpers#preserve helper.
|
|
|
|
# This means that any content given on the same line as the tag will be preserved.
|
|
|
|
# For example:
|
|
|
|
#
|
|
|
|
# %textarea= "Foo\nBar"
|
|
|
|
#
|
|
|
|
# compiles to:
|
|
|
|
#
|
|
|
|
# <textarea>Foo&
Bar</textarea>
|
|
|
|
#
|
|
|
|
# Defaults to <tt>['textarea', 'pre']</tt>.
|
|
|
|
#
|
2008-04-24 15:35:42 -04:00
|
|
|
# See also Whitespace Preservation, above.
|
|
|
|
#
|
2007-12-11 05:03:44 -05:00
|
|
|
module Haml
|
2008-04-11 01:00:42 -04:00
|
|
|
# Returns a hash representing the version of Haml.
|
|
|
|
# The :major, :minor, and :teeny keys have their respective numbers.
|
2008-04-11 01:01:25 -04:00
|
|
|
# The :string key contains a human-readable string representation of the version.
|
2008-04-11 01:08:28 -04:00
|
|
|
# If Haml is checked out from Git,
|
|
|
|
# the :rev key will have the revision hash.
|
2008-04-11 01:00:42 -04:00
|
|
|
def self.version
|
|
|
|
return @@version if defined?(@@version)
|
|
|
|
|
2008-04-11 00:39:48 -04:00
|
|
|
numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
|
2008-04-11 01:00:42 -04:00
|
|
|
@@version = {
|
|
|
|
:major => numbers[0],
|
|
|
|
:minor => numbers[1],
|
|
|
|
:teeny => numbers[2]
|
|
|
|
}
|
2008-04-11 01:01:25 -04:00
|
|
|
@@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')
|
2008-04-11 01:08:28 -04:00
|
|
|
|
2008-04-11 01:54:40 -04:00
|
|
|
if File.exists?(scope('REVISION'))
|
|
|
|
rev = File.read(scope('REVISION')).strip
|
2008-04-25 00:30:48 -04:00
|
|
|
rev = nil if rev !~ /a-f0-9+/
|
|
|
|
end
|
|
|
|
|
|
|
|
if rev.nil? && File.exists?(scope('.git/HEAD'))
|
2008-04-11 01:08:28 -04:00
|
|
|
rev = File.read(scope('.git/HEAD')).strip
|
|
|
|
if rev =~ /^ref: (.*)$/
|
|
|
|
rev = File.read(scope(".git/#{$1}")).strip
|
|
|
|
end
|
2008-04-11 01:54:40 -04:00
|
|
|
end
|
2008-04-11 01:08:28 -04:00
|
|
|
|
2008-04-11 01:54:40 -04:00
|
|
|
if rev
|
2008-04-11 01:08:28 -04:00
|
|
|
@@version[:rev] = rev
|
|
|
|
@@version[:string] << "." << rev[0...7]
|
|
|
|
end
|
|
|
|
|
2008-04-11 01:01:25 -04:00
|
|
|
@@version
|
2008-04-11 01:00:42 -04:00
|
|
|
end
|
|
|
|
|
2008-04-11 00:39:48 -04:00
|
|
|
# Returns the path of file relative to the Haml root.
|
|
|
|
def self.scope(file) # :nodoc:
|
|
|
|
File.join(File.dirname(__FILE__), '..', file)
|
|
|
|
end
|
|
|
|
|
2008-04-11 01:00:42 -04:00
|
|
|
# A string representing the version of Haml.
|
|
|
|
# A more fine-grained representation is generated by Haml.version.
|
2008-04-11 01:01:25 -04:00
|
|
|
VERSION = version[:string] unless defined?(Haml::VERSION)
|
2008-03-15 00:25:36 -04:00
|
|
|
|
2007-12-11 05:03:44 -05:00
|
|
|
# This method is called by init.rb,
|
|
|
|
# which is run by Rails on startup.
|
|
|
|
# We use it rather than putting stuff straight into init.rb
|
|
|
|
# so we can change the initialization behavior
|
|
|
|
# without modifying the file itself.
|
|
|
|
def self.init_rails(binding)
|
2007-12-11 14:14:33 -05:00
|
|
|
%w[haml/template sass sass/plugin].each(&method(:require))
|
2007-12-11 05:03:44 -05:00
|
|
|
end
|
|
|
|
end
|
2006-12-18 21:56:49 -05:00
|
|
|
|
2006-12-03 19:06:39 -05:00
|
|
|
require 'haml/engine'
|