Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sairam/2336405 to your computer and use it in GitHub Desktop.
Save sairam/2336405 to your computer and use it in GitHub Desktop.
Open files in textmate from browser
if Rails.env.development?
module ActionView
class PartialRenderer < AbstractRenderer
alias :render_orig :render
def render(context, options, block)
setup(context, options, block)
file_path = find_partial.inspect
span_tag = "<span class='the-real-file-path' data-uri='txmt://open/?url=file://#{Rails.root.join file_path}'></span>".html_safe if file_path =~ /\.html/
render_orig(context, options, block) + span_tag
end
end
end
end
/*
* Set window.openFileMode = true in order to open partials in browser
* Set window.openFileMode = false in order to stop this from happening.
*/
var prevDate = Date.now();
var filesList = {};
var fileDisplayFunc = function(){
var highestDepth = 0, reqkey= "";
for (var key in filesList) {
if (highestDepth < filesList[key]) {
highestDepth = filesList[key];
reqkey = key;
}
}
window.open(reqkey);
filesList = {};
}
var jsTimeoutFunc = function(){
if (Date.now() - prevDate > 2000)
window.setTimeout("fileDisplayFunc()", 2000)
prevDate = Date.now();
}
$.fn.depth = function() {
return $(this).parents().length;
};
$('.the-real-file-path').siblings().click(function(e) {
if(window.openFileMode == true) {
e.preventDefault();
var element = $(this).nextAll('.the-real-file-path').first();
filesList[element.attr('data-uri')] = element.depth();
jsTimeoutFunc();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment