Sha256: 418288c1d14e8a7cd1afd6a730672889449a23c589540c107d38590c88c4efe8

Contents?: true

Size: 1.61 KB

Versions: 85

Compression:

Stored size: 1.61 KB

Contents

#Code that is relavent to the creation of user-projects and managing user-projects

module Flok
  module Project
    def self.project_template_dir
      #Directory containing erb files and regular folders
      File.join File.dirname(__FILE__), "project_template"
    end

    #Like the unix 'find' command, will list all files and include
    #relative pathnames like './app/controllers/' in an array
    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

    #Keeps erb extension
    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

    #Remove erb extension
    def self.rem_erb str
      str.gsub(/\.erb$/, "")
    end

    #Create a new user-project by coping the templates and compiling the erb files
    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
  end
end

Version data entries

85 entries across 85 versions & 1 rubygems

Version Path
flok-0.0.105 lib/flok/project.rb
flok-0.0.103 lib/flok/project.rb
flok-0.0.102 lib/flok/project.rb
flok-0.0.101 lib/flok/project.rb
flok-0.0.100 lib/flok/project.rb
flok-0.0.99 lib/flok/project.rb
flok-0.0.98 lib/flok/project.rb
flok-0.0.97 lib/flok/project.rb
flok-0.0.96 lib/flok/project.rb
flok-0.0.95 lib/flok/project.rb
flok-0.0.94 lib/flok/project.rb
flok-0.0.93 lib/flok/project.rb
flok-0.0.92 lib/flok/project.rb
flok-0.0.91 lib/flok/project.rb
flok-0.0.90 lib/flok/project.rb
flok-0.0.89 lib/flok/project.rb
flok-0.0.88 lib/flok/project.rb
flok-0.0.87 lib/flok/project.rb
flok-0.0.86 lib/flok/project.rb
flok-0.0.85 lib/flok/project.rb