bormashino 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a039d1ebc67a8050439f8d2f1acd7932f9acfe1da61f865a412e3e74b33c5460
4
+ data.tar.gz: b1b32026abc7293da26ed53b7f021b3501d5946ddfd3cd56759a910bb65dd00c
5
+ SHA512:
6
+ metadata.gz: 7bde9f76ca33436380761a081ced2ee60d38d9dbb2abfe4e45ec5df7a847065e10cbb40315c271cd8f37e68ac3ab0ffe1ef2a1bc7eb9f47f50ab2d5cd4890b77
7
+ data.tar.gz: aa23838aa5de924028dbe99765afc5969bbb6a23fd3b532c0274562eff335d279bb08a7ba9cfc4f3a2cf076c12b7268ed619c00a0285ec9d44cd10b9ebd56b2f
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 keyasuda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Bormashino
2
+
3
+ see https://github.com/keyasuda/bormashino
@@ -0,0 +1,9 @@
1
+ require 'js'
2
+
3
+ module JS
4
+ class Object
5
+ def to_rb
6
+ JSON.parse(JS.global[:JSON].call(:stringify, self).inspect)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ require 'js'
2
+ require 'singleton'
3
+ require_relative 'ext/js'
4
+
5
+ module Bormashino
6
+ class LocalStorage
7
+ include Singleton
8
+
9
+ def initialize
10
+ @storage = JS.global[:localStorage]
11
+ end
12
+
13
+ def length
14
+ @storage[:length].to_rb
15
+ end
16
+
17
+ def key(index)
18
+ @storage.call(:key, index).to_rb
19
+ end
20
+
21
+ def get_item(key_name)
22
+ @storage.call(:getItem, key_name).to_rb
23
+ end
24
+
25
+ def set_item(key_name, key_value)
26
+ @storage.call(:setItem, key_name, key_value)
27
+ end
28
+
29
+ def remove_item(key_name)
30
+ @storage.call(:removeItem, key_name)
31
+ end
32
+
33
+ def clear
34
+ @storage.call(:clear)
35
+ end
36
+ end
37
+
38
+ class SessionStorage < LocalStorage
39
+ def initialize
40
+ super
41
+ @storage = JS.global[:sessionStorage]
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ require 'singleton'
2
+
3
+ module Bormashino
4
+ class LocalStorage
5
+ include Singleton
6
+ attr_reader :store
7
+
8
+ def initialize
9
+ @store = {}
10
+ end
11
+
12
+ def length
13
+ @store.size
14
+ end
15
+
16
+ def key(index)
17
+ @store.keys[index]
18
+ end
19
+
20
+ def get_item(key_name)
21
+ @store[key_name]
22
+ end
23
+
24
+ def set_item(key_name, key_value)
25
+ @store[key_name] = key_value
26
+ end
27
+
28
+ def remove_item(key_name)
29
+ @store.delete(key_name)
30
+ end
31
+
32
+ def clear
33
+ @store.clear
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ require 'uri'
2
+ require 'stringio'
3
+
4
+ module Bormashino
5
+ module Server
6
+ def self.mount(app_class)
7
+ @app = app_class.new
8
+ end
9
+
10
+ def self.request(method, target, payload = '', referer = '')
11
+ u = URI(target)
12
+
13
+ @app.call({
14
+ 'HTTP_HOST' => 'example.com:0',
15
+ 'REQUEST_METHOD' => method,
16
+ 'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
17
+ 'QUERY_STRING' => u.query,
18
+ 'PATH_INFO' => u.path,
19
+ 'HTTP_REFERER' => referer,
20
+ 'rack.input' => StringIO.new(payload),
21
+ 'rack.errors' => StringIO.new(''),
22
+ }).to_json
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ require 'digest/sha2'
2
+
3
+ module OpenSSL
4
+ module Digest
5
+ class SHA1; end
6
+ class SHA256; end
7
+ end
8
+
9
+ module HMAC
10
+ def self.hexdigest(_, secret, data)
11
+ Digest::SHA2.hexdigest("#{secret}#{data}")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module Zlib
2
+ module Deflate
3
+ def self.deflate(src)
4
+ src
5
+ end
6
+ end
7
+
8
+ module Inflate
9
+ def self.inflate(src)
10
+ src
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,52 @@
1
+ require 'fileutils'
2
+ require 'uri'
3
+
4
+ RUBY_RELEASE = 'https://github.com/ruby/ruby.wasm/releases/download/2022-04-25-a/ruby-head-wasm32-unknown-wasi-full-js.tar.gz'.freeze
5
+ WASI_VFS_RELEASE = 'https://github.com/kateinoigakukun/wasi-vfs/releases/download/v0.1.1/wasi-vfs-cli-x86_64-unknown-linux-gnu.zip'.freeze
6
+ RUBY_ROOT = File.basename(URI(RUBY_RELEASE).path).split('.').first.sub('ruby-', '')
7
+ WASI_VFS = './wasi-vfs'.freeze
8
+ TMP = 'tmp'.freeze
9
+ DIGEST = 'js/ruby-digest.js'.freeze
10
+
11
+ namespace :bormashino do
12
+ desc 'ruby.wasm及びwasi-vfsをダウンロードする'
13
+ task :download do
14
+ system "curl -L #{RUBY_RELEASE} | tar xz"
15
+ FileUtils.rm(File.join(RUBY_ROOT, '/usr/local/lib/libruby-static.a'))
16
+ FileUtils.rm_rf(File.join(RUBY_ROOT, '/usr/local/include'))
17
+
18
+ system "curl -L '#{WASI_VFS_RELEASE}' | gzip -d > wasi-vfs"
19
+ system 'chmod u+x wasi-vfs'
20
+ end
21
+
22
+ desc 'wasi_vfsでアプリに使用するRubyスクリプト群を埋め込む'
23
+ task :pack, [:additional_args] do |_, args|
24
+ gem_dir = Gem::Specification.find_by_name('bormashino').gem_dir
25
+
26
+ FileUtils.mkdir_p('tmp')
27
+ system([
28
+ "#{WASI_VFS} pack",
29
+ "#{RUBY_ROOT}/usr/local/bin/ruby",
30
+ "--mapdir /usr::#{RUBY_ROOT}/usr",
31
+ '--mapdir /src::./src',
32
+ "--mapdir /stub::'#{gem_dir}/lib/bormashino/stub'",
33
+ args[:additional_args],
34
+ '-o tmp/ruby.wasm',
35
+ ].compact.join(' '))
36
+ end
37
+
38
+ desc 'pack済みのruby.wasmのMD5を取りファイル名につけてコピーし、import用のJSを出力する'
39
+ task :digest, [:destination] do |_, args|
40
+ digest = `md5sum tmp/ruby.wasm`.split.first
41
+ FileUtils.cp('tmp/ruby.wasm', "#{args[:destination]}/ruby.#{digest}.wasm")
42
+ File.open(DIGEST, 'w') { |f|
43
+ f.puts "export default rubyDigest = '#{digest}'
44
+ "
45
+ }
46
+ end
47
+
48
+ desc '指定ディレクトリ中のdigest付きruby.wasmを削除する'
49
+ task :delete_wasms, [:target] do |_, args|
50
+ Dir.glob(File.join(args[:target], 'ruby.*.wasm')).each { |f| FileUtils.rm(f) }
51
+ end
52
+ end
@@ -0,0 +1,10 @@
1
+ require 'json/pure'
2
+ require 'cgi'
3
+
4
+ module Bormashino
5
+ module Utils
6
+ def self.to_rb_value(escaped_json)
7
+ JSON.parse(CGI.unescape(escaped_json))
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bormashino
4
+ VERSION = '0.1.0'
5
+ end
data/lib/bormashino.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative 'bormashino/version'
2
+ require_relative 'bormashino/utils'
3
+ require_relative 'bormashino/server'
4
+
5
+ module Bormashino
6
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bormashino
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenichiro Yasuda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json_pure
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.6.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.6.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: sinatra
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: ruby2_keywords
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.4
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '='
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.4
61
+ description: ' With "Bormaŝino" you can build SPAs written in Ruby powered by Ruby
62
+ WebAssembly build and Sinatra (or other rack-based web application frameworks).
63
+
64
+ '
65
+ email:
66
+ - keyasuda@users.noreply.github.com
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - LICENSE.txt
72
+ - README.md
73
+ - lib/bormashino.rb
74
+ - lib/bormashino/ext/js.rb
75
+ - lib/bormashino/local_storage.rb
76
+ - lib/bormashino/mock/local_storage.rb
77
+ - lib/bormashino/server.rb
78
+ - lib/bormashino/stub/openssl.rb
79
+ - lib/bormashino/stub/zlib.rb
80
+ - lib/bormashino/tasks/bormashino.rake
81
+ - lib/bormashino/utils.rb
82
+ - lib/bormashino/version.rb
83
+ homepage: https://github.com/keyasuda/bormashino
84
+ licenses:
85
+ - MIT
86
+ metadata:
87
+ homepage_uri: https://github.com/keyasuda/bormashino
88
+ source_code_uri: https://github.com/keyasuda/bormashino
89
+ changelog_uri: https://github.com/keyasuda/bormashino/blob/main/CHANGELOG.md
90
+ rubygems_mfa_required: 'true'
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 3.2.0.pre.preview1
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.4.0.dev
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: The package to build SPAs with Ruby
110
+ test_files: []