trmnl_preview 0.5.6 → 0.5.8

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: abf6757d447adc5c12e7eed3baa049bc80757bc536f0da60af8ccb624d4216d4
4
- data.tar.gz: a533ae492f2ea9b71a55130977a88988ec3767c1393b2ebbbf618364a5a0f53b
3
+ metadata.gz: a9fb3cbe39aa3d0e8677b94b1bf224296d09ba045fac80e34b4d7438838a7c9c
4
+ data.tar.gz: 290000660480be5eca61e6a100dd9d737460e41daccdc2bbaa1088c330a3968c
5
5
  SHA512:
6
- metadata.gz: a88985299e6c183a0ee61fa609f117dffad48b42e1abdd4c2ea8303051725f44fc411870d9b5999d0ce7b1f78e6923d10974cf79ea79787ed61212eed36c3aa4
7
- data.tar.gz: bbdd8ac78d326b086eb56c8a66cf2aaf96096e1beb879ee951cda37b6f699cf14fc5d796fac34d4711b20c8d750075f38c1110d2829d0ebe1ed0d5fafa44c9c3
6
+ metadata.gz: '078876141ae2f419ae91dc343a2375a0aee31fcb18eb127324d280c0286dfab6b1785f4a79d92a06ed3c4bdece76f8d989d4d92b1dba928c2948b75cb4a374f7'
7
+ data.tar.gz: fb0fb7099bdb48ed80568448fa322f202e593d7089f4504546c38c6dade57929a580384a307203225a018abf45a7f1187c577391c64df25cd6a36f6e881a5ff9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.8
4
+
5
+ - Improve Docker commands in `bin/trmnlp` (@jrand0m, @jbarreiros)
6
+
7
+ ## 0.5.7
8
+
9
+ - Use the `trmnl-liquid` gem so tags and filters stay up-to-date with the core offering
10
+
3
11
  ## 0.5.6
4
12
 
5
13
  - Fixed bug that left blank plugins on server after upload failed
data/README.md CHANGED
@@ -4,6 +4,8 @@ A basic self-hosted web server to ease the development and sharing of [TRMNL](ht
4
4
 
5
5
  [Liquid](https://shopify.github.io/liquid/) templates are rendered leveraging the [TRMNL Design System](https://usetrmnl.com/framework). They may be generated as HTML (faster, and a good approximation of the final result) or as PNG images (slower, but more accurate).
6
6
 
7
+ Custom Liquid filters and tags are provided by the [trmnl-liquid](https://github.com/usetrmnl/trmnl-liquid) gem.
8
+
7
9
  The server watches the filesystem for changes to the Liquid templates, seamlessly updating the preview without the need to refresh.
8
10
 
9
11
  ![Screenshot](docs/preview.png)
@@ -81,7 +83,7 @@ trmnlp serve
81
83
  ```sh
82
84
  docker run \
83
85
  --publish 4567:4567 \
84
- --volume ".:/plugin" \
86
+ --volume "$(pwd):/plugin" \
85
87
  trmnl/trmnlp serve
86
88
  ```
87
89
 
@@ -1,3 +1,4 @@
1
+ require 'trmnl/liquid'
1
2
  require 'yaml'
2
3
 
3
4
  module TRMNLP
@@ -33,7 +34,7 @@ module TRMNLP
33
34
  # for interpolating custom_fields into polling_* options
34
35
  def with_custom_fields(value)
35
36
  custom_fields_with_env = custom_fields.transform_values { |v| with_env(v) }
36
- Liquid::Template.parse(value).render(custom_fields_with_env)
37
+ parse_liquid(value).render(custom_fields_with_env)
37
38
  end
38
39
 
39
40
  def time_zone = @config['time_zone'] || 'UTC'
@@ -42,7 +43,11 @@ module TRMNLP
42
43
 
43
44
  # for interpolating ENV vars into custom_fields
44
45
  def with_env(value)
45
- Liquid::Template.parse(value).render({ 'env' => ENV.to_h })
46
+ parse_liquid(value).render({ 'env' => ENV.to_h })
47
+ end
48
+
49
+ def parse_liquid(contents)
50
+ Liquid::Template.parse(contents, environment: TRMNL::Liquid.build_environment)
46
51
  end
47
52
  end
48
53
  end
@@ -3,11 +3,10 @@ require 'erb'
3
3
  require 'faraday'
4
4
  require 'filewatcher'
5
5
  require 'json'
6
- require 'liquid'
6
+ require 'trmnl/liquid'
7
7
 
8
8
  require_relative 'config'
9
9
  require_relative 'paths'
10
- require_relative '../markup/template'
11
10
 
12
11
  module TRMNLP
13
12
  class Context
@@ -129,7 +128,7 @@ module TRMNLP
129
128
  full_markup = template_path.read
130
129
  end
131
130
 
132
- user_template = Markup::Template.parse(full_markup, environment: liquid_environment)
131
+ user_template = Liquid::Template.parse(full_markup, environment: liquid_environment)
133
132
  user_template.render(user_data)
134
133
  rescue StandardError => e
135
134
  e.message
@@ -206,10 +205,7 @@ module TRMNLP
206
205
  end
207
206
 
208
207
  def liquid_environment
209
- @liquid_environment ||= Liquid::Environment.build do |env|
210
- env.register_filter(Markup::CustomLiquidFilters)
211
- env.register_tag('template', Markup::TemplateTag)
212
-
208
+ @liquid_environment ||= TRMNL::Liquid.build_environment do |env|
213
209
  config.project.user_filters.each do |module_name, relative_path|
214
210
  require paths.root_dir.join(relative_path)
215
211
  env.register_filter(Object.const_get(module_name))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TRMNLP
4
- VERSION = "0.5.6".freeze
4
+ VERSION = "0.5.8".freeze
5
5
  end
@@ -10,12 +10,25 @@ then
10
10
  exit
11
11
  fi
12
12
 
13
+ # Determine XDG config directory on host OS
14
+ if [ -n "$XDG_CONFIG_HOME" ]; then
15
+ CONFIG_DIR="$XDG_CONFIG_HOME/trmnlp"
16
+ else
17
+ CONFIG_DIR="$HOME/.config/trmnlp"
18
+ fi
19
+
20
+ if [ ! -d "$CONFIG_DIR" ]; then
21
+ mkdir -p "$CONFIG_DIR"
22
+ fi
23
+
13
24
  if command -v docker &> /dev/null
14
25
  then
15
26
  docker run \
27
+ -it \
16
28
  --rm \
17
29
  --publish 4567:4567 \
18
30
  --volume "$(pwd):/plugin" \
31
+ --volume "$CONFIG_DIR:/root/.config/trmnlp" \
19
32
  trmnl/trmnlp "$@"
20
33
  exit
21
34
  fi
@@ -43,9 +43,8 @@ Gem::Specification.new do |spec|
43
43
  spec.add_dependency "faye-websocket", "~> 0.11.3"
44
44
 
45
45
  # HTML rendering
46
- spec.add_dependency "liquid", "~> 5.6"
47
46
  spec.add_dependency "activesupport", "~> 8.0"
48
- spec.add_dependency "actionview", "~> 8.0"
47
+ spec.add_dependency "trmnl-liquid", "~> 0.2.0"
49
48
 
50
49
  # PNG rendering
51
50
  spec.add_dependency 'puppeteer-ruby', '~> 0.45.6'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trmnl_preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rockwell Schrock
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-07-10 00:00:00.000000000 Z
10
+ date: 2025-08-26 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: sinatra
@@ -65,20 +65,6 @@ dependencies:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
67
  version: 0.11.3
68
- - !ruby/object:Gem::Dependency
69
- name: liquid
70
- requirement: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '5.6'
75
- type: :runtime
76
- prerelease: false
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '5.6'
82
68
  - !ruby/object:Gem::Dependency
83
69
  name: activesupport
84
70
  requirement: !ruby/object:Gem::Requirement
@@ -94,19 +80,19 @@ dependencies:
94
80
  - !ruby/object:Gem::Version
95
81
  version: '8.0'
96
82
  - !ruby/object:Gem::Dependency
97
- name: actionview
83
+ name: trmnl-liquid
98
84
  requirement: !ruby/object:Gem::Requirement
99
85
  requirements:
100
86
  - - "~>"
101
87
  - !ruby/object:Gem::Version
102
- version: '8.0'
88
+ version: 0.2.0
103
89
  type: :runtime
104
90
  prerelease: false
105
91
  version_requirements: !ruby/object:Gem::Requirement
106
92
  requirements:
107
93
  - - "~>"
108
94
  - !ruby/object:Gem::Version
109
- version: '8.0'
95
+ version: 0.2.0
110
96
  - !ruby/object:Gem::Dependency
111
97
  name: puppeteer-ruby
112
98
  requirement: !ruby/object:Gem::Requirement
@@ -260,10 +246,6 @@ files:
260
246
  - README.md
261
247
  - bin/rake
262
248
  - bin/trmnlp
263
- - lib/markup/custom_liquid_filters.rb
264
- - lib/markup/inline_templates_file_system.rb
265
- - lib/markup/template.rb
266
- - lib/markup/template_tag.rb
267
249
  - lib/trmnlp.rb
268
250
  - lib/trmnlp/api_client.rb
269
251
  - lib/trmnlp/app.rb
@@ -1,36 +0,0 @@
1
- require 'action_view'
2
- require 'singleton'
3
-
4
- module Markup
5
- module CustomLiquidFilters
6
- class ActionViewHelpers
7
- include Singleton
8
- include ActionView::Helpers
9
- end
10
-
11
- def number_with_delimiter(number, delimiter = ',', separator = ',')
12
- ActionViewHelpers.instance.number_with_delimiter(number, delimiter:, separator:)
13
- end
14
-
15
- def number_to_currency(number, unit = '$', delimiter = ',', separator = '.')
16
- ActionViewHelpers.instance.number_to_currency(number, unit: unit, delimiter:, separator:)
17
- end
18
-
19
- def l_word(word, locale)
20
- I18n.t("custom_plugins.#{word}", locale: locale)
21
- end
22
-
23
- def l_date(date, format, locale = 'en')
24
- format = format.to_sym unless format.include?('%')
25
- I18n.l(date.to_datetime, :format => format, locale: locale)
26
- end
27
-
28
- def pluralize(singular, count)
29
- ActionViewHelpers.instance.pluralize(count, singular)
30
- end
31
-
32
- def json(obj)
33
- JSON.generate(obj)
34
- end
35
- end
36
- end
@@ -1,19 +0,0 @@
1
- module Markup
2
- # This in-memory "file system" is the backing storage for custom templates defined {% template [name] %} tags.
3
- class InlineTemplatesFileSystem < Liquid::BlankFileSystem
4
- def initialize
5
- super
6
- @templates = {}
7
- end
8
-
9
- # called by Markup::LiquidTemplateTag to save users' custom shared templates via our custom {% template %} tag
10
- def register(name, body)
11
- @templates[name] = body
12
- end
13
-
14
- # called by Liquid::Template for {% render 'foo' %} when rendering screen markup
15
- def read_template_file(name)
16
- @templates[name] || raise(Liquid::FileSystemError, "Template not found: #{name}")
17
- end
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- # get all files in the current directory as this file
2
- Pathname.new(__dir__).glob('*.rb').each { |file| require file }
3
-
4
- module Markup
5
- # A very thin wrapper around Liquid::Template with TRMNL-specific functionality.
6
- class Template < Liquid::Template
7
- def self.parse(*)
8
- template = super
9
-
10
- # set up a temporary in-memory file system for custom user templates, via the magic :file_system register
11
- # which will override the default file system
12
- template.registers[:file_system] = InlineTemplatesFileSystem.new
13
-
14
- template
15
- end
16
- end
17
- end
@@ -1,31 +0,0 @@
1
- module Markup
2
- # The {% template [name] %} tag block is used in conjunction with InlineTemplatesFileSystem to allow users to define
3
- # custom templates within the context of the current Liquid template. Generally speaking, they will define their own
4
- # templates in the "shared" markup content, which is prepended to the individual screen templates before rendering.
5
- class TemplateTag < Liquid::Block
6
- NAME_REGEX = %r{\A[a-zA-Z0-9_/]+\z}
7
-
8
- def initialize(tag_name, markup, options)
9
- super
10
- @name = markup.strip
11
- end
12
-
13
- def parse(tokens)
14
- @body = ""
15
- while (token = tokens.shift)
16
- break if token.strip == "{% endtemplate %}"
17
-
18
- @body << token
19
- end
20
- end
21
-
22
- def render(context)
23
- unless @name =~ NAME_REGEX
24
- return "Liquid error: invalid template name #{@name.inspect} - template names must contain only letters, numbers, underscores, and slashes"
25
- end
26
-
27
- context.registers[:file_system].register(@name, @body.strip)
28
- ''
29
- end
30
- end
31
- end