class Trekyll::TrekyllFileManager

Constants

DIR_DEFAULTS

Defoult directory structure

FILE_DEFAULTS

Defoult file structure

Public Class Methods

new() click to toggle source

Adding new attribute => value in DIR_DEFOULTS this constructor creates getter and setter method for newly entered property (directory)

# File lib/trekyll/filemanager.rb, line 26
def initialize()

    DIR_DEFAULTS.map{ |attribute_name, attribute_value|

        self.class.send(:define_method, "#{attribute_name}=".to_sym) do |value|
          instance_variable_set("@" + attribute_name.to_s, value)
        end

        self.class.send(:define_method, attribute_name.to_sym) do
          instance_variable_get("@" + attribute_name.to_s)
        end

        self.send("#{attribute_name}=".to_sym, attribute_value)

    }
end

Public Instance Methods

create_file_struct() click to toggle source
# File lib/trekyll/filemanager.rb, line 57
def create_file_struct
    #Create directories
    DIR_DEFAULTS.map { |k,dir|
        dirname = File.dirname(dir + "/empty")
        puts "Creating dir: #{dirname}"
        unless File.directory?(dirname)
            FileUtils::mkdir_p(dirname)
        end
    }
    # Create files in correspondin directories
    FILE_DEFAULTS.map { |dir,file|
        puts "Creating file: #{file}"
        File.new(dir + "/" + file, 'w')
    }
end
delete_file_struct() click to toggle source
# File lib/trekyll/filemanager.rb, line 43
def delete_file_struct
    # Clear all existing md files except index.md
    Dir.glob( Dir.pwd + '/*.md').each do |file|
        if file != Dir.pwd + "/index.md"
            File.delete(file)
        end
    end
    puts "+++++ Trekyll is: +++++"
    puts "** Flushing old data **"

    # Clear dir structure
    DIR_DEFAULTS.map{ |k,dir_name| FileUtils.rm_rf(dir_name) }
end