diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 5b8ca56..affa76b 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -15,6 +15,8 @@ jobs: - run: mix test - run: mix credo --strict - run: mix docs + - name: Check if versions showcase mix script finishes + run: mix run scripts/generate_version_showcase.ex demo: runs-on: ubuntu-latest name: Demo diff --git a/.gitignore b/.gitignore index 863a391..c1ff8c5 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ erl_crash.dump # Ignore package tarball (built via "mix hex.build"). bitstyles_phoenix-*.tar +/version_showcase diff --git a/README.md b/README.md index 3cd9af2..bc512f8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,9 @@ Basic helpers for [bitstyles](https://github.com/bitcrowd/bitstyles) for elixir ## Requirements -bitstyles must be installed separately into the asset generation. The helpers in this project just output classes for working with bitstyles. +Bitstyles must be installed separately into the asset generation. The helpers in this project just output classes for working with bitstyles. + +Bitstyles versions from 4.3.0 down to 1.3.0 are supported. ## Installation diff --git a/docs/bitstyles_version_compatibility.md b/docs/bitstyles_version_compatibility.md new file mode 100644 index 0000000..82743e7 --- /dev/null +++ b/docs/bitstyles_version_compatibility.md @@ -0,0 +1,103 @@ +# Bitstyles version compatibility + +General rules: + +- We don't drop bitstyles version support. Users of bitstyles_phoenix should be able to upgrade bitstyles_phoenix to the newest version without having to upgrade bitstyles. +- We don't skip bitstyles versions. Users of bitstyles_phoenix should be able to upgrade bitstyles to any version between the highest and lowest currently supported bitstyles version. + +## Doctests ("stories") + +The `story` macro is used to generate doctests, as well as the component preview in docs. + +The first argument is the story's description (`"An error tag"`), the second argument is an iex code snippet, and the third argument is the expected result when the code snippet gets executed. The third argument can be a single charlist, or a keyword lists that maps bitstyles version numbers to charlists. If the third argument is a single charlist, it's assumed that is the expected result for the default bitstyles version. + +⚠️ Note that the 4 space indentation in the code snippet and the expected result is important. + +### Multi-version doctest example + +```elixir + story( + "An error tag", + ''' + iex> assigns = %{} + ...> render ~H""" + ...> <.ui_error error={{"Foo error", []}} /> + ...> """ + ''', + "4.3.0": ''' + """ + + Foo error + + """ + ''', + "3.0.0": ''' + """ + + Foo error + + """ + ''' + ) +``` + +## Versions showcase + +A showcase of components in all supported bitstyles versions can be generated by running: + +```bash +mix run scripts/generate_version_showcase.ex +``` + +The script accepts multiple `--only` arguments if you want to limit the showcase to only a handful of versions: + +```bash +mix run scripts/generate_version_showcase.ex --only 4.3.0 --only 4.2.0 +``` + +This script will create a `version_showcase` directory with static web pages. Open the starting page with: + +```bash +open version_showcase/index.html +``` + +## How to upgrade the default bitstyles version in bitstyles_phoenix? + +1. Choose the smallest possible version jump (do not skip versions). +2. Read about the changes in version in [the bitstyles Changelog](https://github.com/bitcrowd/bitstyles/blob/main/CHANGELOG.md). +3. Update the highest supported version mentioned in the [README](../README.md). +4. Update the `@default_version` in [`BitstylesPhoenix.Bitstyles`](../lib/bitstyles_phoenix/bitstyles.ex). +5. Add the new version to the version lists in [`generate_version_showcase`](../scripts/generate_version_showcase.ex). +6. Handle classes renamed by bitstyles by adding new clauses of the `classname/2` function in [`BitstylesPhoenix.Bitstyles`](../lib/bitstyles_phoenix/bitstyles.ex). +7. If renaming classes is not enough to upgrade correctly, you can perform [a bitstyles version check in a component](#an-example-of-a-bitstyles-version-check-in-a-component). +8. Run `mix test`. Fix all doctests until `mix test` succeeds. Add new expected values for the new version, and keep the current expected value for the previous version (see [multi-version doctest example](#multi-version-doctest-example)) +9. Run `mix docs` to preview components after making changes to them. +10. Use the [versions showcase](#versions-showcase) to test that you didn't break anything for older bitstyles versions. + +### An example of a bitstyles version check in a component + +```elixir +def ui_tricky_component(assigns) do + version = BitstylesPhoenix.Bitstyles.version() + + if version >= "5.0.0" do + ~H""" +
...
+ """ + else + ~H""" +