Sha256: c57a2fbaf07976037f2348c0758a28837de3c51bb768397acdd298c2bee715d9

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

# These overrides allows DebugExceptions middleware to work with Jets.

# Straight override the initialize method to customize the template paths and
# include additiional jets rescue templates when needed.
# Note: With the way the ActionDispatch::DebugView class is written, we cannot
# use super to call the original initialize method.  Got to override the whole
# method.
ActionDispatch::DebugView.class_eval do
  def initialize(assigns)
    jets_templates = File.expand_path("../templates", __dir__)
    paths = [jets_templates, ActionDispatch::DebugView::RESCUES_TEMPLATE_PATH]
    lookup_context = ActionView::LookupContext.new(paths)
    super(lookup_context, assigns, nil)
  end
end

# Override source_fragment to use Jets.root instead of Rails.root
ActionDispatch::ExceptionWrapper.class_eval do
private
  def source_fragment(path, line)
    # Jets.root was Rails.root
    return unless Jets.respond_to?(:root) && Jets.root
    full_path = Jets.root.join(path)
    if File.exist?(full_path)
      File.open(full_path, "r") do |file|
        start = [line - 3, 0].max
        lines = file.each_line.drop(start).take(6)
        Hash[*(start + 1..(lines.count + start)).zip(lines).flatten]
      end
    end
  end
end

load "action_dispatch/middleware/debug_exceptions.rb"

ActionView::Helpers::SanitizeHelper::ClassMethods.module_eval do
  def sanitizer_vendor
    Jets::Html::Sanitizer # was Rails::Html::Sanitizer
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jets-5.0.13 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.12 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.11 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.10 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.9 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.8 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.7 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.6 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.5 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.4 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.3 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.2 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.1 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.0 engines/internal/lib/internal/overrides/debug_exceptions.rb
jets-5.0.0.beta1 engines/internal/lib/internal/overrides/debug_exceptions.rb