Files
terminus/app/structs/model.rb
T
Brooke Kuhlmann f60cf28689 Added model struct CSS variables
Necessary to answer CSS variables as an array for inclusion when rendering screens for devices. This'll make these variables available for overriding the link:https://trmnl.com/framework/docs/3.1/tokens[TRMNL Framework] defaults.

The `#css_classes` method was updated to answer an array in order to be consistent with the `#css_variables` method. This is a breaking change that will be addressed in the next commit.

Milestone: minor
2026-05-27 10:25:44 -06:00

35 lines
719 B
Ruby

# frozen_string_literal: true
require "core"
require "refinements/array"
module Terminus
module Structs
# The model struct.
class Model < DB::Struct
using Refinements::Array
def css_classes
size = css.dig "classes", "size"
density = css.dig "classes", "density"
%W[
screen
screen--#{name}
screen--#{bit_depth}bit
screen--#{orientation}
#{size}
#{density}
].compress
end
def css_variables
css.fetch("variables", Core::EMPTY_ARRAY)
.map { |(key, value)| "#{key}: #{value};" }
end
def orientation = rotation.zero? ? "landscape" : "portrait"
end
end
end