PageRenderTime 61ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/ruby/1.9.1/gems/tilt-1.2.2/TEMPLATES.md

https://github.com/glenngillen/nesta.app
Markdown | 439 lines | 309 code | 130 blank | 0 comment | 0 complexity | 96b36743ac012dd8d0a59f8ab069e310 MD5 | raw file
  1. Tilt Templates
  2. ==============
  3. While all Tilt templates use the same basic interface for template loading and
  4. evaluation, each varies in its capabilities and available options. Detailed
  5. documentation on each supported template engine is provided below.
  6. * [ERB](#erb) - `Tilt::ERBTemplate`
  7. * [Erubis](#erubis) - `Tilt::ErubisTemplate`
  8. * [Haml](#haml) - `Tilt::HamlTemplate`
  9. * [Liquid](#liquid) - `Tilt::LiquidTemplate`
  10. Tilt includes support for CSS processors like [lesscss](http://lesscss.org)
  11. and [sass](http://sass-lang.com/), in addition, it also supports simple
  12. text formats.
  13. * Less - `Tilt::LessTemplate`
  14. * Sass - `Tilt::SassTemplate`
  15. * [Markdown](#markdown) - `Tilt::RDiscountTemplate`
  16. * [RDoc](#rdoc) - `Tilt::RDocTemplate`
  17. <a name='erb'></a>
  18. ERB (`erb`, `rhtml`)
  19. --------------------
  20. An easy to use but powerful templating system for Ruby.
  21. ### Example
  22. Hello <%= world %>!
  23. ### Usage
  24. The `Tilt::ERBTemplate` class is registered for all files ending in `.erb` or
  25. `.rhtml` by default. ERB templates support custom evaluation scopes and locals:
  26. >> require 'erb'
  27. >> template = Tilt.new('hello.html.erb', :trim => '<>')
  28. => #<Tilt::ERBTemplate @file='hello.html.erb'>
  29. >> template.render(self, :world => 'World!')
  30. => "Hello World!"
  31. Or, use the `Tilt::ERBTemplate` class directly to process strings:
  32. require 'erb'
  33. template = Tilt::ERBTemplate.new(nil, :trim => '<>') { "Hello <%= world %>!" }
  34. template.render(self, :world => 'World!')
  35. __NOTE:__ It's suggested that your program `require 'erb'` at load time when
  36. using this template engine within a threaded environment.
  37. ### Options
  38. #### `:trim => '-'`
  39. The ERB trim mode flags. This is a string consisting
  40. of any combination of the following characters:
  41. * `'>'` omits newlines for lines ending in `>`
  42. * `'<>'` omits newlines for lines starting with `<%` and ending in `%>`
  43. * `'-'` omits newlines for lines ending in `-%>`.
  44. * `'%'` enables processing of lines beginning with `%`
  45. #### `:safe => nil`
  46. The `$SAFE` level; when set, ERB code will be run in a
  47. separate thread with `$SAFE` set to the provided level.
  48. #### `:outvar => '_erbout'`
  49. The name of the variable used to accumulate template output. This can be
  50. any valid Ruby expression but must be assignable. By default a local
  51. variable named `_erbout` is used.
  52. ### See also
  53. * [ERB documentation](http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html)
  54. <a name='erubis'></a>
  55. Erubis (`erubis`)
  56. -----------------
  57. Erubis is a fast, secure, and very extensible implementation of eRuby.
  58. ### Usage
  59. To use Erubis instead of ERB for all `.erb` and `.rhtml` files, register
  60. the extensions as follows:
  61. Tilt.register 'erb', Tilt::ErubisTemplate
  62. Tilt.register 'rhtml', Tilt::ErubisTemplate
  63. ### Options
  64. #### `:engine_class => Erubis::Eruby`
  65. Allows you to specify a custom engine class to use instead of the
  66. default which is `Erubis::Eruby`.
  67. #### `:escape_html => false`
  68. When `true`, `Erubis::EscapedEruby` will be used as the engine class
  69. instead of the default. All content within `<%= %>` blocks will be
  70. automatically html escaped.
  71. #### `:outvar => '_erbout'`
  72. The name of the variable used to accumulate template output. This can be
  73. any valid Ruby expression but must be assignable. By default a local
  74. variable named `_erbout` is used.
  75. #### `:pattern => '<% %>'`
  76. Set pattern for embedded Ruby code.
  77. See the [ERB](#erb) template documentation for examples, usage, and options.
  78. #### `:trim => true`
  79. Delete spaces around '<% %>'. (But, spaces around '<%= %>' are preserved.)
  80. ### See also
  81. * [Erubis Home](http://www.kuwata-lab.com/erubis/)
  82. * [Erubis User's Guide](http://www.kuwata-lab.com/erubis/users-guide.html)
  83. __NOTE:__ It's suggested that your program `require 'erubis'` at load time when
  84. using this template engine within a threaded environment.
  85. <a name='haml'></a>
  86. Haml (`haml`)
  87. -------------
  88. Haml is a markup language thats used to cleanly and simply describe the HTML of
  89. any web document without the use of inline code. Haml functions as a replacement
  90. for inline page templating systems such as PHP, ASP, and ERB, the templating
  91. language used in most Ruby on Rails applications. However, Haml avoids the
  92. need for explicitly coding HTML into the template, because it itself is a
  93. description of the HTML, with some code to generate dynamic content.
  94. ([more](http://haml-lang.com/about.html))
  95. ### Example
  96. %html
  97. %head
  98. %title= @title
  99. %body
  100. %h1
  101. Hello
  102. = world + '!'
  103. ### Usage
  104. The `Tilt::HamlTemplate` class is registered for all files ending in `.haml`
  105. by default. Haml templates support custom evaluation scopes and locals:
  106. >> require 'haml'
  107. >> template = Tilt.new('hello.haml')
  108. => #<Tilt::HamlTemplate @file='hello.haml'>
  109. >> @title = "Hello Haml!"
  110. >> template.render(self, :world => 'Haml!')
  111. => "
  112. <html>
  113. <head>
  114. <title>Hello Haml!</title>
  115. </head>
  116. <body>
  117. <h1>Hello Haml!</h1>
  118. </body>
  119. </html>"
  120. Or, use the `Tilt::HamlTemplate` class directly to process strings:
  121. >> require 'haml'
  122. >> template = Tilt::HamlTemplate.new { "%h1= 'Hello Haml!'" }
  123. => #<Tilt::HamlTemplate @file=nil ...>
  124. >> template.render
  125. => "<h1>Hello Haml!</h1>"
  126. __NOTE:__ It's suggested that your program `require 'haml'` at load time when
  127. using this template engine within a threaded environment.
  128. ### Options
  129. #### `:format => :xhtml`
  130. Determines the output format. The default is `:xhtml`. Other options are
  131. `:html4` and `:html5`, which are identical to `:xhtml` except there are no
  132. self-closing tags, the XML prolog is ignored and correct DOCTYPEs are generated.
  133. #### `:escape_html => false`
  134. Sets whether or not to escape HTML-sensitive characters in script. If this is
  135. true, `=` behaves like `&=;` otherwise, it behaves like `!=`. Note that if this
  136. is set, `!=` should be used for yielding to subtemplates and rendering partials.
  137. Defaults to false.
  138. #### `:ugly => false`
  139. If set to true, Haml makes no attempt to properly indent or format the HTML
  140. output. This causes the rendering to be done much quicker than it would
  141. otherwise, but makes viewing the source unpleasant. Defaults to false.
  142. #### `:suppress_eval => false`
  143. Whether or not attribute hashes and Ruby scripts designated by `=` or `~` should
  144. be evaluated. If this is true, said scripts are rendered as empty strings.
  145. Defaults to false.
  146. #### `:attr_wrapper => "'"`
  147. The character that should wrap element attributes. This defaults to `'` (an
  148. apostrophe). Characters of this type within the attributes will be escaped (e.g.
  149. by replacing them with `&apos;`) if the character is an apostrophe or a
  150. quotation mark.
  151. #### `:autoclose => %w[meta img link br hr input area param col base]`
  152. A list of tag names that should be automatically self-closed if they have no
  153. content. Defaults to `['meta', 'img', 'link', 'br', 'hr', 'input', 'area',
  154. 'param', 'col', 'base']`.
  155. #### `:preserve => %w[textarea pre]`
  156. A list of tag names that should automatically have their newlines preserved
  157. using the `Haml::Helpers#preserve` helper. This means that any content given on
  158. the same line as the tag will be preserved. For example, `%textarea= "Foo\nBar"`
  159. compiles to `<textarea>Foo&#x000A;Bar</textarea>`. Defaults to `['textarea',
  160. 'pre']`.
  161. #### `:encoding => 'utf-8'`
  162. The encoding to use for the HTML output. Only available in Ruby 1.9 or higher.
  163. This can be a string or an Encoding Object. Note that Haml does not
  164. automatically re-encode Ruby values; any strings coming from outside the
  165. application should be converted before being passed into the Haml template.
  166. Defaults to `Encoding.default_internal` or, if that's not set, `"utf-8"`.
  167. ### See also
  168. * [#haml.docs](http://haml-lang.com/docs.html)
  169. * [Haml Tutorial](http://haml-lang.com/tutorial.html)
  170. * [Haml Reference](http://haml-lang.com/docs/yardoc/HAML_REFERENCE.md.html)
  171. * [Whitespace Preservation](http://haml-lang.com/docs/yardoc/HAML_REFERENCE.md.html#whitespace_preservation)
  172. <a name='liquid'></a>
  173. Liquid (`liquid`)
  174. -----------------
  175. Liquid is for rendering safe templates which cannot affect the security
  176. of the server they are rendered on.
  177. ### Example
  178. <html>
  179. <head>
  180. <title>{{ title }}</title>
  181. </head>
  182. <body>
  183. <h1>Hello {{ world }}!</h1>
  184. </body>
  185. </html>
  186. ### Usage
  187. `Tilt::LiquidTemplate` is registered for all files ending in `.liquid` by
  188. default. Liquid templates support locals and objects that respond to
  189. `#to_h` as scopes:
  190. >> require 'liquid'
  191. >> require 'tilt'
  192. >> template = Tilt.new('hello.liquid')
  193. => #<Tilt::LiquidTemplate @file='hello.liquid'>
  194. >> scope = { :title => "Hello Liquid Templates" }
  195. >> template.render(nil, :world => "Liquid")
  196. => "
  197. <html>
  198. <head>
  199. <title>Hello Liquid Templates</title>
  200. </head>
  201. <body>
  202. <h1>Hello Liquid!</h1>
  203. </body>
  204. </html>"
  205. Or, use `Tilt::LiquidTemplate` directly to process strings:
  206. >> require 'haml'
  207. >> template = Tilt::HamlTemplate.new { "<h1>Hello Liquid!</h1>" }
  208. => #<Tilt::LiquidTemplate @file=nil ...>
  209. >> template.render
  210. => "<h1>Hello Liquid!</h1>"
  211. __NOTE:__ It's suggested that your program `require 'liquid'` at load
  212. time when using this template engine within a threaded environment.
  213. ### See also
  214. * [Liquid for Programmers](http://wiki.github.com/tobi/liquid/liquid-for-programmers)
  215. * [Liquid Docs](http://liquid.rubyforge.org/)
  216. * GitHub: [tobi/liquid](http://github.com/tobi/liquid/)
  217. <a name='markdown'></a>
  218. Markdown (`markdown`, `md`, `mkd`)
  219. ----------------------------------
  220. Markdown is a lightweight markup language, created by John Gruber and
  221. Aaron Swartz. For any markup that is not covered by Markdowns syntax,
  222. HTML is used. Marking up plain text with Markdown markup is easy and
  223. Markdown formatted texts are readable.
  224. Markdown formatted texts are converted to HTML with the [RDiscount][]
  225. engine, which is a Ruby extension over the fast [Discount][] C library.
  226. ### Example
  227. Hello Markdown Templates
  228. ========================
  229. Hello World. This is a paragraph.
  230. ### Usage
  231. To wrap a Markdown formatted document with a layout:
  232. require 'erubis'
  233. require 'rdiscount'
  234. layout = Tilt::ErubisTemplate.new(nil, :pattern => '\{% %\}') do
  235. "<!doctype html><title></title>{%= yield %}"
  236. end
  237. data = Tilt::RDiscountTemplate.new { "# hello tilt" }
  238. layout.render { data.render }
  239. # => "<!doctype html><title></title><h1>hello tilt</h1>\n"
  240. __NOTE:__ It's suggested that your program `require 'rdiscount'` at load time
  241. when using this template engine in a threaded environment.
  242. ### Options
  243. RDiscount supports a variety of flags that control its behavior:
  244. #### `:smart => true|false`
  245. Set `true` to enable [Smarty Pants](http://daringfireball.net/projects/smartypants/)
  246. style punctuation replacement.
  247. #### `:filter_html => true|false`
  248. Set `true` disallow raw HTML in Markdown contents. HTML is converted to
  249. literal text by escaping `<` characters.
  250. ### See also
  251. * [Markdown Syntax Documentation][markdown syntax]
  252. * GitHub: [rtomayko/rdiscount][rdiscount]
  253. [discount]: http://www.pell.portland.or.us/~orc/Code/discount/ "Discount"
  254. [rdiscount]: http://github.com/rtomayko/rdiscount/ "RDiscount"
  255. [markdown syntax]: (http://daringfireball.net/projects/markdown/syntax/) "Markdown Syntax"
  256. <a name='rdoc'></a>
  257. RDoc (`rdoc`)
  258. -------------
  259. RDoc is the simple text markup system that comes with Ruby's standard
  260. library.
  261. ### Usage
  262. __NOTE:__ It's suggested that your program `require 'rdoc/markup'` and
  263. `require 'rdoc/markup/to_html'` at load time when using this template
  264. engine in a threaded environment.
  265. ### Example
  266. = Hello RDoc Templates
  267. Hello World. This is a paragraph.
  268. ### See also
  269. * [RDoc](http://rdoc.sourceforge.net/doc/index.html)
  270. <a name='radius'></a>
  271. Radius (`radius`)
  272. -----------------
  273. Radius is the template language used by Radiant CMS. It is a tag
  274. language designed to be valid XML/HTML.
  275. ### Example
  276. <html>
  277. <body>
  278. <h1><r:title /></h1>
  279. <ul class="<r:type />">
  280. <r:repeat times="3">
  281. <li><r:hello />!</li>
  282. </r:repeat>
  283. </ul>
  284. <r:yield />
  285. </body>
  286. </html>
  287. ### Usage
  288. To render a template such as the one above.
  289. scope = OpenStruct.new
  290. scope.title = "Radius Example"
  291. scope.hello = "Hello, World!"
  292. require 'radius'
  293. template = Tilt::RadiusTemplate.new('example.radius', :tag_prefix=>'r')
  294. template.render(scope, :type=>'hlist'){ "Jackpot!" }
  295. The result will be:
  296. <html>
  297. <body>
  298. <h1>Radius Example</h1>
  299. <ul class="hlist">
  300. <li>Hello, World!</li>
  301. <li>Hello, World!</li>
  302. <li>Hello, World!</li>
  303. </ul>
  304. Jackpot!
  305. </body>
  306. </html>
  307. ### See also
  308. * [Radius](http://radius.rubyforge.org/)
  309. * [Radiant](http://radiantcms.org/)