Module: TailwindTheme

Defined in:
lib/tailwind_theme.rb,
lib/tailwind_theme/version.rb

Overview

Namespace for the tailwind_theme code

Defined Under Namespace

Classes: Theme

Constant Summary collapse

VERSION =
"0.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.mergerObject

Returns the global [TailwindMerge::Merge](github.com/gjtorikian/tailwind_merge) merge object using the global ‘merge_config` object.



22
23
24
# File 'lib/tailwind_theme.rb', line 22

def self.merger
  @merger ||= TailwindMerge::Merger.new(config: merger_config)
end

.merger_configObject



16
17
18
# File 'lib/tailwind_theme.rb', line 16

def self.merger_config
  @merger_config ||= {}
end

.missing_classname(path) ⇒ Nil, String

Generate the missing CSS class name from the path

Parameters:

  • path (Array<String>)

    the missing CSS path

Returns:

  • (Nil, String)

    returns a nil if the global missing_classname is false, otherwise returns a string



44
45
46
47
48
49
50
51
52
# File 'lib/tailwind_theme.rb', line 44

def self.missing_classname(path)
  if @missing_classname.nil? || @missing_classname == true
    "missing-#{path.join "-"}"
  elsif @missing_classname.is_a? Proc
    @missing_classname.call path
  elsif !!@missing_classname
    @missing_classname.to_s
  end
end

Class Method Details

.load_file(path) ⇒ TailwindTheme::Theme

Loads the YAML theme file.

Examples:

TailwindTheme.load_file("path/to/theme.yml")
TailwindTheme.load_file("path/to/theme.yml.erb")

Returns:



35
36
37
38
39
# File 'lib/tailwind_theme.rb', line 35

def self.load_file(path)
  contents = File.read path
  contents = ERB.new(contents).result if path.end_with?(".erb")
  Theme.new YAML.safe_load(contents, aliases: true, filename: path)
end