shenmegui 0.3.3 → 0.3.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: 3c26bdde10d6c5e4af49d747793ad84901e68926
4
- data.tar.gz: c99bb367c9fb6579ce413d256ac315fb6263c743
3
+ metadata.gz: f35798115e8f6d3bec99dc45df4d48b48d2a18e5
4
+ data.tar.gz: 5c0c4d7f0c220f66785e1ba351827a1cd0a137ae
5
5
  SHA512:
6
- metadata.gz: 5b30cf77e527c31e9faaa0d09e894025d5b0601f7fdc8c5e71c81e9147e20bec641af8184976e484e777cc3194d8241cb0130b7a272786e93f8768c164e31e45
7
- data.tar.gz: 4ff794f652ee0e2ad765caab6f550f0aec228ed5a9c6c63d670bf1cb9b8e9f2e9e3ed41f708ac54d73f35bf6156ac80b6fb1fed5ffe8bfe0b73fe5c26754c880
6
+ metadata.gz: bc2f7b20adb10653c15dfe216a622b49552284d59be3bcc8d8962c9036593c5dcfaf56731e2fae56fc14864d3b12e893a87a2ba2c035dfc51f5d3c98ae5d5200
7
+ data.tar.gz: bddf3a53791f9434da210e46b27a851ba2bc49a6c67958da1658b8816d673473d13b3a0b4502413dcb61188833c27a7fa1c4e03e6670fe00ce551692d87994c4
@@ -81,7 +81,7 @@ module ShenmeGUI
81
81
  end
82
82
 
83
83
  def render(material = {})
84
- gem_path = $LOADED_FEATURES.grep(/.*\/lib\/shenmegui/)[0].match(/(.*)\/lib/)[1]
84
+ gem_path = __FILE__.match(/(.*)\/lib/)[1]
85
85
  template_path = gem_path + "/templates"
86
86
  type = self.class.name.match(/(?:.*::)(.+)/)[1].downcase
87
87
  template = ::ERB.new File.read("#{template_path}/#{type}.erb")
@@ -97,12 +97,12 @@ module ShenmeGUI
97
97
  end
98
98
 
99
99
  class Body < Base
100
- def render
101
- gem_path = $LOADED_FEATURES.grep(/.*\/lib\/shenmegui/)[0].match(/(.*)\/lib/)[1]
100
+ def render(material = {})
101
+ gem_path = __FILE__.match(/(.*)\/lib/)[1]
102
102
  static_path = gem_path + "/static"
103
103
  style = %w{style}.collect{|x| File.read("#{static_path}/#{x}.css")}.join("\n")
104
104
  script = File.read("#{static_path}/script.js")
105
- super({style: style, script: script})
105
+ super({style: style, script: script}.merge(material))
106
106
  end
107
107
 
108
108
  end
@@ -154,7 +154,7 @@ module ShenmeGUI
154
154
 
155
155
  class Checkbox < Base
156
156
  property :options, :checked, :arrange
157
- shortcut :options
157
+ shortcut :options
158
158
  end
159
159
 
160
160
  class Progress < Base
@@ -1,3 +1,5 @@
1
+ require 'socket'
2
+
1
3
  module ShenmeGUI
2
4
 
3
5
  @elements = []
@@ -28,7 +30,12 @@ module ShenmeGUI
28
30
 
29
31
  def app(params={}, &block)
30
32
  body(params, &block)
31
- File.open('index.html', 'w'){ |f| f.write @elements[0].render }
33
+ #找一个空闲的端口,不太好看
34
+ temp_server = TCPServer.open('localhost', 0)
35
+ @port = temp_server.addr[1]
36
+ temp_server.close
37
+ app_dir = File.expand_path($PROGRAM_NAME).match(/(.+)\/.+/)[1]
38
+ File.open("#{app_dir}/index.html", 'w'){ |f| f.write @elements[0].render(port: @port) }
32
39
  nil
33
40
  end
34
41
 
@@ -44,7 +51,7 @@ module ShenmeGUI
44
51
  def get_save_file_name(params={})
45
52
  FileDialog.get_save_file_name(params)
46
53
  end
47
-
54
+
48
55
  def enable_debugging
49
56
  Thread.new do
50
57
  ShenmeGUI.instance_eval do
@@ -66,7 +73,7 @@ module ShenmeGUI
66
73
  def start!
67
74
  ws_thread = Thread.new do
68
75
  EM.run do
69
- EM::WebSocket.run(:host => "0.0.0.0", :port => 80) do |ws|
76
+ EM::WebSocket.run(:host => "0.0.0.0", :port => @port) do |ws|
70
77
  ws.onopen do
71
78
  puts "WebSocket connection open"
72
79
  @elements.each do |e|
@@ -81,22 +88,22 @@ module ShenmeGUI
81
88
  puts "Recieved message: #{msg}"
82
89
  handle msg
83
90
  end
84
-
91
+
85
92
  @socket = ws
86
93
  end
87
94
  end
88
95
  end
89
-
90
96
  begin
91
- index_path = "#{Dir.pwd}/index.html"
97
+ app_dir = File.expand_path($PROGRAM_NAME).match(/(.+)\/.+/)[1]
98
+ index_path = "#{app_dir}/index.html"
92
99
  `start file:///#{index_path}`
93
100
  rescue
94
101
  end
95
-
102
+
96
103
  ws_thread.join
97
104
  rescue Interrupt
98
105
  puts 'bye~'
99
106
  end
100
107
 
101
108
  end
102
- end
109
+ end
@@ -70,7 +70,7 @@ module ShenmeGUI
70
70
  def self.get_open_file_name(params={})
71
71
  ofn, path = construct_OPENFILENAME(params)
72
72
  GetOpenFileName(ofn)
73
- ofn = nil
73
+ Fiddle.free(ofn.to_i)
74
74
  path = path.split("\0")
75
75
  path = path[1..-1].collect{|x| "#{path[0]}\\#{x}"} if path.size > 1
76
76
  path.collect{|x| x.force_encoding('GBK').encode('UTF-8')}
@@ -80,7 +80,7 @@ module ShenmeGUI
80
80
  def self.get_save_file_name(params={})
81
81
  ofn, path = construct_OPENFILENAME(params)
82
82
  GetSaveFileName(ofn)
83
- ofn = nil
83
+ Fiddle.free(ofn.to_i)
84
84
  path.force_encoding('GBK').encode('UTF-8')
85
85
  end
86
86
 
@@ -1,59 +1,26 @@
1
1
  module ShenmeGUI
2
- class HookedArray < Array
3
-
4
- @unhook_methods = %i{<< []= clear collect! compact! concat delete delete_at delete_if fill flatten! replace insert keep_if map map! pop push reject! replace rotate! select! shift shuffle! slice! sort! sort_by! uniq! unshift}
5
- @unhook_methods = Hash[@unhook_methods.collect{|x| [x, Array.instance_method(x)]}]
6
-
7
- def initialize(arr, owner)
8
- @owner = owner
9
- super(arr)
10
- end
11
-
12
- @unhook_methods.each do |k, v|
13
- define_method(k) do |*arr, &block|
14
- result = v.bind(self).call(*arr, &block)
15
- @owner.sync
16
- result
2
+ @unhook_methods = {
3
+ array: %i{<< []= clear collect! compact! concat delete delete_at delete_if fill flatten! replace insert keep_if map map! pop push reject! replace rotate! select! shift shuffle! slice! sort! sort_by! uniq! unshift},
4
+ string: %i{<< []= capitalize! chomp! chop! clear concat delete! downcase! encode! force_encoding gsub! insert lstrip! succ! next! prepend replace reverse! rstrip! slice! squeeze! strip! sub! swapcase! tr! tr_s! upcase!},
5
+ hash: %i{[]= clear delete delete_if keep_if merge! update rehash reject! replace select! shift}
6
+ }
7
+ @unhook_methods.each do |k, v|
8
+ const_set("Hooked#{k.to_s.capitalize}", Class.new(const_get(k.to_s.capitalize)))
9
+ const_get("Hooked#{k.to_s.capitalize}").class_eval do
10
+ def initialize(obj, owner)
11
+ @owner = owner
12
+ super(obj)
17
13
  end
18
- end
19
-
20
- end
21
-
22
- class HookedString < String
23
- @unhook_methods = %i{<< []= capitalize! chomp! chop! clear concat delete! downcase! encode! force_encoding gsub! insert lstrip! succ! next! prepend replace reverse! rstrip! slice! squeeze! strip! sub! swapcase! tr! tr_s! upcase!}
24
- @unhook_methods = Hash[@unhook_methods.collect{|x| [x, String.instance_method(x)]}]
25
-
26
- def initialize(str, owner)
27
- @owner = owner
28
- super(str)
29
- end
30
14
 
31
- @unhook_methods.each do |k, v|
32
- define_method(k) do |*arr, &block|
33
- result = v.bind(self).call(*arr, &block)
34
- @owner.sync
35
- result
15
+ methods = Hash[v.collect{|x| [x, const_get(k.to_s.capitalize).instance_method(x)]}]
16
+ methods.each do |k, v|
17
+ define_method(k) do |*arr, &block|
18
+ result = v.bind(self).call(*arr, &block)
19
+ @owner.sync
20
+ result
21
+ end
36
22
  end
37
- end
38
23
 
39
- end
40
-
41
- class HookedHash < Hash
42
- @unhook_methods = %i{[]= clear delete delete_if keep_if merge! update rehash reject! replace select! shift}
43
- @unhook_methods = Hash[@unhook_methods.collect{|x| [x, Hash.instance_method(x)]}]
44
-
45
- def initialize(hsh, owner)
46
- @owner = owner
47
- super(hsh)
48
24
  end
49
-
50
- @unhook_methods.each do |k, v|
51
- define_method(k) do |*arr, &block|
52
- result = v.bind(self).call(*arr, &block)
53
- @owner.sync
54
- result
55
- end
56
- end
57
-
58
25
  end
59
26
  end
data/static/script.js CHANGED
@@ -1,6 +1,6 @@
1
- var websocket =
1
+ var websocket =
2
2
  (function configureWebSocket(){
3
- var wsUrl = "ws://localhost/";
3
+ var wsUrl = "ws://localhost:" + wsPort + "/";
4
4
 
5
5
  var websocket = new WebSocket(wsUrl);
6
6
  websocket.onopen = function(evt){
@@ -166,7 +166,7 @@ var syncHandlers = {
166
166
  }
167
167
  }
168
168
  }
169
-
169
+
170
170
  }),
171
171
 
172
172
  radio: (function(target, data){
@@ -231,4 +231,4 @@ function handleMessage(msg){
231
231
  target.focus();
232
232
  break;
233
233
  }
234
- }
234
+ }
data/templates/body.erb CHANGED
@@ -10,7 +10,8 @@
10
10
  <body id="item-<%= id %>" data-type="body">
11
11
  <%= content %>
12
12
  <script>
13
+ wsPort = <%= material[:port] %>;
13
14
  <%= material[:script] %>
14
15
  </script>
15
16
  </body>
16
- </html>
17
+ </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shenmegui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - CicholGricenchos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-20 00:00:00.000000000 Z
11
+ date: 2015-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-websocket
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.5.1
27
27
  description: a simple HTML GUI for Ruby
28
28
  email: cichol@live.cn
29
29
  executables: []