Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ActionView::Base
- TM_URL = 'txmt://open?url=file://%s&line=%d&column=%d'
- def _render_partial_with_dev(options, &block)
- result = _render_partial_without_dev(options, &block)
- template = @renderer.send(:find_template)
- filepath = template.identifier
- fileurl = TM_URL % [filepath, 0, 0]
- filelink = '<a href="%s" class="dev-tool-txmt" title="%s">✎</a>' % [fileurl, template.virtual_path]
- filelink.html_safe + result
- end
- alias_method_chain :_render_partial, :dev
- end
- class MyFilter
- def self.filter(controller)
- insert_text controller, :before, /<\/head>/i, <<-HTML
- <style type="text/css">
- a.dev-tool-txmt { display: none; margin: 0 2px; text-decoration: none; color: red; }
- #dev-tool { position: fixed; bottom: 2px; right: 2px; z-index: 1000; }
- #dev-tool a { text-decoration: none; color: red; }
- </style>
- HTML
- insert_text controller, :before, /<\/body>/i, <<-HTML
- <div id="dev-tool">
- <a href="javascript:void(0);" onclick="$('.dev-tool-txmt').toggle()" title="Show dev tools">✵</a>
- </div>
- HTML
- end
- def self.insert_text(controller, position, pattern, new_text)
- index = if match = controller.response.body.match(pattern)
- match.offset(0)[position == :before ? 0 : 1]
- else
- controller.response.body.size
- end
- controller.response.body = controller.response.body.insert index, new_text
- end
- end
- class ActionController::Base
- after_filter MyFilter
- end
Add Comment
Please, Sign In to add comment