Module: Fleek::StyleInjector

Defined in:
lib/fleek/style_injector.rb

Instance Method Summary collapse

Instance Method Details



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
# File 'lib/fleek/style_injector.rb', line 3

def stylesheet_link_tag(*sources)
  options = sources.extract_options!.stringify_keys
  sources.map { |source|
    options['original_source'] = source
    options['debug'] = false
    super source, options
  }.join("\n").html_safe + javascript_tag do
    "(function(){\nvar ws = new WebSocket((location.protocol === \"https:\" ? \"wss:\" : \"ws:\") + \"//\" + location.host + \"/.fleek-connection\");\nws.onopen = function() {\n  ws.send(JSON.stringify({\n\"identifier\": \"register_assets\",\n\"assets\": \#{sources.to_json},\n  }));\n};\nws.onmessage = function(event) {\n  var msg = JSON.parse(event.data);\n  if (msg.identifier == 'asset_updated') {\ndocument.querySelector(\"link[original_source='\" + msg.asset + \"']\").href = msg.new_url;\n  }\n};\n})();\n  JS\n  end\nend\n".html_safe