Sha256: d38f6831d855659f5eed2621d2f8c4223fe0ee576a17371b0859ce1f1730937e

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

module Lookbook
  class ActionViewConfigHandler < Service
    attr_reader :disable_annotations, :disable_partial_prefixes

    def initialize(disable_annotations: true, disable_partial_prefixes: true)
      @disable_annotations = disable_annotations
      @disable_partial_prefixes = disable_partial_prefixes
    end

    def call
      handle_annotations
      handle_partial_prefixes

      yield
    ensure
      restore_annotations
      restore_partial_prefixes
    end

    private

    def handle_annotations
      return unless disable_annotations && ActionView::Base.respond_to?(:annotate_rendered_view_with_filenames)

      @original_annotations_value = ActionView::Base.annotate_rendered_view_with_filenames
      ActionView::Base.annotate_rendered_view_with_filenames = false
    end

    def restore_annotations
      return if @original_annotations_value.nil?

      ActionView::Base.annotate_rendered_view_with_filenames = @original_annotations_value
      @original_annotations_value = nil
    end

    def handle_partial_prefixes
      return unless disable_partial_prefixes && ActionView::Base.respond_to?(:prefix_partial_path_with_controller_namespace)

      @original_partial_prefix_value = ActionView::Base.prefix_partial_path_with_controller_namespace
      ActionView::Base.prefix_partial_path_with_controller_namespace = false
    end

    def restore_partial_prefixes
      return if @original_partial_prefix_value.nil?

      ActionView::Base.prefix_partial_path_with_controller_namespace = @original_partial_prefix_value
      @original_partial_prefix_value = nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lookbook-2.3.4 lib/lookbook/services/templates/action_view_config_handler.rb
lookbook-2.3.3 lib/lookbook/services/templates/action_view_config_handler.rb
lookbook-2.3.2 lib/lookbook/services/templates/action_view_config_handler.rb
lookbook-2.3.0 lib/lookbook/services/templates/action_view_config_handler.rb