Class: TailwindTheme::Theme
- Inherits:
-
Object
- Object
- TailwindTheme::Theme
- Defined in:
- lib/tailwind_theme.rb
Overview
The Tailwind CSS Theme object
Constant Summary collapse
- BASE_KEY =
The base key name for the sub theme
"base"- NIL_KEY =
The key to use for a nil value
"nil"
Instance Method Summary collapse
-
#[](path) ⇒ String, ...
Lookup the raw value of the path.
-
#css(path, options = {}) ⇒ String
Get the merged Tailwind CSS classes.
-
#css!(path, options = {}) ⇒ String
Get the merged Tailwind CSS classes.
-
#initialize(theme_hash = {}) ⇒ Theme
constructor
A new instance of Theme.
-
#key?(path) ⇒ Boolean
Returns if the path exists.
-
#merge_css(paths, options = {}) ⇒ String
Combine multiple paths and merging the combined Tailwind CSS classes.
-
#merge_css!(paths, options = {}) ⇒ String
Combine multiple paths and merging the combined Tailwind CSS classes.
Constructor Details
#initialize(theme_hash = {}) ⇒ Theme
Returns a new instance of Theme.
65 66 67 |
# File 'lib/tailwind_theme.rb', line 65 def initialize(theme_hash = {}) @theme = theme_hash end |
Instance Method Details
#[](path) ⇒ String, ...
Lookup the raw value of the path
162 163 164 165 |
# File 'lib/tailwind_theme.rb', line 162 def [](path) path = normalize_path path lookup_path path, raise: false end |
#css(path, options = {}) ⇒ String
Get the merged Tailwind CSS classes
Default options are:
:raise => false
87 88 89 90 |
# File 'lib/tailwind_theme.rb', line 87 def css(path, = {}) classnames = build path, merge classnames, end |
#css!(path, options = {}) ⇒ String
Get the merged Tailwind CSS classes. Raises an IndexError if the path cannot be found.
106 107 108 |
# File 'lib/tailwind_theme.rb', line 106 def css!(path, = {}) css path, .merge(raise: true) end |
#key?(path) ⇒ Boolean
Returns if the path exists
154 155 156 157 |
# File 'lib/tailwind_theme.rb', line 154 def key?(path) path = normalize_path path !!lookup_path(path, raise: false) end |
#merge_css(paths, options = {}) ⇒ String
Combine multiple paths and merging the combined Tailwind CSS classes.
Default options are:
:raise => false
128 129 130 131 |
# File 'lib/tailwind_theme.rb', line 128 def merge_css(paths, = {}) classnames = paths.map { |path| build path, }.compact.join(" ") merge classnames, end |
#merge_css!(paths, options = {}) ⇒ String
Combine multiple paths and merging the combined Tailwind CSS classes. Raises an IndexError if a path
cannot be found.
148 149 150 |
# File 'lib/tailwind_theme.rb', line 148 def merge_css!(paths, = {}) merge_css paths, .merge(raise: true) end |