browser_app_base 0.1.9 → 0.2.1
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 +5 -2
- data/README.md +32 -1
- data/README_ja.md +351 -0
- data/bin/create_browser_app.rb +5 -6
- data/bin/ruby-lsp +27 -0
- data/bin/ruby-lsp-check +27 -0
- data/bin/ruby-lsp-launcher +27 -0
- data/bin/ruby-lsp-test-exec +27 -0
- data/bin/start_sample.rb +12 -11
- data/browser_app_base.gemspec +2 -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 +3 -2
- data/lib/template/config.ru +9 -8
- 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 +16 -18
- data/lib/template/start.rb +15 -13
- data/lib/template/wsserver.rb +32 -16
- metadata +32 -9
- data/lib/template/html/test.html +0 -0
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,4 @@ configure do
|
|
|
102
105
|
|
|
103
106
|
end
|
|
104
107
|
|
|
105
|
-
#\ --port 34921
|
|
106
|
-
|
|
107
108
|
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:36539/wsserver")
|
|
424
434
|
window.onload = function (e) {
|
|
425
435
|
// サーバに接続
|
|
426
|
-
//server_connect("ws://localhost:
|
|
436
|
+
//server_connect("ws://localhost:36539/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,36 @@ 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
|
+
home_dir = @config&.key?(:home_dir) ? @config[:home_dir] : ($home_dir || "./")
|
|
45
|
+
history_dir = home_dir + "history/"
|
|
46
|
+
path = File.join(history_dir, file)
|
|
44
47
|
begin
|
|
45
|
-
buf = File.read
|
|
48
|
+
buf = File.read(path)
|
|
49
|
+
data = JSON.parse(buf)
|
|
46
50
|
rescue
|
|
47
|
-
buf = ""
|
|
48
|
-
end
|
|
49
|
-
data = eval(buf)
|
|
50
|
-
if data == nil
|
|
51
51
|
data = []
|
|
52
52
|
end
|
|
53
53
|
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
|
|
54
|
+
data.unshift(history_data)
|
|
59
55
|
end
|
|
56
|
+
data = data.uniq[0, max]
|
|
57
|
+
File.write(path, JSON.pretty_generate(data))
|
|
60
58
|
end
|
|
61
59
|
end
|
|
62
60
|
|
|
63
|
-
|
|
61
|
+
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")
|
|
@@ -75,17 +75,14 @@ end
|
|
|
75
75
|
port = get_unused_port
|
|
76
76
|
puts "port=#{port}"
|
|
77
77
|
|
|
78
|
-
# config.ru
|
|
79
|
-
buf = File.binread("config.ru").toutf8
|
|
80
|
-
buf.gsub!(/port [0-9]+/, "port #{port}")
|
|
81
|
-
File.binwrite("config.ru", buf)
|
|
78
|
+
# config.ruの編集は不要(port引数で渡すように変更)
|
|
82
79
|
|
|
83
80
|
# main.jsの編集
|
|
84
81
|
buf = File.binread("js/main.js").toutf8
|
|
85
82
|
buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
|
|
86
83
|
File.binwrite("js/main.js", buf)
|
|
87
84
|
|
|
88
|
-
# index.
|
|
85
|
+
# index.htmlの編集
|
|
89
86
|
buf = File.binread("html/index.html").toutf8
|
|
90
87
|
buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
|
|
91
88
|
File.binwrite("html/index.html", buf)
|
|
@@ -108,10 +105,10 @@ begin
|
|
|
108
105
|
json_file = "#{$home_dir}/config/browser.json"
|
|
109
106
|
json = JSON.parse(File.read json_file)
|
|
110
107
|
puts json
|
|
111
|
-
kernel =
|
|
112
|
-
if kernel == "windows"
|
|
108
|
+
kernel = get_os_type
|
|
109
|
+
if kernel.downcase == "windows"
|
|
113
110
|
browser = json["chrome_win"]
|
|
114
|
-
elsif kernel == "
|
|
111
|
+
elsif kernel.downcase == "linux"
|
|
115
112
|
browser = json["chrome_linux"]
|
|
116
113
|
else
|
|
117
114
|
browser = json["chrome_win"]
|
|
@@ -122,7 +119,12 @@ begin
|
|
|
122
119
|
}
|
|
123
120
|
|
|
124
121
|
# start web server
|
|
125
|
-
Rack
|
|
122
|
+
if Rack.release >= "3"
|
|
123
|
+
require "rackup"
|
|
124
|
+
Rackup::Server.start(:Port => port, :config => "config.ru", :server => "thin")
|
|
125
|
+
else
|
|
126
|
+
Rack::Server.start(:Port => port, :config => "config.ru", :server => "thin")
|
|
127
|
+
end
|
|
126
128
|
rescue
|
|
127
129
|
puts $!
|
|
128
130
|
puts $@
|