clearwater-hot_loader 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f5d107c5ec54c7e5e0589812fbfbcf318126e3b5758a0e24a6f27bdf9469a62
4
- data.tar.gz: 04e047ae417e91e91685a2f25a3591b523ec1160458ace6e4f1ba91c6b1c6e0e
3
+ metadata.gz: '09405aae0dd6f8b113f7a03cebc18b60a46f776450444c0575edb41e5e14f12d'
4
+ data.tar.gz: 4e1e0a0a7e981a1fc6795e2613ac4c819083d1b09a0ade53f4b8c011d7ce4fc8
5
5
  SHA512:
6
- metadata.gz: 2f64e7c10fc4ef4599d04d356020804fb7939a12f9309ea16394e90029e216318e9f171f9eaf88faee7820b2285654650d5288d95391cca94c2a82103bc90e8e
7
- data.tar.gz: d819b6704345c1fd635d2d51e0fa60e13605ffe723d7d96359768115f671bd105b9a598d56724c6867a0e8cc7de1427ae48eb6c52a2468842afb6ae2457de96d
6
+ metadata.gz: 6b7b9f5bbdd4d958c83249617ccd5946933ba147a981d13a54259de44d61434c378c996ed4a0eaa52d9d76b3eee993375431475b08f56e2f8967ecb808a82b42
7
+ data.tar.gz: 7018ba87929270f6c6bd24edfd74f9e53528961f66613238bf3b60106b4e31b46f933943dbe33842da2f8968e1606a12d18cc4c6723dd149f5b1163be22488fe
@@ -7,7 +7,9 @@ module Clearwater
7
7
  candidate_directories = Dir[
8
8
  *%w(
9
9
  app/assets/javascripts
10
+ app/assets/stylesheets
10
11
  assets/js
12
+ assets/css
11
13
  )
12
14
  ]
13
15
  self.directories = candidate_directories
@@ -34,14 +34,17 @@ module Clearwater
34
34
  code = File.read(filename)
35
35
 
36
36
  if filename.end_with? '.rb'
37
- Opal.compile(code)
37
+ { js: Opal.compile(code) }
38
38
  elsif filename.end_with? '.js'
39
- code
39
+ { js: code }
40
+ elsif filename.end_with? '.scss'
41
+ { css: { filename: filename, body: Sass.compile(code.gsub(/^\s*@import.*$/, '')) } }
40
42
  else
41
- ''
43
+ {}
42
44
  end
43
45
  rescue => e
44
- ''
46
+ warn "[Clearwater::HotLoader] #{e}"
47
+ {}
45
48
  end
46
49
  end
47
50
  end
@@ -1,5 +1,5 @@
1
1
  module Clearwater
2
2
  module HotLoader
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ require 'clearwater/hot_loader/server'
3
3
  require 'clearwater/hot_loader/file_listener'
4
4
  require 'clearwater/hot_loader/configuration'
5
5
  require 'set'
6
+ require 'json'
6
7
 
7
8
  module Clearwater
8
9
  module HotLoader
@@ -33,11 +34,12 @@ module Clearwater
33
34
  code = server.compile_file(filename)
34
35
  rescue SyntaxError => e
35
36
  puts "ONOES! #{e.class} - #{e.message}"
37
+ code = {}
36
38
  end
37
39
 
38
40
  puts "[Clearwater::HotLoader] Hot-loading #{filename}..."
39
41
  sockets.each do |ws|
40
- ws.send code
42
+ ws.send code.to_json
41
43
  end
42
44
  end
43
45
  }
@@ -40,18 +40,29 @@ module Clearwater
40
40
  end
41
41
 
42
42
  @socket.on :message do |msg|
43
- begin
44
- %x{ eval(msg.native.data) }
45
-
46
- # We need to perform the renders synchronously so we can rescue
47
- # exceptions, but the app registry doesn't give us a way to do that,
48
- # so we reach in and do this manually. Don't try this at home.
49
- Clearwater::Application::AppRegistry
50
- .instance_exec { @apps }
51
- .each { |app| app.perform_render }
52
- rescue => e
53
- error_message = "[Clearwater::HotLoader] Error #{e.class}: #{e.message}"
54
- `console.error(error_message)`
43
+ data = msg.data
44
+ if data.key? :js
45
+ begin
46
+ %x{ eval(#{data[:js]}) }
47
+
48
+ # We need to perform the renders synchronously so we can rescue
49
+ # exceptions, but the app registry doesn't give us a way to do that,
50
+ # so we reach in and do this manually. Don't try this at home.
51
+ Clearwater::Application::AppRegistry
52
+ .instance_exec { @apps }
53
+ .each { |app| app.perform_render }
54
+ rescue => e
55
+ error_message = "[Clearwater::HotLoader] Error #{e.class}: #{e.message}"
56
+ `console.error(error_message)`
57
+ end
58
+ elsif data.key? :css
59
+ id = "clearwater-hot-loader-style-#{data[:css][:filename].gsub(/\W/, '-')}"
60
+ style = Bowser.document["##{id}"] || Bowser.document.create_element(:style)
61
+ new_element = style.id.empty?
62
+ style.id = id
63
+ style.text_content = data[:css][:body]
64
+
65
+ Bowser.document.head.append style if new_element
55
66
  end
56
67
  end
57
68
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clearwater-hot_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Gaskins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-29 00:00:00.000000000 Z
11
+ date: 2018-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clearwater
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.7.3
139
+ rubygems_version: 2.7.6
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Reload your Clearwater app without refreshing the browser