File: base.rb

package info (click to toggle)
ruby-uniform-notifier 1.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 240 kB
  • sloc: ruby: 915; makefile: 4
file content (46 lines) | stat: -rw-r--r-- 1,019 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

class UniformNotifier
  class Base
    class << self
      def active?
        false
      end

      def inline_notify(data)
        return unless active?

        # For compatibility to the old protocol
        data = { title: data } if data.is_a?(String)

        _inline_notify(data)
      end

      def out_of_channel_notify(data)
        return unless active?

        # For compatibility to the old protocol
        data = { title: data } if data.is_a?(String)

        _out_of_channel_notify(data)
      end

      protected

      def _inline_notify(data); end

      def _out_of_channel_notify(data); end

      def wrap_js_association(code, attributes = {})
        attributes = { type: 'text/javascript' }.merge(attributes || {})
        attributes_string = attributes.map { |k, v| "#{k}=#{v.to_s.inspect}" }.join(' ')

        <<~CODE
          <script #{attributes_string}>/*<![CDATA[*/
          #{code}
          /*]]>*/</script>
        CODE
      end
    end
  end
end