trmnl_preview 0.30.4 → 0.31.1

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: b21d300476e67904c34d0187c12b11c59904e67429ead767147d24d50ca1db9d
4
+ data.tar.gz: 5e77e6666b47b187f558d04c158907cc0441e90899f7e444cea1cc136a49a6cd
5
5
  SHA512:
6
- metadata.gz: ec019e1a423c47855cd9a96b1ef39578135e99aa9fb8b2b807e67f919b08884d360a180bc4619dcbdace7bf99095eeea4d1a69d672f6821a66ea3d33a78ee9c7
7
- data.tar.gz: 4bb9acf58ffd364b56a265a16e4a4d2cafa48847cc763c27f7d74d0fd0b261cc69fca465e6af327cfbdd7fb8e116cff46f9fff372e636b9733679af875834758
6
+ metadata.gz: eedd5d2c1275ac5f7a8dbc4767472e0dc5e1ff456ea352e3bbb6373190c0f98b04d8fe56f14cddcc8a2982ec57dd1ec21037d5a0c3d37b856c98830db5f81826
7
+ data.tar.gz: 7e9e0209e2102edf63ccc05efe67ed69912b206cae2f4c8e33d8bc67b8f83349cc8b1f35e2694b3246e6179c487e15368746ebfa259495db9306361dca834559
data/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
 
2
2
  # Changelog
3
3
 
4
+ ## 0.31.1
5
+
6
+ - A view with no `.liquid` file draws the shared markup alone, as TRMNL does when a recipe keeps all of its markup in shared. Before, trmnlp drew "Missing template" there, so `trmnlp test` showed a blank screen for a recipe that draws on TRMNL. A view with no file and no shared markup still says "Missing template".
7
+
8
+ - `trmnlp test` mocks the HTTPS requests of a Python transform on Python 3.13 and newer, which the Docker image ships. Before, Python 3.13 refused the test proxy's certificate ("Missing Authority Key Identifier"), so every request failed and the screens showed the transform's error path.
9
+
10
+ - A Python transform can `import requests`, as on TRMNL, where it is installed. When the Python on your PATH does not have it, trmnlp makes a virtual environment with it in `~/.cache/trmnl/python` the first time and runs Python transforms there. Before, such a transform failed with `No module named 'requests'` and `trmnlp test` drew its error screen. The Docker image now has it installed.
11
+
12
+ ## 0.31.0
13
+
14
+ - `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.
15
+ - `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.
16
+ - `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.
17
+
4
18
  ## 0.30.4
5
19
 
6
20
  - `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.
@@ -1,6 +1,6 @@
1
1
  # Mirrored from the TRMNL design-system source.
2
2
  # Refresh with `rake framework:sync` — do not edit manually.
3
- latest: 3.4.2
3
+ latest: 3.4.3
4
4
  versions:
5
5
  - number: 0.0.1
6
6
  released_at: '2024-06-22'
@@ -98,3 +98,5 @@ versions:
98
98
  released_at: '2026-10-14'
99
99
  - number: 3.4.2
100
100
  released_at: '2026-10-14'
101
+ - number: 3.4.3
102
+ released_at: '2026-10-15'
@@ -63,7 +63,9 @@ module TRMNLP
63
63
  # of 500-ing. Anything that's not a RenderError bubbles up as a bug.
64
64
  def render_liquid_template(view, device: {})
65
65
  template_path = paths.template(view)
66
- raise RenderError, "Missing template: #{template_path}" unless template_path.exist?
66
+ unless template_path.exist? || paths.shared_template.exist?
67
+ raise RenderError, "Missing template: #{template_path}"
68
+ end
67
69
 
68
70
  parse_and_render(template_path, device:)
69
71
  end
@@ -89,8 +91,7 @@ module TRMNLP
89
91
  end
90
92
 
91
93
  def full_markup(template_path)
92
- shared = paths.shared_template
93
- shared.exist? ? shared.read + template_path.read : template_path.read
94
+ [paths.shared_template, template_path].select(&:exist?).map(&:read).join
94
95
  end
95
96
 
96
97
  def liquid_environment
@@ -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)
@@ -57,6 +57,8 @@ module TRMNLP
57
57
 
58
58
  def add_extensions(certificate, authority, host)
59
59
  factory = OpenSSL::X509::ExtensionFactory.new(authority ? certificate : @certificate, certificate)
60
+ certificate.add_extension(factory.create_extension('subjectKeyIdentifier', 'hash'))
61
+ certificate.add_extension(factory.create_extension('authorityKeyIdentifier', 'keyid:always'))
60
62
  if authority
61
63
  certificate.add_extension(factory.create_extension('basicConstraints', 'CA:TRUE', true))
62
64
  certificate.add_extension(factory.create_extension('keyUsage', 'keyCertSign,cRLSign', true))
@@ -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
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'xdg'
4
+
5
+ module TRMNLP
6
+ module TransformBackend
7
+ # TRMNL's serverless Python has requests installed. A Python without it runs transforms from a
8
+ # virtual environment in the cache that has it, made once; if that fails, the Python runs as it is.
9
+ module Python
10
+ module_function
11
+
12
+ def interpreter(python, venv_dir: XDG.new.cache_home.join('trmnl', 'python'))
13
+ resolved[python] ||= imports_requests?(python) ? python : venv_python(python, venv_dir)
14
+ end
15
+
16
+ def venv_python(python, venv_dir)
17
+ venv_dir.dirname.mkpath
18
+ venv = venv_dir.join(Gem.win_platform? ? 'Scripts/python.exe' : 'bin/python').to_s
19
+ created = File.open("#{venv_dir}.lock", File::RDWR | File::CREAT) do |lock|
20
+ lock.flock(File::LOCK_EX)
21
+ imports_requests?(venv) || created_venv?(python, venv_dir, venv)
22
+ end
23
+ created ? venv : python
24
+ end
25
+
26
+ def created_venv?(python, venv_dir, venv)
27
+ succeeds?(python, '-m', 'venv', '--clear', venv_dir.to_s) && succeeds?(venv, '-m', 'pip', 'install', 'requests')
28
+ end
29
+
30
+ def imports_requests?(python) = succeeds?(python, '-c', 'import requests')
31
+
32
+ def succeeds?(*command) = system(*command, out: File::NULL, err: File::NULL) == true
33
+
34
+ def resolved = @resolved ||= {}
35
+ end
36
+ end
37
+ end
@@ -4,6 +4,7 @@ require 'open3'
4
4
  require 'tmpdir'
5
5
 
6
6
  require_relative '../transform_client'
7
+ require_relative 'python'
7
8
  require_relative 'which'
8
9
  require_relative 'wrapper'
9
10
 
@@ -52,7 +53,9 @@ module TRMNLP
52
53
  output_path = File.join(dir, 'output.json')
53
54
  src_path = File.join(dir, "transform.#{spec[:ext]}")
54
55
  File.write(src_path, Wrapper.for(language, code, sink_for(language, output_path)))
55
- run_process(Which.resolve(spec[:cmds]), src_path, stdin, timeout_seconds, output_path)
56
+ command = Which.resolve(spec[:cmds])
57
+ command = Python.interpreter(command) if language == 'python'
58
+ run_process(command, src_path, stdin, timeout_seconds, output_path)
56
59
  end
57
60
  rescue Errno::ENOENT, Errno::EACCES => e
58
61
  failure("interpreter not available: #{e.message}")
@@ -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.1'
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rockwell Schrock
@@ -500,6 +500,7 @@ files:
500
500
  - lib/trmnlp/testing/snapshot.rb
501
501
  - lib/trmnlp/testing/text_ink.rb
502
502
  - lib/trmnlp/transform_backend/http.rb
503
+ - lib/trmnlp/transform_backend/python.rb
503
504
  - lib/trmnlp/transform_backend/subprocess.rb
504
505
  - lib/trmnlp/transform_backend/which.rb
505
506
  - lib/trmnlp/transform_backend/wrapper.rb