https://github.com/sirscriptalot/tempeh
Tasty Ruby Templates
https://github.com/sirscriptalot/tempeh
ruby template
Last synced: 8 months ago
JSON representation
Tasty Ruby Templates
- Host: GitHub
- URL: https://github.com/sirscriptalot/tempeh
- Owner: sirscriptalot
- License: mit
- Created: 2017-07-02T05:23:44.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-02T19:22:55.000Z (almost 9 years ago)
- Last Synced: 2024-04-25T11:02:38.754Z (about 2 years ago)
- Topics: ruby, template
- Language: Ruby
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tempeh
Tasty Ruby Templates
## Description
Tempeh is an opininated template engine for rendering html. It steals
most of its ideas from [Mote](https://github.com/soveran/mote)
and the [Herb](https://github.com/frodsan/herb) fork. The motivation for
a new library is the different rendering API that is designed
for lazily binding a context with instance_eval for use with view components.
## Installation
`gem install tempeh`
## Example
```ruby
# ./templates/eat.tempeh
#
# % if hungry? %
# Eat {{ food }}!
# % end %
require 'tempeh'
class View
include Tempeh::Helpers
def initialize(food)
@food = food
end
def food
@food
end
def hungry?
true
end
end
View.new('Tempeh').render('./templates/eat.tempeh') # Eat Tempeh!
```
## API
### Templates
`% code %`: Ruby to be evaluated but not outputted.
`{{ code }}`: Ruby that gets outputted as an escaped string. Safe for user input.
`{{& code }}`: Ruby that gets outputted as an unescaped string. Useful for rendering partials and other content that is guarenteed to be safe.
### Module Methods
`cache`: Hash of compiled templates, populated by the `render` helper.
`compile`: Creates a proc from the the given string.
`escape`: HTML escapes the given string.
### Helpers
`render`: instance_eval's a template found at a file path. Saves the compiled template in `Tempeh::cache` for reuse.