Sha256: 9517a9dd8011ea9e0047ac268d63e91241ebdac289825c7624d0abdff6fc9b80
Contents?: true
Size: 1.3 KB
Versions: 3
Compression:
Stored size: 1.3 KB
Contents
module DebugExtras class Injector def initialize(response) @response = response @result = @response.body end def process_response if response_is_html? inject_messages inject_styles end @result end private def response_is_html? return false unless @response.headers['Content-Type'].include?('html') tags = %w[<html <head </head> <body </body> </html>] tags.each do |tag| return false unless @response.body.include? tag end true end def inject_messages return if $debug_extras_messages.blank? $debug_extras_messages.map! { |message| DebugExtras::Dumper.new(message, 'debug-wp').render } injection = $debug_extras_messages.join('') @result = inject_content('<body') do |html| body = html.second.split('>') body.second.prepend(injection) if body.size > 1 html[1] = body.join('>') end end def inject_styles return unless $debug_extras_add_styles injection = File.read(File.expand_path('../templates/styles.html', __FILE__)) @result = inject_content('</head>') { |html| html.first << injection } end def inject_content(tag) html = @result.split(tag) yield html if block_given? html.join(tag) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
debug-extras-0.4.2 | lib/debug_extras/injector.rb |
debug-extras-0.4.1 | lib/debug_extras/injector.rb |
debug-extras-0.4.0 | lib/debug_extras/injector.rb |