Module: Flok::Project
- Defined in:
- lib/flok/project.rb
Class Method Summary collapse
-
.create(directory) ⇒ Object
Create a new user-project by coping the templates and compiling the erb files.
-
.list ⇒ Object
Like the unix ‘find’ command, will list all files and include relative pathnames like ‘./app/controllers/’ in an array.
- .project_template_dir ⇒ Object
-
.raw_list ⇒ Object
Keeps erb extension.
-
.rem_erb(str) ⇒ Object
Remove erb extension.
Class Method Details
.create(directory) ⇒ Object
Create a new user-project by coping the templates and compiling the erb files
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/flok/project.rb', line 41 def self.create directory #Create new directory for project FileUtils.mkdir_p directory Dir.chdir directory do project_dir = Dir.pwd #Go into project_template_dir Dir.chdir project_template_dir do raw_list.each do |n| if File.directory?(n) FileUtils.mkdir_p File.join(project_dir, n) else #Render erb erb = ERB.new(File.read(n)) out = erb.result File.write File.join(project_dir, rem_erb(n)), out end end end end end |
.list ⇒ Object
Like the unix ‘find’ command, will list all files and include relative pathnames like ‘./app/controllers/’ in an array
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/flok/project.rb', line 12 def self.list Dir.chdir project_template_dir do #Get all files/folders recursiv and strip erb ls = raw_list.map do |e| rem_erb e end return ls end end |
.project_template_dir ⇒ Object
5 6 7 8 |
# File 'lib/flok/project.rb', line 5 def self.project_template_dir #Directory containing erb files and regular folders File.join File.dirname(__FILE__), "project_template" end |
.raw_list ⇒ Object
Keeps erb extension
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/flok/project.rb', line 24 def self.raw_list Dir.chdir project_template_dir do #Get all files/folders recursiv and strip erb ls = Dir["**/*"].map do |e| e end return ls end end |
.rem_erb(str) ⇒ Object
Remove erb extension
36 37 38 |
# File 'lib/flok/project.rb', line 36 def self.rem_erb str str.gsub(/\.erb$/, "") end |