-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation about upgrading bitstyles versions; add versions sh…
…owcase dev tool (#119) * Render static pages with showcases for all bitstyles versions * Add an --only flag * Refactoring * Hide showcase task from library users * Add to CI to ensure it continues working in the future * Describe how to approach upgrading bitstyles * Fix credo problem * Don't include test fixtures in documentation * Don't link from hexdoc to a dev-only doc * Fix plural vs singular * Split doctest into two parts in story macro * Allow doctests for other bitstyles versions * Extend version doc with new multi-version doctests * credo * Make tests async again with process dict
- Loading branch information
1 parent
8953954
commit 3e5d5e5
Showing
32 changed files
with
1,701 additions
and
824 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ erl_crash.dump | |
# Ignore package tarball (built via "mix hex.build"). | ||
bitstyles_phoenix-*.tar | ||
|
||
/version_showcase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": ''' | ||
""" | ||
<span class="u-fg-warning"> | ||
Foo error | ||
</span> | ||
""" | ||
''', | ||
"3.0.0": ''' | ||
""" | ||
<span class="u-fg--warning"> | ||
Foo error | ||
</span> | ||
""" | ||
''' | ||
) | ||
``` | ||
|
||
## 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""" | ||
<p class={classnames("u-new-class-that-does-everything")}>...</p> | ||
""" | ||
else | ||
~H""" | ||
<div class={classnames("u-old-class1 u-old-class2")}> | ||
<div class={classnames("u-old-class3")}> | ||
... | ||
</div> | ||
</div> | ||
""" | ||
end | ||
end | ||
``` | ||
|
||
## Adding new components | ||
|
||
Ideally, if you're adding a completely new component, make sure it works with all supported bitstyles versions by using the [versions showcase](#versions-showcase) to test it. | ||
|
||
If it's not practical to support it in other version, you can perform [a bitstyles version check in the component](#an-example-of-a-bitstyles-version-check-in-a-component). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.