Module: AIA::DynamicContent

Included in:
Main, Prompt
Defined in:
lib/aia/dynamic_content.rb

Instance Method Summary collapse

Instance Method Details

#render_env(a_string) ⇒ Object

inserts environment variables (envars) and dynamic content into a prompt replaces patterns like $HOME and $HOME with the value of ENV replaces patterns like $(shell command) with the output of the shell command



11
12
13
14
15
16
17
# File 'lib/aia/dynamic_content.rb', line 11

def render_env(a_string)
  a_string.gsub(/\$(\w+|\{\w+\})/) do |match|
    ENV[match.tr('$', '').tr('{}', '')]
  end.gsub(/\$\((.*?)\)/) do |match|
    `#{match[2..-2]}`.chomp
  end
end

#render_erb(the_prompt_text) ⇒ Object

Need to use instance variables in assignments to maintain binding from one follow up prompt to another.



23
24
25
# File 'lib/aia/dynamic_content.rb', line 23

def render_erb(the_prompt_text)
  ERB.new(the_prompt_text).result(binding)
end