tailwind_theme-rails 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af4a596650d11be93a96ed08a70b8155b5865c1ff40c3053b3b4a39ee6585fc3
4
- data.tar.gz: 787ff82ef8f220ec9bdd71c880bf50ead8775e2e41727c0237d88244aea6a3be
3
+ metadata.gz: 18191fa8841941cdc327577d881f84df3ca83ee896d17974a37fed3400c52544
4
+ data.tar.gz: e1f175bf51411ef809522e71ce34400f1a8305b2c8dcd5d73b402abf264faf96
5
5
  SHA512:
6
- metadata.gz: bdfa4e58b4079e6204b90a6476cb6e5b87e8b636781ef3efbaca6947eb742fb998be868d08bed4b76f9019d84bcb9f8d869cbf7ed4691bc34619d18759603602
7
- data.tar.gz: cfc8b8ea25b3a6997b16e2423ff7ddf9eb88f223712dbd36543424098b6af585524251935e1560d21a19a0520dfd02018c736b8354dc8cbb93276baa6c725231
6
+ metadata.gz: ed16d1b3b95e90a6a4e7088e6723f10f596415296ffa9118252a66ff153ce66db95466bbe4dc3eac5f194dbcbded7019c42887dedd7d431b604ea0bd25000a73
7
+ data.tar.gz: eb65340148626e7c1183248a78184e9686717c06af3f76fb1ce6ed2c28b9a1ec983f92d92986b86536968256b88719c1a0b720a2eb95e1e3c52e042907f1200e
@@ -8,7 +8,7 @@ module TailwindTheme
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- class_attribute :_theme # :nodoc:
11
+ class_attribute :_theme, default: :default # :nodoc:
12
12
 
13
13
  # Add the helper method for the views
14
14
  helper_method :theme
@@ -23,13 +23,16 @@ module TailwindTheme
23
23
  #
24
24
  # See the [Factory](#Factory) class for more details
25
25
  def theme(name)
26
- self._theme = name
26
+ self._theme = name.presence || :default
27
27
  end
28
28
  end
29
29
 
30
30
  # The specified TailwindTheme for the controller
31
- def theme
32
- theme_factory.theme self.class._theme
31
+ # @param [String, Symbol, NilClass] name the name of the theme to use. Defaults to the theme set by the `theme`
32
+ # class method.
33
+ # @return [TailwindTheme::Theme, NilClass] returns the specified theme or Nil if the theme is not defined.
34
+ def theme(name = nil)
35
+ theme_factory.theme(name.presence || self.class._theme)
33
36
  end
34
37
 
35
38
  private
@@ -12,8 +12,7 @@ module TailwindTheme
12
12
  # TailwindTheme::Factory.new.theme :admin
13
13
  #
14
14
  class Factory
15
- def initialize(config_dir = nil)
16
- @config_dir = config_dir || ::Rails.root.join("config").to_s
15
+ def initialize
17
16
  @themes = {}
18
17
  end
19
18
 
@@ -28,43 +27,44 @@ module TailwindTheme
28
27
  # @return [TailwindTheme::Theme, NilClass] returns the theme or nil if the theme cannot be found.
29
28
  def theme(name = nil)
30
29
  if name.nil? || name.to_s == "default"
31
- default_theme
30
+ @themes[:default] ||= load_default_theme
32
31
  else
33
- theme_by_name name
32
+ @themes[name.to_sym] = load_by_name name.to_sym
34
33
  end
35
34
  end
36
35
 
37
36
  private
38
37
 
39
- def default_theme
40
- return @themes[:default] if @themes[:default]
41
-
42
- files = Dir[
43
- File.expand_path("themes/default.{yml,yml.erb}"),
44
- File.expand_path("theme.{yml,yml.erb}", @config_dir)
45
- ]
38
+ def load_default_theme
39
+ load_theme :default, %w[themes/default.{yml,yml.erb} theme.{yml,yml.erb}]
40
+ end
46
41
 
47
- load_theme :default, files
42
+ def load_by_name(name)
43
+ load_theme name, %W[themes/#{name}.{yml,yml.erb}]
48
44
  end
49
45
 
50
- def theme_by_name(name)
51
- return @themes[name.to_sym] if @themes[name.to_sym]
46
+ def find_theme(paths)
47
+ patterns = TailwindTheme.load_paths.each_with_object([]) do |dir, patterns|
48
+ paths.each do |path|
49
+ patterns << File.expand_path(path, dir)
50
+ end
51
+ end
52
52
 
53
- files = Dir[File.expand_path("themes/#{name}.{yml,yml.erb}", @config_dir)]
54
- load_theme name, files
53
+ Dir.glob(patterns, 0).first
55
54
  end
56
55
 
57
56
  def load_theme(name, files)
58
- return if files.empty?
57
+ file = find_theme files
58
+ return unless file
59
59
 
60
- theme = TailwindTheme.load_file files.first.to_s
60
+ theme = TailwindTheme.load_file file.to_s
61
61
  theme.instance_eval <<-RUBY
62
62
  def name
63
63
  "#{name}"
64
64
  end
65
65
  RUBY
66
66
 
67
- @themes[name.to_sym] = theme
67
+ theme
68
68
  end
69
69
  end
70
70
  end
@@ -1,5 +1,5 @@
1
1
  module TailwindTheme
2
2
  module Rails
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -6,3 +6,13 @@ require "tailwind_theme/rails/version"
6
6
  require "tailwind_theme/factory"
7
7
  require "tailwind_theme/controller_concern"
8
8
  require "tailwind_theme/engine"
9
+
10
+ module TailwindTheme
11
+ mattr_writer :load_paths
12
+
13
+ def self.load_paths
14
+ @@load_paths ||= [::Rails.root.join("config")]
15
+ end
16
+
17
+ ActiveSupport.run_load_hooks :tailwind_theme, self
18
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailwind_theme-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fawks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-29 00:00:00.000000000 Z
11
+ date: 2024-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tailwind_theme
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: 0.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '0.1'
26
+ version: 0.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: railties
29
29
  requirement: !ruby/object:Gem::Requirement