Created
May 13, 2011 20:22
-
-
Save gerred/971244 to your computer and use it in GitHub Desktop.
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
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 |
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
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 |
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
window.JST = | |
open_chat: <%= Templater.render_template :open_chat %> | |
message: <%= Templater.render_template :message %> |
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
.test Test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just wound up here after a google search. I hate you.