Class: TRMNLP::Config::Plugin
- Inherits:
-
Object
- Object
- TRMNLP::Config::Plugin
- Defined in:
- lib/trmnlp/config/plugin.rb
Instance Method Summary collapse
-
#custom_field_definitions ⇒ Object
The custom-field definitions declared in settings.yml — the list of field hashes (keyname/name/field_type/…).
- #dark_mode ⇒ Object
-
#framework_version ⇒ Object
The TRMNL design-system version this plugin renders against.
- #id ⇒ Object
-
#initialize(paths, project_config) ⇒ Plugin
constructor
A new instance of Plugin.
- #no_screen_padding ⇒ Object
- #polling? ⇒ Boolean
- #polling_body ⇒ Object
- #polling_headers ⇒ Object
-
#polling_headers_encoded ⇒ Object
for trmnl }.
-
#polling_url_text ⇒ Object
for trmnl }.
- #polling_urls ⇒ Object
- #polling_verb ⇒ Object
- #reload! ⇒ Object
-
#serverless_language ⇒ Object
Explicit language for transform.* code.
-
#settings ⇒ Object
The raw parsed settings.yml hash.
- #static? ⇒ Boolean
- #static_data ⇒ Object
- #strategy ⇒ Object
- #webhook? ⇒ Boolean
Constructor Details
#initialize(paths, project_config) ⇒ Plugin
Returns a new instance of Plugin.
12 13 14 15 16 |
# File 'lib/trmnlp/config/plugin.rb', line 12 def initialize(paths, project_config) @paths = paths @project_config = project_config reload! end |
Instance Method Details
#custom_field_definitions ⇒ Object
The custom-field definitions declared in settings.yml — the list of field hashes (keyname/name/field_type/…). Distinct from Config::Project#custom_fields, which holds the field values.
99 |
# File 'lib/trmnlp/config/plugin.rb', line 99 def custom_field_definitions = @config['custom_fields'] || [] |
#dark_mode ⇒ Object
61 |
# File 'lib/trmnlp/config/plugin.rb', line 61 def dark_mode = @config['dark_mode'] || 'no' |
#framework_version ⇒ Object
The TRMNL design-system version this plugin renders against. Lives on the plugin (settings.yml), like serverless_language, because production stores it on the plugin_setting record — so it round-trips through ‘trmnlp push` / `pull`. Accepts ’latest’ (default), a pinned version, or nil (treated as latest). See db/data/framework_versions.yml for the supported set.
90 91 92 93 94 |
# File 'lib/trmnlp/config/plugin.rb', line 90 def framework_version FrameworkVersion.new(@config['framework_version'], asset_host: project_config.asset_host) rescue ArgumentError => e raise InvalidConfig, e. end |
#id ⇒ Object
65 |
# File 'lib/trmnlp/config/plugin.rb', line 65 def id = @config['id'] |
#no_screen_padding ⇒ Object
63 |
# File 'lib/trmnlp/config/plugin.rb', line 63 def no_screen_padding = @config['no_screen_padding'] || 'no' |
#polling? ⇒ Boolean
29 |
# File 'lib/trmnlp/config/plugin.rb', line 29 def polling? = strategy == 'polling' |
#polling_body ⇒ Object
59 |
# File 'lib/trmnlp/config/plugin.rb', line 59 def polling_body = with_custom_fields(@config['polling_body'] || '') |
#polling_headers ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/trmnlp/config/plugin.rb', line 48 def polling_headers # NOTE: render Liquid across the full headers string first so {% if %} blocks # spanning multiple key=value pairs are preserved. Splitting on # '&' or '=' before rendering would shatter tags into multiple values. rendered = with_custom_fields(@config['polling_headers'] || '') string_to_hash(rendered) end |
#polling_headers_encoded ⇒ Object
for trmnl }
57 |
# File 'lib/trmnlp/config/plugin.rb', line 57 def polling_headers_encoded = polling_headers.map { |k, v| "#{k}=#{v}" }.join('&') |
#polling_url_text ⇒ Object
for trmnl }
44 |
# File 'lib/trmnlp/config/plugin.rb', line 44 def polling_url_text = polling_urls.join("\r\n") |
#polling_urls ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/trmnlp/config/plugin.rb', line 33 def polling_urls # allow project-level config to override urls = project_config.user_data_overrides.dig('trmnl', 'plugin_settings', 'polling_url') || @config['polling_url'] return [] if urls.nil? with_custom_fields(urls).strip.split("\n") end |
#polling_verb ⇒ Object
46 |
# File 'lib/trmnlp/config/plugin.rb', line 46 def polling_verb = @config['polling_verb'] || 'GET' |
#reload! ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/trmnlp/config/plugin.rb', line 18 def reload! @config = if paths.plugin_config.exist? YAML.safe_load_file(paths.plugin_config, permitted_classes: [Date, Time]) || {} else {} end rescue Psych::SyntaxError => e raise InvalidConfig, "settings.yml is not valid YAML: #{e.}" end |
#serverless_language ⇒ Object
Explicit language for transform.* code. If absent, the language is inferred from the file extension by Paths#transform_file. This one lives on the plugin (settings.yml) because production stores it on the plugin_setting record. The scaffold emits ‘serverless_language: ”`, so empty strings collapse to nil here to let the `||` in the pipeline fall through to the inferred value.
79 80 81 82 |
# File 'lib/trmnlp/config/plugin.rb', line 79 def serverless_language value = @config['serverless_language'] value unless value.to_s.empty? end |
#settings ⇒ Object
The raw parsed settings.yml hash. Most callers want the semantic readers above; ‘trmnlp lint` needs the uninterpreted values because it searches the raw } templates the semantic readers render away.
104 |
# File 'lib/trmnlp/config/plugin.rb', line 104 def settings = @config |
#static? ⇒ Boolean
31 |
# File 'lib/trmnlp/config/plugin.rb', line 31 def static? = strategy == 'static' |
#static_data ⇒ Object
67 68 69 70 71 |
# File 'lib/trmnlp/config/plugin.rb', line 67 def static_data JSON.parse(@config['static_data'] || '{}') rescue JSON::ParserError raise InvalidConfig, 'invalid JSON in static_data' end |
#strategy ⇒ Object
28 |
# File 'lib/trmnlp/config/plugin.rb', line 28 def strategy = @config['strategy'] |
#webhook? ⇒ Boolean
30 |
# File 'lib/trmnlp/config/plugin.rb', line 30 def webhook? = strategy == 'webhook' |