Class: AdminSuite::Renderers::LegacyGleania::PromptTemplateRenderer
- Inherits:
-
AdminSuite::Renderer
- Object
- AdminSuite::Renderer
- AdminSuite::Renderers::LegacyGleania::PromptTemplateRenderer
- Defined in:
- lib/admin_suite/renderers/legacy_gleania.rb
Overview
Verbatim from BaseHelper#render_prompt_template.
Instance Attribute Summary
Attributes inherited from AdminSuite::Renderer
Instance Method Summary collapse
Methods inherited from AdminSuite::Renderer
Constructor Details
This class inherits a constructor from AdminSuite::Renderer
Instance Method Details
#render ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/admin_suite/renderers/legacy_gleania.rb', line 43 def render LegacyGleania.warn_once(:prompt_template_preview) template = record.respond_to?(:prompt_template) ? record.prompt_template : nil return content_tag(:p, "No template defined", class: "text-slate-500 italic") if template.blank? highlighted_template = h(template).gsub(/\{\{(\w+)\}\}/) do "<span class=\"text-amber-400 bg-amber-900/30 px-1 rounded\">{{#{$1}}}</span>" end content_tag(:div, class: "relative group") do view.concat(content_tag(:div, class: "absolute top-2 right-2 flex items-center gap-2") do view.concat(content_tag(:span, "TEMPLATE", class: "text-xs font-medium text-slate-400 uppercase tracking-wider")) view.concat(content_tag(:button, '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/></svg>'.html_safe, type: "button", class: "p-1 text-slate-400 hover:text-slate-600 opacity-0 group-hover:opacity-100 transition-opacity", data: { controller: "admin-suite--clipboard", action: "click->admin-suite--clipboard#copy", "admin-suite--clipboard-text-value": template }, title: "Copy to clipboard")) end) view.concat(content_tag(:pre, class: "bg-slate-900 text-slate-100 p-4 rounded-lg overflow-x-auto text-sm font-mono max-h-[600px] overflow-y-auto whitespace-pre-wrap leading-relaxed") do highlighted_template.html_safe end) variables = template.scan(/\{\{(\w+)\}\}/).flatten.uniq if variables.any? view.concat(content_tag(:div, class: "mt-3 pt-3 border-t border-slate-700") do view.concat(content_tag(:span, "Variables: ", class: "text-sm text-slate-400")) view.concat(content_tag(:div, class: "inline-flex flex-wrap gap-1 mt-1") do variables.each do |var| view.concat(content_tag(:code, "{{#{var}}}", class: "text-xs px-2 py-0.5 bg-amber-900/30 text-amber-400 rounded")) end end) end) end end end |