I’ve got some a basic framework for a webapp (some static pages, user authentication, basic testing with rpec). I’d like to use this as a foundation for future webapps. I’ve named my project “framework,” so if I fork it, I’ll have about a dozen instances where I have to replace the term “Framework” with the name of the new app I’m creating. This project is as github.com/bnd5k/framework. The README file contains a list of the files where I need to make the change. I can make those changes by hand by hand, but I’d prefer to automate this process. I figure that the easiest thing to do would be to include a rake file in Framework. So, I created rake file called renamer.rake. My rake file is based on this post: How to search file text for a pattern and replace it with a given value. Here's what I came up with.
task :rename do
file_names = ['config/environments/test.rb', 'config/environments/production.rb',
'config/environment.rb']
file_names.each do |file_name|
text = File.read(file_name)
puts text.gsub("Framework", "funktrunkgunk")
end
end
This code works insofar as it replaces the term "framework" with a different term, but it only does to in the console. I need it to actually change the contents of the files. What do I need to do? Do I need to open the each file instead of just read it?
FYI this code only lists a few files (just so I can test out whether this method works) and the replacement term will ultimately be a variable, not “funktrunkgunk”. Once I get this part down, I’d like to have it setup so that anyone can clone the framework repo to their machine, cd into the framework directory, start rails server, then go to local host on their browser to rename the file from there. I’ll setup public/index.html to be a basic page that contains a form field where the user can enter their own name for the app. Once the user clicks a “Name App” button , it’ll run the rake file. Does that sound feasible?