File: disableable.rb

package info (click to toggle)
ruby-liquid 5.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,176 kB
  • sloc: ruby: 10,561; makefile: 6
file content (22 lines) | stat: -rw-r--r-- 606 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

module Liquid
  class Tag
    module Disableable
      def render_to_output_buffer(context, output)
        if context.tag_disabled?(tag_name)
          output << disabled_error(context)
          return
        end
        super
      end

      def disabled_error(context)
        # raise then rescue the exception so that the Context#exception_renderer can re-raise it
        raise DisabledError, "#{tag_name} #{parse_context[:locale].t('errors.disabled.tag')}"
      rescue DisabledError => exc
        context.handle_error(exc, line_number)
      end
    end
  end
end