Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Tails by turboprop #84

Merged
merged 3 commits into from
Nov 15, 2024
Merged

Replace Tails by turboprop #84

merged 3 commits into from
Nov 15, 2024

Conversation

bluzky
Copy link
Owner

@bluzky bluzky commented Nov 14, 2024

Some forks report issue related to tails as discussed here: https://elixirforum.com/t/turboprop-toolkit-to-create-accessible-component-libraries/64228

I decided to borrow Merge module from Turboprop and copied to SaladUI code base. Sadly because Turboprop is now discontinued.

I've tested on all existing components, and so far so good.

Summary by Sourcery

Replace 'tails' with 'turboprop' for merging Tailwind CSS classes, update related configurations, and refactor tests to improve maintainability.

Enhancements:

  • Refactor tests to use a more modular approach for asserting HTML class presence, improving readability and maintainability.

Documentation:

  • Update documentation to replace references to 'tails' with 'turboprop' and adjust installation instructions accordingly.

Tests:

  • Remove tests related to 'tails' configuration and update tests to reflect the new 'turboprop' integration.

Chores:

  • Remove 'tails' dependency and related configuration from the project.

Copy link

sourcery-ai bot commented Nov 14, 2024

Reviewer's Guide by Sourcery

This pull request replaces the Tails dependency with a custom implementation borrowed from the Turboprop project for merging Tailwind CSS classes. The implementation includes a comprehensive class merging system with caching capabilities and support for various Tailwind features.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Replace Tails dependency with custom Turboprop-based implementation
  • Add new Merge module with class merging functionality
  • Add Cache module for performance optimization
  • Add ClassTree module for handling Tailwind class hierarchies
  • Add Parser module using NimbleParsec for class parsing
  • Add Validator module for validating Tailwind class values
  • Add comprehensive test suite for the new implementation
lib/utils/merge.ex
lib/utils/merge/class_tree.ex
lib/utils/merge/class.ex
lib/utils/merge/parser.ex
lib/utils/merge/validator.ex
lib/utils/cache.ex
test/utils/merge_test.exs
test/utils/validator_test.exs
Update configuration and dependencies
  • Remove Tails configuration from config files
  • Add new dependencies: nimble_parsec and deep_merge
  • Remove Tails dependency from mix.exs
  • Update installation instructions in README.md
config/config.exs
mix.exs
README.md
Refactor test assertions to use more granular class checking
  • Replace single large class string assertions with individual class checks
  • Update test helper to initialize cache before tests
  • Add new test cases for class merging functionality
test/salad_ui/input_test.exs
test/salad_ui/popover_test.exs
test/salad_ui/hover_card_test.exs
test/salad_ui/pagination_test.exs
test/salad_ui/menu_test.exs
test/salad_ui/form_test.exs
test/salad_ui/dialog_test.exs
test/salad_ui/label_test.exs
test/support/component_case.ex

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bluzky bluzky mentioned this pull request Nov 14, 2024
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @bluzky - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟡 Complexity: 1 issue found
  • 🟡 Documentation: 2 issues found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider adding tests for all new utility modules

I notice that while several utility modules are being added (class.ex, class_tree.ex, config.ex, parser.ex), there are only tests for merge and validator. Consider adding dedicated test files for each module to ensure complete coverage of the new functionality.

defmodule SaladUI.Utils.ClassTest do
  use ExUnit.Case
  alias SaladUI.Utils.Class

  test "class utility functions" do
    assert Class.join(["btn", "primary"]) == "btn primary"
    assert Class.join(["btn", nil, "primary"]) == "btn primary"
  end
end



4. **Add javascript to handle event from server**
3. **Add javascript to handle event from server**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (documentation): Step numbering needs to be updated after removal of tails section

The steps go from 2 to 4, skipping 3. Please update the numbering to be sequential.

Comment on lines 50 to +53
#> mix salad.add label button
```

2. **Using `salad_ui` as a library:**

- Adding `salad_ui` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:salad_ui, "~> 0.13.0", only: [:dev]}
]
end
```

3. **Using `salad_ui` as a library:**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (documentation): Installation methods could be more clearly distinguished

Consider adding a brief comparison of when to use each installation method at the start of the installation section to help users choose the appropriate approach.

## Installation

Choose your installation method:
- **As a library**: Use this if you want to use pre-built components without modifications
- **As a project dependency**: Use this if you need to customize components or use specific ones

2. **Using `salad_ui` as part of your project:**

> Install only the components you need and customize the source code to fit your requirements.

- Init Salad UI in your project

end
end

def generate do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider flattening the nested tree structure into a single-level map with compound keys

The nested tree structure with recursive operations can be simplified to a flat map while maintaining the same functionality. Consider this approach:

def generate do
  config = Config.config()
  theme = Map.get(config, :theme, %{})
  prefix = Map.get(config, :prefix)
  groups = Map.get(config, :groups, [])

  classes =
    groups
    |> Enum.flat_map(fn {group, next} ->
      flatten_classes(next, group, prefix)
    end)
    |> Map.new()
end

defp flatten_classes(next, group, prefix, path \\ "") do
  Enum.flat_map(next, fn
    {sub_group, sub_next} ->
      new_path = join_path(path, sub_group)
      flatten_classes(sub_next, group, prefix, new_path)

    part when is_binary(part) ->
      full_path = join_path(path, part)
      [{full_path, %{"group" => group, "validators" => %{}}}]

    part when is_function(part) ->
      handle_function(part, group, path)
  end)
end

This approach:

  1. Uses a flat map with compound keys instead of nested "next" structures
  2. Eliminates deep merges and complex recursion
  3. Maintains the same functionality with simpler code
  4. Makes the data structure easier to traverse and modify

The resulting data structure would be a single-level map with paths as keys, making it more efficient to look up and modify values.

@bluzky bluzky merged commit c0d36d4 into main Nov 15, 2024
2 of 3 checks passed
@bluzky bluzky deleted the feature/tailwind-merge branch November 15, 2024 15:40
@bmalum
Copy link
Contributor

bmalum commented Nov 25, 2024

Just noticed that we need to ass TwMerge.Cache to the application.ex children to properly work, otherwise the ETS Table is not available. 😊 @bluzky

@bluzky
Copy link
Owner Author

bluzky commented Nov 26, 2024

thanks @bmalum I'll update document

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants