rails_prompts 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/rails_prompts/version.rb +5 -0
- data/lib/rails_prompts.rb +63 -0
- metadata +105 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 207485f6457081520bb54b841b850c9d89f0d6c25a15376e79c540bc167f6252
|
|
4
|
+
data.tar.gz: 9d8bde3d842ed98b6b2ce968e02cfc443db215bb9e311b3b1f1b18b8b75449f5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 26c27a09a193384f0a6c997393c367d783c57e35f24e46ff4a572446642a8a832449ccd988f48d73a026672e7e9720a3914682da11bbeb87889b87ba6fd46ec0
|
|
7
|
+
data.tar.gz: 85a50e1d629625926ad50fb26baa8c728949c55767cb0937a6128823f303a315293236ef5ef29480c400ea083352be031cbc96caba71e21e60eea99d57ee04e5
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'rails_prompts/version'
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# Service class for managing AI prompts stored in markdown files with ERB interpolation.
|
|
7
|
+
# This centralizes prompt management and makes them easier to review and modify.
|
|
8
|
+
|
|
9
|
+
class RailsPrompts
|
|
10
|
+
class << self
|
|
11
|
+
attr_writer :prompts_dir
|
|
12
|
+
|
|
13
|
+
def prompts_dir
|
|
14
|
+
@prompts_dir ||= defined?(Rails) && Rails.root ? Rails.root.join('app', 'prompts') : Pathname.new('app/prompts')
|
|
15
|
+
end
|
|
16
|
+
# Renders a prompt template with the provided variables
|
|
17
|
+
# @param template_name [String] The name of the template file (without .md.erb extension)
|
|
18
|
+
# @param variables [Hash] Variables to be interpolated into the template
|
|
19
|
+
# @return [String] The rendered prompt
|
|
20
|
+
def render_prompt(template_name, variables = {})
|
|
21
|
+
|
|
22
|
+
template_path = prompts_dir.join("#{template_name}.md.erb")
|
|
23
|
+
|
|
24
|
+
unless File.exist?(template_path)
|
|
25
|
+
raise ArgumentError, "Prompt template '#{template_name}' not found at #{template_path}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
template_content = File.read(template_path)
|
|
29
|
+
|
|
30
|
+
# Create an ERB template with the content
|
|
31
|
+
erb_template = ERB.new(template_content, trim_mode: '-')
|
|
32
|
+
|
|
33
|
+
# Create a binding with the provided variables
|
|
34
|
+
binding_context = create_binding_context(variables)
|
|
35
|
+
|
|
36
|
+
# Render the template
|
|
37
|
+
erb_template.result(binding_context)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Lists all available prompt templates
|
|
41
|
+
# @return [Array<String>] Array of template names (without extensions)
|
|
42
|
+
def available_prompts
|
|
43
|
+
Dir.glob(prompts_dir.join('*.md.erb')).map do |file|
|
|
44
|
+
File.basename(file, '.md.erb')
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
# Creates a binding context with the provided variables. This method uses an
|
|
51
|
+
# anonymous Struct to create a clean, isolated binding
|
|
52
|
+
# @param variables [Hash] Variables to be made available in the template
|
|
53
|
+
# @return [Binding] A binding object with the variables defined
|
|
54
|
+
def create_binding_context(variables)
|
|
55
|
+
# Return an empty binding if no variables are provided
|
|
56
|
+
return binding if variables.empty?
|
|
57
|
+
|
|
58
|
+
# Create an anonymous Struct with keys from the variables hash,
|
|
59
|
+
# instantiate it with the values, and return its binding.
|
|
60
|
+
Struct.new(*variables.keys.map(&:to_sym)).new(*variables.values).instance_eval { binding }
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rails_prompts
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ritesh Chaudhary
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '6.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '6.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rake
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '13.0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '13.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rspec
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '3.0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '3.0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rubocop
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '1.0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '1.0'
|
|
68
|
+
description: A Ruby gem for managing AI prompts stored in markdown files with ERB
|
|
69
|
+
interpolation. Centralizes prompt management and makes them easier to review, version
|
|
70
|
+
control, and modify.
|
|
71
|
+
email:
|
|
72
|
+
- chaudharyritesh7100@gmail.com
|
|
73
|
+
executables: []
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- lib/rails_prompts.rb
|
|
78
|
+
- lib/rails_prompts/version.rb
|
|
79
|
+
homepage: https://github.com/riteshchaudhary/rails_prompts
|
|
80
|
+
licenses:
|
|
81
|
+
- MIT
|
|
82
|
+
metadata:
|
|
83
|
+
bug_tracker_uri: https://github.com/riteshchaudhary/rails_prompts/issues
|
|
84
|
+
changelog_uri: https://github.com/riteshchaudhary/rails_prompts/blob/main/CHANGELOG.md
|
|
85
|
+
documentation_uri: https://github.com/riteshchaudhary/rails_prompts/blob/main/README.md
|
|
86
|
+
source_code_uri: https://github.com/riteshchaudhary/rails_prompts
|
|
87
|
+
rubygems_mfa_required: 'true'
|
|
88
|
+
rdoc_options: []
|
|
89
|
+
require_paths:
|
|
90
|
+
- lib
|
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: 2.7.0
|
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
|
+
requirements:
|
|
98
|
+
- - ">="
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
version: '0'
|
|
101
|
+
requirements: []
|
|
102
|
+
rubygems_version: 3.7.2
|
|
103
|
+
specification_version: 4
|
|
104
|
+
summary: Manage AI prompts in Rails applications with ERB templates
|
|
105
|
+
test_files: []
|