Skip to content

Instantly share code, notes, and snippets.

@gerred
Created May 13, 2011 20:22
Show Gist options
  • Save gerred/971244 to your computer and use it in GitHub Desktop.
Save gerred/971244 to your computer and use it in GitHub Desktop.
module Templater
extend self
def render_template(template, opts = {})
Tilt.new(build_file(template, opts)).render.inspect.split("\\n").join
end
private
def build_file(file, opts)
relative_path = opts[:path] || "/app/views/templates"
extension = opts[:extension] || ".html.haml"
File.join Rails.root, "#{relative_path}/#{file.to_s}#{extension}"
end
end
require 'spec_helper'
describe Templater do
describe "render_template" do
it "should render out a haml template when given a file that has a div" do
template = Templater.render_template(:test, path: "/spec/support")
template.should include("div")
end
end
end
window.JST =
open_chat: <%= Templater.render_template :open_chat %>
message: <%= Templater.render_template :message %>
@alexmcpherson
Copy link

I just wound up here after a google search. I hate you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment