Class: CabooseHelper
- Inherits:
-
Object
- Object
- CabooseHelper
- Defined in:
- lib/caboose/caboose_helper.rb
Instance Method Summary collapse
- #create_app ⇒ Object
-
#init_skeleton_files ⇒ Object
Copies all the files in the sample directory to the host application.
-
#initialize(vars) ⇒ CabooseHelper
constructor
A new instance of CabooseHelper.
-
#remove_public_index ⇒ Object
Removes the public/index.html file from the rails app.
Constructor Details
#initialize(vars) ⇒ CabooseHelper
Returns a new instance of CabooseHelper.
7 8 9 10 11 12 13 |
# File 'lib/caboose/caboose_helper.rb', line 7 def initialize(vars) @vars = vars @vars['APP_NAME'] = @vars['APP_NAME'].downcase.capitalize @vars['APP_NAME_LOWERCASE'] = @vars['APP_NAME'].downcase @vars['CABOOSE_SALT'] = Digest::SHA1.hexdigest(DateTime.now.to_s) if @vars['CABOOSE_SALT'].nil? @vars['CABOOSE_VERSION'] = Caboose::VERSION if @vars['CABOOSE_VERSION'].nil? end |
Instance Method Details
#create_app ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/caboose/caboose_helper.rb', line 15 def create_app # Create the rails app puts "Creating the rails app..." `rails _3.2.15_ new #{@vars['APP_NAME'].downcase} -d=postgresql` # Do the caboose init init_skeleton_files remove_public_index end |
#init_skeleton_files ⇒ Object
Copies all the files in the sample directory to the host application
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/caboose/caboose_helper.rb', line 26 def init_skeleton_files puts "Adding files to rails app..." gem_root = Gem::Specification.find_by_name('caboose-cms').gem_dir skeleton_root = File.join(gem_root,'lib','sample_files') Find.find(skeleton_root).each do |file| next if File.directory?(file) file2 = file.gsub(skeleton_root, '') file2 = File.join(File.(@vars['APP_NAME'].downcase), file2) FileUtils.cp(file, file2) # Replace any variables f = File.open(file2, 'rb') str = f.read f.close @vars.each { |k,v| str.gsub!("|#{k}|",v) } File.open(file2, 'w') { |f| f.write(str) } end end |
#remove_public_index ⇒ Object
Removes the public/index.html file from the rails app
48 49 50 51 52 53 54 |
# File 'lib/caboose/caboose_helper.rb', line 48 def remove_public_index puts "Removing the public/index.html file... " filename = File.join(File.(@vars['APP_NAME'].downcase),'public','index.html') return if !File.exists?(filename) File.delete(filename) end |