Class: Phlexi::Field::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/phlexi/field/theme.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inherited(subclass) ⇒ Object



6
7
8
9
# File 'lib/phlexi/field/theme.rb', line 6

def self.inherited(subclass)
  super
  subclass.extend Fiber::Local
end

.themeHash

Retrieves the theme hash

This method returns a hash containing theme definitions for various display components. If a theme has been explicitly set in the options, it returns that. Otherwise, it initializes and returns a default theme.

The theme hash defines CSS classes or references to other theme keys for different components, allowing for a flexible and inheritance-based theming system.

Examples:

Accessing the theme

theme[:text]
# => "text-gray-700 text-sm"

Theme inheritance

theme[:email] # Returns :text, indicating email inherits text's theme

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/phlexi/field/theme.rb', line 28

def self.theme
  raise NotImplementedError, "#{self} must implement #self.theme"
end

Instance Method Details

#resolve_theme(property, visited = Set.new) ⇒ String?

Recursively resolves the theme for a given property, handling nested symbol references

Examples:

Basic usage

# Assuming the theme is: { text: "text-gray-700", email: :text }
themed(:text)
# => "text-gray-700 text-sm"

Cascading themes

# Assuming the theme is: { text: "text-gray-700", email: :text }
resolve_theme(:email)
# => "text-gray-700"


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/phlexi/field/theme.rb', line 51

def resolve_theme(property, visited = Set.new)
  return nil if !property.present? || visited.include?(property)
  visited.add(property)

  result = theme[property]
  if result.is_a?(Symbol)
    resolve_theme(result, visited)
  else
    result
  end
end

#themeObject



32
33
34
# File 'lib/phlexi/field/theme.rb', line 32

def theme
  @theme ||= self.class.theme.freeze
end