browser_app_base 0.0.9 → 0.1.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: d8f803f44d98065ce973ec89c418d7d9d8fb75ce8c1f6dc74f8e449681a3a0f5
4
- data.tar.gz: 0bf164a5280e040b5efa5fe0221ae17f19d77b4569c3c4db5e4893d19a5e0efb
3
+ metadata.gz: c449614e4619060aa9e9f5799bc67822e61c1f603ff099914aff5e60593828dd
4
+ data.tar.gz: c146b0df93c05a64dceb9d6987895635bef0d733f9421581aa421c51d7077fd9
5
5
  SHA512:
6
- metadata.gz: 881fd8551b75678a1825a1cb227918f22ce9e6db9377e940bd7b25d04d7827d491c4f42c0c4da372607666533ada91239fb4f79f3792b3252dedf3c589424de4
7
- data.tar.gz: 1c630a5c7affe753747bc2aee0789b384249676f6a90a036fce54471084e0bf471c2c88bdd701e13851f5f7d33f53e8360a52e6898a29bc09e9f045183791b9d
6
+ metadata.gz: ed31b5268858c2ac45a01f20924cfe569c0f360797bfad8650a37cf07eff9452b229dbc30ecd0b3200ac5ebcbddc20fcca8f485d4a49440573ee0c6c6a6b7cd2
7
+ data.tar.gz: 00fa73805f8d27f12464fea9bee92720c9303960890e23a02d804f060b6e1429f5b9b02c0dc58ff1bd0ae90ffd4f8ed38c918bdc45e843e203f68563dbce9009
data/README.md CHANGED
@@ -58,8 +58,9 @@ ui application sample
58
58
 
59
59
  ## Start application
60
60
 
61
- $ cd ~/test/
62
- $ ruby start.rb
61
+ ```shell
62
+ $ /tmp/test/bin/start_my_app.rb
63
+ ```
63
64
 
64
65
  ## browser setting
65
66
 
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "fileutils"
4
+ require "facter"
5
+ require "tmpdir"
6
+
7
+ # tmpdirディレクトリにコピー
8
+ dir = File.dirname(File.expand_path(__FILE__)) + "/../"
9
+ Dir.mktmpdir { |tmpdir|
10
+ puts tmpdir
11
+ Dir.glob("#{dir}/lib/*") do |f|
12
+ puts "#{f} => #{tmpdir}"
13
+ FileUtils.cp_r f, "#{tmpdir}"
14
+ end
15
+
16
+ FileUtils.cd "#{tmpdir}"
17
+ kernel = Facter.value(:kernel)
18
+ if kernel == "windows"
19
+ system "rubyw ./start.rb"
20
+ elsif kernel == "Linux"
21
+ system "ruby ./start.rb"
22
+ else
23
+ system "ruby ./start.rb"
24
+ end
25
+ }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrowserAppBase
4
- VERSION = "0.0.9"
4
+ VERSION = "0.1.0"
5
5
  end
@@ -37,28 +37,33 @@ module BrowserAppBase
37
37
  puts "create application base #{dir}"
38
38
 
39
39
  FileUtils.mkdir_p dir
40
+ FileUtils.mkdir_p dir + "/lib/"
41
+ FileUtils.mkdir_p dir + "/bin/"
40
42
 
41
- path = File.dirname(File.expand_path(__FILE__))
42
- Dir.glob("#{path}/template/*") do |f|
43
- puts "#{f} => #{dir}"
44
- FileUtils.cp_r f, "#{dir}/"
43
+ path = File.dirname(File.expand_path(__FILE__)) + "/../"
44
+ Dir.glob("#{path}/lib/template/*") do |f|
45
+ puts "#{f} => #{dir}/lib"
46
+ FileUtils.cp_r f, "#{dir}/lib"
45
47
  end
46
48
 
47
49
  if app
48
50
  app_file = get_app_file(app)
49
51
 
52
+ puts "#{path}/bin/start_sample.rb #{dir}/bin/start_#{app_file}"
53
+ FileUtils.cp_r "#{path}/bin/start_sample.rb", "#{dir}/bin/start_#{app_file}"
54
+
50
55
  load_app = <<"EOS"
51
56
  require '#{app_file}'
52
57
  $app = #{get_app_name(app)}.new
53
58
  EOS
54
59
 
55
- File.open("#{dir}/app_load.rb", "w") do |f|
60
+ File.open("#{dir}/lib/app_load.rb", "w") do |f|
56
61
  f.write load_app
57
62
  end
58
63
 
59
64
  puts "create #{app_file}"
60
- new_file = "#{dir}/#{app_file}"
61
- FileUtils.cp("#{dir}/my_app_sample.rb", new_file)
65
+ new_file = "#{dir}/lib/#{app_file}"
66
+ FileUtils.cp("#{dir}/lib/my_app_sample.rb", new_file)
62
67
  buf = File.binread(new_file)
63
68
  File.binwrite(new_file, buf.gsub(/MyApp/, get_app_name(app)))
64
69
  end
@@ -1,50 +1,50 @@
1
- [
2
- {
3
- "name": "name1",
4
- "value": "value1",
5
- "type": "input",
6
- "select": "",
7
- "description": "設定項目1"
8
- },
9
- {
10
- "name": "name2",
11
- "value": true,
12
- "type": "checkbox",
13
- "select": "",
14
- "description": "有効にする場合はチェック"
15
- },
16
- {
17
- "name": "name3",
18
- "value": "1",
19
- "type": "select",
20
- "select": [
21
- "1",
22
- "2",
23
- "3",
24
- "4",
25
- "5"
26
- ],
27
- "description": "選択項目"
28
- },
29
- {
30
- "name": "name4",
31
- "value": "value4",
32
- "type": "input",
33
- "select": "",
34
- "description": "設定項目4"
35
- },
36
- {
37
- "name": "name5",
38
- "value": "value5",
39
- "type": "input",
40
- "select": "",
41
- "description": "設定項目5"
42
- },
43
- {
44
- "name": "name6",
45
- "value": "value6",
46
- "type": "input",
47
- "select": "",
48
- "description": "設定項目6"
49
- }
50
- ]
1
+ [
2
+ {
3
+ "name": "name1",
4
+ "value": "value1 2 3 4",
5
+ "type": "input",
6
+ "select": "",
7
+ "description": "設定項目1"
8
+ },
9
+ {
10
+ "name": "name2",
11
+ "value": true,
12
+ "type": "checkbox",
13
+ "select": "",
14
+ "description": "有効にする場合はチェック"
15
+ },
16
+ {
17
+ "name": "name3",
18
+ "value": "2",
19
+ "type": "select",
20
+ "select": [
21
+ "1",
22
+ "2",
23
+ "3",
24
+ "4",
25
+ "5"
26
+ ],
27
+ "description": "選択項目"
28
+ },
29
+ {
30
+ "name": "name4",
31
+ "value": "value4",
32
+ "type": "input",
33
+ "select": "",
34
+ "description": "設定項目4"
35
+ },
36
+ {
37
+ "name": "name5",
38
+ "value": "value5",
39
+ "type": "input",
40
+ "select": "",
41
+ "description": "設定項目5"
42
+ },
43
+ {
44
+ "name": "name6",
45
+ "value": "value6",
46
+ "type": "input",
47
+ "select": "",
48
+ "description": "設定項目6"
49
+ }
50
+ ]
@@ -8,8 +8,20 @@ require "json"
8
8
  require "./server"
9
9
  require "./wsserver"
10
10
 
11
+ temp_dir = ENV["temp"]
12
+ temp_dir = "/tmp" if temp_dir == nil
13
+ puts "temp_dir=#{temp_dir}"
14
+ access_log = File.new("#{temp_dir}/logs/sinatra.log", "a+")
15
+ access_log.sync = true
16
+ use Rack::CommonLogger, access_log
17
+
11
18
  get "/" do
12
- File.read("index.html")
19
+ File.read("html/index.html")
20
+ end
21
+
22
+ get "*.html" do |file|
23
+ content_type "text/html", :charset => "utf-8"
24
+ File.read "./html/#{file}.html"
13
25
  end
14
26
 
15
27
  get "/css/:name.css" do
@@ -80,7 +92,7 @@ end
80
92
 
81
93
  configure do
82
94
  set :DoNotReverseLookup, true
83
- set :logging, false
95
+ set :logging, true
84
96
  set :default_encoding, "utf-8"
85
97
  set :server, :thin
86
98
 
@@ -89,6 +101,6 @@ configure do
89
101
 
90
102
  end
91
103
 
92
- #\ --port 61047
104
+ #\ --port 36809
93
105
 
94
106
  run Sinatra::Application
@@ -66,6 +66,15 @@ textarea.long {
66
66
  color: black;
67
67
  }
68
68
 
69
+ .ui-autocomplete.ui-front {
70
+ max-height: 250px;
71
+ overflow-y: auto;
72
+ /* prevent horizontal scrollbar */
73
+ overflow-x: hidden;
74
+ /* add padding to account for vertical scrollbar */
75
+ z-index: 1000 !important;
76
+ }
77
+
69
78
  .ui-dialog {
70
79
  position: absolute;
71
80
  top: 0;
@@ -11,8 +11,8 @@
11
11
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
12
12
  <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
13
13
 
14
- <script src="http://localhost:61047/js/main.js"></script>
15
- <link rel="stylesheet" href="http://localhost:61047/css/index.css" type="text/css">
14
+ <script src="http://localhost:36809/js/main.js"></script>
15
+ <link rel="stylesheet" href="http://localhost:36809/css/index.css" type="text/css">
16
16
  </head>
17
17
 
18
18
  <body>
@@ -39,7 +39,7 @@
39
39
  </table>
40
40
 
41
41
  <div id="dialog1" style="display:none;">
42
- <input class="inarea" type="text" name="search_str" id="search_str">
42
+ <input class="inarea" type="search" name="search_str" id="search_str">
43
43
  </div>
44
44
  <table>
45
45
  <tr>
@@ -49,7 +49,7 @@
49
49
  </table>
50
50
 
51
51
  <div id="dialog2" style="display:none;">
52
- <input class="inarea" type="text" name="search_str2" id="search_str2">
52
+ <input class="inarea" type="search" name="search_str2" id="search_str2">
53
53
  </div>
54
54
  <table>
55
55
  <tr>
@@ -0,0 +1,85 @@
1
+ <!DOCTYPE html>
2
+ <html lang="ja">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title>modalをcomponentで作る</title>
7
+ </head>
8
+
9
+ <style>
10
+ #content {
11
+ z-index: 10;
12
+ width: 50%;
13
+ padding: 1em;
14
+ background: #fff;
15
+ }
16
+
17
+ #overlay {
18
+ /* 要素を重ねた時の順番 */
19
+
20
+ z-index: 1;
21
+
22
+ /* 画面全体を覆う設定 */
23
+ position: fixed;
24
+ top: 0;
25
+ left: 0;
26
+ width: 100%;
27
+ height: 100%;
28
+ background-color: rgba(0, 0, 0, 0.5);
29
+
30
+ /* 画面の中央に要素を表示させる設定 */
31
+ display: flex;
32
+ align-items: center;
33
+ justify-content: center;
34
+
35
+ }
36
+ </style>
37
+
38
+ <body>
39
+ <div id="app">
40
+
41
+ <button v-on:click="openModal">Click</button>
42
+
43
+ <open-modal v-show="showContent" v-on:from-child="closeModal">slotからモーダルウィンドウへ</open-modal>
44
+
45
+ </div>
46
+
47
+ <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
48
+ <script>
49
+ Vue.component('open-modal', {
50
+ template: `
51
+ <div id="overlay" v-on:click="clickEvent">
52
+ <div id="content"  v-on:click="stopEvent">
53
+ <p><slot></slot></p>
54
+ <button v-on:click="clickEvent">close</button>
55
+ </div>
56
+ </div>
57
+ `,
58
+ methods: {
59
+ clickEvent: function () {
60
+ this.$emit('from-child')
61
+ },
62
+ stopEvent: function () {
63
+ event.stopPropagation()
64
+ }
65
+ }
66
+ })
67
+
68
+ new Vue({
69
+ el: '#app',
70
+ data: {
71
+ showContent: false
72
+ },
73
+ methods: {
74
+ openModal: function () {
75
+ this.showContent = true
76
+ },
77
+ closeModal: function () {
78
+ this.showContent = false
79
+ },
80
+ }
81
+ })
82
+ </script>
83
+ </body>
84
+
85
+ </html>
@@ -3,26 +3,35 @@
3
3
  var $ws = null;
4
4
  var $auto_scroll = true;
5
5
  var dialog = null;
6
+ var dialog_timeout = null;
6
7
 
7
- function open_dialog(msg) {
8
+ function open_dialog(msg, timeout = 0) {
8
9
  console.log("msg=" + msg);
9
10
  $("#msg_text").html(msg);
10
- $("#msg_dialog").dialog({
11
+ d = $("#msg_dialog").dialog({
11
12
  modal: true
12
13
  , show: "slide" //表示時のアニメーション
13
14
  , hide: "slide" //閉じた時のアニメーション
14
15
  , title: "Message" //ダイアログのタイトル
15
- , width: 400 //ダイアログの横幅
16
- , height: 200 //ダイアログの高さ
16
+ , width: 500 //ダイアログの横幅
17
+ , height: 300 //ダイアログの高さ
17
18
  , resizable: true //リサイズ可
18
19
  , closeOnEscape: false //[ESC]キーで閉じられなくする
19
20
  , draggable: true //ダイアログの移動を可に
20
21
  , buttons: {
21
22
  "OK": function () { //Cancelボタン
23
+ if (dialog_timeout != null) {
24
+ clearTimeout(dialog_timeout);
25
+ }
22
26
  $(this).dialog("close");
23
27
  }
24
28
  }
25
29
  });
30
+ if (timeout != 0) {
31
+ dialog_timeout = setTimeout(function () {
32
+ d.dialog("close");
33
+ }, timeout);
34
+ }
26
35
  }
27
36
 
28
37
  function open_dialog_org(msg) {
@@ -62,11 +71,14 @@ function server_connect(url) {
62
71
  else if (evt.data.match(/^app_end:normal/)) {
63
72
  open_dialog("終了しました");
64
73
  }
74
+ else if (evt.data.match(/^app_end:stop/)) {
75
+ open_dialog("中止しました");
76
+ }
65
77
  else if (evt.data.match(/^app_end:error/)) {
66
78
  open_dialog("<font color='red'>エラーが発生しました</font>");
67
79
  }
68
80
  else if (evt.data.match(/^popup:/)) {
69
- open_dialog(evt.data.replace(/^popup:/, ""));
81
+ open_dialog(evt.data.replace(/^popup:/, ""), 3000);
70
82
  } else {
71
83
  var log = "<li>" + evt.data + "</li>";
72
84
  $('#log').append(log);
@@ -103,7 +115,7 @@ function autocomp(id, file_kind) {
103
115
  },
104
116
  source: function (req, resp) {
105
117
  $.ajax({
106
- url: "http://localhost:61047/search?path=" + $("#" + id).val() + "&kind=" + file_kind,
118
+ url: "http://localhost:36809/search?path=" + $("#" + id).val() + "&kind=" + file_kind,
107
119
  type: "GET",
108
120
  cache: false,
109
121
  dataType: "json",
@@ -136,7 +148,7 @@ function autocomp_history(id, file_name) {
136
148
  },
137
149
  source: function (req, resp) {
138
150
  $.ajax({
139
- url: "http://localhost:61047/history/" + file_name,
151
+ url: "http://localhost:36809/history/" + file_name,
140
152
  type: "POST",
141
153
  cache: false,
142
154
  dataType: "json",
@@ -197,7 +209,7 @@ function setting_dialog(open_id, dialog_id, json_file) {
197
209
  if (s[i].type == "input") {
198
210
  var h = "<table><tr>"
199
211
  + "<td class='setting_name'>" + s[i].description + "</td>"
200
- + "<td><input class='setting_value' type='text' " + "id=" + s[i].name + "_value " + "value=" + s[i].value + ">"
212
+ + "<td><input class='setting_value' type='text' " + "id=" + s[i].name + "_value " + "value=" + "'" + s[i].value + "'" + ">"
201
213
  + "</td></tr></table>"
202
214
  $("dl#wrap").append(h);
203
215
  } else if (s[i].type == "checkbox") {
@@ -314,7 +326,7 @@ $(document).ready(function () {
314
326
  window.onload = function (e) {
315
327
  console.log("onload");
316
328
  // サーバに接続
317
- server_connect("ws://localhost:61047/wsserver")
329
+ server_connect("ws://localhost:36809/wsserver")
318
330
  }
319
331
 
320
332
  // ウインドウサイズ
@@ -40,7 +40,7 @@ class AppMainBase
40
40
  end
41
41
 
42
42
  # 履歴の保存
43
- def add_history(file, history_data)
43
+ def add_history(file, history_data, max = 10)
44
44
  buf = File.read "history/#{file}"
45
45
  data = eval(buf)
46
46
  if data == nil
@@ -49,8 +49,9 @@ class AppMainBase
49
49
  if history_data.to_s != ""
50
50
  data.prepend history_data
51
51
  end
52
+ data = data.uniq[0..max - 1]
52
53
  File.open("history/#{file}", "w") do |f|
53
- f.write JSON.pretty_generate data.uniq
54
+ f.write JSON.pretty_generate data
54
55
  end
55
56
  end
56
57
  end
@@ -12,33 +12,50 @@ require "facter"
12
12
 
13
13
  # ログ出力
14
14
  module Output
15
- def self.console_and_file(output_file)
16
- defout = File.new(output_file, "a+")
15
+ def self.console_and_file(output_file, stdout = true)
16
+ begin
17
+ defout = File.new(output_file, "a+")
18
+ rescue
19
+ puts $!
20
+ puts $@
21
+ return nil
22
+ end
17
23
  class << defout
18
24
  alias_method :write_org, :write
19
25
 
26
+ def initialize(stdout)
27
+ @stdout = false
28
+ end
29
+
30
+ attr_accessor :stdout
31
+
20
32
  def puts(str)
21
- STDOUT.write(str.to_s + "\n")
33
+ STDOUT.write(str.to_s + "\n") if @stdout
22
34
  self.write_org(str.to_s + "\n")
23
35
  self.flush
24
36
  end
25
37
 
26
38
  def write(str)
27
- STDOUT.write(str)
39
+ STDOUT.write(str) if @stdout
28
40
  self.write_org(str)
29
41
  self.flush
30
42
  end
31
43
  end
32
44
  $stdout = defout
45
+ $stdout.stdout = stdout
33
46
  end
34
47
  end
35
48
 
36
- Output.console_and_file("log.txt")
37
-
38
49
  # ディレクトリ移動
39
50
  dir = File.dirname(File.expand_path(__FILE__))
40
51
  FileUtils.cd dir
41
52
 
53
+ temp_dir = ENV["temp"]
54
+ temp_dir = "/tmp" if temp_dir == nil
55
+ puts "temp_dir=#{temp_dir}"
56
+ FileUtils.mkdir_p("#{temp_dir}/logs")
57
+ Output.console_and_file("#{temp_dir}/logs/app.log", true)
58
+
42
59
  # 空きポートを取得
43
60
  def get_unused_port
44
61
  s = TCPServer.open(0)
@@ -62,9 +79,9 @@ buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
62
79
  File.binwrite("js/main.js", buf)
63
80
 
64
81
  # index.htaの編集
65
- buf = File.binread("index.html").toutf8
82
+ buf = File.binread("html/index.html").toutf8
66
83
  buf.gsub!(/localhost:[0-9]+\//, "localhost:#{port}/")
67
- File.binwrite("index.html", buf)
84
+ File.binwrite("html/index.html", buf)
68
85
 
69
86
  begin
70
87
  Thread.start {
@@ -51,11 +51,11 @@ class WsServer < Sinatra::Base
51
51
  end
52
52
  ws.onmessage do |msg|
53
53
  puts msg
54
+ json = JSON.parse(File.read("config/setting.json"))
55
+ json_config = config_json_hash(json)
56
+ $app.set_config(json_config)
54
57
  if msg =~ /^exec:/
55
58
  if exec_thread == nil
56
- json = JSON.parse(File.read("config/setting.json"))
57
- json_config = config_json_hash(json)
58
- $app.set_config(json_config)
59
59
  argv = msg.gsub(/^exec:/, "")
60
60
  exec_thread = Thread.new {
61
61
  begin
@@ -80,6 +80,8 @@ class WsServer < Sinatra::Base
80
80
  end
81
81
  if msg =~ /^stop/
82
82
  if exec_thread
83
+ Thread.kill exec_thread
84
+ ws_send("app_end:stop")
83
85
  $app.stop
84
86
  end
85
87
  end
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.0.9
4
+ version: 0.1.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: 2021-12-31 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -99,6 +99,7 @@ email:
99
99
  - masataka.kuwayama@gmail.com
100
100
  executables:
101
101
  - create_browser_app.rb
102
+ - start_sample.rb
102
103
  extensions: []
103
104
  extra_rdoc_files: []
104
105
  files:
@@ -110,6 +111,7 @@ files:
110
111
  - README.md
111
112
  - Rakefile
112
113
  - bin/create_browser_app.rb
114
+ - bin/start_sample.rb
113
115
  - browser_app_base.gemspec
114
116
  - lib/browser_app_base.rb
115
117
  - lib/browser_app_base/version.rb
@@ -119,7 +121,8 @@ files:
119
121
  - lib/template/config/setting.json
120
122
  - lib/template/css/index.css
121
123
  - lib/template/history/history.json
122
- - lib/template/index.html
124
+ - lib/template/html/index.html
125
+ - lib/template/html/test.html
123
126
  - lib/template/js/main.js
124
127
  - lib/template/my_app_sample.rb
125
128
  - lib/template/server.rb