mirror of
https://github.com/usetrmnl/terminus.git
synced 2026-08-13 14:29:27 -07:00
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
35 lines
719 B
Ruby
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
|