Permalink
Browse files

talk about tags first. they're important.

  • Loading branch information...
1 parent 671f6aa commit 0b217cfe42cd94c2f7d94ffc0c458e994f94ed55 @defunkt defunkt committed Sep 24, 2009
Showing with 79 additions and 74 deletions.
  1. +79 −74 README.md
View
153 README.md
@@ -9,6 +9,7 @@ rtemplate is a framework agnostic way to render your views.
It's not a markup language because there is no language. There is no
logic.
+
Overview
--------
@@ -27,6 +28,7 @@ but reference methods in your view.
This strict separation makes it easier to write clean templates,
easier to test your views, and more fun to work on your app's front end.
+
Usage
-----
@@ -74,6 +76,81 @@ Which returns the following:
Simple.
+
+Tag Types
+---------
+
+Tags are indicated by the double mustaches. `{{name}}` is a tag. Let's
+talk about the different types of tags.
+
+### Variables
+
+The most basic tag is the variable. A `{{name}}` tag in a basic
+template will try to call the `name` method on your view. If there is
+no `name` method, an exception will be raised.
+
+All variables are HTML escaped by default. If you want, for some
+reason, to return unescaped HTML you can use the triple mustache:
+`{{{name}}}`.
+
+### Boolean Sections
+
+A section begins with a pound and ends with a slash. That is,
+`{{#person}}` begins a "person" section while `{{/person}}` ends it.
+
+If the `person` method exists and calling it returns false, the HTML
+between the pound and slash will not be displayed.
+
+If the `person` method exists and calling it returns true, the HTML
+between the pound and slash will be rendered and displayed.
+
+### Enumerable Sections
+
+Enumerable sections are syntactically identical to boolean sections in
+that they begin with a pound and end with a slash. The difference,
+however, is in the view: if the method called returns an enumerable,
+the section is repeated as the enumerable is iterated over.
+
+Each item in the enumerable is expected to be a hash which will then
+become the context of the corresponding iteration. In this way we can
+construct loops.
+
+For example, imagine this template:
+
+ {{#repo}}
+ <b>{{name}}</b>
+ {{/repo}}
+
+And this view code:
+
+ def repo
+ Repository.all.map { |r| { :name => r.to_s } }
+ end
+
+When rendered, our view will contain a list of all repository names in
+the database.
+
+### Comments
+
+Comments begin with a bang and are ignored. The following template:
+
+ <h1>Today{{! ignore me }}.</h1>
+
+Will render as follows:
+
+ <h1>Today.</h1>
+
+### Partials
+
+Partials begin with a less than sign, like `{{< box}}`.
+
+If a partial's view is loaded, we use that to render the HTML. If
+nothing is loaded we render the template directly using our current context.
+
+In this way partials can reference variables or sections the calling
+view defines.
+
+
Dict-Style Views
----------------
@@ -105,6 +182,7 @@ We can re-use the same object, too:
Hello Tony
You have just won $100!
+
Templates
---------
@@ -136,6 +214,7 @@ You can also go ahead and set the template directly:
Whatever works.
+
Helpers
-------
@@ -205,80 +284,6 @@ Now:
Convoluted but you get the idea.
-Tag Types
----------
-
-Tags are indicated by the double mustaches. `{{name}}` is a tag. Let's
-talk about the different types of tags.
-
-### Variables
-
-The most basic tag is the variable. A `{{name}}` tag in a basic
-template will try to call the `name` method on your view. If there is
-no `name` method, an exception will be raised.
-
-All variables are HTML escaped by default. If you want, for some
-reason, to return unescaped HTML you can use the triple mustache:
-`{{{name}}}`.
-
-### Boolean Sections
-
-A section begins with a pound and ends with a slash. That is,
-`{{#person}}` begins a "person" section while `{{/person}}` ends it.
-
-If the `person` method exists and calling it returns false, the HTML
-between the pound and slash will not be displayed.
-
-If the `person` method exists and calling it returns true, the HTML
-between the pound and slash will be rendered and displayed.
-
-### Enumerable Sections
-
-Enumerable sections are syntactically identical to boolean sections in
-that they begin with a pound and end with a slash. The difference,
-however, is in the view: if the method called returns an enumerable,
-the section is repeated as the enumerable is iterated over.
-
-Each item in the enumerable is expected to be a hash which will then
-become the context of the corresponding iteration. In this way we can
-construct loops.
-
-For example, imagine this template:
-
- {{#repo}}
- <b>{{name}}</b>
- {{/repo}}
-
-And this view code:
-
- def repo
- Repository.all.map { |r| { :name => r.to_s } }
- end
-
-When rendered, our view will contain a list of all repository names in
-the database.
-
-### Comments
-
-Comments begin with a bang and are ignored. The following template:
-
- <h1>Today{{! ignore me }}.</h1>
-
-Will render as follows:
-
- <h1>Today.</h1>
-
-### Partials
-
-Partials begin with a less than sign, like `{{< box}}`.
-
-If a partial's view is loaded, we use that to render the HTML. If
-nothing is loaded we render the template directly using our current context.
-
-In this way partials can reference variables or sections the calling
-view defines.
-
-
Author
------

0 comments on commit 0b217cf

Please sign in to comment.