Class: Spectre::Prompt
- Inherits:
-
Object
- Object
- Spectre::Prompt
- Defined in:
- lib/spectre/prompt.rb
Defined Under Namespace
Classes: Context
Constant Summary collapse
- PROMPTS_PATH =
File.join(Dir.pwd, 'app', 'spectre', 'prompts')
Class Method Summary collapse
-
.render(template:, locals: {}) ⇒ String
Render a prompt by reading and rendering the YAML template.
Class Method Details
.render(template:, locals: {}) ⇒ String
Render a prompt by reading and rendering the YAML template
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/spectre/prompt.rb', line 16 def self.render(template:, locals: {}) type, prompt = split_template(template) file_path = prompt_file_path(type, prompt) raise "Prompt file not found: #{file_path}" unless File.exist?(file_path) template_content = File.read(file_path) erb_template = ERB.new(template_content) context = Context.new(locals) rendered_prompt = erb_template.result(context.get_binding) YAML.safe_load(rendered_prompt)[prompt] end |