Sha256: c344edd817a5246f64c0203a121e9a028296f060cda830bfb212eb1c4b04a689

Contents?: true

Size: 721 Bytes

Versions: 12

Compression:

Stored size: 721 Bytes

Contents

# aia/lib/aia/dynamic_content.rb

require 'erb'

module AIA::DynamicContent

  # inserts environment variables (envars) and dynamic content into a prompt
  # replaces patterns like $HOME and ${HOME} with the value of ENV['HOME']
  # replaces patterns like $(shell command) with the output of the shell command
  #
  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


  # Need to use instance variables in assignments
  # to maintain binding from one follow up prompt
  # to another.
  def render_erb(the_prompt_text)
    ERB.new(the_prompt_text).result(binding)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
aia-0.5.18 lib/aia/dynamic_content.rb
aia-0.5.16 lib/aia/dynamic_content.rb
aia-0.5.15 lib/aia/dynamic_content.rb
aia-0.5.14 lib/aia/dynamic_content.rb
aia-0.5.13 lib/aia/dynamic_content.rb
aia-0.5.12 lib/aia/dynamic_content.rb
aia-0.5.11 lib/aia/dynamic_content.rb
aia-0.5.10 lib/aia/dynamic_content.rb
aia-0.5.9 lib/aia/dynamic_content.rb
aia-0.5.8 lib/aia/dynamic_content.rb
aia-0.5.7 lib/aia/dynamic_content.rb
aia-0.5.6 lib/aia/dynamic_content.rb