opal_hot_reloader 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: 865340375e8aa257f1549b30bbd885936945cf4b
4
- data.tar.gz: ddeda2019446cfb76d09697480307151448603e1
3
+ metadata.gz: a867c114bf9d71275cc023f35c644944abe5decc
4
+ data.tar.gz: 4d0c10c661b6180a2881e5d6fbac3a10d6b77e02
5
5
  SHA512:
6
- metadata.gz: 368168c04d5cfacb65812fbe28eb7db1234921141546b69da816c479ea0add8de3c60a62b614b4baa8f821014403ac2f47e8695ed83ed9bc0d406b0443e223d7
7
- data.tar.gz: baa7598ef9b20d827dbde90d92ac883c7c2f1c05627a189b092207c181bfafa64a148e396a2a973b570ecafb0d98aca8548e91fab7a83dce8d45ce2cdf30c077
6
+ metadata.gz: 267a9d178686be33693532036a2bd8919f2f15e362f6ab20df3f293c60070eee5b9988dfeb8097519077aafcb7a2f3cf523a1f6e20390d0b55e08478780f2ff3
7
+ data.tar.gz: 637125fea8cf8526c70c7e84badc5b5587243d3fec496fc9aef8d45c96c530e883d54001e396005b418adea48143ea5e2beea114e66c74213f9d99186cb872e1
@@ -1,3 +1,5 @@
1
+ * 0.1.4
2
+ - make alerts configurable via OpalHotReloader.alerts_off!/OpalHotReloader.alerts_on!
1
3
  * 0.1.3
2
4
  - handle Rails 5 asset pipeline css change
3
5
  * 0.1.2
data/README.md CHANGED
@@ -70,10 +70,34 @@ If you are using the default port then you can just call:
70
70
  OpalHotReloader.listen
71
71
  ```
72
72
 
73
+ #### Alerts
74
+
75
+ ![Reload Error Alert](images/reload_error.png)
76
+ By default, if there is an error hot loading code, opal_hot_reloader
77
+ will present an alert of the error. The following options can be used
78
+ to turn the alerts on and off:
79
+
80
+ ```ruby
81
+ OpalHotReloader.alerts_on! # turns on alerts
82
+ OpalHotReloader.alerts_off! # turns off alerts
83
+
84
+ ```
85
+
86
+
73
87
  This will open up a websocket from the client to the server on the given port. The server-side should already be running.
74
88
 
75
89
  Enjoy!
76
90
 
91
+ #### Run only in development on Rails
92
+ One way to run this only in development on Rails is to change your application.js.rb to application.js.rb.erb and add this to the bottom of the file
93
+
94
+ ```ruby
95
+ <% if Rails.env.development? %>
96
+ require 'opal_hot_reloader'
97
+ OpalHotReloader.listen
98
+ <% end %>
99
+ ```
100
+
77
101
  ## Vision
78
102
 
79
103
  Some of you might be asking? Why do this, isn't this reinventing the
@@ -1,3 +1,3 @@
1
1
  module OpalHotReloader
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -20,6 +20,25 @@ class OpalHotReloader
20
20
  }
21
21
  end
22
22
 
23
+ def notify_error(reload_request)
24
+ msg = "OpalHotReloader #{reload_request[:filename]} RELOAD ERROR:\n\n#{$!}"
25
+ puts msg
26
+ alert msg if use_alert?
27
+ end
28
+
29
+ @@USE_ALERT = true
30
+ def self.alerts_on!
31
+ @@USE_ALERT = true
32
+ end
33
+
34
+ def self.alerts_off!
35
+ @@USE_ALERT = false
36
+ end
37
+
38
+ def use_alert?
39
+ @@USE_ALERT
40
+ end
41
+
23
42
  def reload(e)
24
43
  reload_request = JSON.parse(`e.data`)
25
44
  if reload_request[:type] == "ruby"
@@ -27,7 +46,7 @@ class OpalHotReloader
27
46
  begin
28
47
  $eval_proc.call reload_request[:source_code]
29
48
  rescue
30
- alert "OpalHotReloader RELOAD ERROR:\n\n#{$!}"
49
+ notify_error(reload_request)
31
50
  end
32
51
  if @reload_post_callback
33
52
  @reload_post_callback.call
@@ -42,37 +61,37 @@ class OpalHotReloader
42
61
 
43
62
  # @param port [Integer] opal hot reloader port to connect to
44
63
  # @param reload_post_callback [Proc] optional callback to be called after re evaluating a file for example in react.rb files we want to do a React::Component.force_update!
45
- def initialize(port=25222, &reload_post_callback)
46
- @port = port
47
- @reload_post_callback = reload_post_callback
48
- @css_reloader = CssReloader.new
49
- end
50
- # Opens a websocket connection that evaluates new files and runs the optional @reload_post_callback
51
- def listen
52
- connect_to_websocket(@port)
53
- end
64
+ def initialize(port=25222, &reload_post_callback)
65
+ @port = port
66
+ @reload_post_callback = reload_post_callback
67
+ @css_reloader = CssReloader.new
68
+ end
69
+ # Opens a websocket connection that evaluates new files and runs the optional @reload_post_callback
70
+ def listen
71
+ connect_to_websocket(@port)
72
+ end
54
73
 
55
- # convenience method to start a listen w/one line
56
- # @param port [Integer] opal hot reloader port to connect to. Defaults to 25222 to match opal-hot-loader default
57
- # @deprecated reactrb - this flag no longer necessary and will be removed in gem release 0.2
58
- def self.listen(port=25222, reactrb=false)
59
- return if @server
60
- if reactrb
61
- warn "OpalHotReloader.listen(#{port}): reactrb flag is deprectated and will be removed in gem release 0.2. React will automatically be detected"
62
- end
63
- create_framework_aware_server(port)
74
+ # convenience method to start a listen w/one line
75
+ # @param port [Integer] opal hot reloader port to connect to. Defaults to 25222 to match opal-hot-loader default
76
+ # @deprecated reactrb - this flag no longer necessary and will be removed in gem release 0.2
77
+ def self.listen(port=25222, reactrb=false)
78
+ return if @server
79
+ if reactrb
80
+ warn "OpalHotReloader.listen(#{port}): reactrb flag is deprectated and will be removed in gem release 0.2. React will automatically be detected"
64
81
  end
65
- # Automatically add in framework specific hooks
82
+ create_framework_aware_server(port)
83
+ end
84
+ # Automatically add in framework specific hooks
66
85
 
67
- def self.create_framework_aware_server(port)
68
- if defined? ::React
69
- ReactrbPatches.patch!
70
- @server = OpalHotReloader.new(port) { React::Component.force_update! }
71
- else
72
- puts "No framework detected"
73
- @server = OpalHotReloader.new(port)
74
- end
75
- @server.listen
86
+ def self.create_framework_aware_server(port)
87
+ if defined? ::React
88
+ ReactrbPatches.patch!
89
+ @server = OpalHotReloader.new(port) { React::Component.force_update! }
90
+ else
91
+ puts "No framework detected"
92
+ @server = OpalHotReloader.new(port)
76
93
  end
94
+ @server.listen
95
+ end
77
96
 
78
97
  end
@@ -0,0 +1,10 @@
1
+ require 'opal_hot_reloader'
2
+ describe OpalHotReloader do
3
+ context 'alerts' do
4
+ it 'should be controllable' do
5
+ expect(subject.use_alert?).to eq true
6
+ OpalHotReloader.alerts_off!
7
+ expect(subject.use_alert?).to eq false
8
+ end
9
+ end
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal_hot_reloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Forrest Chang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-23 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,6 +125,7 @@ files:
125
125
  - opal/opal_hot_reloader/socket.rb
126
126
  - opal_hot_reloader.gemspec
127
127
  - spec-opal/opal_hot_reloader/css_reloader_spec.rb
128
+ - spec-opal/opal_hot_reloader_spec.rb
128
129
  homepage: https://github.com/fkchang/opal-hot-reloader
129
130
  licenses:
130
131
  - MIT