Created
October 1, 2015 07:00
-
-
Save munky69rock/5e74642f4245bb2dd284 to your computer and use it in GitHub Desktop.
underscore.js like template class in ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SimpleTemplate | |
| class Renderer < OpenStruct | |
| def render(template) | |
| template.result(binding) | |
| end | |
| end | |
| def initialize(html) | |
| @template = ERB.new(html) | |
| end | |
| def render(params) | |
| Renderer.new(params).render(@template) | |
| end | |
| class << self | |
| def template?(body) | |
| body[/<%.*%>/].present? | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment