scarpe-components 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -1
  3. data/Gemfile.lock +2 -3
  4. data/README.md +2 -2
  5. data/assets/bootstrap-themes/bootstrap-cerulean.css +12229 -0
  6. data/assets/bootstrap-themes/bootstrap-cosmo.css +11810 -0
  7. data/assets/bootstrap-themes/bootstrap-cyborg.css +12210 -0
  8. data/assets/bootstrap-themes/bootstrap-darkly.css +12153 -0
  9. data/assets/bootstrap-themes/bootstrap-flatly.css +12126 -0
  10. data/assets/bootstrap-themes/bootstrap-icons.min.css +5 -0
  11. data/assets/bootstrap-themes/bootstrap-journal.css +12099 -0
  12. data/assets/bootstrap-themes/bootstrap-litera.css +12211 -0
  13. data/assets/bootstrap-themes/bootstrap-lumen.css +12369 -0
  14. data/assets/bootstrap-themes/bootstrap-lux.css +11928 -0
  15. data/assets/bootstrap-themes/bootstrap-materia.css +13184 -0
  16. data/assets/bootstrap-themes/bootstrap-minty.css +12177 -0
  17. data/assets/bootstrap-themes/bootstrap-morph.css +12750 -0
  18. data/assets/bootstrap-themes/bootstrap-pulse.css +11890 -0
  19. data/assets/bootstrap-themes/bootstrap-quartz.css +12622 -0
  20. data/assets/bootstrap-themes/bootstrap-sandstone.css +12201 -0
  21. data/assets/bootstrap-themes/bootstrap-simplex.css +12186 -0
  22. data/assets/bootstrap-themes/bootstrap-sketchy.css +12451 -0
  23. data/assets/bootstrap-themes/bootstrap-slate.css +12492 -0
  24. data/assets/bootstrap-themes/bootstrap-solar.css +12149 -0
  25. data/assets/bootstrap-themes/bootstrap-spacelab.css +12266 -0
  26. data/assets/bootstrap-themes/bootstrap-superhero.css +12216 -0
  27. data/assets/bootstrap-themes/bootstrap-united.css +12077 -0
  28. data/assets/bootstrap-themes/bootstrap-vapor.css +12549 -0
  29. data/assets/bootstrap-themes/bootstrap-yeti.css +12325 -0
  30. data/assets/bootstrap-themes/bootstrap-zephyr.css +12283 -0
  31. data/assets/bootstrap-themes/bootstrap.bundle.min.js +7 -0
  32. data/lib/scarpe/components/asset_server.rb +219 -0
  33. data/lib/scarpe/components/base64.rb +22 -0
  34. data/lib/scarpe/components/calzini/{art_widgets.rb → art_drawables.rb} +42 -18
  35. data/lib/scarpe/components/calzini/border.rb +38 -0
  36. data/lib/scarpe/components/calzini/button.rb +6 -8
  37. data/lib/scarpe/components/calzini/misc.rb +7 -17
  38. data/lib/scarpe/components/calzini/para.rb +213 -11
  39. data/lib/scarpe/components/calzini/slots.rb +14 -60
  40. data/lib/scarpe/components/calzini.rb +88 -1
  41. data/lib/scarpe/components/errors.rb +4 -0
  42. data/lib/scarpe/components/html.rb +4 -1
  43. data/lib/scarpe/components/minitest_export_reporter.rb +11 -3
  44. data/lib/scarpe/components/minitest_result.rb +41 -0
  45. data/lib/scarpe/components/print_logger.rb +17 -2
  46. data/lib/scarpe/components/process_helpers.rb +37 -0
  47. data/lib/scarpe/components/segmented_file_loader.rb +1 -1
  48. data/lib/scarpe/components/tiranti.rb +42 -100
  49. data/lib/scarpe/components/unit_test_helpers.rb +3 -1
  50. data/lib/scarpe/components/version.rb +1 -1
  51. metadata +34 -6
  52. data/lib/scarpe/components/calzini/text_widgets.rb +0 -65
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # These can be used for unit tests, but also more generally.
4
+
5
+ require_relative "file_helpers"
6
+
7
+ module Scarpe::Components::ProcessHelpers
8
+ include Scarpe::Components::FileHelpers
9
+
10
+ # Run the command and capture its stdout and stderr output, and whether
11
+ # it succeeded or failed. Return after the command has completed.
12
+ # The awkward name is because this is normally a component of another
13
+ # library. Ordinarily you'd want to raise a library-specific exception
14
+ # on failure, print a library-specific message or delimiter, or otherwise
15
+ # handle success and failure. This is too general as-is.
16
+ #
17
+ # @param cmd [String,Array<String>] the command to run in Kernel#spawn format
18
+ # @return [Array(String,String,bool)] the stdout output, stderr output and success/failure of the command in a 3-element Array
19
+ def run_out_err_result(cmd)
20
+ out_str = ""
21
+ err_str = ""
22
+ success = nil
23
+
24
+ with_tempfiles([
25
+ ["scarpe_cmd_stdout", ""],
26
+ ["scarpe_cmd_stderr", ""],
27
+ ]) do |stdout_file, stderr_file|
28
+ pid = Kernel.spawn(cmd, out: stdout_file, err: stderr_file)
29
+ Process.wait(pid)
30
+ success = $?.success?
31
+ out_str = File.read stdout_file
32
+ err_str = File.read stderr_file
33
+ end
34
+
35
+ [out_str, err_str, success]
36
+ end
37
+ end
@@ -176,7 +176,7 @@ module Scarpe::Components
176
176
  "shoes" => proc { |seg_file| after_load { load seg_file } },
177
177
  "app_test" => proc do |seg_file|
178
178
  ENV["SHOES_SPEC_TEST"] = seg_file
179
- ENV["SHOES_MINITEST_EXPORT_FILE"] = "sspec.json"
179
+ ENV["SHOES_MINITEST_EXPORT_FILE"] ||= "sspec.json"
180
180
  end,
181
181
  }
182
182
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  # In Italian, tiranti are bootstraps -- the literal pull-on-a-boot kind, not a step to something better.
4
4
  # Tiranti.rb builds on calzini.rb, but renders a Bootstrap-decorated version of the HTML output.
5
- # You would ordinarily set either Calzini or Tiranti as the top-level HTML renderer, not both.
6
- # You'll include both if you use Tiranti, because it falls back to Calzini for a lot of its rendering.
5
+ # You can set Tiranti as your HTML renderer and you'll get Bootstrap versions of all the drawables.
6
+ # Tiranti requires Calzini's files because it falls back to Calzini for a lot of its rendering.
7
7
 
8
8
  require "scarpe/components/calzini"
9
9
 
@@ -17,45 +17,22 @@ module Scarpe::Components::Tiranti
17
17
  include Scarpe::Components::Calzini
18
18
  extend self
19
19
 
20
- # Currently we're using Bootswatch 5
21
- BOOTSWATCH_THEMES = [
22
- "cerulean",
23
- "cosmo",
24
- "cyborg",
25
- "darkly",
26
- "flatly",
27
- "journal",
28
- "litera",
29
- "lumen",
30
- "lux",
31
- "materia",
32
- "minty",
33
- "morph",
34
- "pulse",
35
- "quartz",
36
- "sandstone",
37
- "simplex",
38
- "sketchy",
39
- "slate",
40
- "solar",
41
- "spacelab",
42
- "superhero",
43
- "united",
44
- "vapor",
45
- "yeti",
46
- "zephyr",
47
- ]
48
-
49
- BOOTSWATCH_THEME = ENV["SCARPE_BOOTSTRAP_THEME"] || "sketchy"
50
-
51
- def empty_page_element
20
+ # Currently we're using Bootswatch 5.
21
+ # Bootswatch themes downloaded from https://bootswatch.com/5/THEME_NAME/bootstrap.css
22
+
23
+ def empty_page_element(theme: ENV["SCARPE_BOOTSTRAP_THEME"] || "sketchy")
24
+ comp_dir = File.expand_path("#{__dir__}/../../..")
25
+ bootstrap_js_url = Scarpe::Webview.asset_server.asset_url("#{comp_dir}/assets/bootstrap-themes/bootstrap.bundle.min.js", url_type: :asset)
26
+ theme_url = Scarpe::Webview.asset_server.asset_url("#{comp_dir}/assets/bootstrap-themes/bootstrap-#{theme}.css", url_type: :asset)
27
+ icons_url = Scarpe::Webview.asset_server.asset_url("#{comp_dir}/assets/bootstrap-themes/bootstrap-icons.min.css", url_type: :asset)
28
+
52
29
  <<~HTML
53
30
  <html>
54
31
  <head id='head-wvroot'>
55
32
  <meta charset="utf-8">
56
33
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
57
- <link rel="stylesheet" href="https://bootswatch.com/5/#{BOOTSWATCH_THEME}/bootstrap.css">
58
- <link rel="stylesheet" href="https://bootswatch.com/_vendor/bootstrap-icons/font/bootstrap-icons.min.css">
34
+ <link rel="stylesheet" href=#{theme_url.inspect}>
35
+ <link rel="stylesheet" href=#{icons_url.inspect}>
59
36
  <style id='style-wvroot'>
60
37
  /** Style resets **/
61
38
  body {
@@ -67,22 +44,22 @@ module Scarpe::Components::Tiranti
67
44
  <body id='body-wvroot'>
68
45
  <div id='wrapper-wvroot'></div>
69
46
 
70
- <script src="https://bootswatch.com/_vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
47
+ <script src=#{bootstrap_js_url}></script>
71
48
  </body>
72
49
  </html>
73
50
  HTML
74
51
  end
75
52
 
76
- # def render_stack
77
- # end
78
- # def render_flow
79
- # end
80
-
81
53
  # How do we want to handle theme-specific colours and primary/secondary buttons in Bootstrap?
82
54
  # "Disabled" could be checked in properties. Is there any way we can/should use "outline" buttons?
83
55
  def button_element(props)
84
56
  HTML.render do |h|
85
- h.button(id: html_id, type: "button", class: "btn btn-primary", onclick: handler_js_code("click"), style: button_style(props)) do
57
+ h.button(
58
+ id: html_id,
59
+ type: "button",
60
+ class: props["html_class"] ? "btn #{props["html_class"]}" : "btn btn-primary",
61
+ onclick: handler_js_code("click"), style: button_style(props)
62
+ ) do
86
63
  props["text"]
87
64
  end
88
65
  end
@@ -97,14 +74,11 @@ module Scarpe::Components::Tiranti
97
74
  styles[:"padding-top"] = props["padding_top"] if props["padding_top"]
98
75
  styles[:"padding-bottom"] = props["padding_bottom"] if props["padding_bottom"]
99
76
  styles[:color] = props["text_color"] if props["text_color"]
100
- styles[:width] = dimensions_length(props["width"]) if props["width"]
101
- styles[:height] = dimensions_length(props["height"]) if props["height"]
102
- styles[:"font-size"] = props["font_size"] if props["font_size"]
103
77
 
104
- styles[:top] = dimensions_length(props["top"]) if props["top"]
105
- styles[:left] = dimensions_length(props["left"]) if props["left"]
106
- styles[:position] = "absolute" if props["top"] || props["left"]
78
+ # How do we want to handle font size?
79
+ styles[:"font-size"] = props["font_size"] if props["font_size"]
107
80
  styles[:"font-size"] = dimensions_length(text_size(props["size"])) if props["size"]
81
+
108
82
  styles[:"font-family"] = props["font"] if props["font"]
109
83
 
110
84
  styles
@@ -153,8 +127,11 @@ module Scarpe::Components::Tiranti
153
127
  end
154
128
 
155
129
  def progress_element(props)
130
+ progress_style = drawable_style(props).merge({
131
+ width: "90%",
132
+ })
156
133
  HTML.render do |h|
157
- h.div(class: "progress", style: "width: 90%") do
134
+ h.div(id: html_id, class: "progress", style: progress_style) do
158
135
  pct = "%.1f" % ((props["fraction"] || 0.0) * 100.0)
159
136
  h.div(
160
137
  class: "progress-bar progress-bar-striped progress-bar-animated",
@@ -168,58 +145,23 @@ module Scarpe::Components::Tiranti
168
145
  end
169
146
  end
170
147
 
171
- # para_element is a bit of a hard one, since it does not-entirely-trivial
172
- # mapping between display objects and IDs. But we don't want Calzini
173
- # messing with the display service or display objects.
174
148
  def para_element(props, &block)
175
- tag, opts = para_elt_and_opts(props)
176
-
177
- HTML.render do |h|
178
- h.send(tag, **opts, &block)
179
- end
180
- end
181
-
182
- private
183
-
184
- ELT_AND_SIZE = {
185
- inscription: [:p, 10],
186
- ins: [:p, 10],
187
- para: [:p, 12],
188
- caption: [:p, 14],
189
- tagline: [:p, 18],
190
- subtitle: [:h3, 26],
191
- title: [:h2, 34],
192
- banner: [:h1, 48],
193
- }.freeze
194
-
195
- def para_elt_and_opts(props)
196
- elt, size = para_elt_and_size(props)
197
- size = dimensions_length(size)
198
-
199
- para_style = drawable_style(props).merge({
200
- color: rgb_to_hex(props["stroke"]),
201
- "font-size": para_font_size(props),
202
- "font-family": props["font"],
203
- }.compact)
204
-
205
- opts = (props["html_attributes"] || {}).merge(id: html_id, style: para_style)
206
-
207
- [elt, opts]
208
- end
209
-
210
- def para_elt_and_size(props)
211
- return [:p, nil] unless props["size"]
212
-
213
- ps = props["size"].to_s.to_sym
214
- if ELT_AND_SIZE.key?(ps)
215
- ELT_AND_SIZE[ps]
149
+ ps, _extra = para_style(props)
150
+ size = ps[:"font-size"] || "12px"
151
+ size_int = size.to_i # Mostly useful if it's something like "12px"
152
+ if size.include?("calc") || size.end_with?("%")
153
+ # Very big text!
154
+ props["tag"] = "h2"
155
+ elsif size_int >= 48
156
+ props["tag"] = "h1"
157
+ elsif size_int >= 34
158
+ props["tag"] = "h2"
159
+ elsif size_int >= 26
160
+ props["tag"] = "h3"
216
161
  else
217
- sz = props["size"].to_i
218
- if sz > 18
219
- [:h2, sz]
220
- else
221
- [:p, sz]
222
- end
162
+ props["tag"] = "p"
223
163
  end
164
+
165
+ super
224
166
  end
225
167
  end
@@ -5,6 +5,7 @@ require "json"
5
5
  require "fileutils"
6
6
 
7
7
  require "scarpe/components/file_helpers"
8
+ require "scarpe/components/process_helpers"
8
9
 
9
10
  module Scarpe::Test; end
10
11
 
@@ -20,6 +21,7 @@ ALREADY_SET_UP_LOGGED_TEST_FAILURES = { setup: false }
20
21
  module Scarpe::Test::Helpers
21
22
  # Very useful for tests
22
23
  include Scarpe::Components::FileHelpers
24
+ include Scarpe::Components::ProcessHelpers
23
25
 
24
26
  # Temporarily set env vars for the block of code inside. The old environment
25
27
  # variable values will be restored after the block finishes.
@@ -67,7 +69,7 @@ module Scarpe::Test::LoggedTest
67
69
  @normal_log_config = Shoes::Log.current_log_config
68
70
  Shoes::Log.configure_logger(log_config_for_test)
69
71
 
70
- Shoes::Log.logger("LoggedScarpeTest").info("Test: #{self.class.name}##{self.name}")
72
+ Shoes::Log.logger("LoggedTest").info("Test: #{self.class.name}##{self.name}")
71
73
  end
72
74
 
73
75
  # If you include this module and don't override setup/teardown, everything will
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Scarpe
4
4
  module Components
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scarpe-components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Concetto Rudilosso
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-11-24 00:00:00.000000000 Z
12
+ date: 2024-05-06 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -23,15 +23,43 @@ files:
23
23
  - Gemfile.lock
24
24
  - README.md
25
25
  - Rakefile
26
+ - assets/bootstrap-themes/bootstrap-cerulean.css
27
+ - assets/bootstrap-themes/bootstrap-cosmo.css
28
+ - assets/bootstrap-themes/bootstrap-cyborg.css
29
+ - assets/bootstrap-themes/bootstrap-darkly.css
30
+ - assets/bootstrap-themes/bootstrap-flatly.css
31
+ - assets/bootstrap-themes/bootstrap-icons.min.css
32
+ - assets/bootstrap-themes/bootstrap-journal.css
33
+ - assets/bootstrap-themes/bootstrap-litera.css
34
+ - assets/bootstrap-themes/bootstrap-lumen.css
35
+ - assets/bootstrap-themes/bootstrap-lux.css
36
+ - assets/bootstrap-themes/bootstrap-materia.css
37
+ - assets/bootstrap-themes/bootstrap-minty.css
38
+ - assets/bootstrap-themes/bootstrap-morph.css
39
+ - assets/bootstrap-themes/bootstrap-pulse.css
40
+ - assets/bootstrap-themes/bootstrap-quartz.css
41
+ - assets/bootstrap-themes/bootstrap-sandstone.css
42
+ - assets/bootstrap-themes/bootstrap-simplex.css
43
+ - assets/bootstrap-themes/bootstrap-sketchy.css
44
+ - assets/bootstrap-themes/bootstrap-slate.css
45
+ - assets/bootstrap-themes/bootstrap-solar.css
46
+ - assets/bootstrap-themes/bootstrap-spacelab.css
47
+ - assets/bootstrap-themes/bootstrap-superhero.css
48
+ - assets/bootstrap-themes/bootstrap-united.css
49
+ - assets/bootstrap-themes/bootstrap-vapor.css
50
+ - assets/bootstrap-themes/bootstrap-yeti.css
51
+ - assets/bootstrap-themes/bootstrap-zephyr.css
52
+ - assets/bootstrap-themes/bootstrap.bundle.min.js
53
+ - lib/scarpe/components/asset_server.rb
26
54
  - lib/scarpe/components/base64.rb
27
55
  - lib/scarpe/components/calzini.rb
28
56
  - lib/scarpe/components/calzini/alert.rb
29
- - lib/scarpe/components/calzini/art_widgets.rb
57
+ - lib/scarpe/components/calzini/art_drawables.rb
58
+ - lib/scarpe/components/calzini/border.rb
30
59
  - lib/scarpe/components/calzini/button.rb
31
60
  - lib/scarpe/components/calzini/misc.rb
32
61
  - lib/scarpe/components/calzini/para.rb
33
62
  - lib/scarpe/components/calzini/slots.rb
34
- - lib/scarpe/components/calzini/text_widgets.rb
35
63
  - lib/scarpe/components/errors.rb
36
64
  - lib/scarpe/components/file_helpers.rb
37
65
  - lib/scarpe/components/html.rb
@@ -40,6 +68,7 @@ files:
40
68
  - lib/scarpe/components/minitest_result.rb
41
69
  - lib/scarpe/components/modular_logger.rb
42
70
  - lib/scarpe/components/print_logger.rb
71
+ - lib/scarpe/components/process_helpers.rb
43
72
  - lib/scarpe/components/promises.rb
44
73
  - lib/scarpe/components/segmented_file_loader.rb
45
74
  - lib/scarpe/components/string_helpers.rb
@@ -51,7 +80,6 @@ licenses:
51
80
  - MIT
52
81
  metadata:
53
82
  homepage_uri: https://github.com/scarpe-team/scarpe
54
- source_code_uri: https://github.com/scarpe-team/scarpe
55
83
  changelog_uri: https://github.com/scarpe-team/scarpe/blob/main/CHANGELOG.md
56
84
  post_install_message:
57
85
  rdoc_options: []
@@ -68,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
96
  - !ruby/object:Gem::Version
69
97
  version: '0'
70
98
  requirements: []
71
- rubygems_version: 3.4.10
99
+ rubygems_version: 3.5.3
72
100
  signing_key:
73
101
  specification_version: 4
74
102
  summary: Reusable components for Scarpe display libraries
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Scarpe::Components::Calzini
4
- def link_element(props)
5
- HTML.render do |h|
6
- h.a(**link_attributes(props)) do
7
- props["text"]
8
- end
9
- end
10
- end
11
-
12
- def span_element(props, &block)
13
- HTML.render do |h|
14
- h.span(**span_options(props), &block)
15
- end
16
- end
17
-
18
- def code_element(props, &block)
19
- HTML.render do |h|
20
- h.code(&block)
21
- end
22
- end
23
-
24
- def em_element(props, &block)
25
- HTML.render do |h|
26
- h.em(&block)
27
- end
28
- end
29
-
30
- def strong_element(props, &block)
31
- HTML.render do |h|
32
- h.strong(&block)
33
- end
34
- end
35
-
36
- private
37
-
38
- def link_attributes(props)
39
- {
40
- id: html_id,
41
- href: props["click"],
42
- onclick: (handler_js_code("click") if props["has_block"]),
43
- style: drawable_style(props),
44
- }.compact
45
- end
46
-
47
- def span_style(props)
48
- {
49
- color: props["stroke"],
50
- "font-size": span_font_size(props),
51
- "font-family": props["font"],
52
- }.compact
53
- end
54
-
55
- def span_options(props)
56
- (props["html_attributes"] || {}).merge(id: html_id, style: span_style(props))
57
- end
58
-
59
- def span_font_size(props)
60
- sz = props["size"]
61
- font_size = SIZES.key?(sz.to_s.to_sym) ? SIZES[sz.to_s.to_sym] : sz
62
-
63
- dimensions_length(font_size)
64
- end
65
- end