browser_app_base 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +7 -1
- data/bin/create_browser_app.rb +5 -5
- data/bin/start_sample.rb +12 -11
- data/browser_app_base.gemspec +0 -1
- data/lib/browser_app_base/version.rb +1 -1
- data/lib/browser_app_base.rb +14 -9
- data/lib/template/common.rb +13 -0
- data/lib/template/config/browser.json +1 -0
- data/lib/template/config.ru +10 -7
- data/lib/template/css/index.css +1 -1
- data/lib/template/history/history.json +0 -5
- data/lib/template/js/main.js +98 -89
- data/lib/template/my_app_sample.rb +2 -2
- data/lib/template/server.rb +29 -15
- data/lib/template/server_app_base.rb +15 -18
- data/lib/template/start.rb +8 -8
- data/lib/template/wsserver.rb +32 -16
- metadata +3 -17
- data/lib/template/html/test.html +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9137852eb791f7b49f75aae1dce1fd563a0a7b8c8597793de85eb27b068fcf57
|
4
|
+
data.tar.gz: a7d2f4e61de2b98dd65085590e7daf3a1372cc45856c29805e58533f3e4bd35d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1caf4b5aaadd3f5f3beeb7fa347250f7f50b291ada0192f5a02b03e4dec6078fb71bab45d9025b5429e8e0b0c1778dd1e6f2c9f61138bf1c6fddf86483ac868e
|
7
|
+
data.tar.gz: a7a6e2c5b924a97ea0e1664eb7708890039705073d49e3e680f9f0af6ec80a1f47082bc91fe5465b9b188261cf8853629027498e1db83b2824bb575b9e7f0226
|
data/Gemfile
CHANGED
data/bin/create_browser_app.rb
CHANGED
@@ -6,19 +6,19 @@ require "optparse"
|
|
6
6
|
|
7
7
|
opt = OptionParser.new
|
8
8
|
o = {}
|
9
|
-
opt.on("-d
|
10
|
-
opt.on("-a
|
9
|
+
opt.on("-d DIR_NAME", "--dir DIR_NAME", "application directory") { |v| o[:dir] = v }
|
10
|
+
opt.on("-a APP_NAME", "--app APP_NAME", "application name") { |v| o[:app] = v }
|
11
11
|
opt.on("-h", "--help", "command help") { puts opt; exit }
|
12
12
|
begin
|
13
13
|
opt.parse!(ARGV)
|
14
|
-
rescue
|
14
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
15
15
|
puts opt
|
16
16
|
exit
|
17
17
|
end
|
18
18
|
|
19
|
-
if o[:dir]
|
19
|
+
if o[:dir].nil? || o[:dir].strip.empty?
|
20
20
|
puts opt
|
21
21
|
exit
|
22
22
|
end
|
23
23
|
|
24
|
-
BrowserAppBase.create o
|
24
|
+
BrowserAppBase.create o
|
data/bin/start_sample.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
$LOAD_PATH << File.dirname(File.expand_path(__FILE__)).gsub(/bin$/, "lib")
|
3
4
|
require "fileutils"
|
4
|
-
require "facter"
|
5
5
|
require "tmpdir"
|
6
6
|
require "json"
|
7
|
+
require "common"
|
7
8
|
|
8
9
|
# tmpdirディレクトリにコピー
|
9
10
|
dir = File.dirname(File.expand_path(__FILE__ + "/../"))
|
10
|
-
home_dir = ENV["HOME"] + "/" + dir.split("/")[-1].gsub(/-[0-9\.-]+/,"")
|
11
|
+
home_dir = ENV["HOME"] + "/" + dir.split("/")[-1].gsub(/-[0-9\.-]+/, "")
|
11
12
|
puts "home_dir=#{home_dir}"
|
12
|
-
Dir.mktmpdir
|
13
|
+
Dir.mktmpdir do |tmpdir|
|
13
14
|
outdir = tmpdir + "/" + dir.split("/")[-1]
|
14
15
|
FileUtils.mkdir_p outdir
|
15
16
|
FileUtils.mkdir_p home_dir
|
@@ -27,8 +28,8 @@ Dir.mktmpdir { |tmpdir|
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
begin
|
30
|
-
|
31
|
-
|
31
|
+
json = JSON.parse(File.read("#{home_dir}/config/setting.json"))
|
32
|
+
old_version = json["version"]
|
32
33
|
rescue
|
33
34
|
old_version = ""
|
34
35
|
end
|
@@ -39,14 +40,14 @@ Dir.mktmpdir { |tmpdir|
|
|
39
40
|
FileUtils.cp "#{dir}/lib/config/setting.json", "#{home_dir}/config/setting.json"
|
40
41
|
end
|
41
42
|
|
42
|
-
FileUtils.cd
|
43
|
-
kernel =
|
44
|
-
if kernel == "windows"
|
43
|
+
FileUtils.cd outdir
|
44
|
+
kernel = get_os_type
|
45
|
+
if kernel.downcase == "windows"
|
45
46
|
system "rubyw ./start.rb"
|
46
|
-
elsif kernel == "
|
47
|
+
elsif kernel.downcase == "linux"
|
47
48
|
system "ruby ./start.rb"
|
48
49
|
else
|
49
50
|
system "ruby ./start.rb"
|
50
51
|
end
|
51
52
|
FileUtils.cd ENV["HOME"]
|
52
|
-
|
53
|
+
end
|
data/browser_app_base.gemspec
CHANGED
@@ -35,7 +35,6 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_dependency "sinatra-websocket"
|
36
36
|
spec.add_dependency "thin"
|
37
37
|
spec.add_dependency "json"
|
38
|
-
spec.add_dependency "facter"
|
39
38
|
|
40
39
|
# For more information and examples about making a new gem, checkout our
|
41
40
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/lib/browser_app_base.rb
CHANGED
@@ -21,8 +21,8 @@ module BrowserAppBase
|
|
21
21
|
|
22
22
|
def self.get_app_name(app)
|
23
23
|
app_name = ""
|
24
|
-
app.each_char do |s|
|
25
|
-
if s =~ /[a-z]/
|
24
|
+
app.each_char.with_index do |s, i|
|
25
|
+
if s =~ /[a-z]/ && app_name.size == 0
|
26
26
|
app_name += s.upcase
|
27
27
|
else
|
28
28
|
app_name += s
|
@@ -37,8 +37,8 @@ module BrowserAppBase
|
|
37
37
|
puts "create application base #{dir}"
|
38
38
|
|
39
39
|
FileUtils.mkdir_p dir
|
40
|
-
FileUtils.mkdir_p dir
|
41
|
-
FileUtils.mkdir_p dir
|
40
|
+
FileUtils.mkdir_p "#{dir}/lib/"
|
41
|
+
FileUtils.mkdir_p "#{dir}/bin/"
|
42
42
|
|
43
43
|
path = File.dirname(File.expand_path(__FILE__)) + "/../"
|
44
44
|
Dir.glob("#{path}/lib/template/*") do |f|
|
@@ -51,7 +51,7 @@ module BrowserAppBase
|
|
51
51
|
|
52
52
|
puts "#{path}/bin/start_sample.rb #{dir}/bin/start_#{app_file}"
|
53
53
|
FileUtils.cp_r "#{path}/bin/start_sample.rb", "#{dir}/bin/start_#{app_file}"
|
54
|
-
FileUtils.cp_r "#{path}/bin/start_sample.rb", "#{dir}/bin/start_#{app_file.gsub(/rb$/,"rbw")}"
|
54
|
+
FileUtils.cp_r "#{path}/bin/start_sample.rb", "#{dir}/bin/start_#{app_file.gsub(/rb$/, "rbw")}"
|
55
55
|
|
56
56
|
load_app = <<"EOS"
|
57
57
|
require '#{app_file}'
|
@@ -64,9 +64,14 @@ EOS
|
|
64
64
|
|
65
65
|
puts "create #{app_file}"
|
66
66
|
new_file = "#{dir}/lib/#{app_file}"
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
sample_file = "#{dir}/lib/my_app_sample.rb"
|
68
|
+
if File.exist?(sample_file)
|
69
|
+
FileUtils.cp(sample_file, new_file)
|
70
|
+
buf = File.binread(new_file)
|
71
|
+
File.binwrite(new_file, buf.gsub(/MyApp/, get_app_name(app)))
|
72
|
+
else
|
73
|
+
warn "Sample file #{sample_file} does not exist. Skipping app file creation."
|
74
|
+
end
|
70
75
|
end
|
71
76
|
end
|
72
|
-
end
|
77
|
+
end
|
data/lib/template/config.ru
CHANGED
@@ -8,29 +8,32 @@ require "json"
|
|
8
8
|
require "./server"
|
9
9
|
require "./wsserver"
|
10
10
|
|
11
|
+
base_dir = File.dirname(File.expand_path(__FILE__))
|
12
|
+
|
11
13
|
access_log = File.new("#{$home_dir}/logs/sinatra.log", "a+")
|
12
14
|
access_log.sync = true
|
13
15
|
use Rack::CommonLogger, access_log
|
14
16
|
|
15
17
|
get "/" do
|
16
|
-
|
18
|
+
puts "base_dir=#{base_dir}"
|
19
|
+
File.read("#{base_dir}/html/index.html")
|
17
20
|
end
|
18
21
|
|
19
22
|
get "*.html" do |file|
|
20
23
|
content_type "text/html", :charset => "utf-8"
|
21
|
-
File.read "
|
24
|
+
File.read "#{base_dir}//html/#{file}.html"
|
22
25
|
end
|
23
26
|
|
24
27
|
get "/css/:name.css" do
|
25
28
|
content_type "text/css", :charset => "utf-8"
|
26
|
-
puts "css/#{params[:name]}.css"
|
27
|
-
File.read "css/#{params[:name]}.css"
|
29
|
+
puts "#{base_dir}/css/#{params[:name]}.css"
|
30
|
+
File.read "#{base_dir}/css/#{params[:name]}.css"
|
28
31
|
end
|
29
32
|
|
30
33
|
get "/js/:name.js" do
|
31
34
|
content_type "text/javascript", :charset => "utf-8"
|
32
|
-
puts "js/#{params[:name]}.js"
|
33
|
-
File.read "js/#{params[:name]}.js"
|
35
|
+
puts "#{base_dir}/js/#{params[:name]}.js"
|
36
|
+
File.read "#{base_dir}/js/#{params[:name]}.js"
|
34
37
|
end
|
35
38
|
|
36
39
|
get "/config/*.*" do |file, ext|
|
@@ -102,6 +105,6 @@ configure do
|
|
102
105
|
|
103
106
|
end
|
104
107
|
|
105
|
-
#\ --port
|
108
|
+
#\ --port 45739
|
106
109
|
|
107
110
|
run Sinatra::Application
|
data/lib/template/css/index.css
CHANGED
data/lib/template/js/main.js
CHANGED
@@ -8,18 +8,18 @@ var dialog_timeout = null;
|
|
8
8
|
function open_dialog(msg, timeout = 0) {
|
9
9
|
console.log("msg=" + msg);
|
10
10
|
$("#msg_text").html(msg);
|
11
|
-
d = $("#msg_dialog").dialog({
|
12
|
-
modal: true
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
"OK": function () { //
|
11
|
+
var d = $("#msg_dialog").dialog({
|
12
|
+
modal: true,
|
13
|
+
show: "slide", //表示時のアニメーション
|
14
|
+
hide: "slide", //閉じた時のアニメーション
|
15
|
+
title: "Message", //ダイアログのタイトル
|
16
|
+
width: 500, //ダイアログの横幅
|
17
|
+
height: 300, //ダイアログの高さ
|
18
|
+
resizable: true, //リサイズ可
|
19
|
+
closeOnEscape: false, //[ESC]キーで閉じられなくする
|
20
|
+
draggable: true, //ダイアログの移動を可に
|
21
|
+
buttons: {
|
22
|
+
"OK": function () { //OKボタン
|
23
23
|
if (dialog_timeout != null) {
|
24
24
|
clearTimeout(dialog_timeout);
|
25
25
|
}
|
@@ -40,7 +40,7 @@ function open_dialog_org(msg) {
|
|
40
40
|
if (dialog != null) {
|
41
41
|
dialog.close();
|
42
42
|
}
|
43
|
-
|
43
|
+
dialog = window.open(
|
44
44
|
"/open_dialog?msg=" + msg,
|
45
45
|
"pop",
|
46
46
|
"width=300, height=100, left=" + left + ", top=" + top
|
@@ -80,8 +80,12 @@ function server_connect(url) {
|
|
80
80
|
else if (evt.data.match(/^popup:/)) {
|
81
81
|
console.log("str=" + evt.data);
|
82
82
|
const timeout_str = evt.data.match(/:(\d+):/);
|
83
|
-
|
84
|
-
|
83
|
+
if (timeout_str && timeout_str[1]) {
|
84
|
+
console.log("timeout_str=" + timeout_str[1]);
|
85
|
+
open_dialog(evt.data.replace(/^popup:(\d+):/, ""), Number(timeout_str[1]));
|
86
|
+
} else {
|
87
|
+
open_dialog(evt.data.replace(/^popup:/, ""));
|
88
|
+
}
|
85
89
|
} else {
|
86
90
|
var log = "<li>" + evt.data + "</li>";
|
87
91
|
$('#log').append(log);
|
@@ -179,16 +183,16 @@ function select_file_dialog(search_id, file_kind, dialog_id, select_file, file_n
|
|
179
183
|
console.log("name=" + $("#" + file_name).val());
|
180
184
|
$("#" + search_id).val($("#" + file_name).val());
|
181
185
|
$("#" + dialog_id).dialog({
|
182
|
-
modal: true
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
186
|
+
modal: true,
|
187
|
+
show: "slide",
|
188
|
+
hide: "explode",
|
189
|
+
title: "Select File",
|
190
|
+
width: 580,
|
191
|
+
height: 400,
|
192
|
+
resizable: true,
|
193
|
+
closeOnEscape: false,
|
194
|
+
draggable: true,
|
195
|
+
open: function (event, ui) {
|
192
196
|
// ダイアログの高さを取得
|
193
197
|
var dialogHeight = $("#" + dialog_id).height();
|
194
198
|
// オートコンプリートリストの高さをダイアログに合わせる
|
@@ -196,8 +200,8 @@ function select_file_dialog(search_id, file_kind, dialog_id, select_file, file_n
|
|
196
200
|
"max-height": dialogHeight + "px",
|
197
201
|
"overflow-y": "auto"
|
198
202
|
});
|
199
|
-
}
|
200
|
-
|
203
|
+
},
|
204
|
+
buttons: {
|
201
205
|
"OK": function () {
|
202
206
|
$("#" + file_name).val($("#" + search_id).val());
|
203
207
|
$(this).dialog("close");
|
@@ -217,66 +221,64 @@ function setting_dialog(open_id, dialog_id, json_file) {
|
|
217
221
|
var is_error = false;
|
218
222
|
|
219
223
|
$("#" + open_id).click(function () {
|
220
|
-
$("#"
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
h += "<td><input class='setting_checkbox' type='checkbox' " + "id=" + s["setting_list"][i].name + "_value checked ></td>";
|
244
|
-
} else {
|
245
|
-
h += "<td><input class='setting_checkbox' type='checkbox' " + "id=" + s["setting_list"][i].name + "_value ></td>";
|
246
|
-
}
|
247
|
-
h += "</tr></table>";
|
248
|
-
$("dl#wrap").append(h);
|
249
|
-
} else if (s["setting_list"][i].type == "select") {
|
250
|
-
var h = "<table><tr>";
|
251
|
-
h += "<td class='setting_name'>" + s["setting_list"][i].description + "</td>";
|
252
|
-
h += "<td> <select class='setting_value' id=" + s["setting_list"][i].name + "_value " + ">";
|
253
|
-
s["setting_list"][i].select.forEach(e => {
|
254
|
-
if (e == s["setting_list"][i].value) {
|
255
|
-
h += "<option value=" + e + " selected >" + e + "</option>";
|
256
|
-
} else {
|
257
|
-
h += "<option value=" + e + ">" + e + "</option>";
|
258
|
-
}
|
259
|
-
});
|
260
|
-
h += "</select></td>";
|
261
|
-
h += "</tr></table>";
|
262
|
-
$("dl#wrap").append(h);
|
224
|
+
$("dl#wrap").empty();
|
225
|
+
$.getJSON(json_file, function (s) {
|
226
|
+
version = s["version"];
|
227
|
+
for (var i in s["setting_list"]) {
|
228
|
+
if (s["setting_list"][i].type == "input") {
|
229
|
+
var h = "<table><tr>"
|
230
|
+
+ "<td class='setting_name'>" + s["setting_list"][i].description + "</td>"
|
231
|
+
+ "<td><input class='setting_value' type='text' " + "id=" + s["setting_list"][i].name + "_value " + "value='" + s["setting_list"][i].value + "'>"
|
232
|
+
+ "</td></tr></table>";
|
233
|
+
$("dl#wrap").append(h);
|
234
|
+
} else if (s["setting_list"][i].type == "textarea") {
|
235
|
+
var h = "<table><tr>"
|
236
|
+
+ "<td class='setting_name'>" + s["setting_list"][i].description + "</td>"
|
237
|
+
+ "<td><textarea class='setting_value' rows='5' " + "id=" + s["setting_list"][i].name + "_value" + ">"
|
238
|
+
+ JSON.stringify(s["setting_list"][i].value, null, 2)
|
239
|
+
+ "</textarea>"
|
240
|
+
+ "</td></tr></table>";
|
241
|
+
$("dl#wrap").append(h);
|
242
|
+
} else if (s["setting_list"][i].type == "checkbox") {
|
243
|
+
var h = "<table><tr>";
|
244
|
+
h += "<td class='setting_name'>" + s["setting_list"][i].description + "</td>";
|
245
|
+
if (s["setting_list"][i].value == true) {
|
246
|
+
h += "<td><input class='setting_checkbox' type='checkbox' " + "id=" + s["setting_list"][i].name + "_value checked ></td>";
|
263
247
|
} else {
|
264
|
-
|
248
|
+
h += "<td><input class='setting_checkbox' type='checkbox' " + "id=" + s["setting_list"][i].name + "_value ></td>";
|
265
249
|
}
|
250
|
+
h += "</tr></table>";
|
251
|
+
$("dl#wrap").append(h);
|
252
|
+
} else if (s["setting_list"][i].type == "select") {
|
253
|
+
var h = "<table><tr>";
|
254
|
+
h += "<td class='setting_name'>" + s["setting_list"][i].description + "</td>";
|
255
|
+
h += "<td> <select class='setting_value' id=" + s["setting_list"][i].name + "_value" + ">";
|
256
|
+
s["setting_list"][i].select.forEach(e => {
|
257
|
+
if (e == s["setting_list"][i].value) {
|
258
|
+
h += "<option value=" + e + " selected >" + e + "</option>";
|
259
|
+
} else {
|
260
|
+
h += "<option value=" + e + ">" + e + "</option>";
|
261
|
+
}
|
262
|
+
});
|
263
|
+
h += "</select></td>";
|
264
|
+
h += "</tr></table>";
|
265
|
+
$("dl#wrap").append(h);
|
266
|
+
} else {
|
267
|
+
//console.log("type=" + s["setting_list"][i].type);
|
266
268
|
}
|
267
|
-
}
|
269
|
+
}
|
268
270
|
});
|
269
271
|
$("#" + dialog_id).dialog({
|
270
|
-
modal: true
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
272
|
+
modal: true,
|
273
|
+
show: "slide", //表示時のアニメーション
|
274
|
+
hide: "explode", //閉じた時のアニメーション
|
275
|
+
title: "Setting", //ダイアログのタイトル
|
276
|
+
width: 650, //ダイアログの横幅
|
277
|
+
height: 600, //ダイアログの高さ
|
278
|
+
resizable: true, //リサイズ可
|
279
|
+
closeOnEscape: false, //[ESC]キーで閉じられなくする
|
280
|
+
draggable: true, //ダイアログの移動を可に
|
281
|
+
buttons: {
|
280
282
|
"OK": function () { //OKボタン
|
281
283
|
var json_obj = {};
|
282
284
|
var json_data = [];
|
@@ -334,10 +336,18 @@ function setting_dialog(open_id, dialog_id, json_file) {
|
|
334
336
|
}
|
335
337
|
console.log("OK Button " + is_error);
|
336
338
|
// Jsonデータをサーバに送信
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
339
|
+
if (is_error == false) {
|
340
|
+
json_obj["setting_list"] = json_data;
|
341
|
+
var json_string = JSON.stringify(json_obj);
|
342
|
+
console.log("json_string:" + json_string);
|
343
|
+
$ws.send("setting:" + json_string);
|
344
|
+
}
|
345
|
+
})
|
346
|
+
.done(function () {
|
347
|
+
if (is_error == false) {
|
348
|
+
$("#" + dialog_id).dialog("close");
|
349
|
+
}
|
350
|
+
});
|
341
351
|
},
|
342
352
|
"Cancel": function () { //Cancelボタン
|
343
353
|
console.log("Cancel Button");
|
@@ -420,10 +430,10 @@ function openFile(file) {
|
|
420
430
|
$(document).ready(function () {
|
421
431
|
|
422
432
|
// サーバに接続
|
423
|
-
server_connect("ws://localhost:
|
433
|
+
server_connect("ws://localhost:45739/wsserver")
|
424
434
|
window.onload = function (e) {
|
425
435
|
// サーバに接続
|
426
|
-
//server_connect("ws://localhost:
|
436
|
+
//server_connect("ws://localhost:45739/wsserver")
|
427
437
|
}
|
428
438
|
|
429
439
|
// menu
|
@@ -495,4 +505,3 @@ $(document).ready(function () {
|
|
495
505
|
autocomp_history("upFile", "history.json")
|
496
506
|
|
497
507
|
});
|
498
|
-
|
data/lib/template/server.rb
CHANGED
@@ -1,23 +1,40 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$LOAD_PATH << File.dirname(File.expand_path(__FILE__))
|
3
|
+
|
4
|
+
require "sinatra"
|
5
|
+
require "sinatra/contrib"
|
6
|
+
require "sinatra-websocket"
|
7
|
+
require "thin"
|
1
8
|
require "json"
|
2
9
|
require "kconv"
|
10
|
+
require "cgi"
|
11
|
+
require "pathname"
|
12
|
+
require "common"
|
3
13
|
|
4
14
|
class Search < Sinatra::Base
|
5
15
|
helpers Sinatra::Streaming
|
6
|
-
get "" do
|
16
|
+
get "/" do
|
17
|
+
content_type "application/json", :charset => "utf-8"
|
7
18
|
q_hash = {}
|
8
19
|
puts request.query_string
|
9
20
|
request.query_string.split("&").each do |q|
|
10
21
|
work = q.split("=")
|
11
22
|
if work[1] != nil
|
12
|
-
q_hash[work[0]] = CGI.unescape
|
23
|
+
q_hash[work[0]] = CGI.unescape(work[1].toutf8)
|
13
24
|
else
|
14
25
|
q_hash[work[0]] = ""
|
15
26
|
end
|
16
27
|
end
|
17
|
-
|
28
|
+
begin
|
29
|
+
str = q_hash["path"].gsub(/\\/, "/")
|
30
|
+
rescue
|
31
|
+
str = "/"
|
32
|
+
end
|
18
33
|
puts "str=#{str}"
|
34
|
+
str = "/" if str.to_s == ""
|
19
35
|
kind = q_hash["kind"].gsub(/\\/, "/")
|
20
36
|
puts "kind=#{kind}"
|
37
|
+
kind = "file" if kind.to_s == ""
|
21
38
|
res = []
|
22
39
|
str = str.gsub(/\\/, "/")
|
23
40
|
dir = File.dirname(str)
|
@@ -25,15 +42,13 @@ class Search < Sinatra::Base
|
|
25
42
|
puts "dir=#{dir}"
|
26
43
|
puts "file=#{file}"
|
27
44
|
|
28
|
-
kernel =
|
29
|
-
if kernel == "windows"
|
30
|
-
dir = "c:/" if dir ==
|
31
|
-
|
32
|
-
|
33
|
-
dir = "/" if dir == nil
|
45
|
+
kernel = get_os_type
|
46
|
+
if kernel.downcase == "windows"
|
47
|
+
dir = "c:/" if dir.nil? || dir == "/"
|
48
|
+
elsif kernel.downcase == "linux"
|
49
|
+
dir = "/" if dir.nil?
|
34
50
|
else
|
35
|
-
dir = "c:/" if dir ==
|
36
|
-
dir = "c:/" if dir == "/"
|
51
|
+
dir = "c:/" if dir.nil? || dir == "/"
|
37
52
|
end
|
38
53
|
|
39
54
|
path = "#{dir}/#{file}"
|
@@ -43,13 +58,13 @@ class Search < Sinatra::Base
|
|
43
58
|
path = path + "*"
|
44
59
|
end
|
45
60
|
path.gsub!(/[\/]+/, "/")
|
46
|
-
puts path
|
61
|
+
puts "path=#{path}"
|
47
62
|
Dir.glob(path, File::FNM_DOTMATCH).each do |file|
|
48
63
|
data = {}
|
49
64
|
next if File.basename(file) == "."
|
50
65
|
next if kind == "dir" and !File.directory?(file)
|
51
66
|
data["label"] = File.basename(file)
|
52
|
-
data["label"] += "/" if
|
67
|
+
data["label"] += "/" if File.directory?(file)
|
53
68
|
data["value"] = File.expand_path(file)
|
54
69
|
res.push data
|
55
70
|
end
|
@@ -57,10 +72,9 @@ class Search < Sinatra::Base
|
|
57
72
|
data = {}
|
58
73
|
pp = Pathname(File.expand_path("#{dir}/#{file}"))
|
59
74
|
data["label"] = "../"
|
60
|
-
data["label"] += "/" if pp.parent == "/"
|
75
|
+
data["label"] += "/" if pp.parent.to_s == "/"
|
61
76
|
data["value"] = pp.parent.to_s
|
62
77
|
data["value"] = "/" if data["value"] =~ /^[\/]+$/
|
63
|
-
#puts "value = #{pp.parent.to_s}"
|
64
78
|
res.push data
|
65
79
|
end
|
66
80
|
JSON.generate res.sort { |a, b| a["value"] <=> b["value"] }
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
require "json"
|
3
|
+
|
2
4
|
class AppMainBase
|
3
5
|
def initialize
|
4
6
|
@config = nil
|
5
|
-
@
|
7
|
+
@abort = false
|
6
8
|
@exec = false
|
7
9
|
@suspend = false
|
8
10
|
@ws = nil
|
9
11
|
end
|
10
12
|
|
11
13
|
def app_send(str)
|
12
|
-
|
13
|
-
@ws.send(str)
|
14
|
-
end
|
14
|
+
@ws&.send(str)
|
15
15
|
end
|
16
16
|
|
17
17
|
def set_ws(ws)
|
@@ -26,38 +26,35 @@ class AppMainBase
|
|
26
26
|
@exec = true
|
27
27
|
end
|
28
28
|
|
29
|
-
def stop
|
29
|
+
def stop
|
30
30
|
@abort = true
|
31
31
|
@exec = false
|
32
32
|
end
|
33
33
|
|
34
|
-
def suspend
|
34
|
+
def suspend
|
35
35
|
@suspend = true
|
36
36
|
end
|
37
37
|
|
38
|
-
def resume
|
38
|
+
def resume
|
39
39
|
@suspend = false
|
40
40
|
end
|
41
41
|
|
42
42
|
# 履歴の保存
|
43
43
|
def add_history(file, history_data, max = 10)
|
44
|
+
history_dir = @config&.fetch(:home_dir, "./") + "history/"
|
45
|
+
path = File.join(history_dir, file)
|
44
46
|
begin
|
45
|
-
buf = File.read
|
47
|
+
buf = File.read(path)
|
48
|
+
data = JSON.parse(buf)
|
46
49
|
rescue
|
47
|
-
buf = ""
|
48
|
-
end
|
49
|
-
data = eval(buf)
|
50
|
-
if data == nil
|
51
50
|
data = []
|
52
51
|
end
|
53
52
|
if history_data.to_s != ""
|
54
|
-
data.
|
55
|
-
end
|
56
|
-
data = data.uniq[0..max - 1]
|
57
|
-
File.open("#{$home_dir}history/#{file}", "w") do |f|
|
58
|
-
f.write JSON.pretty_generate data
|
53
|
+
data.unshift(history_data)
|
59
54
|
end
|
55
|
+
data = data.uniq[0, max]
|
56
|
+
File.write(path, JSON.pretty_generate(data))
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
63
|
-
|
60
|
+
require_relative "app_load"
|
data/lib/template/start.rb
CHANGED
@@ -8,7 +8,7 @@ require "daemons"
|
|
8
8
|
require "fileutils"
|
9
9
|
require "kconv"
|
10
10
|
require "json"
|
11
|
-
require "
|
11
|
+
require "common"
|
12
12
|
|
13
13
|
# ログ出力
|
14
14
|
module Output
|
@@ -24,7 +24,7 @@ module Output
|
|
24
24
|
alias_method :write_org, :write
|
25
25
|
|
26
26
|
def initialize(stdout)
|
27
|
-
@stdout =
|
27
|
+
@stdout = stdout
|
28
28
|
end
|
29
29
|
|
30
30
|
attr_accessor :stdout
|
@@ -54,9 +54,9 @@ FileUtils.cd dir
|
|
54
54
|
pp ARGV
|
55
55
|
if ARGV[0] == "test"
|
56
56
|
$home_dir = "./"
|
57
|
-
ARGV
|
57
|
+
ARGV.clear
|
58
58
|
else
|
59
|
-
$home_dir = ENV["HOME"] + "/" + dir.split("/")[-1].gsub(/-[0-9\.-]+/,"") + "/"
|
59
|
+
$home_dir = ENV["HOME"] + "/" + dir.split("/")[-1].gsub(/-[0-9\.-]+/, "") + "/"
|
60
60
|
end
|
61
61
|
puts "home_dir=#{$home_dir}"
|
62
62
|
FileUtils.mkdir_p("#{$home_dir}/logs")
|
@@ -85,7 +85,7 @@ buf = File.binread("js/main.js").toutf8
|
|
85
85
|
buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
|
86
86
|
File.binwrite("js/main.js", buf)
|
87
87
|
|
88
|
-
# index.
|
88
|
+
# index.htmlの編集
|
89
89
|
buf = File.binread("html/index.html").toutf8
|
90
90
|
buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
|
91
91
|
File.binwrite("html/index.html", buf)
|
@@ -108,10 +108,10 @@ begin
|
|
108
108
|
json_file = "#{$home_dir}/config/browser.json"
|
109
109
|
json = JSON.parse(File.read json_file)
|
110
110
|
puts json
|
111
|
-
kernel =
|
112
|
-
if kernel == "windows"
|
111
|
+
kernel = get_os_type
|
112
|
+
if kernel.downcase == "windows"
|
113
113
|
browser = json["chrome_win"]
|
114
|
-
elsif kernel == "
|
114
|
+
elsif kernel.downcase == "linux"
|
115
115
|
browser = json["chrome_linux"]
|
116
116
|
else
|
117
117
|
browser = json["chrome_win"]
|
data/lib/template/wsserver.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH << File.dirname(File.expand_path(__FILE__))
|
2
|
+
|
3
|
+
require "server_app_base"
|
2
4
|
require "json"
|
3
5
|
require "cgi"
|
4
6
|
require "thread"
|
@@ -18,6 +20,8 @@ class WsServer < Sinatra::Base
|
|
18
20
|
super
|
19
21
|
@ws_list = []
|
20
22
|
@ws_lock = Mutex.new
|
23
|
+
@json_config = nil
|
24
|
+
@exec_thread = nil
|
21
25
|
end
|
22
26
|
|
23
27
|
def ws_send(str)
|
@@ -28,8 +32,8 @@ class WsServer < Sinatra::Base
|
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
|
-
|
32
|
-
|
35
|
+
public :ws_send
|
36
|
+
|
33
37
|
get "" do
|
34
38
|
if !request.websocket?
|
35
39
|
"no supported"
|
@@ -47,17 +51,24 @@ class WsServer < Sinatra::Base
|
|
47
51
|
if $ws_exit_thread != nil
|
48
52
|
puts "ws_exit_thread kill"
|
49
53
|
Thread.kill $ws_exit_thread
|
54
|
+
$ws_exit_thread = nil
|
50
55
|
end
|
51
56
|
end
|
52
57
|
ws.onmessage do |msg|
|
53
58
|
puts msg
|
54
|
-
|
55
|
-
|
56
|
-
|
59
|
+
begin
|
60
|
+
json = JSON.parse(File.read("#{$home_dir}/config/setting.json"))
|
61
|
+
@json_config = config_json_hash(json)
|
62
|
+
$app.set_config(@json_config)
|
63
|
+
rescue
|
64
|
+
puts "Failed to load config/setting.json"
|
65
|
+
@json_config = {}
|
66
|
+
end
|
67
|
+
|
57
68
|
if msg =~ /^exec:/
|
58
|
-
if exec_thread == nil
|
69
|
+
if @exec_thread == nil
|
59
70
|
argv = msg.gsub(/^exec:/, "")
|
60
|
-
exec_thread = Thread.new {
|
71
|
+
@exec_thread = Thread.new {
|
61
72
|
begin
|
62
73
|
$app.start(argv.split(",")) do |out|
|
63
74
|
ws_send(out)
|
@@ -70,7 +81,7 @@ class WsServer < Sinatra::Base
|
|
70
81
|
ws_send("app_end:error")
|
71
82
|
ensure
|
72
83
|
puts "exit thread"
|
73
|
-
exec_thread = nil
|
84
|
+
@exec_thread = nil
|
74
85
|
end
|
75
86
|
}
|
76
87
|
else
|
@@ -79,19 +90,20 @@ class WsServer < Sinatra::Base
|
|
79
90
|
end
|
80
91
|
end
|
81
92
|
if msg =~ /^stop/
|
82
|
-
if exec_thread
|
83
|
-
Thread.kill exec_thread
|
93
|
+
if @exec_thread
|
94
|
+
Thread.kill @exec_thread
|
84
95
|
ws_send("app_end:stop")
|
85
96
|
$app.stop
|
97
|
+
@exec_thread = nil
|
86
98
|
end
|
87
99
|
end
|
88
100
|
if msg =~ /^suspend/
|
89
|
-
if exec_thread
|
101
|
+
if @exec_thread
|
90
102
|
$app.suspend
|
91
103
|
end
|
92
104
|
end
|
93
105
|
if msg =~ /^resume/
|
94
|
-
if exec_thread
|
106
|
+
if @exec_thread
|
95
107
|
$app.resume
|
96
108
|
end
|
97
109
|
end
|
@@ -102,8 +114,8 @@ class WsServer < Sinatra::Base
|
|
102
114
|
File.open("#{$home_dir}/config/setting.json", "w") do |w|
|
103
115
|
w.puts JSON.pretty_generate(json)
|
104
116
|
end
|
105
|
-
json_config = config_json_hash(json)
|
106
|
-
$app.set_config(json_config)
|
117
|
+
@json_config = config_json_hash(json)
|
118
|
+
$app.set_config(@json_config)
|
107
119
|
rescue
|
108
120
|
# jsonファイルではない
|
109
121
|
ws_send("app_end:error")
|
@@ -112,7 +124,11 @@ class WsServer < Sinatra::Base
|
|
112
124
|
if msg =~ /^openfile:/
|
113
125
|
file = msg.gsub(/^openfile:/, "")
|
114
126
|
Thread.new {
|
115
|
-
|
127
|
+
if @json_config && @json_config["editor"]
|
128
|
+
system "#{@json_config["editor"]} #{CGI.unescapeHTML(file)}"
|
129
|
+
else
|
130
|
+
puts "Editor not set in config"
|
131
|
+
end
|
116
132
|
}
|
117
133
|
end
|
118
134
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browser_app_base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- masataka kuwayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: facter
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
description: browser application template
|
98
84
|
email:
|
99
85
|
- masataka.kuwayama@gmail.com
|
@@ -119,13 +105,13 @@ files:
|
|
119
105
|
- lib/browser_app_base.rb
|
120
106
|
- lib/browser_app_base/version.rb
|
121
107
|
- lib/template/app_load.rb
|
108
|
+
- lib/template/common.rb
|
122
109
|
- lib/template/config.ru
|
123
110
|
- lib/template/config/browser.json
|
124
111
|
- lib/template/config/setting.json
|
125
112
|
- lib/template/css/index.css
|
126
113
|
- lib/template/history/history.json
|
127
114
|
- lib/template/html/index.html
|
128
|
-
- lib/template/html/test.html
|
129
115
|
- lib/template/js/main.js
|
130
116
|
- lib/template/my_app_sample.rb
|
131
117
|
- lib/template/server.rb
|
data/lib/template/html/test.html
DELETED
File without changes
|