File: javascript_console.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 (33 lines) | stat: -rw-r--r-- 892 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
# frozen_string_literal: true

class UniformNotifier
  class JavascriptConsole < Base
    class << self
      def active?
        !!UniformNotifier.console
      end

      protected

      def _inline_notify(data)
        message = data.values.compact.join("\n")
        options = UniformNotifier.console.is_a?(Hash) ? UniformNotifier.console : {}
        script_attributes = options[:attributes] || {}

        code = <<~CODE
          if (typeof(console) !== 'undefined' && console.log) {
            if (console.groupCollapsed && console.groupEnd) {
              console.groupCollapsed(#{'Uniform Notifier'.inspect});
              console.log(#{message.inspect});
              console.groupEnd();
            } else {
              console.log(#{message.inspect});
            }
          }
        CODE

        wrap_js_association code, script_attributes
      end
    end
  end
end