Class: ActionPrompt::Renderer
- Inherits:
-
Object
- Object
- ActionPrompt::Renderer
- Defined in:
- lib/action_prompt/renderer.rb
Overview
Handles ERB template rendering for prompt actions via ActionView.
Templates are resolved from the view paths configured on the prompt class
(defaults to app/views/ in a Rails app). The lookup path convention is:
app/views/action_prompts/<prompt_class_name>/<action_name>.text.erb
Examples
ArticleSummarizerPrompt -> action_prompts/article_summarizer_prompt/summarize.text.erb
Admin::ReportPrompt -> action_prompts/admin/report_prompt/generate.text.erb
Instance Method Summary collapse
-
#initialize(prompt_instance, action_name) ⇒ Renderer
constructor
A new instance of Renderer.
-
#render ⇒ String
Renders the ERB template and returns the resulting string.
Constructor Details
#initialize(prompt_instance, action_name) ⇒ Renderer
Returns a new instance of Renderer.
18 19 20 21 |
# File 'lib/action_prompt/renderer.rb', line 18 def initialize(prompt_instance, action_name) @prompt_instance = prompt_instance @action_name = action_name end |
Instance Method Details
#render ⇒ String
Renders the ERB template and returns the resulting string.
27 28 29 30 31 |
# File 'lib/action_prompt/renderer.rb', line 27 def render lookup_context = ActionView::LookupContext.new(resolved_view_paths) view = ActionView::Base.with_empty_template_cache.new(lookup_context, assigns, nil) view.render(template: template_path, formats: [:text], handlers: [:erb]) end |