scarpe 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/.yardopts +11 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +112 -0
  6. data/README.md +31 -24
  7. data/Rakefile +13 -1
  8. data/docs/yard/catscradle.md +44 -0
  9. data/docs/yard/template/default/fulldoc/html/setup.rb +13 -0
  10. data/docs/yard/template/default/layout/html/setup.rb +9 -0
  11. data/examples/background_with_image.rb +16 -0
  12. data/examples/bloopsaphone/working/bronx_army_knife.rb +66 -0
  13. data/examples/bloopsaphone/working/morning_serenity.rb +21 -0
  14. data/examples/bloopsaphone/working/simpsons_theme_song_by_why.rb +6 -4
  15. data/examples/button_go_away.rb +1 -1
  16. data/examples/check.rb +18 -0
  17. data/examples/clear_and_append.rb +24 -0
  18. data/examples/download_and_show_image.rb +28 -0
  19. data/examples/edit_box.rb +3 -5
  20. data/examples/fonts.rb +2 -2
  21. data/examples/get_headers.rb +10 -0
  22. data/examples/highlander.rb +2 -0
  23. data/examples/link.rb +2 -2
  24. data/examples/local_fonts.rb +4 -0
  25. data/examples/local_images.rb +4 -0
  26. data/examples/motion_events.rb +20 -0
  27. data/examples/parse_xl_funnies.rb +58 -0
  28. data/examples/radio/radio.rb +16 -0
  29. data/examples/radio/radio_groups.rb +18 -0
  30. data/examples/radio/radio_same_slot.rb +6 -0
  31. data/examples/ruby_racer.rb +13 -15
  32. data/examples/selfitude.rb +18 -0
  33. data/examples/shapes/shapes_fill.rb +4 -3
  34. data/examples/shoes_school.rb +2 -4
  35. data/examples/show_hide.rb +6 -0
  36. data/examples/skip_ci/change_my_audio_source.rb +21 -0
  37. data/examples/skip_ci/guitar_fretboard.rb +137 -0
  38. data/examples/video.rb +10 -0
  39. data/exe/scarpe +42 -66
  40. data/fonts/Pacifico.ttf +0 -0
  41. data/lacci/Gemfile +22 -0
  42. data/lacci/Gemfile.lock +72 -0
  43. data/lacci/Rakefile +12 -0
  44. data/lacci/lacci.gemspec +37 -0
  45. data/lacci/lib/lacci/scarpe_cli.rb +70 -0
  46. data/lacci/lib/lacci/scarpe_core.rb +21 -0
  47. data/lacci/lib/lacci/version.rb +13 -0
  48. data/lacci/lib/shoes/app.rb +264 -0
  49. data/{lib/scarpe → lacci/lib/shoes}/background.rb +1 -1
  50. data/{lib/scarpe → lacci/lib/shoes}/border.rb +1 -1
  51. data/{lib/scarpe → lacci/lib/shoes}/colors.rb +1 -1
  52. data/lacci/lib/shoes/constants.rb +29 -0
  53. data/{lib/scarpe → lacci/lib/shoes}/display_service.rb +40 -45
  54. data/lacci/lib/shoes/download.rb +123 -0
  55. data/lacci/lib/shoes/log.rb +71 -0
  56. data/lacci/lib/shoes/spacing.rb +9 -0
  57. data/{lib/scarpe → lacci/lib/shoes}/widget.rb +63 -43
  58. data/{lib/scarpe → lacci/lib/shoes/widgets}/alert.rb +3 -3
  59. data/{lib/scarpe → lacci/lib/shoes/widgets}/arc.rb +7 -5
  60. data/{lib/scarpe → lacci/lib/shoes/widgets}/button.rb +3 -3
  61. data/lacci/lib/shoes/widgets/check.rb +28 -0
  62. data/lacci/lib/shoes/widgets/document_root.rb +20 -0
  63. data/{lib/scarpe → lacci/lib/shoes/widgets}/edit_box.rb +10 -5
  64. data/{lib/scarpe → lacci/lib/shoes/widgets}/edit_line.rb +2 -2
  65. data/lacci/lib/shoes/widgets/flow.rb +22 -0
  66. data/lacci/lib/shoes/widgets/font.rb +14 -0
  67. data/{lib/scarpe → lacci/lib/shoes/widgets}/image.rb +3 -7
  68. data/lacci/lib/shoes/widgets/line.rb +18 -0
  69. data/{lib/scarpe → lacci/lib/shoes/widgets}/link.rb +2 -2
  70. data/{lib/scarpe → lacci/lib/shoes/widgets}/list_box.rb +2 -2
  71. data/{lib/scarpe → lacci/lib/shoes/widgets}/para.rb +4 -26
  72. data/lacci/lib/shoes/widgets/radio.rb +35 -0
  73. data/lacci/lib/shoes/widgets/shape.rb +37 -0
  74. data/lacci/lib/shoes/widgets/slot.rb +75 -0
  75. data/{lib/scarpe → lacci/lib/shoes/widgets}/span.rb +2 -2
  76. data/lacci/lib/shoes/widgets/stack.rb +24 -0
  77. data/{lib/scarpe → lacci/lib/shoes/widgets}/star.rb +6 -9
  78. data/lacci/lib/shoes/widgets/subscription_item.rb +60 -0
  79. data/lacci/lib/shoes/widgets/text_widget.rb +51 -0
  80. data/lacci/lib/shoes/widgets/video.rb +15 -0
  81. data/lacci/lib/shoes/widgets.rb +29 -0
  82. data/lacci/lib/shoes.rb +127 -0
  83. data/lacci/test/test_colors.rb +39 -0
  84. data/lacci/test/test_helper.rb +9 -0
  85. data/lacci/test/test_lacci.rb +9 -0
  86. data/lib/scarpe/cats_cradle.rb +249 -0
  87. data/lib/scarpe/evented_assertions.rb +88 -0
  88. data/lib/scarpe/version.rb +1 -1
  89. data/lib/scarpe/wv/alert.rb +3 -2
  90. data/lib/scarpe/wv/app.rb +30 -8
  91. data/lib/scarpe/wv/arc.rb +5 -6
  92. data/lib/scarpe/wv/background.rb +10 -1
  93. data/lib/scarpe/wv/border.rb +5 -3
  94. data/lib/scarpe/wv/button.rb +11 -9
  95. data/lib/scarpe/wv/check.rb +29 -0
  96. data/lib/scarpe/wv/control_interface.rb +14 -20
  97. data/lib/scarpe/wv/control_interface_test.rb +13 -28
  98. data/lib/scarpe/wv/document_root.rb +3 -45
  99. data/lib/scarpe/wv/edit_box.rb +5 -7
  100. data/lib/scarpe/wv/edit_line.rb +2 -2
  101. data/lib/scarpe/wv/flow.rb +10 -20
  102. data/lib/scarpe/wv/font.rb +36 -0
  103. data/lib/scarpe/wv/html.rb +3 -2
  104. data/lib/scarpe/wv/image.rb +7 -2
  105. data/lib/scarpe/wv/line.rb +4 -7
  106. data/lib/scarpe/wv/link.rb +1 -0
  107. data/lib/scarpe/wv/list_box.rb +3 -3
  108. data/lib/scarpe/wv/para.rb +16 -14
  109. data/lib/scarpe/wv/radio.rb +34 -0
  110. data/lib/scarpe/wv/shape.rb +44 -8
  111. data/lib/scarpe/wv/slot.rb +81 -0
  112. data/lib/scarpe/wv/spacing.rb +1 -1
  113. data/lib/scarpe/wv/span.rb +10 -8
  114. data/lib/scarpe/wv/stack.rb +10 -30
  115. data/lib/scarpe/wv/star.rb +11 -12
  116. data/lib/scarpe/wv/subscription_item.rb +50 -0
  117. data/lib/scarpe/wv/video.rb +34 -0
  118. data/lib/scarpe/wv/web_wrangler.rb +238 -58
  119. data/lib/scarpe/wv/webview_local_display.rb +27 -5
  120. data/lib/scarpe/wv/webview_relay_display.rb +18 -119
  121. data/lib/scarpe/wv/webview_relay_util.rb +143 -0
  122. data/lib/scarpe/wv/widget.rb +80 -11
  123. data/lib/scarpe/wv/wv_display_worker.rb +17 -4
  124. data/lib/scarpe/wv.rb +33 -4
  125. data/lib/scarpe/wv_local.rb +1 -1
  126. data/lib/scarpe/wv_relay.rb +1 -1
  127. data/lib/scarpe.rb +3 -32
  128. data/scarpe-components/.gitignore +1 -0
  129. data/scarpe-components/Gemfile +22 -0
  130. data/scarpe-components/README.md +35 -0
  131. data/scarpe-components/Rakefile +12 -0
  132. data/scarpe-components/lib/scarpe/components/base64.rb +29 -0
  133. data/scarpe-components/lib/scarpe/components/file_helpers.rb +65 -0
  134. data/scarpe-components/lib/scarpe/components/modular_logger.rb +113 -0
  135. data/scarpe-components/lib/scarpe/components/print_logger.rb +43 -0
  136. data/{lib/scarpe → scarpe-components/lib/scarpe/components}/promises.rb +102 -35
  137. data/scarpe-components/lib/scarpe/components/segmented_file_loader.rb +170 -0
  138. data/scarpe-components/lib/scarpe/components/unit_test_helpers.rb +217 -0
  139. data/scarpe-components/lib/scarpe/components/version.rb +7 -0
  140. data/scarpe-components/scarpe-components.gemspec +38 -0
  141. data/scarpe-components/test/test_components.rb +9 -0
  142. data/scarpe-components/test/test_helper.rb +23 -0
  143. data/scarpe-components/test/test_promises.rb +260 -0
  144. data/scarpe-components/test/test_segmented_app_files.rb +182 -0
  145. data/{lib/scarpe → spikes}/glibui/widget.rb +2 -2
  146. data/{lib/scarpe → spikes}/glibui.rb +1 -1
  147. data/templates/basic_class_template.erb +1 -1
  148. data/templates/class_template_with_event_bind.erb +1 -1
  149. data/templates/class_template_with_shapes.erb +1 -1
  150. data/templates/webview_template.erb +0 -3
  151. metadata +165 -117
  152. data/examples/fill.rb +0 -25
  153. data/examples/legacy/not_checked/shoes-contrib/basic/class-book.yaml +0 -387
  154. data/examples/legacy/not_checked/shoes-contrib/good/good-clock.rb +0 -51
  155. data/examples/legacy/not_checked/shoes-contrib/good/good-follow.rb +0 -26
  156. data/examples/legacy/not_checked/shoes-contrib/good/good-reminder.rb +0 -174
  157. data/examples/legacy/not_checked/shoes-contrib/good/good-vjot.rb +0 -56
  158. data/examples/legacy/not_checked/shoes-contrib/simple/simple-timer.rb +0 -13
  159. data/examples/legacy/not_checked/shoes-dep-samples/good-clock.rb +0 -51
  160. data/examples/legacy/not_checked/shoes-dep-samples/good-follow.rb +0 -26
  161. data/examples/legacy/not_checked/shoes-dep-samples/good-reminder.rb +0 -174
  162. data/examples/legacy/not_checked/shoes-dep-samples/good-vjot.rb +0 -56
  163. data/examples/legacy/not_checked/shoes-dep-samples/simple-accordion.rb +0 -75
  164. data/examples/legacy/not_checked/shoes-dep-samples/simple-anim-shapes.rb +0 -17
  165. data/examples/legacy/not_checked/shoes-dep-samples/simple-anim-text.rb +0 -13
  166. data/examples/legacy/not_checked/shoes-dep-samples/simple-arc.rb +0 -23
  167. data/examples/legacy/not_checked/shoes-dep-samples/simple-bounce.rb +0 -24
  168. data/examples/legacy/not_checked/shoes-dep-samples/simple-calc.rb +0 -70
  169. data/examples/legacy/not_checked/shoes-dep-samples/simple-chipmunk.rb +0 -26
  170. data/examples/legacy/not_checked/shoes-dep-samples/simple-control-sizes.rb +0 -24
  171. data/examples/legacy/not_checked/shoes-dep-samples/simple-curve.rb +0 -26
  172. data/examples/legacy/not_checked/shoes-dep-samples/simple-dialogs.rb +0 -29
  173. data/examples/legacy/not_checked/shoes-dep-samples/simple-draw.rb +0 -13
  174. data/examples/legacy/not_checked/shoes-dep-samples/simple-editor.rb +0 -28
  175. data/examples/legacy/not_checked/shoes-dep-samples/simple-form.rb +0 -28
  176. data/examples/legacy/not_checked/shoes-dep-samples/simple-form.shy +0 -0
  177. data/examples/legacy/not_checked/shoes-dep-samples/simple-mask.rb +0 -21
  178. data/examples/legacy/not_checked/shoes-dep-samples/simple-menu.rb +0 -31
  179. data/examples/legacy/not_checked/shoes-dep-samples/simple-menu1.rb +0 -35
  180. data/examples/legacy/not_checked/shoes-dep-samples/simple-rubygems.rb +0 -29
  181. data/examples/legacy/not_checked/shoes-dep-samples/simple-slide.rb +0 -45
  182. data/examples/legacy/not_checked/shoes-dep-samples/simple-sphere.rb +0 -28
  183. data/examples/legacy/not_checked/shoes-dep-samples/simple-sqlite3.rb +0 -13
  184. data/examples/legacy/not_checked/shoes-dep-samples/simple-timer.rb +0 -13
  185. data/examples/legacy/not_checked/shoes-dep-samples/simple-video.rb +0 -13
  186. data/examples/legacy/not_checked/simple/anim-text.rb +0 -13
  187. data/examples/legacy/not_checked/simple/arc.rb +0 -23
  188. data/examples/legacy/not_checked/simple/bounce.rb +0 -24
  189. data/examples/legacy/not_checked/simple/chipmunk.rb +0 -26
  190. data/examples/legacy/not_checked/simple/curve.rb +0 -26
  191. data/examples/legacy/not_checked/simple/dialogs.rb +0 -29
  192. data/examples/legacy/not_checked/simple/downloader.rb +0 -40
  193. data/examples/legacy/not_checked/simple/draw.rb +0 -13
  194. data/examples/legacy/not_checked/simple/mask.rb +0 -21
  195. data/examples/legacy/not_checked/simple/slide.rb +0 -45
  196. data/examples/legacy/not_checked/simple/sphere.rb +0 -28
  197. data/lib/constants.rb +0 -5
  198. data/lib/scarpe/app.rb +0 -78
  199. data/lib/scarpe/document_root.rb +0 -20
  200. data/lib/scarpe/fill.rb +0 -23
  201. data/lib/scarpe/flow.rb +0 -19
  202. data/lib/scarpe/line.rb +0 -25
  203. data/lib/scarpe/logger.rb +0 -155
  204. data/lib/scarpe/shape.rb +0 -19
  205. data/lib/scarpe/spacing.rb +0 -9
  206. data/lib/scarpe/stack.rb +0 -70
  207. data/lib/scarpe/text_widget.rb +0 -42
  208. data/lib/scarpe/unit_test_helpers.rb +0 -163
  209. data/lib/scarpe/widgets.rb +0 -30
  210. data/lib/scarpe/wv/fill.rb +0 -30
  211. data/lib/scarpe/wv/shape_helper.rb +0 -44
  212. /data/{lib/scarpe → spikes}/glibui/README.md +0 -0
  213. /data/{lib/scarpe → spikes}/glibui/alert.rb +0 -0
  214. /data/{lib/scarpe → spikes}/glibui/app.rb +0 -0
  215. /data/{lib/scarpe → spikes}/glibui/background.rb +0 -0
  216. /data/{lib/scarpe → spikes}/glibui/border.rb +0 -0
  217. /data/{lib/scarpe → spikes}/glibui/button.rb +0 -0
  218. /data/{lib/scarpe → spikes}/glibui/dimensions.rb +0 -0
  219. /data/{lib/scarpe → spikes}/glibui/document_root.rb +0 -0
  220. /data/{lib/scarpe → spikes}/glibui/edit_box.rb +0 -0
  221. /data/{lib/scarpe → spikes}/glibui/edit_line.rb +0 -0
  222. /data/{lib/scarpe → spikes}/glibui/flow.rb +0 -0
  223. /data/{lib/scarpe → spikes}/glibui/html.rb +0 -0
  224. /data/{lib/scarpe → spikes}/glibui/image.rb +0 -0
  225. /data/{lib/scarpe → spikes}/glibui/link.rb +0 -0
  226. /data/{lib/scarpe → spikes}/glibui/local_display.rb +0 -0
  227. /data/{lib/scarpe → spikes}/glibui/para.rb +0 -0
  228. /data/{lib/scarpe → spikes}/glibui/spacing.rb +0 -0
  229. /data/{lib/scarpe → spikes}/glibui/stack.rb +0 -0
  230. /data/{lib/scarpe → spikes}/glibui/text_widget.rb +0 -0
  231. /data/{lib/scarpe → spikes}/libui/alert.rb +0 -0
  232. /data/{lib/scarpe → spikes}/libui/button.rb +0 -0
  233. /data/{lib/scarpe → spikes}/libui/colors.rb +0 -0
  234. /data/{lib/scarpe → spikes}/libui/core.rb +0 -0
  235. /data/{lib/scarpe → spikes}/libui/flow.rb +0 -0
  236. /data/{lib/scarpe → spikes}/libui/libui.rb +0 -0
  237. /data/{lib/scarpe → spikes}/libui/notepad.md +0 -0
  238. /data/{lib/scarpe → spikes}/libui/para.rb +0 -0
  239. /data/{lib/scarpe → spikes}/libui/stack.rb +0 -0
@@ -1,40 +0,0 @@
1
- Shoes.app do
2
- background "#eee"
3
- @list = stack do
4
- para "Enter a URL to download:", :margin => [10, 8, 10, 0]
5
- flow :margin => 10 do
6
- @url = edit_line :width => -120
7
- @url.text ='http://walkabout.mvmanila.com/public/share/Ytm-2.exe'
8
- st_time = 0
9
- end_time = 0
10
- totalsz = 0
11
- button "Download", :width => 120 do
12
- st_time = Time.now
13
- @list.append do
14
- stack do
15
- background "#eee".."#ccd"
16
- stack :margin => 10 do
17
- dld = nil
18
- para @url.text, " [", link("cancel") { @dld.abort }, "]", :margin => 0
19
- d = inscription "Beginning transfer.", :margin => 0
20
- p = progress :width => 1.0, :height => 14
21
- @dld = download @url.text, :save => File.basename(@url.text),
22
- :pause => 0.02,
23
- :progress => proc { |dl|
24
- d.text = "Transferred #{dl.transferred} of #{dl.length} bytes (#{dl.percent.to_s[0..6]}%)"
25
- p.fraction = dl.percent
26
- },
27
- :finish => proc { |dl|
28
- end_time = Time.now
29
- secs = (end_time.to_i - st_time.to_i)
30
- kb = dl.length < 1024 ? 1: dl.length / 1024
31
- d.text = "Download completed KB/s: #{kb/secs} seconds:#{secs}"
32
- }
33
- para "Should appear after button press"
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,13 +0,0 @@
1
- Shoes.app do
2
- background "#999"
3
- stroke "#000"
4
- x, y = nil, nil
5
- motion do |_x, _y|
6
- if x and y and (x != _x or y != _y)
7
- append do
8
- line x, y, _x, _y
9
- end
10
- end
11
- x, y = _x, _y
12
- end
13
- end
@@ -1,21 +0,0 @@
1
- Shoes.app do
2
- background black
3
-
4
- stack :top => 0.4, :left => 0.2 do
5
- @stripes = stack
6
-
7
- mask do
8
- title "Shoes", :weight => "bold", :size => 82
9
- end
10
- end
11
-
12
- animate 10 do
13
- @stripes.clear do
14
- 20.times do |i|
15
- strokewidth 4
16
- stroke rgb((0.0..0.5).rand, (0.0..1.0).rand, (0.0..0.3).rand)
17
- line 0, i * 5, 400, i * 8
18
- end
19
- end
20
- end
21
- end
@@ -1,45 +0,0 @@
1
- #
2
- # mimicking the mootools demo for Fx.Slide
3
- # http://demos.mootools.net/Fx.Slide
4
- #
5
- Shoes.app do
6
- def stop_anim
7
- @anim.stop
8
- @anim = nil
9
- end
10
- def slide_anim &blk
11
- stop_anim if @anim
12
- @anim = animate 30, &blk
13
- end
14
- def slide_out slot
15
- slide_anim do |i|
16
- slot.height = 150 - (i * 3)
17
- slot.contents[0].top = -i * 3
18
- if slot.height == 0
19
- stop_anim
20
- slot.hide
21
- end
22
- end
23
- end
24
- def slide_in slot
25
- slot.show
26
- slide_anim do |i|
27
- slot.height = i * 6
28
- slot.contents[0].top = slot.height - 150
29
- stop_anim if slot.height == 150
30
- end
31
- end
32
-
33
- background white
34
- stack :margin => 10 do
35
- para link("slide out") { slide_out @lipsum }, " | ",
36
- link("slide in") { slide_in @lipsum }
37
- @lipsum = stack :width => 1.0, :height => 150 do
38
- stack do
39
- background "#ddd"
40
- border "#eee", :strokewidth => 5
41
- para "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", :margin => 10
42
- end
43
- end
44
- end
45
- end
@@ -1,28 +0,0 @@
1
- Shoes.app :width => 500, :height => 500, :resizable => false do
2
- image 400, 470, :top => 30, :left => 50 do
3
- nostroke
4
- fill "#127"
5
- image :top => 230, :left => 0 do
6
- oval 70, 130, 260, 40
7
- blur 30
8
- end
9
- oval 10, 10, 380, 380
10
- image :top => 0, :left => 0 do
11
- fill "#46D"
12
- oval 30, 30, 338, 338
13
- blur 10
14
- end
15
- fill gradient(rgb(1.0, 1.0, 1.0, 0.7), rgb(1.0, 1.0, 1.0, 0.0))
16
- oval 80, 14, 240, 176
17
- image :top => 0, :left => 0 do
18
- fill "#79F"
19
- oval 134, 134, 130, 130
20
- blur 40
21
- end
22
- image :top => 150, :left => 40, :width => 320, :height => 260 do
23
- fill gradient(rgb(0.7, 0.9, 1.0, 0.0), rgb(0.7, 0.9, 1.0, 0.6))
24
- oval 60, 60, 200, 136
25
- blur 20
26
- end
27
- end
28
- end
data/lib/constants.rb DELETED
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Constants
4
- LIB_DIR = File.join(Dir.home, "Desktop")
5
- end
data/lib/scarpe/app.rb DELETED
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Scarpe
4
- class App < Scarpe::Widget
5
- class << self
6
- attr_accessor :next_test_code
7
- end
8
- include Scarpe::Log
9
-
10
- display_properties :title, :width, :height, :resizable, :debug
11
-
12
- def initialize(
13
- title: "Scarpe!",
14
- width: 480,
15
- height: 420,
16
- resizable: true,
17
- debug: ENV["SCARPE_DEBUG"] ? true : false,
18
- test_code: nil,
19
- &app_code_body
20
- )
21
- log_init("Scarpe::App")
22
-
23
- @do_shutdown = false
24
-
25
- if Scarpe::App.next_test_code
26
- test_code = Scarpe::App.next_test_code
27
- Scarpe::App.next_test_code = nil
28
- end
29
-
30
- super
31
-
32
- test_code&.call(self)
33
-
34
- # This creates the DocumentRoot, including its corresponding display widget
35
- @document_root = Scarpe::DocumentRoot.new
36
-
37
- create_display_widget
38
-
39
- @app_code_body = app_code_body
40
-
41
- # Try to de-dup as much as possible and not send repeat or multiple
42
- # destroy events
43
- @watch_for_destroy = bind_shoes_event(event_name: "destroy") do
44
- DisplayService.unsub_from_events(@watch_for_destroy) if @watch_for_destroy
45
- @watch_for_destroy = nil
46
- self.destroy(send_event: false)
47
- end
48
-
49
- Signal.trap("INT") do
50
- @log.warning("App interrupted by signal, stopping...")
51
- puts "\nStopping Scarpe app..."
52
- destroy
53
- end
54
- end
55
-
56
- def init
57
- send_shoes_event(event_name: "init")
58
- return if @do_shutdown
59
-
60
- @document_root.instance_eval(&@app_code_body)
61
- end
62
-
63
- # This isn't supposed to return. The display service should take control
64
- # of the main thread. Local Webview even stops any background threads.
65
- def run
66
- if @do_shutdown
67
- $stderr.puts "Destroy has already been signaled, but we just called Shoes::App.run!"
68
- return
69
- end
70
- send_shoes_event(event_name: "run")
71
- end
72
-
73
- def destroy(send_event: true)
74
- @do_shutdown = true
75
- send_shoes_event(event_name: "destroy") if send_event
76
- end
77
- end
78
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Scarpe
4
- class DocumentRoot < Scarpe::Widget
5
- include Scarpe::Background
6
-
7
- def initialize
8
- super
9
-
10
- create_display_widget
11
- end
12
-
13
- # This can be absolutely huge in console output, and it's frequently printed.
14
- def inspect
15
- "<Scarpe::DocumentRoot>"
16
- end
17
-
18
- alias_method :info, :puts
19
- end
20
- end
data/lib/scarpe/fill.rb DELETED
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Scarpe
4
- class Fill < Scarpe::Widget
5
- display_properties :color
6
-
7
- def initialize(color)
8
- @color = color
9
- super
10
- create_display_widget
11
- end
12
-
13
- def element
14
- HTML.render do |h|
15
- h.style(<<~CSS)
16
- ##{html_id} {
17
- background-color: #{@color};
18
- }
19
- CSS
20
- end
21
- end
22
- end
23
- end
data/lib/scarpe/flow.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Scarpe
4
- class Flow < Scarpe::Widget
5
- include Scarpe::Background
6
- include Scarpe::Border
7
-
8
- display_properties :width, :height, :margin, :padding
9
-
10
- def initialize(width: nil, height: "100%", margin: nil, padding: nil, &block)
11
- super
12
-
13
- # Create the display-side widget *before* instance_eval, which will add child widgets with their display widgets
14
- create_display_widget
15
-
16
- instance_eval(&block)
17
- end
18
- end
19
- end
data/lib/scarpe/line.rb DELETED
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "wv/shape_helper"
4
-
5
- class Scarpe
6
- class Line < Scarpe::Widget
7
- include ShapeHelper
8
-
9
- display_properties :left, :top, :x2, :y2, :color
10
-
11
- def initialize(left, top, x2, y2)
12
- validate_coordinates(x2, y2)
13
- @left = left
14
- @top = top
15
- @x2 = x2
16
- @y2 = y2
17
- @color = color_for_fill
18
-
19
- # validate_coordinates(x2, y2)
20
-
21
- super()
22
- create_display_widget
23
- end
24
- end
25
- end
data/lib/scarpe/logger.rb DELETED
@@ -1,155 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "logging"
4
- require "json"
5
-
6
- class Scarpe
7
- LOG_LEVELS = [:debug, :info, :warning, :error, :fatal].freeze
8
-
9
- # Include this module to get a @log instance variable to log as your
10
- # configured component.
11
- module Log
12
- DEFAULT_LOG_CONFIG = {
13
- "default" => "info",
14
- }
15
- DEFAULT_DEBUG_LOG_CONFIG = {
16
- "default" => "debug",
17
- }
18
-
19
- def log_init(component = self)
20
- @log = Logging.logger[component]
21
- end
22
- end
23
-
24
- class Logger
25
- DEFAULT_COMPONENT = "default"
26
-
27
- class << self
28
- attr_reader :current_log_config
29
-
30
- def logger(component = self)
31
- Logging.logger[component]
32
- end
33
-
34
- private
35
-
36
- def name_to_severity(data)
37
- case data
38
- when "debug"
39
- :debug
40
- when "info"
41
- :info
42
- when "warn", "warning"
43
- :warn
44
- when "err", "error"
45
- :error
46
- when "fatal"
47
- :fatal
48
- else
49
- raise "Don't know how to treat #{data.inspect} as a logger severity!"
50
- end
51
- end
52
-
53
- def json_to_appender(data)
54
- case data.downcase
55
- when "stdout"
56
- Logging.appenders.stdout layout: @custom_log_layout
57
- when "stderr"
58
- Logging.appenders.stderr layout: @custom_log_layout
59
- when String
60
- Logging.appenders.file data, layout: @custom_log_layout
61
- else
62
- raise "Don't know how to convert #{data.inspect} to an appender!"
63
- end
64
- end
65
-
66
- def json_configure_logger(logger, data)
67
- case data
68
- in String
69
- sev = name_to_severity(data)
70
- logger.level = sev
71
- in [level, *locations]
72
- if logger.name != "root"
73
- # The Logging gem doesn't have an additive property on the root logger
74
- logger.additive = false # Don't also log to parent/root loggers
75
- end
76
-
77
- logger.appenders = locations.map { |where| json_to_appender(where) }
78
-
79
- logger.level = name_to_severity(level)
80
- else
81
- raise "Don't know how to use #{data.inspect} to specify a logger!"
82
- end
83
- end
84
-
85
- def freeze_log_config(log_config)
86
- log_config.each do |k, v|
87
- k.freeze
88
- v.freeze
89
- v.each(&:freeze) if v.is_a?(Array)
90
- end
91
- log_config.freeze
92
- end
93
-
94
- public
95
-
96
- def configure_logger(log_config)
97
- # TODO: custom coloring? https://github.com/TwP/logging/blob/master/examples/colorization.rb
98
- @custom_log_layout = Logging.layouts.pattern pattern: '[%r] %-5l %c: %m\n'
99
-
100
- if log_config.is_a?(String) && File.exist?(log_config)
101
- log_config = JSON.load_file(log_config)
102
- end
103
-
104
- log_config = freeze_log_config(log_config) unless log_config.nil?
105
- @current_log_config = log_config # Save a copy for later
106
-
107
- Logging.reset # Reset all Logging settings to defaults
108
- Logging.reopen # For log-reconfig (e.g. test failures), often important to *not* store an open handle to a moved file
109
- return if log_config.nil?
110
-
111
- Logging.logger.root.appenders = [Logging.appenders.stdout]
112
-
113
- default_logger = log_config[DEFAULT_COMPONENT] || "info"
114
- json_configure_logger(Logging.logger.root, default_logger)
115
-
116
- log_config.each do |component, logger_data|
117
- next if component == DEFAULT_COMPONENT
118
-
119
- sublogger = Logging.logger[component]
120
- json_configure_logger(sublogger, logger_data)
121
- end
122
- end
123
- end
124
- end
125
-
126
- class LoggedWrapper
127
- include ::Scarpe::Log
128
- def initialize(instance, component = instance)
129
- log_init(component)
130
-
131
- @instance = instance
132
- end
133
-
134
- def method_missing(method, ...)
135
- self.singleton_class.define_method(method) do |*args, **kwargs, &block|
136
- ret = @instance.send(method, *args, **kwargs, &block)
137
- @log.info("Method: #{method} Args: #{args.inspect} KWargs: #{kwargs.inspect} Block: #{block ? "y" : "n"} Return: #{ret.inspect}")
138
- ret
139
- end
140
- send(method, ...)
141
- end
142
- end
143
- end
144
-
145
- class Logging::Logger
146
- alias_method :warning, :warn
147
- end
148
-
149
- log_config = if ENV["SCARPE_LOG_CONFIG"]
150
- JSON.load_file(ENV["SCARPE_LOG_CONFIG"])
151
- else
152
- ENV["SCARPE_DEBUG"] ? Scarpe::Log::DEFAULT_DEBUG_LOG_CONFIG : Scarpe::Log::DEFAULT_LOG_CONFIG
153
- end
154
-
155
- Scarpe::Logger.configure_logger(log_config)
data/lib/scarpe/shape.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "wv/shape_helper"
4
-
5
- class Scarpe
6
- class Shape < Scarpe::Widget
7
- include ShapeHelper
8
- display_properties :left, :top
9
-
10
- def initialize(left: nil, top: nil, path_commands: nil, &block)
11
- @left = left
12
- @top = top
13
-
14
- super()
15
- create_display_widget
16
- instance_eval(&block) if block_given?
17
- end
18
- end
19
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Scarpe
4
- module Spacing
5
- def self.included(includer)
6
- includer.display_properties :margin, :padding
7
- end
8
- end
9
- end
data/lib/scarpe/stack.rb DELETED
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "net/http"
4
- require "openssl"
5
- require "nokogiri"
6
-
7
- class Scarpe
8
- class Stack < Scarpe::Widget
9
- include Scarpe::Background
10
- include Scarpe::Border
11
- include Scarpe::Spacing
12
-
13
- display_properties :width, :height, :margin, :padding, :scroll, :margin_top, :margin_left, :margin_right, :margin_bottom, :options
14
-
15
- def initialize(width: nil, height: "100%", margin: nil, padding: nil, scroll: false, margin_top: nil, margin_bottom: nil, margin_left: nil,
16
- margin_right: nil, **options, &block)
17
-
18
- # TODO: what are these options? Are they guaranteed serializable?
19
- @options = options
20
-
21
- super
22
-
23
- create_display_widget
24
- # Create the display-side widget *before* instance_eval, which will add child widgets with their display widgets
25
- instance_eval(&block) if block_given?
26
- end
27
- end
28
-
29
- class Widget
30
- def download(url)
31
- Thread.new do
32
- begin
33
- uri = URI(url)
34
- http = Net::HTTP.new(uri.host, uri.port)
35
- http.use_ssl = true
36
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
37
-
38
- request = Net::HTTP::Get.new(uri.request_uri)
39
-
40
- http.request(request) do |response|
41
- case response
42
- when Net::HTTPSuccess
43
- # content = response.body
44
-
45
- # headers = response.header
46
-
47
- get_title(content)
48
- else
49
- Scarpe.error("Failed to download content. Response code: #{response.code}")
50
- end
51
- end
52
- rescue StandardError => e
53
- Scarpe.error("Error occurred while downloading: #{e.message}")
54
- end
55
- end
56
- end
57
-
58
- private
59
-
60
- def get_title(content)
61
- doc = Nokogiri::HTML(content)
62
-
63
- title = doc.at_css("title")&.text&.strip || ""
64
-
65
- # headings = doc.css("h1").map(&:text)
66
-
67
- title
68
- end
69
- end
70
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Scarpe::TextWidget
4
-
5
- class Scarpe
6
- class TextWidget < Scarpe::Widget
7
- class << self
8
- # rubocop:disable Lint/MissingSuper
9
- def inherited(subclass)
10
- Scarpe::Widget.widget_classes ||= []
11
- Scarpe::Widget.widget_classes << subclass
12
- end
13
- # rubocop:enable Lint/MissingSuper
14
- end
15
- end
16
-
17
- class << self
18
- def default_text_widget_with(element)
19
- class_name = element.capitalize
20
-
21
- widget_class = Class.new(Scarpe::TextWidget) do
22
- display_property :content
23
-
24
- def initialize(content)
25
- @content = content
26
-
27
- super
28
-
29
- create_display_widget
30
- end
31
- end
32
- Scarpe.const_set class_name, widget_class
33
- widget_class.class_eval do
34
- display_property :content
35
- end
36
- end
37
- end
38
- end
39
-
40
- Scarpe.default_text_widget_with(:code)
41
- Scarpe.default_text_widget_with(:em)
42
- Scarpe.default_text_widget_with(:strong)