tailwindcss-rb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +110 -0
- data/LICENSE.txt +21 -0
- data/README.md +244 -0
- data/Rakefile +15 -0
- data/lib/tailwindcss/arbitrary_value.rb +15 -0
- data/lib/tailwindcss/asset_helper.rb +15 -0
- data/lib/tailwindcss/compiler/channel.rb +18 -0
- data/lib/tailwindcss/compiler/connection.rb +6 -0
- data/lib/tailwindcss/compiler/file_classes_extractor.rb +24 -0
- data/lib/tailwindcss/compiler/file_parser.rb +55 -0
- data/lib/tailwindcss/compiler/hash_args_extractor.rb +93 -0
- data/lib/tailwindcss/compiler/output.rb +48 -0
- data/lib/tailwindcss/compiler/runner.rb +64 -0
- data/lib/tailwindcss/constants.rb +322 -0
- data/lib/tailwindcss/helpers.rb +26 -0
- data/lib/tailwindcss/installer.rb +17 -0
- data/lib/tailwindcss/installers/config_file_generator.rb +37 -0
- data/lib/tailwindcss/style.rb +29 -0
- data/lib/tailwindcss/style_attributes_to_list_converter.rb +44 -0
- data/lib/tailwindcss/version.rb +3 -0
- data/lib/tailwindcss.rb +78 -0
- data/lib/tasks/tailwindcss.rake +28 -0
- data/sig/tailwindcss.rbs +4 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 465ca9281b589424b1a007d5bfbcb89034320a000f5d899118edbe91025a7e40
|
4
|
+
data.tar.gz: ba1a1fb55f9bdfa63e844cc3de171e10e96af3e3ddfe7c4503eae7b2d5b79b1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8bfd4b6f430ffd48cf8bf9f9d5b25c088f655025e7ff911c5bede8160c555045038b2c2d035d97a4bbfc86db3890d94fb9166d1a3afe72f043f973c3867ffc47
|
7
|
+
data.tar.gz: 1fb7dca1f70798606a5182ddbca025a1592a420a5e2fff8b4e3a04f84e16d7b801179e83aa948d4ad6a3e7e1082b0a71798b766bc208e32c792ab60a5c5a2db2
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at guilherme.andrade.ao@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in tailwindcss.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem "pry"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tailwindcss-rb (0.1.0)
|
5
|
+
activesupport (~> 7.0)
|
6
|
+
deep_merge (~> 1.0)
|
7
|
+
dry-configurable (~> 1.0)
|
8
|
+
listen
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (7.1.3.4)
|
14
|
+
base64
|
15
|
+
bigdecimal
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
connection_pool (>= 2.2.5)
|
18
|
+
drb
|
19
|
+
i18n (>= 1.6, < 2)
|
20
|
+
minitest (>= 5.1)
|
21
|
+
mutex_m
|
22
|
+
tzinfo (~> 2.0)
|
23
|
+
ast (2.4.2)
|
24
|
+
base64 (0.2.0)
|
25
|
+
bigdecimal (3.1.8)
|
26
|
+
coderay (1.1.3)
|
27
|
+
concurrent-ruby (1.3.3)
|
28
|
+
connection_pool (2.4.1)
|
29
|
+
deep_merge (1.2.2)
|
30
|
+
diff-lcs (1.5.1)
|
31
|
+
drb (2.2.1)
|
32
|
+
dry-configurable (1.2.0)
|
33
|
+
dry-core (~> 1.0, < 2)
|
34
|
+
zeitwerk (~> 2.6)
|
35
|
+
dry-core (1.0.1)
|
36
|
+
concurrent-ruby (~> 1.0)
|
37
|
+
zeitwerk (~> 2.6)
|
38
|
+
ffi (1.17.0)
|
39
|
+
i18n (1.14.5)
|
40
|
+
concurrent-ruby (~> 1.0)
|
41
|
+
json (2.7.2)
|
42
|
+
language_server-protocol (3.17.0.3)
|
43
|
+
listen (3.9.0)
|
44
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
45
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
46
|
+
method_source (1.1.0)
|
47
|
+
minitest (5.24.1)
|
48
|
+
mutex_m (0.2.0)
|
49
|
+
parallel (1.25.1)
|
50
|
+
parser (3.3.4.0)
|
51
|
+
ast (~> 2.4.1)
|
52
|
+
racc
|
53
|
+
pry (0.14.2)
|
54
|
+
coderay (~> 1.1)
|
55
|
+
method_source (~> 1.0)
|
56
|
+
racc (1.8.0)
|
57
|
+
rainbow (3.1.1)
|
58
|
+
rake (13.2.1)
|
59
|
+
rb-fsevent (0.11.2)
|
60
|
+
rb-inotify (0.11.1)
|
61
|
+
ffi (~> 1.0)
|
62
|
+
regexp_parser (2.9.2)
|
63
|
+
rexml (3.3.2)
|
64
|
+
strscan
|
65
|
+
rspec (3.13.0)
|
66
|
+
rspec-core (~> 3.13.0)
|
67
|
+
rspec-expectations (~> 3.13.0)
|
68
|
+
rspec-mocks (~> 3.13.0)
|
69
|
+
rspec-core (3.13.0)
|
70
|
+
rspec-support (~> 3.13.0)
|
71
|
+
rspec-expectations (3.13.1)
|
72
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
73
|
+
rspec-support (~> 3.13.0)
|
74
|
+
rspec-mocks (3.13.1)
|
75
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
+
rspec-support (~> 3.13.0)
|
77
|
+
rspec-support (3.13.1)
|
78
|
+
rubocop (1.65.0)
|
79
|
+
json (~> 2.3)
|
80
|
+
language_server-protocol (>= 3.17.0)
|
81
|
+
parallel (~> 1.10)
|
82
|
+
parser (>= 3.3.0.2)
|
83
|
+
rainbow (>= 2.2.2, < 4.0)
|
84
|
+
regexp_parser (>= 2.4, < 3.0)
|
85
|
+
rexml (>= 3.2.5, < 4.0)
|
86
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
87
|
+
ruby-progressbar (~> 1.7)
|
88
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
89
|
+
rubocop-ast (1.31.3)
|
90
|
+
parser (>= 3.3.1.0)
|
91
|
+
ruby-progressbar (1.13.0)
|
92
|
+
strscan (3.1.0)
|
93
|
+
tzinfo (2.0.6)
|
94
|
+
concurrent-ruby (~> 1.0)
|
95
|
+
unicode-display_width (2.5.0)
|
96
|
+
zeitwerk (2.6.16)
|
97
|
+
|
98
|
+
PLATFORMS
|
99
|
+
arm64-darwin-22
|
100
|
+
x86_64-linux
|
101
|
+
|
102
|
+
DEPENDENCIES
|
103
|
+
pry
|
104
|
+
rake (~> 13.0)
|
105
|
+
rspec (~> 3.0)
|
106
|
+
rubocop (~> 1.21)
|
107
|
+
tailwindcss-rb!
|
108
|
+
|
109
|
+
BUNDLED WITH
|
110
|
+
2.4.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Guilherme Andrade
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
# Tailwindcss-rb
|
2
|
+
|
3
|
+
This is a ruby gem that adds a ruby-like library and compiler for tailwindcss. It's goal is to serve as a an atomic set of functions
|
4
|
+
that help you build your own UI framework in ruby.
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'tailwindcss'
|
10
|
+
```
|
11
|
+
|
12
|
+
Then execute:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
bundle install
|
16
|
+
```
|
17
|
+
|
18
|
+
And run the installer:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
bundle exec rake tailwindcss:install
|
22
|
+
```
|
23
|
+
|
24
|
+
|
25
|
+
## Basic Usage
|
26
|
+
|
27
|
+
At its core of the gem, is the `Style` class. This class is used to generate tailwindcss classes in a ruby-like way.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Tailwindcss::Style.new(bg: :red).to_s
|
31
|
+
# => "bg-red-500"
|
32
|
+
```
|
33
|
+
|
34
|
+
Or using the `tailwind` helper.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
include Tailwindcss::Helpers
|
38
|
+
|
39
|
+
tailwind(bg: :red, text: :white)
|
40
|
+
# => "bg-red-500 text-white"
|
41
|
+
```
|
42
|
+
|
43
|
+
## Configuration
|
44
|
+
|
45
|
+
You can configure the gem by creating an initializer file in your rails app.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
# config/initializers/tailwindcss.rb
|
49
|
+
|
50
|
+
Tailwindcss.configure do |config|
|
51
|
+
config.package_json_path = "./package.json"
|
52
|
+
config.config_file_path = "./tailwind.config.js"
|
53
|
+
config.compiler.output_path = "./public/assets/styles.css"
|
54
|
+
config.compiler.compile_classes_dir = "./tmp/tailwindcss"
|
55
|
+
config.content = []
|
56
|
+
config.prefix = ""
|
57
|
+
config.watch_content = false
|
58
|
+
config.breakpoints = %i[xs sm md lg xl 2xl]
|
59
|
+
config.pseudo_selectors = %i[hover focus active visited disabled first last first_of_type last_of_type odd even group_hover]
|
60
|
+
config.pseudo_elements = %i[before after file first_letter first_line selection backdrop marker]
|
61
|
+
config.logger = Logger.new(STDOUT)
|
62
|
+
config.theme.color_scheme = {
|
63
|
+
primary: :red,
|
64
|
+
secondary: :blue,
|
65
|
+
tertiary: :green
|
66
|
+
}
|
67
|
+
# other theme configurations
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
## Compiling your styles
|
72
|
+
|
73
|
+
You can compile your styles by running the following command.
|
74
|
+
|
75
|
+
```bash
|
76
|
+
bundle exec rake tailwindcss:compile
|
77
|
+
```
|
78
|
+
|
79
|
+
Or by starting a process that watches for changes.
|
80
|
+
|
81
|
+
```bash
|
82
|
+
bundle exec rake tailwindcss:compile:watch
|
83
|
+
```
|
84
|
+
|
85
|
+
### How it works
|
86
|
+
|
87
|
+
The `tailwindcss-rb` compiler parses through the files in the `config.content`, and attempts to stactically extract the arguments you pass to the `tailwind` helper method. It then generates the tailwindcss classes and writes them to the `config.compiler.output_path`.
|
88
|
+
|
89
|
+
This file is then used by the tailwindcss compiler to generate the final css file.
|
90
|
+
|
91
|
+
##### Example
|
92
|
+
|
93
|
+
Given that you configured the gem as follows:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
Tailwindcss.configure do |config|
|
97
|
+
config.content = [
|
98
|
+
"app/views/**/*.html.erb",
|
99
|
+
]
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
And that you're writing the following code in your view file:
|
104
|
+
|
105
|
+
```erb
|
106
|
+
# app/views/layouts/application.html.erb
|
107
|
+
|
108
|
+
<div class="<%= tailwind(bg: :red, text: :white) %>">
|
109
|
+
Hello World
|
110
|
+
</div>
|
111
|
+
```
|
112
|
+
|
113
|
+
The compiler will generate the following "classes" file.
|
114
|
+
|
115
|
+
```
|
116
|
+
bg-red-500 text-white
|
117
|
+
```
|
118
|
+
|
119
|
+
And these classes will be added by the tailwind compiler to the final css file.
|
120
|
+
|
121
|
+
|
122
|
+
### Recommended use in development
|
123
|
+
|
124
|
+
When making changes related to your css, it is recommended that you set up a process that watches for changes and compiles the css file.
|
125
|
+
|
126
|
+
You can either do this by running the following command in a separate terminal window:
|
127
|
+
|
128
|
+
```bash
|
129
|
+
bundle exec rake tailwindcss:compile:watch
|
130
|
+
```
|
131
|
+
|
132
|
+
Or by adding the following line to your `Procfile.dev` file when using foreman.
|
133
|
+
|
134
|
+
```yaml
|
135
|
+
tailwindcss: bundle exec rake tailwindcss:compile:watch
|
136
|
+
```
|
137
|
+
|
138
|
+
### Recommended use in production
|
139
|
+
|
140
|
+
When deploying to production, it is recommended that you compile the css file before deploying.
|
141
|
+
|
142
|
+
You can do this by running the following command:
|
143
|
+
|
144
|
+
```bash
|
145
|
+
bundle exec rake tailwindcss:compile
|
146
|
+
```
|
147
|
+
|
148
|
+
### Heroku
|
149
|
+
|
150
|
+
If you're deploying to heroku, you can add the following line to your `Procfile` file to make sure the css file is compiled before deploying.
|
151
|
+
|
152
|
+
```yaml
|
153
|
+
release: bundle exec rake tailwindcss:compile
|
154
|
+
```
|
155
|
+
|
156
|
+
### Uploading to a CDN
|
157
|
+
|
158
|
+
If you're uploading your assets to a CDN, you can add the following line to your `Rakefile` to make sure the css file is compiled before uploading.
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
task "assets:precompile" => "tailwindcss:compile"
|
162
|
+
```
|
163
|
+
|
164
|
+
And make sure that your configuration is set up to use the correct file url in helpers.
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
Tailwindcss.configure do |config|
|
168
|
+
config.tailwind_css_file_path = proc { "https://cdn.example.com/assets/styles.css" }
|
169
|
+
end
|
170
|
+
```
|
171
|
+
> We're currently working on a fix to make this easier to configure and support fingerprinting.
|
172
|
+
|
173
|
+
## Advanced Usage
|
174
|
+
|
175
|
+
### Using Modifiers
|
176
|
+
|
177
|
+
Any key that starts with an underscore is considered a modifier. Modifiers are used to add pseudo classes and elements to the class.
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
tailwind(bg: :red, text: :white, _hover: { bg: :blue })
|
181
|
+
# => "bg-red-500 text-white hover:bg-blue-500"
|
182
|
+
|
183
|
+
tailwind(bg: :red, text: :white, _hover: { bg: :blue }, _before: { content: '[""]' })
|
184
|
+
# => "bg-red-500 text-white hover:bg-blue-500 before:content-[\"\"]"
|
185
|
+
```
|
186
|
+
|
187
|
+
|
188
|
+
### Using arbitrary values
|
189
|
+
|
190
|
+
When using arbitrary values, you have one of two options.
|
191
|
+
|
192
|
+
1. Wrap the value in `[]` to use the value as is.
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
tailwind(bg: "[url('image.png')]")
|
196
|
+
# => "bg-[url('image.png')]"
|
197
|
+
```
|
198
|
+
|
199
|
+
2. Use the `ab` method to add arbitrary values.
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
include Tailwindcss::Helpers
|
203
|
+
|
204
|
+
tailwind(bg: ab("url('image.png')"))
|
205
|
+
```
|
206
|
+
|
207
|
+
### Using color scheme values
|
208
|
+
|
209
|
+
You can use the color scheme values by using the `color_scheme_token` method.
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
Tailwindcss.configure do |config|
|
213
|
+
config.theme.color_scheme = {
|
214
|
+
primary: :red,
|
215
|
+
secondary: :blue,
|
216
|
+
tertiary: :green
|
217
|
+
}
|
218
|
+
end
|
219
|
+
|
220
|
+
tailwind(bg: color_scheme_token(:primary))
|
221
|
+
# => "bg-red-500"
|
222
|
+
```
|
223
|
+
|
224
|
+
Optionally, you can specify a shade.
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
tailwind(bg: color_scheme_token(:primary, 100))
|
228
|
+
# => "bg-red-100"
|
229
|
+
```
|
230
|
+
|
231
|
+
## Contributing
|
232
|
+
|
233
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/guilherme-andrade/tailwindcss-rb.
|
234
|
+
|
235
|
+
|
236
|
+
## License
|
237
|
+
|
238
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
239
|
+
|
240
|
+
|
241
|
+
## Development
|
242
|
+
|
243
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
244
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "bundler/setup"
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
require "rubocop/rake_task"
|
10
|
+
|
11
|
+
RuboCop::RakeTask.new
|
12
|
+
|
13
|
+
task default: %i[spec rubocop]
|
14
|
+
|
15
|
+
Dir.glob('lib/tasks/**/*.rake').each { |r| load r }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Tailwindcss
|
2
|
+
module AssetHelper
|
3
|
+
include ActionView::Helpers::AssetTagHelper
|
4
|
+
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def tailwind_stylesheet_path
|
8
|
+
Tailwindcss.tailwind_css_file_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def view_component_ui_asset_tags
|
12
|
+
stylesheet_link_tag(tailwind_stylesheet_path)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "tailwindcss/asset_helper"
|
2
|
+
|
3
|
+
module Tailwindcss
|
4
|
+
module Compiler
|
5
|
+
class Channel < ActionCable::Channel::Base
|
6
|
+
extend AssetHelper
|
7
|
+
|
8
|
+
def subscribed
|
9
|
+
stream_from "compiler_channel"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.broadcast_css_changed
|
13
|
+
css_path = vite_asset_path("style.css")
|
14
|
+
ActionCable.server.broadcast("compiler_channel", {css_path:})
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Tailwindcss
|
2
|
+
module Compiler
|
3
|
+
class FileClassesExtractor
|
4
|
+
require "tailwindcss/compiler/output"
|
5
|
+
require "tailwindcss/compiler/file_parser"
|
6
|
+
|
7
|
+
def call(file_path:)
|
8
|
+
ast = file_parser.call(file_path:)
|
9
|
+
return unless ast
|
10
|
+
|
11
|
+
hash_args = hash_args_extractor.call(ast:)
|
12
|
+
hash_args.map { class_list_builder.call(**_1) }.flatten.compact
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def hash_args_extractor = HashArgsExtractor.new
|
18
|
+
|
19
|
+
def file_parser = FileCompiler.new
|
20
|
+
|
21
|
+
def class_list_builder = StyleAttributesToListConverter.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Tailwindcss
|
2
|
+
module Compiler
|
3
|
+
class FileCompiler
|
4
|
+
require "parser/current"
|
5
|
+
require "tailwindcss/compiler/hash_args_extractor"
|
6
|
+
|
7
|
+
def call(file_path:)
|
8
|
+
file_content = File.read(file_path)
|
9
|
+
code = if file_is_ruby?(file_path:)
|
10
|
+
extract_ruby_from_rb(file_content:)
|
11
|
+
elsif file_is_erb?(file_path:)
|
12
|
+
extract_ruby_from_erb(erb: file_content)
|
13
|
+
else
|
14
|
+
return
|
15
|
+
end
|
16
|
+
|
17
|
+
buffer = Parser::Source::Buffer.new(file_path)
|
18
|
+
buffer.source = code
|
19
|
+
|
20
|
+
parser = Parser::CurrentRuby.new
|
21
|
+
parser.parse(buffer)
|
22
|
+
rescue Parser::SyntaxError
|
23
|
+
Rails.logger.error("Tailwindcss: Failed to parse #{file_path}. Skipping...")
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def file_is_ruby?(file_path:)
|
29
|
+
file_path.end_with?(".rb")
|
30
|
+
end
|
31
|
+
|
32
|
+
def file_is_erb?(file_path:)
|
33
|
+
file_path.end_with?(".html.erb")
|
34
|
+
end
|
35
|
+
|
36
|
+
def erb_template_in_ruby?(file_path:)
|
37
|
+
file_is_ruby?(file_path:) && File.read(file_path).match?(/<<(~|-)ERB/)
|
38
|
+
end
|
39
|
+
|
40
|
+
def extract_ruby_from_rb(file_content:)
|
41
|
+
[file_content, erb_code_from_rb(file_content:)].flatten.compact.join("\n")
|
42
|
+
end
|
43
|
+
|
44
|
+
def erb_code_from_rb(file_content:)
|
45
|
+
match_erb = file_content.match(/<<[~-]ERB(.*)ERB/m)
|
46
|
+
extract_ruby_from_erb(erb: match_erb[1]) if match_erb
|
47
|
+
end
|
48
|
+
|
49
|
+
def extract_ruby_from_erb(erb:)
|
50
|
+
# Use a regex to extract ruby code from ERB
|
51
|
+
erb.scan(/<%=?([\s\S]*?)%>/m).flatten.compact.join("\n")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|