trmnl_preview 0.1.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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +4 -0
- data/exe/trmnlp +5 -0
- data/lib/trmnl_preview/app.rb +97 -0
- data/lib/trmnl_preview/liquid_filters.rb +6 -0
- data/lib/trmnl_preview/version.rb +5 -0
- data/lib/trmnl_preview.rb +12 -0
- data/sig/trmnl_preview.rbs +4 -0
- data/trmnl_preview.gemspec +43 -0
- data/views/index.erb +42 -0
- data/views/render_view.erb +20 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7db91035d25c8dc02576fa945d520f09a65faace724c38e419070c7c7c44d10e
|
4
|
+
data.tar.gz: 43f5bc530d71e08fde73546a5d0a8010dbd6282dd05925da4e46d74874b4b8ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e6540892b142f4dc9414a2daae31fa8b062845a792c730d5b369025b0cc73d1fce374b833402bd1598cba162a07064c3de17460a0305492f912e2310ffe32f85
|
7
|
+
data.tar.gz: 0a89a7cafcbd6621e8b6f64af93d744e4673590b02380e6869b8d90c56036fa9e36dfe2468ef6d465b6ad4ac2af61faa4ad687c7246bec8bc78bc8149f3a0d5a
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Rockwell Schrock
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# trmnl_preview
|
2
|
+
|
3
|
+
A little self-hosted web server to ease the development and sharing of [TRMNL](https://usetrmnl.com/) plugins.
|
4
|
+
|
5
|
+
## Prerequisites
|
6
|
+
|
7
|
+
- Ruby 3.x
|
8
|
+
|
9
|
+
## Getting Started
|
10
|
+
|
11
|
+
Clone a fork of https://github.com/schrockwell/trmnl-hello.
|
12
|
+
|
13
|
+
Run `bundle`.
|
14
|
+
|
15
|
+
Modify `config.toml` (see below for reference).
|
16
|
+
|
17
|
+
Modify the four view templates in `views/*.liquid`
|
18
|
+
|
19
|
+
Run `trmnlp` to start the local web server.
|
20
|
+
|
21
|
+
Browse it locally at http://127.0.0.1:4567/
|
22
|
+
|
23
|
+
## Usage Notes
|
24
|
+
|
25
|
+
Simply refresh the page to re-render.
|
26
|
+
|
27
|
+
When the polling strategy is "polling", the specified URL will be fetched once when the server starts.
|
28
|
+
|
29
|
+
When the polling strategy is "webhook", you can POST payloads to the `/webhook` endpoint. They are saved to `tmp/data.json` for future renders.
|
30
|
+
|
31
|
+
## `config.toml` Reference
|
32
|
+
|
33
|
+
- `strategy` - Either "polling" or "webhook"
|
34
|
+
- `url` - The URL from which to fetch JSON data (polling strategy only)
|
35
|
+
- `[polling_headers]` - A section of headers to append to the HTTP poll request (polling strategy only)
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/schrockwell/trmnl_preview.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/trmnlp
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'liquid'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'sinatra'
|
5
|
+
require 'sinatra/base'
|
6
|
+
require 'toml'
|
7
|
+
|
8
|
+
require_relative '../trmnl_preview'
|
9
|
+
require_relative 'liquid_filters'
|
10
|
+
|
11
|
+
class TRMNLPreview::App < Sinatra::Base
|
12
|
+
set :views, File.join(File.dirname(__FILE__), '..', '..', 'views')
|
13
|
+
|
14
|
+
# Constants
|
15
|
+
VIEWS = %w{full half_horizontal half_vertical quadrant}
|
16
|
+
CONFIG_PATH = File.join(Dir.pwd, 'config.toml')
|
17
|
+
USER_VIEWS_DIR = File.join(Dir.pwd, 'views')
|
18
|
+
TEMP_DIR = File.join(Dir.pwd, 'tmp')
|
19
|
+
DATA_JSON_PATH = File.join(TEMP_DIR, 'data.json')
|
20
|
+
|
21
|
+
unless File.exist?(CONFIG_PATH)
|
22
|
+
puts "No config.toml found in #{Dir.pwd}"
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
|
26
|
+
unless Dir.exist?(USER_VIEWS_DIR)
|
27
|
+
puts "No views found at #{USER_VIEWS_DIR}"
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
FileUtils.mkdir_p(TEMP_DIR)
|
32
|
+
|
33
|
+
config = TOML.load_file(CONFIG_PATH)
|
34
|
+
strategy = config['strategy']
|
35
|
+
|
36
|
+
unless ['polling', 'webhook'].include?(strategy)
|
37
|
+
puts "Invalid strategy: #{strategy} (must be 'polling' or 'webhook')"
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
|
41
|
+
url = config['url']
|
42
|
+
polling_headers = config['polling_headers'] || {}
|
43
|
+
|
44
|
+
if strategy == 'polling'
|
45
|
+
if url.nil?
|
46
|
+
puts "URL is required for polling strategy"
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
|
50
|
+
print "Fetching #{url}... "
|
51
|
+
payload = URI.open(url, polling_headers).read
|
52
|
+
File.write(DATA_JSON_PATH, payload)
|
53
|
+
puts "got #{payload.size} bytes"
|
54
|
+
end
|
55
|
+
|
56
|
+
environment = Liquid::Environment.build do |env|
|
57
|
+
env.register_filter(TRMNLPreview::LiquidFilters)
|
58
|
+
end
|
59
|
+
|
60
|
+
get '/' do
|
61
|
+
redirect '/full'
|
62
|
+
end
|
63
|
+
|
64
|
+
if config['strategy'] == 'webhook'
|
65
|
+
post '/webhook' do
|
66
|
+
body = request.body.read
|
67
|
+
File.write(DATA_JSON_PATH, body)
|
68
|
+
"OK"
|
69
|
+
end
|
70
|
+
|
71
|
+
puts "Listening for POSTs to /webhook"
|
72
|
+
end
|
73
|
+
|
74
|
+
VIEWS.each do |view|
|
75
|
+
get "/render/#{view}" do
|
76
|
+
path = File.join(USER_VIEWS_DIR, "#{view}.liquid")
|
77
|
+
unless File.exist?(path)
|
78
|
+
halt 404, "Plugin template not found: views/#{view}.liquid"
|
79
|
+
end
|
80
|
+
|
81
|
+
user_template = Liquid::Template.parse(File.read(path), environment: environment)
|
82
|
+
|
83
|
+
@view = view
|
84
|
+
erb :render_view do
|
85
|
+
data = JSON.parse(File.read(DATA_JSON_PATH))
|
86
|
+
data = { data: data } if data.is_a?(Array) # per TRMNL docs, bare array is wrapped in 'data' key
|
87
|
+
|
88
|
+
user_template.render(data)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
get "/#{view}" do
|
93
|
+
@view = view
|
94
|
+
erb :index
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TRMNLPreview; end
|
4
|
+
|
5
|
+
require_relative "trmnl_preview/app"
|
6
|
+
require_relative "trmnl_preview/liquid_filters"
|
7
|
+
require_relative "trmnl_preview/version"
|
8
|
+
|
9
|
+
module TRMNLPreview
|
10
|
+
class Error < StandardError; end
|
11
|
+
# Your code goes here...
|
12
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/trmnl_preview/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "trmnl_preview"
|
7
|
+
spec.version = TRMNLPreview::VERSION
|
8
|
+
spec.authors = ["Rockwell Schrock"]
|
9
|
+
spec.email = ["rockwell@schrock.me"]
|
10
|
+
|
11
|
+
spec.summary = "Local web server to preview TRMNL plugins"
|
12
|
+
spec.description = "Automatically rebuild and preview TRNML plugins in multiple views"
|
13
|
+
spec.homepage = "https://github.com/schrockwell/trmnl_preview"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/schrockwell/trmnl_preview"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(File.expand_path(f) == __FILE__) ||
|
27
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = ["trmnlp"]
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
spec.add_dependency "sinatra", "~> 4.1"
|
36
|
+
spec.add_dependency "rackup", "~> 2.2"
|
37
|
+
spec.add_dependency "puma", "~> 6.5"
|
38
|
+
spec.add_dependency "liquid", "~> 5.6"
|
39
|
+
spec.add_dependency "toml-rb", "~> 3.0"
|
40
|
+
|
41
|
+
# For more information and examples about making a new gem, check out our
|
42
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
43
|
+
end
|
data/views/index.erb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>TRMNL Preview</title>
|
7
|
+
<style>
|
8
|
+
body {
|
9
|
+
font-family: sans-serif;
|
10
|
+
background: #eee;
|
11
|
+
}
|
12
|
+
.menu {
|
13
|
+
margin-bottom: 1em;
|
14
|
+
}
|
15
|
+
.menu a {
|
16
|
+
padding: 0.5em 1em;
|
17
|
+
background: #ddd;
|
18
|
+
border-radius: 0.5em;
|
19
|
+
display: inline-block;
|
20
|
+
text-decoration: none;
|
21
|
+
color: black;
|
22
|
+
}
|
23
|
+
.menu a:hover {
|
24
|
+
background: #ccc;
|
25
|
+
}
|
26
|
+
.menu a.active {
|
27
|
+
background: #333;
|
28
|
+
color: white;
|
29
|
+
}
|
30
|
+
</style>
|
31
|
+
</head>
|
32
|
+
<body>
|
33
|
+
<div class="menu">
|
34
|
+
<a class="<%= 'active' if @view == 'full' %>" href="/full">Full</a>
|
35
|
+
<a class="<%= 'active' if @view == 'half_horizontal' %>" href="/half_horizontal">Half Horizontal</a>
|
36
|
+
<a class="<%= 'active' if @view == 'half_vertical' %>" href="/half_vertical">Half Vertical</a>
|
37
|
+
<a class="<%= 'active' if @view == 'quadrant' %>" href="/quadrant">Quadrant</a>
|
38
|
+
</div>
|
39
|
+
|
40
|
+
<iframe src="/render/<%= @view %>" width="800" height="480"></iframe>
|
41
|
+
</body>
|
42
|
+
</html>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<link rel="stylesheet" href="https://usetrmnl.com/css/latest/plugins.css" />
|
5
|
+
<script src="https://usetrmnl.com/js/latest/plugins.js"></script>
|
6
|
+
|
7
|
+
<!-- Begin Inter font -->
|
8
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
9
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
10
|
+
<link href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap" rel="stylesheet">
|
11
|
+
<!-- End Inter font -->
|
12
|
+
</head>
|
13
|
+
<body class="environment trmnl">
|
14
|
+
<div class="screen">
|
15
|
+
<div class="view view--<%= @view %>">
|
16
|
+
<%= yield %>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
</body>
|
20
|
+
</html>
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trmnl_preview
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rockwell Schrock
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sinatra
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rackup
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: puma
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '6.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '6.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: liquid
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.6'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: toml-rb
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Automatically rebuild and preview TRNML plugins in multiple views
|
84
|
+
email:
|
85
|
+
- rockwell@schrock.me
|
86
|
+
executables:
|
87
|
+
- trmnlp
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- exe/trmnlp
|
95
|
+
- lib/trmnl_preview.rb
|
96
|
+
- lib/trmnl_preview/app.rb
|
97
|
+
- lib/trmnl_preview/liquid_filters.rb
|
98
|
+
- lib/trmnl_preview/version.rb
|
99
|
+
- sig/trmnl_preview.rbs
|
100
|
+
- trmnl_preview.gemspec
|
101
|
+
- views/index.erb
|
102
|
+
- views/render_view.erb
|
103
|
+
homepage: https://github.com/schrockwell/trmnl_preview
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata:
|
107
|
+
allowed_push_host: https://rubygems.org
|
108
|
+
homepage_uri: https://github.com/schrockwell/trmnl_preview
|
109
|
+
source_code_uri: https://github.com/schrockwell/trmnl_preview
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 3.0.0
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubygems_version: 3.4.10
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Local web server to preview TRMNL plugins
|
129
|
+
test_files: []
|