trmnl_preview 0.30.4 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19d57b76b4b9fac2e897d2b4f18459bce312329e9ed647cb950781e5834387e6
4
- data.tar.gz: 3f12fe83acc40963e8a36a218275e42713aa5211ea80761cb46a44d72889de01
3
+ metadata.gz: 549b443e84d37972c94d74e4db9559deb402ce49f526e52ad1625ba704db50d5
4
+ data.tar.gz: c0588a1cd534aa350c525efd02410635cd095ccd17974eb6180812e4ae5ca25f
5
5
  SHA512:
6
- metadata.gz: ec019e1a423c47855cd9a96b1ef39578135e99aa9fb8b2b807e67f919b08884d360a180bc4619dcbdace7bf99095eeea4d1a69d672f6821a66ea3d33a78ee9c7
7
- data.tar.gz: 4bb9acf58ffd364b56a265a16e4a4d2cafa48847cc763c27f7d74d0fd0b261cc69fca465e6af327cfbdd7fb8e116cff46f9fff372e636b9733679af875834758
6
+ metadata.gz: d66bb390b64ab86df09562ab6a789d58973b1510cc0adbfe72dd6a853e7382ea869ee45d8a96b11004148fc2f392047f4b0bc649b0b772bfc258647938f157cf
7
+ data.tar.gz: d805eb40ec0b503e85b724f0ee6ce4a267ac4aa396882144e123221318f585920be6cd09b858720428702152846954cda8ccca5413bbf2da95b438c7b1f9c802
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
 
2
2
  # Changelog
3
3
 
4
+ ## 0.31.0
5
+
6
+ - `trmnlp test`'s publishable recipe draws the full view with each boolean field on and off, as `"true"` and `"false"`, the strings TRMNL saves. Before, only select fields were drawn with each option, so a recipe that breaks or goes blank with a switch off passed.
7
+ - `option_screens:` draws those options on the screens you name, such as `[{ device: 'og_png' }, { device: 'v2' }]` to try each one on the TRMNL X too. It defaults to the first screen, as before.
8
+ - `trmnlp serve`'s HTML preview draws a device TRMNL scales at its CSS size again, so a TRMNL X fits its 1040 by 780 frame. Since 0.16.0 it drew 1872 by 1404 and ran past the frame. PNG renders and `trmnlp test` are unchanged.
9
+
4
10
  ## 0.30.4
5
11
 
6
12
  - `trmnlp lint` reports a margin, padding, gap or position class with a leading minus (`no_negative_spacing`), such as `-mt--2` or `lg:-top--1`. Tailwind writes negative values this way, but no Framework release defines a class that starts with a minus, so TRMNL ignores it and says nothing: an icon nudged up with `-mt--1` stays where it was.
@@ -69,9 +69,13 @@ module TRMNLP
69
69
  })();
70
70
  JS
71
71
 
72
+ # The preview frame has the device's CSS size, so the screen stays unscaled there.
73
+ LIVE_PREVIEW_SIZE_STYLE = '<style>.trmnl .screen { --pixel-ratio: 1 !important; }</style>'
74
+
72
75
  def self.live_preview(html)
73
76
  timeout = html.match?(MAPS_DOCUMENT_PATTERN) ? READINESS_TIMEOUT_WITH_MAPS_SECONDS : READINESS_TIMEOUT_SECONDS
74
- html.sub('</head>', "#{LAYOUT_PASS_STYLE}<script>#{format(SETTLE_LIVE_PREVIEW, timeout)}</script></head>")
77
+ script = "<script>#{format(SETTLE_LIVE_PREVIEW, timeout)}</script>"
78
+ html.sub('</head>', "#{LIVE_PREVIEW_SIZE_STYLE}#{LAYOUT_PASS_STYLE}#{script}</head>")
75
79
  end
76
80
 
77
81
  def initialize(pool:, viewport_timeout: 5, fonts_timeout: FONTS_TIMEOUT_SECONDS)
@@ -25,21 +25,29 @@ module TRMNLP
25
25
  # Share of an image's ink its dark mode render must keep: lost icons kept 0%, the lowest one shown 17% (10-14).
26
26
  DARK_MODE_MIN_IMAGE_INK_KEPT = 0.05
27
27
 
28
- # Each select field's keyname and the values its options save, from the plugin's settings.yml.
29
- def self.select_field_values
28
+ # Each select and boolean field's keyname and the values it can save, from the plugin's settings.yml.
29
+ def self.option_field_values
30
30
  path = File.join(plugin_dir, 'src', 'settings.yml')
31
31
  fields = File.exist?(path) ? Array(YAML.safe_load_file(path, aliases: true)&.dig('custom_fields')) : []
32
- fields.select { it['field_type'] == 'select' }.to_h do |field|
33
- values = SelectFieldChoices.new(field).pairs.map { it.last.to_s }
32
+ fields.select { %w[select boolean].include?(it['field_type']) }.to_h do |field|
33
+ # TRMNL saves a boolean field as the string "true" or "false".
34
+ values = if field['field_type'] == 'boolean' then %w[true false]
35
+ else SelectFieldChoices.new(field).pairs.map { it.last.to_s }
36
+ end
34
37
  [field['keyname'], values.size > PUBLISHABLE_RECIPE_MAX_OPTIONS ? values.values_at(0, -1) : values]
35
38
  end
36
39
  end
40
+
41
+ def self.screen_name(screen)
42
+ device = screen[:device].is_a?(Hash) ? screen[:device][:model] : screen[:device]
43
+ [device, screen[:orientation], screen[:palette], ('dark mode' if screen[:dark_mode])].compact.join(' ')
44
+ end
37
45
  end
38
46
  end
39
47
 
40
48
  # rubocop:disable-next Metrics/BlockLength -- one shared group, one check per example
41
49
  RSpec.shared_examples 'a publishable recipe' do |screens: TRMNLP::Testing::PUBLISHABLE_RECIPE_SCREENS,
42
- dark_mode_screen: { device: 'v2' }|
50
+ dark_mode_screen: { device: 'v2' }, option_screens: screens.first(1)|
43
51
  let(:recipe_inputs) do
44
52
  { mocks: respond_to?(:mocks) ? mocks : {}, custom_fields: respond_to?(:custom_fields) ? custom_fields : {},
45
53
  variables: respond_to?(:variables) ? variables : {}, now: respond_to?(:now) ? now : nil,
@@ -52,11 +60,7 @@ RSpec.shared_examples 'a publishable recipe' do |screens: TRMNLP::Testing::PUBLI
52
60
  end
53
61
 
54
62
  TRMNLP::Testing::PUBLISHABLE_RECIPE_VIEWS.product(screens).each do |view, screen|
55
- device = screen[:device].is_a?(Hash) ? screen[:device][:model] : screen[:device]
56
- dark_mode = 'dark mode' if screen[:dark_mode]
57
- screen_name = [device, screen[:orientation], screen[:palette], dark_mode].compact.join(' ')
58
-
59
- it "draws the #{view} view on #{screen_name} without page errors" do
63
+ it "draws the #{view} view on #{TRMNLP::Testing.screen_name(screen)} without page errors" do
60
64
  expect(trmnl.render(view:, **screen, **recipe_inputs)).to draw_cleanly
61
65
  end
62
66
  end
@@ -76,11 +80,11 @@ RSpec.shared_examples 'a publishable recipe' do |screens: TRMNLP::Testing::PUBLI
76
80
  end
77
81
  end
78
82
 
79
- TRMNLP::Testing.select_field_values.each do |keyname, values|
80
- values.each do |value|
81
- it "draws the full view with #{keyname} set to #{value}" do
83
+ TRMNLP::Testing.option_field_values.each do |keyname, values|
84
+ option_screens.product(values).each do |screen, value|
85
+ it "draws the full view on #{TRMNLP::Testing.screen_name(screen)} with #{keyname} set to #{value}" do
82
86
  custom_fields = recipe_inputs[:custom_fields].merge(keyname => value)
83
- expect(trmnl.render(**screens.first, **recipe_inputs, custom_fields:)).to draw_cleanly
87
+ expect(trmnl.render(**screen, **recipe_inputs, custom_fields:)).to draw_cleanly
84
88
  end
85
89
  end
86
90
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TRMNLP
4
- VERSION = '0.30.4'
4
+ VERSION = '0.31.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trmnl_preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.4
4
+ version: 0.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rockwell Schrock