tailwind_theme 0.1.0 → 0.1.1

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: e46f95b20a0a3dcbd2d84b08c6a5bb4c64a4647b9dbbb52062cb8b99d3cd9d97
4
- data.tar.gz: d99001bb8cb8c02c4cec4379b4674dc1777ce90e9a08459cbb181edc541e9510
3
+ metadata.gz: 84b51de462d19381fd5ca8b0f59fc4dbd868b1a9d76038e8b69bc44bf2b7c7b7
4
+ data.tar.gz: 937ae47435258ed338e80adaa5106f7577d85426d3f95573b4db1b8bcf1b1d0f
5
5
  SHA512:
6
- metadata.gz: 210f53e3e2a6bfd0be2f274876843824a74b4c76769dbbe207f5f9395c0c175a9a5266c98dcc2c8a5c5ff8326ad03b4e5e6e17aa3767261802818c28ce0261be
7
- data.tar.gz: cf9f9d1bdf9d56ba98741ad908d2175c93f2f4376ba1d739c995b471fdcacc1ac347adadbac24b3053111327aac6064fe5282976e1428f4dd92c843018587fb5
6
+ metadata.gz: 31b143b742d196ada6ddbdc0a44146960aea3233ff73b2dd22bc133e567378e69b5c1c01dce3dd83841e593fdb45d0e105275e621460c72a17984baba027cf81
7
+ data.tar.gz: 887428da5aea0aa9fc6bc5697eff4c5e2e3f7db3108acd42502c770c5f7d088a299f8622a315d75ccfe85518157385fc44536a16798562ee63aafe56f8584980
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TailwindTheme
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -35,7 +35,7 @@ module TailwindTheme
35
35
  def self.load_file(path)
36
36
  contents = File.read path
37
37
  contents = ERB.new(contents).result if path.end_with?(".erb")
38
- Theme.new YAML.safe_load(contents)
38
+ Theme.new YAML.safe_load(contents, aliases: true, filename: path)
39
39
  end
40
40
 
41
41
  # Generate the missing CSS class name from the path
@@ -70,6 +70,8 @@ module TailwindTheme
70
70
  #
71
71
  # @param [String, Symbol, Array<String, Symbol>] path the path to the css classes or sub theme
72
72
  # @param [Hash<Symbol, Object>] options the options to use when parsing the css theme
73
+ # @option options [prepend] prepend the classnames before merging the Tailwind Classes
74
+ # @option options [append] append the classnames before merging the Tailwind Classes
73
75
  # @option options [Boolean] raise raise an `IndexError` if the `path` does not exist
74
76
  # @option options [Object] object the object to apply the sub theme
75
77
  # @option options [Hash<String, Object>] attributes the attributes to apply the sub theme. Overrides
@@ -84,13 +86,15 @@ module TailwindTheme
84
86
  # @raise [ArgumentError] if processing an object theme and the object or attributes option is not defined
85
87
  def css(path, options = {})
86
88
  classnames = build path, options
87
- merge classnames
89
+ merge classnames, options
88
90
  end
89
91
 
90
92
  # Get the merged Tailwind CSS classes. Raises an IndexError if the path cannot be found.
91
93
  #
92
94
  # @param [String, Symbol, Array<String, Symbol>] path the path to the css classes or sub theme
93
95
  # @param [Hash<Symbol, Object>] options the options to use when parsing the css theme
96
+ # @option options [prepend] prepend the classnames before merging the Tailwind Classes
97
+ # @option options [append] append the classnames before merging the Tailwind Classes
94
98
  # @option options [Object] object the object to apply the sub theme
95
99
  # @option options [Hash<String, Object>] attributes the attributes to apply the sub theme. Overrides
96
100
  # the attributes defined in `options[:object]`.
@@ -107,6 +111,8 @@ module TailwindTheme
107
111
  #
108
112
  # @param [Array<String, Symbol, Array<String, Symbol>>] paths the array of paths to combine
109
113
  # @param [Hash<Symbol, Object>] options the options to use when parsing the css theme
114
+ # @option options [prepend] prepend the classnames before merging the Tailwind Classes
115
+ # @option options [append] append the classnames before merging the Tailwind Classes
110
116
  # @option options [Boolean] raise raise an `IndexError` if the a path does not exist
111
117
  # @option options [Object] object the object to apply the sub theme
112
118
  # @option options [Hash<String, Object>] attributes the attributes to apply the sub theme. Overrides
@@ -121,7 +127,7 @@ module TailwindTheme
121
127
  # @raise [ArgumentError] if processing an object theme and the object or attributes option is not defined
122
128
  def merge_css(paths, options = {})
123
129
  classnames = paths.map { |path| build path, options }.compact.join(" ")
124
- merge classnames
130
+ merge classnames, options
125
131
  end
126
132
 
127
133
  # Combine multiple paths and merging the combined Tailwind CSS classes. Raises an IndexError if a path
@@ -129,6 +135,8 @@ module TailwindTheme
129
135
  #
130
136
  # @param [Array<String, Symbol, Array<String, Symbol>>] paths the array of paths to combine
131
137
  # @param [Hash<Symbol, Object>] options the options to use when parsing the css theme
138
+ # @option options [prepend] prepend the classnames before merging the Tailwind Classes
139
+ # @option options [append] append the classnames before merging the Tailwind Classes
132
140
  # @option options [Object] object the object to apply the sub theme
133
141
  # @option options [Hash<String, Object>] attributes the attributes to apply the sub theme. Overrides
134
142
  # the attributes defined in `options[:object]`.
@@ -273,8 +281,8 @@ module TailwindTheme
273
281
  end
274
282
  end
275
283
 
276
- def merge(classnames)
277
- classnames = Array(classnames).flatten.compact.join(" ")
284
+ def merge(classnames, options)
285
+ classnames = Array(classnames).prepend(options[:prepend]).append(options[:append]).flatten.compact.join(" ")
278
286
  TailwindTheme.merger.merge classnames
279
287
  end
280
288
  end
@@ -1,8 +1,10 @@
1
1
  basic: "basic-classes"
2
- multipart:
2
+ multipart: &test_alias
3
3
  key: "multi-part-key"
4
4
  complex:
5
5
  base: "complex-base"
6
+ alias:
7
+ <<: *test_alias
6
8
  value_with_theme:
7
9
  base: "variant-base"
8
10
  default:
@@ -25,6 +25,14 @@ RSpec.describe TailwindTheme::Theme do
25
25
  expect(theme.css("multipart.key")).to eq "multi-part-key"
26
26
  end
27
27
 
28
+ it "appends the class name" do
29
+ expect(theme.css("multipart.key", append: "p-6")).to eq "multi-part-key p-6"
30
+ end
31
+
32
+ it "prepend the class name" do
33
+ expect(theme.css("multipart.key", prepend: "p-6")).to eq "p-6 multi-part-key"
34
+ end
35
+
28
36
  context "when string css path" do
29
37
  it "returns a css string" do
30
38
  expect(theme.css("basic")).to eq "basic-classes"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailwind_theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-25 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_merge