Created
June 21, 2012 04:02
-
-
Save twetzel/2963752 to your computer and use it in GitHub Desktop.
.eco - Partials .. Render Partials in .jst.eco templates (for Rails + Spine / maybe Backbone)
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
# Render Partials in ECO-Templates like in Rails-ERB | |
# | |
# usefull to clean up structure in spine.js and other js-mvc´s like backbone | |
# | |
# usage: | |
# <%- render_partial 'path/to/partial' %> .. will render ../spine-app/views/path/to/_partial.jst.eco | |
# <%- render_partial 'path/to/partial', foo: 'bar' %> .. will render ../spine-app/views/path/to/_partial.jst.eco .. locals = @foo | |
# | |
window.render_partial = ( path, options = {} ) -> | |
# add the leading underscore (like rails-partials) | |
path = path.split('/') | |
path[ path.length - 1 ] = '_' + path[ path.length - 1 ] | |
path = path.join('/') | |
# render and return the partial if existing | |
try | |
JST["app/views/#{ path }"]( options ) | |
catch error | |
# if App.Environment != 'production' then "<p class='error'>Sorry, there is no partial named '#{ path }'.</p>" else '' | |
"<p class='error'>Sorry, there is no partial named '#{ path }'.</p>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1 Great job, ty!!