Skip to content

Commit

Permalink
Undeprecate Example and rename it to LiveExample
Browse files Browse the repository at this point in the history
  • Loading branch information
msaraiva committed Sep 19, 2024
1 parent 06e1c8f commit 4c1f4c6
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 24 deletions.
5 changes: 4 additions & 1 deletion lib/surface/catalogue/examples.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
defmodule Surface.Catalogue.Examples do
@moduledoc since: "0.8.0"
@moduledoc ~S'''
A generic LiveView to create multiple examples for catalogue tools.
A generic LiveView to create multiple stateless examples for the Surface Catalogue.
Each example must be a function component defined with the module attribute `@example`.
> **NOTE**: If your examples require manipulating state (data) through `handle_event` callbacks,
> use `Surface.Catalogue.LiveExample` instead.
## Options
Besides the buit-in options provided by the LiveView itself, examples can also
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
defmodule Surface.Catalogue.Example do
defmodule Surface.Catalogue.LiveExample do
@moduledoc """
> #### Deprecation warning {: .warning}
>
> This component has been deprecated in favor of `Surface.Catalogue.Examples`.
A generic LiveView to create a single live example for the Surface Catalogue.
A generic LiveView to create a single example for catalogue tools.
Use `LiveExample` if your example requires manipulating state (data) through
`handle_event` callbacks. For stateless examples, you should use `Surface.Catalogue.Examples`
as it allows defining multiple examples on a single module.
## Options
Expand Down Expand Up @@ -36,16 +36,7 @@ defmodule Surface.Catalogue.Example do
"""

@moduledoc deprecated: "Use `Surface.Catalogue.Examples` instead"

defmacro __using__(opts) do
if Mix.env() != :test do
IO.warn(
"`Surface.Catalogue.Example` is deprecated. Use `Surface.Catalogue.Examples` instead",
Macro.Env.stacktrace(__CALLER__)
)
end

subject = Surface.Catalogue.fetch_subject!(opts, __MODULE__, __CALLER__)

quote do
Expand Down
2 changes: 1 addition & 1 deletion test/support/catalogue/fake_example.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Surface.Catalogue.FakeExample do
use Surface.Catalogue.Example,
use Surface.Catalogue.LiveExample,
subject: Surface.FakeComponent,
title: "A fake example",
assert: ["The code"]
Expand Down
2 changes: 1 addition & 1 deletion test/support/catalogue/fake_example_moduledoc.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Surface.Catalogue.FakeExampleModuleDocFalse do
@moduledoc false

use Surface.Catalogue.Example,
use Surface.Catalogue.LiveExample,
subject: Surface.FakeComponent,
title: "A fake example"

Expand Down
2 changes: 1 addition & 1 deletion test/support/catalogue/fake_example_with_user_config.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Surface.Catalogue.FakeExampleWithUserConfig do
use Surface.Catalogue.Example,
use Surface.Catalogue.LiveExample,
subject: Surface.FakeComponent,
head_css: "User's fake css",
head_js: "User's fake js"
Expand Down
2 changes: 1 addition & 1 deletion test/support/live_view_test/fake_example.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Surface.LiveViewTestTest.FakeExample do
use Surface.Catalogue.Example,
use Surface.Catalogue.LiveExample,
subject: Surface.LiveViewTestTest.FakeComponent,
title: "A fake example",
assert: "the code"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Surface.LiveViewTestTest.FakeExampleForOtherFakeComponent do
use Surface.Catalogue.Example,
use Surface.Catalogue.LiveExample,
subject: Surface.LiveViewTestTest.OtherFakeComponent,
title: "A fake example"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Surface.Catalogue.ExampleTest do
defmodule Surface.Catalogue.LiveExampleTest do
use ExUnit.Case

alias Surface.Catalogue.FakeExample
Expand Down Expand Up @@ -31,16 +31,16 @@ defmodule Surface.Catalogue.ExampleTest do
test "subject is required" do
code = """
defmodule ExampleTest_subject_is_required do
use Surface.Catalogue.Example
use Surface.Catalogue.LiveExample
end
"""

message = """
code.exs:2: no subject defined for Surface.Catalogue.Example
code.exs:2: no subject defined for Surface.Catalogue.LiveExample
Hint: You can define the subject using the :subject option. Example:
use Surface.Catalogue.Example, subject: MyApp.MyButton
use Surface.Catalogue.LiveExample, subject: MyApp.MyButton
"""

assert_raise CompileError, message, fn ->
Expand Down

0 comments on commit 4c1f4c6

Please sign in to comment.