Guest User

Untitled

a guest
Jul 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. class ActionView::Base
  2. TM_URL = 'txmt://open?url=file://%s&line=%d&column=%d'
  3.  
  4. def _render_partial_with_dev(options, &block)
  5. result = _render_partial_without_dev(options, &block)
  6. template = @renderer.send(:find_template)
  7. filepath = template.identifier
  8. fileurl = TM_URL % [filepath, 0, 0]
  9. filelink = '<a href="%s" class="dev-tool-txmt" title="%s">&#9998;</a>' % [fileurl, template.virtual_path]
  10. filelink.html_safe + result
  11. end
  12. alias_method_chain :_render_partial, :dev
  13. end
  14.  
  15. class MyFilter
  16. def self.filter(controller)
  17. insert_text controller, :before, /<\/head>/i, <<-HTML
  18. <style type="text/css">
  19. a.dev-tool-txmt { display: none; margin: 0 2px; text-decoration: none; color: red; }
  20. #dev-tool { position: fixed; bottom: 2px; right: 2px; z-index: 1000; }
  21. #dev-tool a { text-decoration: none; color: red; }
  22. </style>
  23. HTML
  24. insert_text controller, :before, /<\/body>/i, <<-HTML
  25. <div id="dev-tool">
  26. <a href="javascript:void(0);" onclick="$('.dev-tool-txmt').toggle()" title="Show dev tools">&#10037</a>
  27. </div>
  28. HTML
  29. end
  30.  
  31. def self.insert_text(controller, position, pattern, new_text)
  32. index = if match = controller.response.body.match(pattern)
  33. match.offset(0)[position == :before ? 0 : 1]
  34. else
  35. controller.response.body.size
  36. end
  37. controller.response.body = controller.response.body.insert index, new_text
  38. end
  39. end
  40.  
  41. class ActionController::Base
  42. after_filter MyFilter
  43. end
Add Comment
Please, Sign In to add comment