class GlimExtensions::EditInTextMate
Public Class Methods
new(site)
click to toggle source
# File glim-edit-in-textmate.rb, line 7 def initialize(site) @enabled = site.config['environment'] == 'development' end
Public Instance Methods
edit_in_textmate_script(path)
click to toggle source
# File glim-edit-in-textmate.rb, line 25 def edit_in_textmate_script(path) <<~HTML <script> window.onkeydown = function (e) { if(!document.activeElement || document.activeElement == document.body) { if(e.key == 'e' && !(e.altKey || e.shiftKey || e.ctrlKey || e.metaKey)) { window.location = "txmt://open?url=#{CGI.escape('file://' + path)}"; } } }; </script> HTML end
transform(content, page, options)
click to toggle source
# File glim-edit-in-textmate.rb, line 11 def transform(content, page, options) if @enabled && page.path script_tag = edit_in_textmate_script(page.path) if content =~ /<head.*?>/ content = "#$`#$&#{script_tag}#$'" elsif content =~ /<html.*?>/ content = "#$`#$&#{script_tag}#$'" else content = script_tag + content end end content end