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 +4 -4
- data/lib/tailwind_theme/controller_concern.rb +7 -4
- data/lib/tailwind_theme/factory.rb +19 -19
- data/lib/tailwind_theme/rails/version.rb +1 -1
- data/lib/tailwind_theme-rails.rb +10 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18191fa8841941cdc327577d881f84df3ca83ee896d17974a37fed3400c52544
|
4
|
+
data.tar.gz: e1f175bf51411ef809522e71ce34400f1a8305b2c8dcd5d73b402abf264faf96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
32
|
-
|
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
|
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
|
-
|
30
|
+
@themes[:default] ||= load_default_theme
|
32
31
|
else
|
33
|
-
|
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
|
40
|
-
|
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
|
-
|
42
|
+
def load_by_name(name)
|
43
|
+
load_theme name, %W[themes/#{name}.{yml,yml.erb}]
|
48
44
|
end
|
49
45
|
|
50
|
-
def
|
51
|
-
|
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
|
-
|
54
|
-
load_theme name, files
|
53
|
+
Dir.glob(patterns, 0).first
|
55
54
|
end
|
56
55
|
|
57
56
|
def load_theme(name, files)
|
58
|
-
|
57
|
+
file = find_theme files
|
58
|
+
return unless file
|
59
59
|
|
60
|
-
theme = TailwindTheme.load_file
|
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
|
-
|
67
|
+
theme
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
data/lib/tailwind_theme-rails.rb
CHANGED
@@ -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.
|
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-
|
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:
|
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:
|
26
|
+
version: 0.1.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|