Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes found while updating Scarpe-Wasm to current #434

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/scarpe/shoes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

require "minitest"
require "scarpe/cats_cradle" # Currently needed for CCHelpers
require "scarpe/components/string_helpers"

# Test framework code to allow Scarpe to execute Shoes-Spec test code.
# This will run inside the exe/scarpe child process, then send
# results back to the parent Minitest process.

module Scarpe::Test
# Cut down from Rails camelize
def self.camelize(string)
string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
end

# Is it at all reasonable to define more than one test to run in the same Shoes run? Probably not.
# They'll leave in-memory residue.
def self.run_shoes_spec_test_code(code, class_name: "TestShoesSpecCode", test_name: "test_shoes_spec")
Expand Down Expand Up @@ -43,7 +38,7 @@ class << test_obj
end

test_class = Class.new(Scarpe::ShoesSpecTest)
Object.const_set(camelize(class_name), test_class)
Object.const_set(Scarpe::Components::StringHelpers.camelize(class_name), test_class)
test_name = "test_" + test_name unless test_name.start_with?("test_")
test_class.define_method(test_name) do
eval(code)
Expand Down
8 changes: 7 additions & 1 deletion lib/scarpe/wv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require "scarpe/components/html" # HTML renderer
require "scarpe/components/modular_logger"
require "scarpe/components/promises"
require "scarpe/components/string_helpers"

# Module to contain the various Scarpe Webview classes
module Scarpe::Webview
Expand All @@ -21,6 +22,12 @@ module Scarpe::Webview
ren = ENV["SCARPE_HTML_RENDERER"] || "calzini"
# This should *not* be require_relative so that other gems can implement HTML renderers.
require "scarpe/components/#{ren}"
class Scarpe::Webview::Drawable < Shoes::Linkable
# By default it's Scarpe::Components::Calzini
comp = Scarpe::Components::StringHelpers.camelize(ENV["SCARPE_HTML_RENDERER"] || "calzini")
mod = Scarpe::Components.const_get(comp)
include mod
end

# Set up hierarchical logging using the SCARPE_LOG_CONFIG var for configuration
log_config = if ENV["SCARPE_LOG_CONFIG"]
Expand Down Expand Up @@ -69,7 +76,6 @@ module Scarpe::Webview
require_relative "wv/edit_box"
require_relative "wv/edit_line"
require_relative "wv/list_box"
require_relative "wv/alert"
require_relative "wv/span"
require_relative "wv/shape"

Expand Down
17 changes: 0 additions & 17 deletions lib/scarpe/wv/alert.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/scarpe/wv/list_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ListBox < Drawable
attr_reader :selected_item, :items, :height, :width, :choose

def initialize(properties)
super(properties)
super

bind("change") do |new_item|
send_self_event(new_item, event_name: "change")
Expand Down
6 changes: 1 addition & 5 deletions lib/scarpe/wv/shape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

module Scarpe::Webview
class Shape < Drawable
def initialize(properties)
super(properties)
end

def to_html
@children ||= []
child_markup = @children.map(&:to_html).join

color = @draw_context["fill"] || "black"
self_markup = ::Scarpe::Components::HTML.render do |h|
self_markup = HTML.render do |h|
h.div(id: html_id, style: style) do
h.svg(width: "400", height: "500") do
h.path(d: path_from_shape_commands, style: "fill:#{color};stroke-width:2;")
Expand Down
4 changes: 2 additions & 2 deletions lib/scarpe/wv/web_wrangler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ def run

# From webview:
# 0 - Width and height are default size
# 1 - Width and height are minimum bonds
# 2 - Width and height are maximum bonds
# 1 - Width and height are minimum bounds
# 2 - Width and height are maximum bounds
# 3 - Window size can not be changed by a user
hint = @resizable ? 0 : 3

Expand Down
6 changes: 0 additions & 6 deletions scarpe-components/lib/scarpe/components/calzini.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,3 @@ def radians_to_degrees(radians)
radians * (180.0 / Math::PI)
end
end

if ENV["SCARPE_HTML_RENDERER"].nil? || ENV["SCARPE_HTML_RENDERER"] == "calzini"
class Scarpe::Webview::Drawable < Shoes::Linkable
include Scarpe::Components::Calzini
end
end
10 changes: 10 additions & 0 deletions scarpe-components/lib/scarpe/components/string_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Scarpe; module Components; end; end
module Scarpe::Components::StringHelpers
# Cut down from Rails camelize
def self.camelize(string)
string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
end
end
6 changes: 0 additions & 6 deletions scarpe-components/lib/scarpe/components/tiranti.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,3 @@ def para_elt_and_size(props)
end
end
end

if ENV["SCARPE_HTML_RENDERER"] == "tiranti"
class Scarpe::Webview::Drawable < Shoes::Linkable
include Scarpe::Components::Tiranti
end
end
7 changes: 6 additions & 1 deletion test/test_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class TestExamplesWithWebview < LoggedScarpeTest

examples_to_test.each do |example_filename|
example = example_filename.gsub("/", "_").gsub("-", "_").gsub(/.rb\Z/, "")
define_method("test_webview_#{example}") do
define_method("test_webview_calzini_#{example}") do
ENV["SCARPE_HTML_RENDERER"] = "calzini"
run_test_scarpe_app(example_filename, exit_immediately: true)
end
define_method("test_webview_tiranti_#{example}") do
ENV["SCARPE_HTML_RENDERER"] = "tiranti"
run_test_scarpe_app(example_filename, exit_immediately: true)
end
end
Expand Down