-
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.
introduce preview; wire up list of previews and prompts
- Loading branch information
Showing
9 changed files
with
70 additions
and
12 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "active_support/descendants_tracker" | ||
|
||
module ActionPrompt | ||
class Preview | ||
# We need to be able to do the following: | ||
# - find all the preview objects | ||
# - find all the preview methods on those objects | ||
# - render a preview | ||
# | ||
class << self | ||
def all | ||
load_previews if descendants.empty? | ||
descendants.sort_by(&:name) | ||
end | ||
|
||
def load_previews | ||
# TODO: this preview path could be made configurable in order to have equivalent | ||
# functionality to Rails mailer previews | ||
Dir[Rails.root.join("test", "prompts", "**", "*_preview.rb")].each do |path| | ||
require path | ||
end | ||
end | ||
|
||
def preview_name | ||
name.delete_suffix("Preview").underscore | ||
end | ||
|
||
def prompts | ||
public_instance_methods(false).map(&:to_s).sort | ||
end | ||
end | ||
end | ||
end |
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,14 @@ | ||
require "test_helper" | ||
|
||
class ActionPrompt::PreviewTest < ActiveSupport::TestCase | ||
test "all" do | ||
previews = ActionPrompt::Preview.all | ||
assert_equal 1, previews.count | ||
end | ||
|
||
test "preview_name" do | ||
preview = ActionPrompt::Preview.all.first | ||
|
||
assert_equal "hello_world", preview.preview_name | ||
end | ||
end |
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,9 @@ | ||
class HelloWorldPreview < ActionPrompt::Preview | ||
def hello_world | ||
ActivePrompt.render("hello_world") | ||
end | ||
|
||
def hello_somebody | ||
ActivePrompt.render("hello_somebody", locals: { name: "Lenny" }) | ||
end | ||
end |