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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54f5d83ea13920bcfc80e7ecd82c099c5749847535fb593de2f36ff942027555
4
- data.tar.gz: 0a692e22ea4182825b0e6dd35c9c483c8e8d41ebbf9387155fcd4b53900b1f29
3
+ metadata.gz: e3a2860c691d1d3804149cd68211e0d2ddbc05dd6bc198c27af21c9dc31b82be
4
+ data.tar.gz: d315366358a5e02d9180a207c950b8872bf230c07d8b6f4bbaefed7fd9db8483
5
5
  SHA512:
6
- metadata.gz: d2be55260153ca5ea4ff173c72c5a368c5fc020ad426247bb4bdb6d40e875b1a83b56c2d61234a671ed4e650ea79e48bd5bfa0aa3038ba0681405e435d66d721
7
- data.tar.gz: 06ba92962030bef3b58a5fb44ea8aa1c6596741fe82a12d40cbcf8bd1d040ddeeaf6e717046714ab76ae7623954b118edaa127ae6cbe0e9a8999770eb0a66db5
6
+ metadata.gz: 8f786c2046c321408bb51c353df8fe672735b00ed40feae90e38331d3dee32e1535ce476770028af4ceafbccf14bdd5e40e34eddc44136405c02382dd92bec43
7
+ data.tar.gz: b606cef5fb889cecf391b90dbe829fd6d0d94424958831b79f3ed1c556f9b9adf4b4045347c62f7222df68ea77f83bce42e22184e511cd7249e4a1a3615b9ea4
data/Gemfile CHANGED
@@ -5,6 +5,9 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in browser_app_base.gemspec
6
6
  gemspec
7
7
 
8
+ gem "rack", ">= 3.0"
9
+ gem "rackup"
8
10
  gem "rake", "~> 13.0"
9
-
10
- gem "rspec", "~> 3.0"
11
+ gem "rspec", ">= 0"
12
+ gem "rack-test"
13
+ gem "sinatra"
data/README.md CHANGED
@@ -18,6 +18,13 @@ On Windows, the Edge browser is used by default.
18
18
 
19
19
  ---
20
20
 
21
+ ## Latest Changes
22
+ - Added support for Rack 3
23
+ - Added ruby-lsp environment
24
+ - Added Docker test environment for Ubuntu
25
+
26
+ ---
27
+
21
28
  ## Installation
22
29
 
23
30
  Add this line to your application's Gemfile:
@@ -281,6 +288,30 @@ This image displays the detailed setting screen, allowing you to edit individual
281
288
 
282
289
  ---
283
290
 
291
+ ## Docker Test Environment
292
+
293
+ A Docker-based test environment is available for testing the application on Ubuntu.
294
+ This setup uses X11 forwarding to display the browser window on your host machine.
295
+
296
+ ```shell
297
+ $ cd test/docker/ubuntu
298
+ $ docker-compose up -d
299
+ $ docker exec -it ubuntu bash
300
+ ```
301
+
302
+ For Ubuntu 24.04:
303
+ ```shell
304
+ $ docker-compose -f docker-compose-24.04.yml up -d
305
+ ```
306
+
307
+ Inside the container:
308
+ ```shell
309
+ $ cd /work
310
+ $ rake
311
+ ```
312
+
313
+ ---
314
+
284
315
  ## Running Tests
285
316
 
286
317
  From v0.1.9, RSpec-based testing is supported.
@@ -294,7 +325,7 @@ bundle exec rake
294
325
  or
295
326
 
296
327
  ```sh
297
- bundle exec rspec
328
+ RACK_ENV=test bundle exec rspec
298
329
  ```
299
330
 
300
331
  RSpec tasks are defined in the `Rakefile`, so `rake` will automatically run all tests.
data/README_ja.md ADDED
@@ -0,0 +1,351 @@
1
+ # BrowserAppBase
2
+
3
+ WindowsおよびLinux向けのブラウザベースデスクトップアプリケーションのテンプレートです。
4
+
5
+ LinuxではデフォルトでChromeブラウザが使用されます。
6
+ WindowsではデフォルトでEdgeブラウザが使用されます。
7
+
8
+ ---
9
+
10
+ ## 機能
11
+
12
+ - クロスプラットフォームのブラウザベースデスクトップアプリテンプレート(Windows/Linux)
13
+ - シンプルなアプリ生成コマンド (`create_browser_app`)
14
+ - `setting.json` による柔軟なアプリケーション設定
15
+ - ブラウザUIとRubyバックエンド間の通信
16
+ - RSpecベースのテストフレームワーク(v0.1.9以降)
17
+ - OSごとの簡単なブラウザ設定
18
+
19
+ ---
20
+
21
+ ## 最新の変更点
22
+ - Rack 3 をサポートしました
23
+ - ruby-lspの環境を追加しました
24
+ - Ubuntu用のDockerテスト環境を追加しました
25
+
26
+ ---
27
+
28
+ ## インストール
29
+
30
+ アプリケーションのGemfileに以下の行を追加します:
31
+
32
+ ```ruby
33
+ gem 'browser_app_base'
34
+ ```
35
+
36
+ そして実行します:
37
+
38
+ $ bundle install
39
+
40
+ または、直接インストールします:
41
+
42
+ $ gem install browser_app_base
43
+
44
+ ---
45
+
46
+ ## 使い方
47
+
48
+ create_browser_app [options]
49
+ -d, --dir dir_name アプリケーションのディレクトリ
50
+ -a, --app app_name アプリケーション名
51
+ -h, --help コマンドのヘルプ
52
+
53
+ ---
54
+
55
+ ## アプリケーションテンプレートの作成
56
+
57
+ $ create_browser_app -d /path/to/test/ -a MyApp
58
+
59
+ ---
60
+
61
+ ## アプリケーションコードの追加
62
+
63
+ $ cd /path/to/test/
64
+ $ vi my_app.rb
65
+
66
+ ```ruby
67
+ class MyApp < AppMainBase
68
+ def start(argv)
69
+ super
70
+ # ここにアプリケーションコードを追加
71
+ end
72
+
73
+ def stop()
74
+ super
75
+ # ここにアプリケーションコードを追加
76
+ end
77
+ end
78
+ ```
79
+
80
+ ---
81
+
82
+ ## UIアプリケーションのサンプル
83
+
84
+ index.html
85
+ css/index.css
86
+ js/main.js
87
+
88
+ ---
89
+
90
+ ## アプリケーションの起動
91
+
92
+ ```shell
93
+ $ /path/to/test/bin/start_my_app.rb
94
+ ```
95
+
96
+ ![app](img/app.png)
97
+
98
+ ---
99
+
100
+ ## ブラウザの設定
101
+
102
+ WindowsまたはLinux用にブラウザを設定します。
103
+
104
+ ${home}/${app_name}/config/browser.json
105
+
106
+ ```json
107
+ {
108
+ "chrome_win": "start msedge",
109
+ "chrome_win_": "start chrome",
110
+ "chrome_linux": "/bin/google-chrome"
111
+ }
112
+ ```
113
+
114
+ ---
115
+
116
+ ## ブラウザアプリケーションからRubyアプリケーションへのメッセージ送信
117
+
118
+ `send_message` 関数を使用します。
119
+
120
+ main.jsのサンプル:
121
+ ```javascript
122
+ $("#exec").click(function () {
123
+ send_message("exec:" + $("#upFile").val());
124
+ });
125
+ ```
126
+
127
+ ---
128
+
129
+ ## Rubyアプリケーションからブラウザアプリケーションへのメッセージ送信
130
+
131
+ `app_send` 関数を使用します。
132
+
133
+ my_app_sample.rbのサンプル:
134
+ ```ruby
135
+ class MyApp < AppMainBase
136
+ def start(argv)
137
+ # ポップアップメッセージ
138
+ app_send("popup:message string")
139
+
140
+ # ログメッセージ
141
+ yield "log message"
142
+ end
143
+ end
144
+ ```
145
+
146
+ ---
147
+
148
+ ## アプリケーションの設定
149
+
150
+ `setting.json` を変更することで設定を追加できます。
151
+
152
+ ${home}/${app_name}/config/setting.json
153
+
154
+ 設定例 (`setting.json`):
155
+
156
+ ```json
157
+ {
158
+ "version": 0.1,
159
+ "setting_list": [
160
+ {
161
+ "name": "name1",
162
+ "value": "value1 2 3 4",
163
+ "type": "input",
164
+ "select": "",
165
+ "description": "Setting item 1"
166
+ },
167
+ {
168
+ "name": "name2",
169
+ "value": true,
170
+ "type": "checkbox",
171
+ "select": "",
172
+ "description": "Check to enable"
173
+ },
174
+ {
175
+ "name": "name3",
176
+ "value": "3",
177
+ "type": "select",
178
+ "select": [
179
+ "1",
180
+ "2",
181
+ "3",
182
+ "4",
183
+ "5"
184
+ ],
185
+ "description": "Select item"
186
+ },
187
+ {
188
+ "name": "name4",
189
+ "value": "value4",
190
+ "type": "input",
191
+ "select": "",
192
+ "description": "Setting item 4"
193
+ },
194
+ {
195
+ "name": "name5",
196
+ "value": "value5",
197
+ "type": "input",
198
+ "select": "",
199
+ "description": "Setting item 5"
200
+ },
201
+ {
202
+ "name": "name6",
203
+ "value": "value6",
204
+ "type": "input",
205
+ "select": "",
206
+ "description": "Setting item 6"
207
+ },
208
+ {
209
+ "name": "jaon_area",
210
+ "value": {
211
+ "DEBUG": true,
212
+ "VERSION": 1
213
+ },
214
+ "type": "textarea",
215
+ "select": "",
216
+ "description": "JSON string<br>Example:<br>{<br> \"DEBUG\": true,<br> \"VERSION\": 1<br>}"
217
+ }
218
+ ]
219
+ }
220
+ ```
221
+
222
+ Rubyアプリケーションからは以下のように設定にアクセスできます:
223
+
224
+ ```ruby
225
+ class MyApp < AppMainBase
226
+ def start(argv)
227
+ # 設定値へのアクセス
228
+ puts @config["name1"]
229
+ # jaon_areaへのハッシュとしてのアクセス
230
+ p @config["jaon_area"] # => {"DEBUG"=>true, "VERSION"=>1}
231
+ end
232
+ end
233
+ ```
234
+
235
+ ---
236
+
237
+ ### setting.jsonの `jaon_area` について
238
+
239
+ `setting.json` の `jaon_area` 項目を使用すると、設定値としてJSON文字列を入力できます。
240
+ このフィールドのタイプは `"textarea"` であり、追加の設定、フラグ、カスタムパラメータなどの柔軟な構造化データを保存することを目的としています。
241
+
242
+ **例:**
243
+ ```json
244
+ {
245
+ "DEBUG": true,
246
+ "VERSION": 1
247
+ }
248
+ ```
249
+
250
+ - このフィールドは設定画面で直接編集できます。
251
+ - 値は有効なJSON形式である必要があります。
252
+ - アプリケーションは必要に応じてこのデータを解析して使用できます。
253
+
254
+ **使用例:**
255
+ - デバッグモードの切り替え (`"DEBUG": true`)
256
+ - バージョンや環境情報の保存
257
+ - 高度な設定のための任意のキーバリューペアの保存
258
+
259
+ **Rubyアプリケーションでの使用方法:**
260
+ `@config["jaon_area"]` を介してRubyのハッシュとして `jaon_area` の値にアクセスできます。
261
+ 例:
262
+ ```ruby
263
+ class MyApp < AppMainBase
264
+ def start(argv)
265
+ debug_mode = @config["jaon_area"]["DEBUG"]
266
+ version = @config["jaon_area"]["VERSION"]
267
+ puts "Debug mode: #{debug_mode}, Version: #{version}"
268
+ end
269
+ end
270
+ ```
271
+
272
+ **注意:**
273
+ 必ず有効なJSONを入力してください。フォーマットが正しくない場合、アプリケーションが設定を正しく読み込めない可能性があります。
274
+
275
+ **ヒント:**
276
+ - 実行時にアプリケーションが必要とする任意の構造化データを保存するために `jaon_area` を使用できます。
277
+ - これは機能フラグ、環境固有の設定、または単純な文字列や真偽値に収まらない高度な設定に便利です。
278
+
279
+ ---
280
+
281
+ ## 設定メニュー
282
+ 以下の画像はアプリケーションの設定メニューを示しており、ここから様々な設定オプションにアクセスして変更できます。
283
+ ![app](img/setting_menu.png)
284
+
285
+ 設定画面
286
+ この画像は詳細な設定画面を表示しており、個々の設定項目を編集できます。
287
+ ![app](img/setting.png)
288
+
289
+ ---
290
+
291
+ ## Dockerテスト環境
292
+
293
+ UbuntuでアプリケーションをテストするためのDockerベースのテスト環境が利用可能です。
294
+ この設定ではX11フォワーディングを使用して、ホストマシン上にブラウザウィンドウを表示します。
295
+
296
+ ```shell
297
+ $ cd test/docker/ubuntu
298
+ $ docker-compose up -d
299
+ $ docker exec -it ubuntu bash
300
+ ```
301
+
302
+ Ubuntu 24.04の場合:
303
+ ```shell
304
+ $ docker-compose -f docker-compose-24.04.yml up -d
305
+ ```
306
+
307
+ コンテナ内での操作:
308
+ ```shell
309
+ $ cd /work
310
+ $ rake
311
+ ```
312
+
313
+ ---
314
+
315
+ ## テストの実行
316
+
317
+ v0.1.9からRSpecベースのテストがサポートされています。
318
+ 依存関係をインストールした後、以下のコマンドでテストを実行できます:
319
+
320
+ ```sh
321
+ bundle install
322
+ bundle exec rake
323
+ ```
324
+
325
+ または
326
+
327
+ ```sh
328
+ RACK_ENV=test bundle exec rspec
329
+ ```
330
+
331
+ RSpecタスクは `Rakefile` で定義されているため、`rake` コマンドですべてのテストが自動的に実行されます。
332
+ テストコードは `spec/` ディレクトリの下に配置してください。
333
+
334
+ ---
335
+
336
+ ## 開発
337
+
338
+ このgemをローカルマシンにインストールするには、`bundle exec rake install` を実行します。
339
+ 新しいバージョンをリリースするには、`version.rb` でバージョン番号を更新し、`bundle exec rake release` を実行します。これによりバージョンのgitタグが作成され、gitコミットと作成されたタグがプッシュされ、`.gem` ファイルが [rubygems.org](https://rubygems.org) にプッシュされます。
340
+
341
+ ---
342
+
343
+ ## コントリビューション
344
+
345
+ バグレポートとプルリクエストはGitHubの [https://github.com/kuwayama1971/BrowserAppBase](https://github.com/kuwayama1971/BrowserAppBase) で歓迎します。
346
+
347
+ ---
348
+
349
+ ## ライセンス
350
+
351
+ このgemは [MIT License](https://opensource.org/licenses/MIT) の条件の下でオープンソースとして利用可能です。
@@ -1,24 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
3
  require "browser_app_base"
5
4
  require "optparse"
6
5
 
7
6
  opt = OptionParser.new
8
7
  o = {}
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 }
8
+ opt.on("-d DIR_NAME", "--dir DIR_NAME", "application directory") { |v| o[:dir] = v }
9
+ opt.on("-a APP_NAME", "--app APP_NAME", "application name") { |v| o[:app] = v }
11
10
  opt.on("-h", "--help", "command help") { puts opt; exit }
12
11
  begin
13
12
  opt.parse!(ARGV)
14
- rescue
13
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
15
14
  puts opt
16
15
  exit
17
16
  end
18
17
 
19
- if o[:dir] == nil
18
+ if o[:dir].nil? || o[:dir].strip.empty?
20
19
  puts opt
21
20
  exit
22
21
  end
23
22
 
24
- BrowserAppBase.create o
23
+ BrowserAppBase.create o
data/bin/ruby-lsp ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby3.2
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'ruby-lsp' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("ruby-lsp", "ruby-lsp")
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby3.2
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'ruby-lsp-check' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("ruby-lsp", "ruby-lsp-check")
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby3.2
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'ruby-lsp-launcher' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("ruby-lsp", "ruby-lsp-launcher")
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby3.2
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'ruby-lsp-test-exec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("ruby-lsp", "ruby-lsp-test-exec")
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 { |tmpdir|
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
- json = JSON.parse(File.read("#{home_dir}/config/setting.json"))
31
- old_version = json["version"]
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 "#{outdir}"
43
- kernel = Facter.value(: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 == "Linux"
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
@@ -30,12 +30,13 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  # Uncomment to register a new dependency of your gem
32
32
  # spec.add_dependency "example-gem", "~> 1.0"
33
+ spec.add_dependency "rack", ">= 3.0"
34
+ spec.add_dependency "rackup"
33
35
  spec.add_dependency "sinatra"
34
36
  spec.add_dependency "sinatra-contrib"
35
37
  spec.add_dependency "sinatra-websocket"
36
38
  spec.add_dependency "thin"
37
39
  spec.add_dependency "json"
38
- spec.add_dependency "facter"
39
40
 
40
41
  # For more information and examples about making a new gem, checkout our
41
42
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrowserAppBase
4
- VERSION = "0.1.9"
4
+ VERSION = "0.2.1"
5
5
  end