mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 11:37:58 +00:00
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sojan Jose <sojan@pepalo.com> Co-authored-by: Pranav <pranav@chatwoot.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
26 lines
637 B
Ruby
26 lines
637 B
Ruby
require 'liquid'
|
|
|
|
class Captain::PromptRenderer
|
|
class << self
|
|
def render(template_name, context = {})
|
|
template = load_template(template_name)
|
|
liquid_template = Liquid::Template.parse(template)
|
|
liquid_template.render(stringify_keys(context))
|
|
end
|
|
|
|
private
|
|
|
|
def load_template(template_name)
|
|
template_path = Rails.root.join('enterprise', 'lib', 'captain', 'prompts', "#{template_name}.liquid")
|
|
|
|
raise "Template not found: #{template_name}" unless File.exist?(template_path)
|
|
|
|
File.read(template_path)
|
|
end
|
|
|
|
def stringify_keys(hash)
|
|
hash.deep_stringify_keys
|
|
end
|
|
end
|
|
end
|