Skip to content

Instantly share code, notes, and snippets.

@munky69rock
Created October 1, 2015 07:00
Show Gist options
  • Select an option

  • Save munky69rock/5e74642f4245bb2dd284 to your computer and use it in GitHub Desktop.

Select an option

Save munky69rock/5e74642f4245bb2dd284 to your computer and use it in GitHub Desktop.
underscore.js like template class in ruby
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