Skip to content

Commit

Permalink
fix(tailwindcss): Add required mark config (#5)
Browse files Browse the repository at this point in the history
This change is adding the required CSS color to the required fields.
  • Loading branch information
JuanVqz authored Jul 7, 2024
1 parent ba3ad7e commit c882925
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,31 @@ However, if you install the gem, you will get the latest updates and improvement

## Usage

### Install Tailwind CSS initializer
### Install Tailwind CSS files

```bash
bin/rails generate simple_form:theme:tailwind install
```

### Install Bulma CSS initializer
After running this generator, you will see the `config/initializers/simple_form_tailwindcss.rb` file.
This file adds the Tailwind CSS styles to your application.
Additionally, the `config/locales/simple_form_tailwind.en.yml` file will add the "required" mark to the required fields.
However, you need to communicate Tailwind to "watch" those files by adding the following configuration:

```js
# tailwind.config.js

module.exports = {
...
content: [
'./config/initializers/simple_form_tailwindcss.rb',
'./config/locales/simple_form*.yml',
...
],
}
```

### Install Bulma CSS files

```bash
bin/rails generate simple_form:theme:bulma install
Expand Down
6 changes: 2 additions & 4 deletions lib/generators/simple_form/theme/tailwind/USAGE
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Description:
Install the simple form tailwindcss config file in your app.

Example:
Install Command:
bin/rails generate simple_form:theme:tailwind install

This will create:
config/initializers/simple_form_tailwindcss.rb
config/locales/
23 changes: 21 additions & 2 deletions lib/generators/simple_form/theme/tailwind/tailwind_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@
class SimpleForm::Theme::TailwindGenerator < Rails::Generators::NamedBase
source_root File.expand_path('templates', __dir__)

desc 'Copy the tailwindcss initializer file for simple_form'
def copy_initializer_file
desc 'Copy the tailwindcss files for simple_form'
def generate
install if install?
end

private

def install
copy_initializers
copy_locales
end

def install?
name == 'install'
end

def copy_initializers
template 'config/initializers/simple_form_tailwindcss.rb', 'config/initializers/simple_form_tailwindcss.rb'
end

def copy_locales
directory 'config/locales'
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
en:
simple_form:
required:
text: 'required'
mark: '*'
html: '<abbr class="text-red-500 no-underline" title="required">*</abbr>'
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ class SimpleForm::Theme::TailwindGeneratorTest < Rails::Generators::TestCase

test 'generator runs without errors' do
assert_nothing_raised do
run_generator ['install']
run_generator ['random']
end
end

test 'generator copies the initializer file' do
run_generator ['install']
assert_file 'config/initializers/simple_form_tailwindcss.rb'
end

test 'generator copies the locales files' do
run_generator ['install']
assert_directory 'config/locales'
end
end
end

0 comments on commit c882925

Please sign in to comment.