scarpe 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -1
- data/CHANGELOG.md +36 -4
- data/Gemfile +2 -1
- data/Gemfile.lock +13 -3
- data/LICENSE.txt +7 -1
- data/README.md +77 -14
- data/Rakefile +67 -0
- data/examples/Edit_box_Styles.rb +8 -0
- data/examples/Kerning.rb +7 -0
- data/examples/border.rb +11 -0
- data/examples/check.rb +2 -0
- data/examples/download_and_show_image.rb +3 -0
- data/examples/flags/finland.rb +15 -0
- data/examples/flags/italy.rb +11 -0
- data/examples/flags/mauritius.rb +14 -0
- data/examples/font_family.rb +17 -0
- data/examples/font_shorthand.rb +9 -0
- data/examples/gen.rb +4 -0
- data/examples/legacy/not_checked/shoes-manual/append.rb +10 -0
- data/examples/legacy/not_checked/shoes-manual/background_change.rb +12 -0
- data/examples/legacy/not_checked/shoes-manual/background_pattern.rb +5 -0
- data/examples/legacy/not_checked/shoes-manual/basic_app.rb +8 -0
- data/examples/legacy/not_checked/shoes-manual/border.rb +9 -0
- data/examples/legacy/not_checked/shoes-manual/builtins/FONTS.rb +5 -0
- data/examples/legacy/not_checked/shoes-manual/builtins/ask.rb +2 -0
- data/examples/legacy/not_checked/shoes-manual/builtins/ask_color.rb +5 -0
- data/examples/legacy/not_checked/shoes-manual/builtins/ask_open_file.rb +5 -0
- data/examples/legacy/not_checked/shoes-manual/builtins/ask_save_folder.rb +2 -0
- data/examples/legacy/not_checked/shoes-manual/builtins/confirm.rb +4 -0
- data/examples/legacy/not_checked/shoes-manual/builtins/debug.rb +2 -0
- data/examples/legacy/not_checked/shoes-manual/builtins/info.rb +3 -0
- data/examples/legacy/not_checked/shoes-manual/button.rb +9 -0
- data/examples/legacy/not_checked/shoes-manual/clear.rb +7 -0
- data/examples/legacy/not_checked/shoes-manual/custom_header.rb +13 -0
- data/examples/legacy/not_checked/shoes-manual/displace.rb +14 -0
- data/examples/legacy/not_checked/shoes-manual/edit_box.rb +8 -0
- data/examples/legacy/not_checked/shoes-manual/fill_pattern.rb +5 -0
- data/examples/legacy/not_checked/shoes-manual/fonts.rb +7 -0
- data/examples/legacy/not_checked/shoes-manual/gutter.rb +6 -0
- data/examples/legacy/not_checked/shoes-manual/image_web.rb +4 -0
- data/examples/legacy/not_checked/shoes-manual/keypress.rb +7 -0
- data/examples/legacy/not_checked/shoes-manual/list_box.rb +10 -0
- data/examples/legacy/not_checked/shoes-manual/motion.rb +10 -0
- data/examples/legacy/not_checked/shoes-manual/mouse.rb +8 -0
- data/examples/legacy/not_checked/shoes-manual/move.rb +14 -0
- data/examples/legacy/not_checked/shoes-manual/nested_ovals.rb +8 -0
- data/examples/legacy/not_checked/shoes-manual/oval.rb +7 -0
- data/examples/legacy/not_checked/shoes-manual/ovals.rb +6 -0
- data/examples/legacy/not_checked/shoes-manual/ovals_image.rb +8 -0
- data/examples/legacy/not_checked/shoes-manual/prepend.rb +7 -0
- data/examples/legacy/not_checked/shoes-manual/progress_bar.rb +10 -0
- data/examples/legacy/not_checked/shoes-manual/radio.rb +18 -0
- data/examples/legacy/not_checked/shoes-manual/radio_alternative_1.rb +7 -0
- data/examples/legacy/not_checked/shoes-manual/radio_alternative_2.rb +9 -0
- data/examples/legacy/not_checked/shoes-manual/rotate_rectangle.rb +6 -0
- data/examples/legacy/not_checked/shoes-manual/shape.rb +11 -0
- data/examples/legacy/not_checked/shoes-manual/static/avatar.png +0 -0
- data/examples/legacy/not_checked/shoes-manual/stroke.rb +5 -0
- data/examples/legacy/not_checked/shoes-manual/style.rb +3 -0
- data/examples/legacy/not_checked/shoes-manual/style_alternative_1.rb +4 -0
- data/examples/legacy/not_checked/shoes-manual/style_alternative_2.rb +5 -0
- data/examples/legacy/not_checked/shoes-manual/style_length.rb +5 -0
- data/examples/legacy/not_checked/shoes-manual/timer.rb +6 -0
- data/examples/legacy/not_checked/shoes-manual/trigger_window.rb +8 -0
- data/examples/legacy/not_checked/shoes-manual/window_owner.rb +8 -0
- data/examples/legacy/working/shoes_manual/alert_button.rb +2 -0
- data/examples/legacy/working/shoes_manual/animate.rb +7 -0
- data/examples/legacy/working/shoes_manual/background_para.rb +4 -0
- data/examples/legacy/working/shoes_manual/button_alternative.rb +7 -0
- data/examples/legacy/working/shoes_manual/checkbox.rb +17 -0
- data/examples/legacy/working/shoes_manual/download.rb +12 -0
- data/examples/legacy/working/shoes_manual/edit_box.rb +6 -0
- data/examples/legacy/working/shoes_manual/editline.rb +7 -0
- data/examples/legacy/working/shoes_manual/fixed_height.rb +8 -0
- data/examples/legacy/working/shoes_manual/fixed_width.rb +12 -0
- data/examples/legacy/working/shoes_manual/image.rb +5 -0
- data/examples/legacy/working/shoes_manual/instance_variable_check.rb +10 -0
- data/examples/legacy/working/shoes_manual/message.rb +18 -0
- data/examples/legacy/working/shoes_manual/rectangle.rb +6 -0
- data/examples/legacy/working/shoes_manual/save_download.rb +12 -0
- data/examples/legacy/working/shoes_manual/self_check.rb +10 -0
- data/examples/legacy/working/shoes_manual/stack.rb +7 -0
- data/examples/legacy/working/shoes_manual/style_info.rb +8 -0
- data/examples/legacy/working/shoes_manual/utf8_support.rb +8 -0
- data/examples/legacy/working/shoes_manual/width.rb +4 -0
- data/examples/local_assets/multi_image.rb +5 -0
- data/examples/local_assets/small.png +0 -0
- data/examples/local_fonts.rb +3 -0
- data/examples/margin.rb +13 -0
- data/examples/margin_check.rb +27 -0
- data/examples/oval-with-kwargs.rb +3 -0
- data/examples/oval.rb +26 -0
- data/examples/para_font_styles.rb +17 -0
- data/examples/para_font_variant.rb +6 -0
- data/examples/para_fontweight.rb +13 -0
- data/examples/parse_xl_funnies.rb +3 -0
- data/examples/rect.rb +1 -1
- data/examples/scarpe_ext.rb +3 -0
- data/examples/shapes/star.rb +1 -3
- data/examples/spacing.rb +1 -1
- data/examples/span.rb +4 -2
- data/lacci/lacci.gemspec +2 -2
- data/lacci/lib/lacci/scarpe_cli.rb +0 -1
- data/lacci/lib/lacci/version.rb +1 -1
- data/lacci/lib/scarpe/niente/display_service.rb +5 -1
- data/lacci/lib/scarpe/niente/drawable.rb +2 -0
- data/lacci/lib/scarpe/niente/shoes_spec.rb +7 -1
- data/lacci/lib/scarpe/niente.rb +14 -2
- data/lacci/lib/shoes/app.rb +44 -50
- data/lacci/lib/shoes/constants.rb +23 -2
- data/lacci/lib/shoes/display_service.rb +43 -4
- data/lacci/lib/shoes/drawable.rb +309 -35
- data/lacci/lib/shoes/drawables/arc.rb +2 -24
- data/lacci/lib/shoes/drawables/arrow.rb +2 -22
- data/lacci/lib/shoes/drawables/border.rb +28 -0
- data/lacci/lib/shoes/drawables/button.rb +4 -20
- data/lacci/lib/shoes/drawables/check.rb +7 -3
- data/lacci/lib/shoes/drawables/document_root.rb +4 -4
- data/lacci/lib/shoes/drawables/edit_box.rb +6 -5
- data/lacci/lib/shoes/drawables/edit_line.rb +5 -4
- data/lacci/lib/shoes/drawables/flow.rb +3 -5
- data/lacci/lib/shoes/drawables/font_helper.rb +62 -0
- data/lacci/lib/shoes/drawables/image.rb +2 -2
- data/lacci/lib/shoes/drawables/line.rb +4 -7
- data/lacci/lib/shoes/drawables/link.rb +5 -8
- data/lacci/lib/shoes/drawables/list_box.rb +8 -5
- data/lacci/lib/shoes/drawables/oval.rb +48 -0
- data/lacci/lib/shoes/drawables/para.rb +106 -18
- data/lacci/lib/shoes/drawables/progress.rb +2 -1
- data/lacci/lib/shoes/drawables/radio.rb +5 -3
- data/lacci/lib/shoes/drawables/rect.rb +5 -4
- data/lacci/lib/shoes/drawables/shape.rb +2 -1
- data/lacci/lib/shoes/drawables/slot.rb +99 -8
- data/lacci/lib/shoes/drawables/stack.rb +6 -11
- data/lacci/lib/shoes/drawables/star.rb +8 -30
- data/lacci/lib/shoes/drawables/text_drawable.rb +93 -34
- data/lacci/lib/shoes/drawables/video.rb +3 -2
- data/lacci/lib/shoes/drawables/widget.rb +8 -3
- data/lacci/lib/shoes/drawables.rb +2 -1
- data/lacci/lib/shoes/errors.rb +13 -3
- data/lacci/lib/shoes/margin_helper.rb +79 -0
- data/lacci/lib/shoes.rb +4 -3
- data/lacci/test/.gitignore +1 -0
- data/lacci/test/test_draw_context.rb +167 -0
- data/lacci/test/test_font_helper.rb +57 -0
- data/lacci/test/test_helper.rb +31 -4
- data/lacci/test/test_lacci.rb +93 -6
- data/lacci/test/test_margin_helper.rb +82 -0
- data/lacci/test/test_niente_test_infra.rb +26 -0
- data/lacci/test/test_oval.rb +82 -0
- data/lacci/test/test_parenting.rb +140 -0
- data/lacci/test/test_text_drawables.rb +23 -0
- data/lib/scarpe/assets.rb +18 -0
- data/lib/scarpe/cats_cradle.rb +57 -98
- data/lib/scarpe/shoes_spec.rb +22 -43
- data/lib/scarpe/version.rb +1 -1
- data/lib/scarpe/wv/app.rb +1 -0
- data/lib/scarpe/wv/arc.rb +0 -4
- data/lib/scarpe/wv/border.rb +15 -0
- data/lib/scarpe/wv/control_interface.rb +2 -10
- data/lib/scarpe/wv/document_root.rb +2 -2
- data/lib/scarpe/wv/drawable.rb +6 -40
- data/lib/scarpe/wv/edit_box.rb +4 -1
- data/lib/scarpe/wv/edit_line.rb +5 -2
- data/lib/scarpe/wv/image.rb +2 -5
- data/lib/scarpe/wv/link.rb +4 -2
- data/lib/scarpe/wv/oval.rb +13 -0
- data/lib/scarpe/wv/para.rb +1 -0
- data/lib/scarpe/wv/scarpe_extensions.rb +8 -0
- data/lib/scarpe/wv/shape.rb +10 -5
- data/lib/scarpe/wv/text_drawable.rb +72 -14
- data/lib/scarpe/wv/web_wrangler.rb +33 -11
- data/lib/scarpe/wv/webview_local_display.rb +6 -2
- data/lib/scarpe/wv.rb +8 -1
- data/scarpe-components/Gemfile +4 -1
- data/scarpe-components/Gemfile.lock +2 -3
- data/scarpe-components/README.md +2 -2
- data/scarpe-components/assets/bootstrap-themes/bootstrap-cerulean.css +12229 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-cosmo.css +11810 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-cyborg.css +12210 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-darkly.css +12153 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-flatly.css +12126 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-icons.min.css +5 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-journal.css +12099 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-litera.css +12211 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-lumen.css +12369 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-lux.css +11928 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-materia.css +13184 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-minty.css +12177 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-morph.css +12750 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-pulse.css +11890 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-quartz.css +12622 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-sandstone.css +12201 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-simplex.css +12186 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-sketchy.css +12451 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-slate.css +12492 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-solar.css +12149 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-spacelab.css +12266 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-superhero.css +12216 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-united.css +12077 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-vapor.css +12549 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-yeti.css +12325 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap-zephyr.css +12283 -0
- data/scarpe-components/assets/bootstrap-themes/bootstrap.bundle.min.js +7 -0
- data/scarpe-components/lib/scarpe/components/asset_server.rb +219 -0
- data/scarpe-components/lib/scarpe/components/base64.rb +22 -0
- data/scarpe-components/lib/scarpe/components/calzini/{art_widgets.rb → art_drawables.rb} +42 -18
- data/scarpe-components/lib/scarpe/components/calzini/border.rb +38 -0
- data/scarpe-components/lib/scarpe/components/calzini/button.rb +6 -8
- data/scarpe-components/lib/scarpe/components/calzini/misc.rb +7 -17
- data/scarpe-components/lib/scarpe/components/calzini/para.rb +213 -11
- data/scarpe-components/lib/scarpe/components/calzini/slots.rb +14 -60
- data/scarpe-components/lib/scarpe/components/calzini.rb +88 -1
- data/scarpe-components/lib/scarpe/components/errors.rb +4 -0
- data/scarpe-components/lib/scarpe/components/html.rb +4 -1
- data/scarpe-components/lib/scarpe/components/minitest_export_reporter.rb +11 -3
- data/scarpe-components/lib/scarpe/components/minitest_result.rb +41 -0
- data/scarpe-components/lib/scarpe/components/print_logger.rb +17 -2
- data/scarpe-components/lib/scarpe/components/process_helpers.rb +37 -0
- data/scarpe-components/lib/scarpe/components/segmented_file_loader.rb +1 -1
- data/scarpe-components/lib/scarpe/components/tiranti.rb +42 -100
- data/scarpe-components/lib/scarpe/components/unit_test_helpers.rb +3 -1
- data/scarpe-components/lib/scarpe/components/version.rb +1 -1
- data/scarpe-components/test/assets/big-image.png +0 -0
- data/scarpe-components/test/assets/big-stylesheet.css +497 -0
- data/scarpe-components/test/assets/little-image.png +0 -0
- data/scarpe-components/test/assets/little-stylesheet.css +1 -0
- data/scarpe-components/test/calzini/test_calzini_art_drawables.rb +7 -7
- data/scarpe-components/test/calzini/test_calzini_button.rb +7 -5
- data/scarpe-components/test/calzini/test_calzini_misc.rb +9 -9
- data/scarpe-components/test/calzini/test_calzini_para.rb +6 -9
- data/scarpe-components/test/calzini/test_calzini_slots.rb +12 -57
- data/scarpe-components/test/calzini/test_calzini_text_drawables.rb +83 -18
- data/scarpe-components/test/calzini/test_various.rb +133 -0
- data/scarpe-components/test/test_asset_server.rb +72 -0
- data/scarpe-components/test/test_components.rb +31 -2
- data/scarpe-components/test/test_helper.rb +0 -1
- data/scarpe-components/test/test_minitest_result.rb +7 -0
- data/scarpe-components/test/test_segmented_app_files.rb +2 -0
- data/tasks/check_html_fixtures.rb +140 -0
- data/tasks/regenerate_html_fixtures.rb +104 -0
- data/templates/class_template_with_shapes.erb +0 -11
- metadata +180 -32
- data/lacci/lib/scarpe/niente/logger.rb +0 -29
- data/lacci/lib/shoes/drawables/span.rb +0 -27
- data/lacci/lib/shoes/spacing.rb +0 -9
- data/lib/scarpe/evented_assertions.rb +0 -121
- data/lib/scarpe/wv/span.rb +0 -44
- data/scarpe-components/lib/scarpe/components/calzini/text_widgets.rb +0 -65
- /data/examples/legacy/{not_checked → working}/shoes3-tests/editline/editline.rb +0 -0
@@ -0,0 +1,140 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
require 'diff/lcs'
|
3
|
+
require 'diff/lcs/hunk'
|
4
|
+
require 'fileutils'
|
5
|
+
require "htmlbeautifier"
|
6
|
+
|
7
|
+
puts "== Checking HTML fixtures =="
|
8
|
+
|
9
|
+
|
10
|
+
# Get top-level Ruby examples
|
11
|
+
file_paths = Dir["examples/*.rb"]
|
12
|
+
|
13
|
+
# Get each filename, or one if supplied as argument
|
14
|
+
file_names = if ENV['SELECTED_FILE']
|
15
|
+
[ENV['SELECTED_FILE']]
|
16
|
+
else
|
17
|
+
file_paths.map do |file|
|
18
|
+
File.basename(file) # Exclude the file extension
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
collection_of_html = []
|
23
|
+
any_failures = false
|
24
|
+
failures = []
|
25
|
+
|
26
|
+
# ASCII color and format codes
|
27
|
+
red = "\e[31m"
|
28
|
+
green = "\e[32m"
|
29
|
+
bold = "\e[1m"
|
30
|
+
reset = "\e[0m"
|
31
|
+
|
32
|
+
def diff_as_string(data_new, data_old, file_name)
|
33
|
+
data_old = data_old.split(/\n/).map! { |e| e.chomp }
|
34
|
+
data_new = data_new.split(/\n/).map! { |e| e.chomp }
|
35
|
+
|
36
|
+
diffs = Diff::LCS.diff(data_old, data_new)
|
37
|
+
return if diffs.empty?
|
38
|
+
|
39
|
+
context_lines = 1
|
40
|
+
|
41
|
+
oldhunk = hunk = nil
|
42
|
+
file_length_difference = 0
|
43
|
+
|
44
|
+
output = ""
|
45
|
+
diffs.each do |piece|
|
46
|
+
begin
|
47
|
+
hunk = Diff::LCS::Hunk.new(data_old, data_new, piece,
|
48
|
+
context_lines,
|
49
|
+
file_length_difference
|
50
|
+
)
|
51
|
+
file_length_difference = hunk.file_length_difference
|
52
|
+
|
53
|
+
next unless oldhunk
|
54
|
+
|
55
|
+
# Hunks may overlap, which is why we need to be careful when our
|
56
|
+
# diff includes lines of context. Otherwise, we might print
|
57
|
+
# redundant lines.
|
58
|
+
if (context_lines > 0) and hunk.overlaps?(oldhunk)
|
59
|
+
hunk.unshift(oldhunk)
|
60
|
+
else
|
61
|
+
output << oldhunk.diff(:unified, "#{file_name}:") << "\n"
|
62
|
+
end
|
63
|
+
ensure
|
64
|
+
oldhunk = hunk
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#Handle the last remaining hunk
|
69
|
+
output << oldhunk.diff(:unified, "#{file_name}:") << "\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
file_names.each do |file_name|
|
73
|
+
# Read the entire file
|
74
|
+
content = File.read(File.join(File.expand_path("../examples", __dir__),"#{file_name}"))
|
75
|
+
# Skip this file if it contains the magic comment
|
76
|
+
next if content.include?("# html_ci: false")
|
77
|
+
|
78
|
+
output = ""
|
79
|
+
pid = nil
|
80
|
+
command = "bundle exec ./exe/scarpe examples/#{file_name} --dev --debug"
|
81
|
+
|
82
|
+
IO.popen(command) do |io|
|
83
|
+
pid = io.pid # captures the pid of the child process
|
84
|
+
io.each_line do |line|
|
85
|
+
output << line
|
86
|
+
if line.include?(":heartbeat")
|
87
|
+
Process.kill("SIGKILL", pid)
|
88
|
+
break
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def match_output(logs)
|
94
|
+
logs.match(/(?<=code_string = ").*(?=")/)[0].split("`")[1]
|
95
|
+
end
|
96
|
+
|
97
|
+
def format_html(html)
|
98
|
+
html.gsub!(/\\/, "") # Remove all backslashes
|
99
|
+
html
|
100
|
+
end
|
101
|
+
|
102
|
+
html = format_html(
|
103
|
+
match_output(output),
|
104
|
+
)
|
105
|
+
# puts formatted_html
|
106
|
+
pretty_html = HtmlBeautifier.beautify(html)
|
107
|
+
|
108
|
+
# Compare to fixture
|
109
|
+
dir_path = "test/wv/html_fixtures"
|
110
|
+
begin
|
111
|
+
file_path = "#{dir_path}/#{file_name.split(".")[0]}.html"
|
112
|
+
expected_output = File.read(file_path)
|
113
|
+
rescue => e
|
114
|
+
raise "Hey, you need to regenerate fixtures, do this using command 'rake test:regenerate_html_fixtures' "
|
115
|
+
end
|
116
|
+
# Do the comparison
|
117
|
+
# diff = Diff::LCS.diff(pretty_html, expected_output)
|
118
|
+
diff_output = diff_as_string(pretty_html, expected_output, file_name)
|
119
|
+
|
120
|
+
if diff_output.nil?
|
121
|
+
puts "#{green}#{bold}PASSED#{reset}: #{file_name}"
|
122
|
+
else
|
123
|
+
puts "#{red}#{bold}FAILED#{reset}: #{file_name}\nDiff:"
|
124
|
+
puts diff_output
|
125
|
+
print reset
|
126
|
+
failures << file_name # Add name of failed file to the array
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
unless failures.empty?
|
131
|
+
puts "\n=== #{bold}Summary#{reset} ==="
|
132
|
+
puts "The following files have had their HTML output change with your changes"
|
133
|
+
puts "This may indicate an error. Please check the diff and update the fixture if necessary."
|
134
|
+
puts "You can update the fixture by running #{bold}`rake test:regenerate_html_fixtures`#{reset}\n\n"
|
135
|
+
failures.each do |file|
|
136
|
+
puts "#{red}#{file}#{reset}"
|
137
|
+
end
|
138
|
+
exit 1
|
139
|
+
end
|
140
|
+
puts "== Completed HTML fixture check =="
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
puts "== Regenerating HTML fixtures =="
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
# Get top-level Ruby examples
|
8
|
+
file_paths = Dir["examples/*.rb"]
|
9
|
+
|
10
|
+
# Get each filename, or one if supplied as argument
|
11
|
+
file_names = if ENV['SELECTED_FILE']
|
12
|
+
[ENV['SELECTED_FILE']]
|
13
|
+
else
|
14
|
+
file_paths.map do |file|
|
15
|
+
File.basename(file) # Exclude the file extension
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
collection_of_html = []
|
20
|
+
file_names.each do |file_name|
|
21
|
+
# Read the entire file
|
22
|
+
content = File.read(File.join(File.expand_path("../examples", __dir__),"#{file_name}"))
|
23
|
+
# Skip this file if it contains the magic comment
|
24
|
+
next if content.include?("# html_ci: false")
|
25
|
+
|
26
|
+
output = ""
|
27
|
+
pid = nil
|
28
|
+
command = "bundle exec ./exe/scarpe examples/#{file_name} --dev --debug"
|
29
|
+
|
30
|
+
IO.popen(command) do |io|
|
31
|
+
pid = io.pid # captures the pid of the child process
|
32
|
+
io.each_line do |line|
|
33
|
+
output << line
|
34
|
+
if line.include?(":heartbeat")
|
35
|
+
Process.kill("SIGKILL", pid)
|
36
|
+
break
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# EXAMPLE_OF_WHAT_OUTPUT_LOOKS_LIKE = <<~OUTPUT
|
42
|
+
# INFO WebviewAPI : Method: set_title Args: ["Shoes!"] KWargs: {} Block: n Return: nil
|
43
|
+
# INFO WebviewAPI : Method: set_size Args: [480, 420, 0] KWargs: {} Block: n Return: nil
|
44
|
+
# INFO WebviewAPI : Method: navigate Args: ["data:text/html, %3Chtml%3E%0A++%3Chead+id%3D%27head-wvroot%27%3E%0A++++%3Cstyle+id%3D%27style-wvroot%27%3E%0A++++++%2F%2A%2A+Style+resets+%2A%2A%2F%0A++++++body+%7B%0A++++++++font-family%3A+arial%2C+Helvetica%2C+sans-serif%3B%0A++++++++margin%3A+0%3B%0A++++++++height%3A+100%25%3B%0A++++++++overflow%3A+hidden%3B%0A++++++%7D%0A++++++p+%7B%0A++++++++margin%3A+0%3B%0A++++++%7D%0A++++++%23wrapper-wvroot+%7B%0A++++++++height%3A+100%25%3B%0A++++++++width%3A+100%25%3B%0A++++++%7D%0A++++%3C%2Fstyle%3E%0A++%3C%2Fhead%3E%0A++%3Cbody+id%3D%27body-wvroot%27%3E%0A++++%3Cdiv+id%3D%27wrapper-wvroot%27%3E%3C%2Fdiv%3E%0A++%3C%2Fbody%3E%0A%3C%2Fhtml%3E%0A"] KWargs: {} Block: n Return: nil
|
45
|
+
# INFO WebviewAPI : Method: eval Args: ["function patchConsole(fn) {\n const original = console[fn];\n console[fn] = function(...args) {\n original(...args);\n puts(...args);\n }\n};\npatchConsole('log');\npatchConsole('info');\npatchConsole('error');\npatchConsole('warn');\n"] KWargs: {} Block: n Return: nil
|
46
|
+
# DEBUG Webview::WebWrangler::DOMWrangler : Requesting DOM replacement...
|
47
|
+
# DEBUG Webview::WebWrangler::DOMWrangler : Requesting redraw with 1 waiting changes and no waiting promise - need to schedule something!
|
48
|
+
# DEBUG Webview::WebWrangler::DOMWrangler : Requesting redraw with 1 waiting changes - scheduling a new redraw for them!
|
49
|
+
# INFO WebviewAPI : Method: eval Args: ["(function() {\n var code_string = "document.getElementById('wrapper-wvroot').innerHTML = `<div id=\\"2\\" style=\\"display:flex;flex-direction:row;flex-wrap:wrap;align-content:flex-start;justify-content:flex-start;align-items:flex-start;width:100%;height:100%\\"><button id=\\"3\\" onclick=\\"scarpeHandler('3-click')\\" onmouseover=\\"scarpeHandler('3-hover')\\">Push me</button><div id=\\"root-fonts\\"></div><div id=\\"root-alerts\\"> </div></div>`; true";\n try {\n result = eval(code_string);\n scarpeAsyncEvalResult("success", 0, result);\n } catch(error) {\n scarpeAsyncEvalResult("error", 0, error.message);\n }\n})();\n"] KWargs: {} Block: n Return: nil
|
50
|
+
# DEBUG Webview::WebWrangler : Scheduled JS: (0)
|
51
|
+
# (function() {
|
52
|
+
# var code_string = "document.getElementById('wrapper-wvroot').innerHTML = `<div id="2" style="display:flex;flex-direction:row;flex-wrap:wrap;align-content:flex-start;justify-content:flex-start;align-items:flex-start;width:100%;height:100%"><button id="3" onclick="scarpeHandler('3-click')" onmouseover="scarpeHandler('3-hover')">Push me</button><div id="root-fonts"></div><div id="root-alerts"> </div></div>`; true";
|
53
|
+
# try {
|
54
|
+
# result = eval(code_string);
|
55
|
+
# scarpeAsyncEvalResult("success", 0, result);
|
56
|
+
# } catch(error) {
|
57
|
+
# scarpeAsyncEvalResult("error", 0, error.message);
|
58
|
+
# }
|
59
|
+
# })();
|
60
|
+
# OUTPUT
|
61
|
+
|
62
|
+
require "htmlbeautifier"
|
63
|
+
|
64
|
+
def match_output(logs)
|
65
|
+
logs.match(/(?<=code_string = ").*(?=")/)[0].split("`")[1]
|
66
|
+
end
|
67
|
+
|
68
|
+
def format_html(html)
|
69
|
+
html.gsub!(/\\/, "") # Remove all backslashes
|
70
|
+
html
|
71
|
+
end
|
72
|
+
|
73
|
+
html = format_html(
|
74
|
+
match_output(output),
|
75
|
+
)
|
76
|
+
# puts formatted_html
|
77
|
+
pretty_html = HtmlBeautifier.beautify(html)
|
78
|
+
|
79
|
+
collection_of_html << [file_name, pretty_html]
|
80
|
+
|
81
|
+
# EXAMPLE_OF_WHAT_PRETTY_HTML_LOOKS_LIKE = <<~PRETTY_HTML
|
82
|
+
# <div id="2" style="display:flex;flex-direction:row;flex-wrap:wrap;align-content:flex-start;justify-content:flex-start;align-items:flex-start;width:100%;height:100%"><button id="3" onclick="scarpeHandler('3-click')" onmouseover="scarpeHandler('3-hover')">Push me</button>
|
83
|
+
# <div id="root-fonts"></div>
|
84
|
+
# <div id="root-alerts"> </div>
|
85
|
+
# </div>
|
86
|
+
# PRETTY_HTML
|
87
|
+
|
88
|
+
# Write to fixtures
|
89
|
+
dir_path = "test/wv/html_fixtures"
|
90
|
+
file_path = "#{dir_path}/#{file_name.split(".")[0]}.html"
|
91
|
+
|
92
|
+
# Create the directory if it doesn't exist
|
93
|
+
FileUtils.mkdir_p(dir_path)
|
94
|
+
|
95
|
+
# Write the HTML to the file
|
96
|
+
File.write(file_path, pretty_html)
|
97
|
+
|
98
|
+
|
99
|
+
collection_of_html << [file_name, html]
|
100
|
+
end
|
101
|
+
|
102
|
+
# Show how it looks
|
103
|
+
# collection_of_html.map { |file_name, html| puts "File: #{file_name}\n\n HTML: #{html}" }
|
104
|
+
puts "HTML fixtures regenerated successfully!"
|
@@ -19,16 +19,5 @@ module Scarpe
|
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def convert_to_integer(value, attribute_name, default = 0)
|
23
|
-
begin
|
24
|
-
value = Integer(value)
|
25
|
-
raise InvalidAttributeValueError, "Negative num '#{value}' not allowed for attribute '#{attribute_name}'" if value < 0
|
26
|
-
|
27
|
-
value
|
28
|
-
rescue ArgumentError
|
29
|
-
error_message = "Invalid value '#{value}' provided for attribute '#{attribute_name}'. The value should be a number."
|
30
|
-
raise InvalidAttributeValueError, error_message
|
31
|
-
end
|
32
|
-
end
|
33
22
|
end
|
34
23
|
end
|