scarpe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6a44360a846b28a39737892026ef474b986dd036ed71eeed8d5c5e6588dad563
4
+ data.tar.gz: 2704f0ed11ffda57b34a359ae5c36400a53c39caf21cc121679a6378aa60999a
5
+ SHA512:
6
+ metadata.gz: c189c1086530de076a059d4911c50f0a89a05f0cba0bcb53251cd730458e604a5e6cd98785e6541e031b81e3fd711f61e60aceef1dbd20f81566a7d22d44de16
7
+ data.tar.gz: 987612a12cc4da3cc846977f1807e316613603f904aa804a90abcb927d8a52fc29920fd3055f83646ca141966f47cb9e0f5f6d35c90e215d054d123233078da9
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-02-09
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in scarpe.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 TODO: Write your name
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,46 @@
1
+ # Scarpe
2
+
3
+ Scarpe is me trying to rebuild shoes using ruby but also new web technology, like using HTML and your browser as the UI backend. The name `scarpe` just means shoes in
4
+ italian, so I thought it would be a fitting name. This is REALLY incomplete and it's not close to be feature complete with shoes (any version) in any way.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'scarpe'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install scarpe
21
+
22
+ ## Usage
23
+
24
+ Create an hello world application with:
25
+
26
+ ```ruby
27
+ require "scarpe"
28
+
29
+ Scarpe.app do
30
+ para "Hello World"
31
+ end
32
+ ```
33
+
34
+ More examples can be found in the `examples` folder!
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/scarpe. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/scarpe/blob/master/CODE_OF_CONDUCT.md).
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
43
+
44
+ ## Code of Conduct
45
+
46
+ Everyone interacting in the Scarpe project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/scarpe/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "scarpe"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ require "scarpe"
2
+
3
+ Scarpe.app do
4
+ @push = button "Push me"
5
+ @note = para "Nothing pushed so far"
6
+ @push.click {
7
+ @note.replace "Aha! Click!"
8
+ }
9
+ end
@@ -0,0 +1,5 @@
1
+ require "scarpe"
2
+
3
+ Scarpe.app do
4
+ para "Hello World"
5
+ end
data/examples/image.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "scarpe"
2
+
3
+ Scarpe.app do
4
+ image "http://shoesrb.com/manual/static/shoes-icon.png"
5
+ end
data/examples/slots.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "scarpe"
2
+
3
+ Scarpe.app do
4
+ flow do
5
+ button "Click"
6
+ button "Clickaty"
7
+ end
8
+ stack do
9
+ button "Boop"
10
+ button "Bip"
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ module Scarpe
2
+ class Button
3
+ def initialize(app, text, &block)
4
+ @app = app
5
+ @text = text
6
+ @block = block
7
+ @app.append(render)
8
+ end
9
+
10
+ def function_name
11
+ object_id
12
+ end
13
+
14
+ def click(&block)
15
+ @block = block
16
+ end
17
+
18
+ def render
19
+ @app.bind(function_name) do
20
+ if @block
21
+ @block.call
22
+ end
23
+ end
24
+ "<button id=#{object_id} onclick='scarpeHandler(#{function_name})'>#{@text}</button>"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ module Scarpe
2
+ module Container
3
+ def append(&block)
4
+ prev_id = @app.current_id
5
+ @app.current_id = object_id
6
+ @app.instance_eval &block
7
+ @app.current_id = prev_id
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ module Scarpe
2
+ class EditLine
3
+ def initialize(app, &block)
4
+ @app = app
5
+ @block = block
6
+ @text = ""
7
+ @app.append(render)
8
+ end
9
+
10
+ def function_name
11
+ object_id
12
+ end
13
+
14
+ def change(&block)
15
+ @block = block
16
+ end
17
+
18
+ def text
19
+ @text
20
+ end
21
+
22
+ def text=(text)
23
+ @text = text
24
+ if @app.window.is_running
25
+ @app.window.eval("document.getElementById(#{object_id}).value = \"#{@text}\";")
26
+ end
27
+ end
28
+
29
+ def render
30
+ @app.bind(function_name) do |text|
31
+ @text = text
32
+ if @block
33
+ @block.call(text)
34
+ end
35
+ end
36
+ "<input id=#{object_id} oninput='scarpeHandler(#{function_name}, this.value)' value='#{@text}'></input>"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ module Scarpe
2
+ class Flow
3
+ include Scarpe::Container
4
+
5
+ attr_reader :app
6
+ def initialize(app, &block)
7
+ @app = app
8
+ @app.append(render)
9
+ append(&block)
10
+ end
11
+
12
+ def render
13
+ "<div style='display: flex; flex-direction: row' id=#{object_id}></div>"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module Scarpe
2
+ class Image
3
+ def initialize(app, url)
4
+ @app = app
5
+ @url = url
6
+ @app.append(render)
7
+ end
8
+
9
+ def render
10
+ puts "<img id=#{object_id} src=\"#{@url}\">"
11
+ "<img id=#{object_id} src='#{@url}'>"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ module Scarpe
2
+ class InternalApp
3
+ attr_reader :window
4
+ attr_accessor :current_id
5
+ def initialize(window)
6
+ @window = window
7
+ @current_id = object_id
8
+ @callbacks = {}
9
+ end
10
+
11
+ def bind(name, &block)
12
+ @callbacks[name] = block
13
+ end
14
+
15
+ def handle_callback(name, *args)
16
+ @callbacks[name].call(*args)
17
+ end
18
+
19
+ def render(&block)
20
+ instance_eval &block
21
+ end
22
+
23
+ def append(el)
24
+ @window.eval("document.getElementById(#{current_id}).insertAdjacentHTML('beforeend', \"#{el}\")")
25
+ end
26
+
27
+ def para(text)
28
+ Scarpe::Para.new(self, text)
29
+ end
30
+ def stack(&block)
31
+ Scarpe::Stack.new(self, &block)
32
+ end
33
+ def flow(&block)
34
+ Scarpe::Flow.new(self, &block)
35
+ end
36
+ def button(text, &block)
37
+ Scarpe::Button.new(self, text, &block)
38
+ end
39
+ def image(url)
40
+ Scarpe::Image.new(self, url)
41
+ end
42
+ def edit_line(&block)
43
+ Scarpe::EditLine.new(self, &block)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ module Scarpe
2
+ class Para
3
+ def initialize(app, text)
4
+ @app = app
5
+ @text = text
6
+ @app.append(render)
7
+ end
8
+
9
+ def render
10
+ "<p id=#{object_id}>#{@text}</p>"
11
+ end
12
+
13
+ def replace(text)
14
+ @text = text
15
+ @app.window.eval("document.getElementById(#{object_id}).innerText = \"#{text}\"")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module Scarpe
2
+ class Stack
3
+ include Scarpe::Container
4
+
5
+ attr_reader :app
6
+ def initialize(app, &block)
7
+ @app = app
8
+ @app.append(render)
9
+ append(&block)
10
+ end
11
+
12
+ def render
13
+ "<div style='display: flex; flex-direction: column' id=#{object_id}></div>"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Scarpe
4
+ VERSION = "0.1.0"
5
+ end
data/lib/scarpe.rb ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "webview_ruby"
4
+ require 'securerandom'
5
+
6
+ require_relative "scarpe/container"
7
+ require_relative "scarpe/version"
8
+ require_relative "scarpe/para"
9
+ require_relative "scarpe/stack"
10
+ require_relative "scarpe/flow"
11
+ require_relative "scarpe/button"
12
+ require_relative "scarpe/image"
13
+ require_relative "scarpe/edit_line"
14
+ require_relative "scarpe/internal_app"
15
+
16
+
17
+ module Scarpe
18
+ def self.app(opts = {}, &blk)
19
+ w = WebviewRuby::Webview.new(debug: true)
20
+ internal_app = Scarpe::InternalApp.new(w)
21
+ w.bind("scarpeInit") do
22
+ internal_app.render(&blk)
23
+ end
24
+ w.bind("scarpeHandler") do |*args|
25
+ internal_app.handle_callback(*args)
26
+ end
27
+ w.init("scarpeInit();")
28
+ w.set_title("example")
29
+ w.set_size(480, 320)
30
+ w.navigate("data:text/html, <body id=#{internal_app.object_id}></body>")
31
+ w.run
32
+ w.destroy
33
+ end
34
+ end
data/sig/scarpe.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Scarpe
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scarpe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marco Concetto Rudilosso
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: webview_ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - marcoc.r@outlook.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
37
+ - Gemfile
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - examples/button.rb
44
+ - examples/hello_world.rb
45
+ - examples/image.rb
46
+ - examples/slots.rb
47
+ - lib/scarpe.rb
48
+ - lib/scarpe/button.rb
49
+ - lib/scarpe/container.rb
50
+ - lib/scarpe/edit_line.rb
51
+ - lib/scarpe/flow.rb
52
+ - lib/scarpe/image.rb
53
+ - lib/scarpe/internal_app.rb
54
+ - lib/scarpe/para.rb
55
+ - lib/scarpe/stack.rb
56
+ - lib/scarpe/version.rb
57
+ - sig/scarpe.rbs
58
+ homepage: https://github.com/Maaarcocr/scarpe
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ homepage_uri: https://github.com/Maaarcocr/scarpe
63
+ source_code_uri: https://github.com/Maaarcocr/scarpe
64
+ changelog_uri: https://github.com/Maaarcocr/scarpe/blob/main/CHANGELOG.md
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 2.6.0
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.3.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Scarpe - shoes but running on webview
84
+ test_files: []