#!/usr/bin/env ruby
###############################################################################
#
# Name: code_wrapper.rb
# Author: Victor Goff
# License: Educational
#
# Version: 0.3
#
###############################################################################

# Usage: code_wrapper.rb filename > newfile.txt
# Or Usage: code_wrapper.rb > newfile.txt
# It will ask you for a file if you provide no argument.
# Open the new text file in your favorite program, copy and paste in the forum
# after placing yourself in HTML mode.  No need to replace < or << marks, and
# no need to use the [code ruby][/code] block, as it wraps your code for you!
#Shoes.app :width => 500, :height => 500, :resizable => false do
def wrapper(program_file = nil)
  program_file = IO.readlines(program_file)
  lines = ''
  lines = lines + '[code ruby]'
  program_file.each do |line|
    lines = lines + line.gsub(/</, "&lt;")

  end
  lines = lines + '[/code]'
  return lines
end
# Note: I 'cheat' with the stderr.print I need to find out how to print to console
# when output is redirected to a file.  (In unix shells it is a pipe)

Shoes.app :width => 500,:height => 500, :resizable => false do
	@file = edit_line("/home/rick/test.rb")
	@text = edit_box("wrapped thing")
	button("Get file") do
		puts wrapper(@file.text)
	end
	button('test') do
		puts wrapper('/home/rick/test.rb')
	end
end
