Skip to content

Commit 90bcc53

Browse files
committed
prepare for doing cooler things with the renderer
1 parent d599065 commit 90bcc53

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

app/views/action_prompt/previews/show.html.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<div>Prompt</div>
21
<h1 class="text-xl font-semibold">
32
<%= @preview_class.name %>: <%= params[:prompt_name] %>
43
</h1>
5-
<div class="py-4">
4+
<div class="pb-2">
5+
<%= link_to "<< Back to prompts", "/action_prompt/previews", class: "cursor-pointer text-blue-500 underline hover:text-blue-600 text-sm" %>
6+
</div>
7+
<div class="py-2">
68
<div>
79
Output
810
</div>

lib/action_prompt.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
require "action_prompt/engine"
33
require "action_prompt/railtie"
44
require "action_prompt/preview"
5+
require "action_prompt/renderer"
56
module ActionPrompt
67
end

lib/action_prompt/preview.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ def initialize(name:, slug:)
5454
end
5555

5656
def render(template_name, locals: {})
57-
controller = ApplicationController.new
58-
controller.prepend_view_path(Rails.root.join("app", "prompts"))
59-
controller.render_to_string(template: template_name, locals: locals)
57+
ActionPrompt::Renderer.new.render(template_name, locals: locals)
6058
end
6159
end
6260
end

lib/action_prompt/renderer.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module ActionPrompt
2+
class Renderer
3+
def initialize
4+
# NOOP
5+
end
6+
7+
def render(template_name, locals: {})
8+
controller = ApplicationController.new
9+
controller.prepend_view_path(Rails.root.join("app", "prompts"))
10+
controller.render_to_string(template: template_name, locals: locals)
11+
end
12+
end
13+
end

lib/tasks/action_prompt_tasks.rake

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)