Skip to content

Commit

Permalink
More fixes to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
guilherme-andrade committed Nov 3, 2024
1 parent 316c9bb commit e3f8bc6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 14 deletions.
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ bundle exec rake tailwindcss:install
```




## Basic Usage

At its core of the gem, is the `Style` class. This class is used to generate tailwindcss classes in a ruby-like way.
Expand All @@ -50,7 +48,7 @@ Any key that starts with an underscore is considered a modifier. Modifiers are u
tailwind(bg: :red, text: :white, _hover: { bg: :blue })
# => "bg-red-500 text-white hover:bg-blue-500"

tailwind(bg: :red, text: :white, _hover: { bg: :blue }, _before: { content: '""' })
tailwind(bg: :red, text: :white, _hover: { bg: :blue }, _before: { content: '[""]' })
# => "bg-red-500 text-white hover:bg-blue-500 before:content-[\"\"]"
```

Expand Down Expand Up @@ -93,9 +91,53 @@ bundle exec rake tailwindcss:compile
Or by starting a process that watches for changes.

```bash
bundle exec rake tailwindcss:compile --watch
bundle exec rake tailwindcss:compile:watch
```

#### Recommended use in development

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.

You can either do this by running the following command in a separate terminal window:

```bash
bundle exec rake tailwindcss:compile:watch
```

Or by adding the following line to your `Procfile.dev` file when using foreman.

```yaml
tailwindcss: bundle exec rake tailwindcss:compile:watch
```
#### Recommended use in production
When deploying to production, it is recommended that you compile the css file before deploying.
You can do this by running the following command:
```bash
bundle exec rake tailwindcss:compile
```

##### Heroku

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.

```yaml
release: bundle exec rake tailwindcss:compile
```
##### Uploading to a CDN
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.

```ruby
task "assets:precompile" => "tailwindcss:compile"
```

And make sure that your configuration is set up

#### How the compiler works

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`.
Expand Down
8 changes: 6 additions & 2 deletions lib/tailwindcss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module Tailwindcss
setting :content, default: proc { [] }
setting :prefix, default: ""

setting :tailwind_css_file_path, default: proc { Tailwindcss.config.compiler.output_path.call }
setting :tailwind_config_overrides, default: proc { {} }

setting :watch_content, default: false

setting :breakpoints, default: BREAKPOINTS
Expand All @@ -45,7 +45,7 @@ def extend_theme(**overrides)
config.extend ExtendTheme

def theme
@theme ||= self.config.theme.to_h.transform_values { _1.respond_to?(:call) ? _1.() : _1 }
@theme ||= OpenStruct.new(self.config.theme.to_h.transform_values { _1.respond_to?(:call) ? _1.() : _1 })
end

def configure(&blk)
Expand All @@ -68,6 +68,10 @@ def output_path
@output_path ||= Tailwindcss.config.compiler.output_path.call
end

def tailwind_css_file_path
@tailwind_css_file_path ||= Tailwindcss.config.tailwind_css_file_path.call
end

def logger
@logger ||= config.logger.call
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tailwindcss/asset_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module AssetHelper
extend self

def tailwind_stylesheet_path
Tailwindcss.output_path
Tailwindcss.tailwind_css_file_path
end

def view_component_ui_asset_tags
Expand Down
4 changes: 2 additions & 2 deletions lib/tailwindcss/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def ab(value)
ArbitraryValue.new(value)
end

# @param token [String] A value your Tailwindcss.config.theme.color_scheme keys
# @param token [String] A value your Tailwindcss.theme.color_scheme keys
# @param weight [Integer] A value between 100 and 900
def color_scheme_token(token, weight = 500)
color_token(Tailwindcss.config.theme.color_scheme[token.to_sym], weight)
color_token(Tailwindcss.theme.color_scheme[token.to_sym], weight)
end

# @param color_token [String] A value your of any of tailwinds color tokens
Expand Down
14 changes: 10 additions & 4 deletions lib/tasks/tailwindcss.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ namespace :tailwindcss do
Tailwindcss::Installers::ConfigFileGenerator.new.call
end


desc "Compile TailwindCSS"
task :compile do |t, args|
task :compile do
require "tailwindcss/compiler/runner"
watch = args[:watch] || false
Tailwindcss::Compiler::Runner.new(watch:).call
Tailwindcss::Compiler::Runner.new.call
end

namespace :compile do
desc "Compile TailwindCSS and watch for file changes"
task :watch do
require "tailwindcss/compiler/runner"
Tailwindcss::Compiler::Runner.new(watch: true).call
end
end
end
1 change: 0 additions & 1 deletion spec/tmp/tailwindcss/styles.css

This file was deleted.

0 comments on commit e3f8bc6

Please sign in to comment.