Class: MDSSInit
- Inherits:
-
Object
- Object
- MDSSInit
- Defined in:
- lib/mdss/init.rb
Overview
MDSSInit serves to create new simple static sites.
Constant Summary collapse
- @@helper =
Instance of our helper methods class
MDSSExtra.new
Class Method Summary collapse
-
.init_dir(name, dirname, warn, file = nil) ⇒ Object
call-seq: MDSSInit.init_dir(name, dirname, warn) => nil MDSSInit.init_dir(name, dirname, warn, file) => nil.
-
.init_file(name, file, contents = nil) ⇒ Object
call-seq: MDSSInit.init_file(name, file) => nil MDSSInit.init_file(name, file, contents) => nil.
-
.mdss_init(name) ⇒ Object
call-seq: MDSSInit.mdss_init(name) => nil.
Class Method Details
.init_dir(name, dirname, warn, file = nil) ⇒ Object
call-seq:
MDSSInit.init_dir(name, dirname, warn) => nil
MDSSInit.init_dir(name, dirname, warn, file) => nil
Create a new directory for the simple static site. warn is used to specify the name of the folder for the warning message if the directory specified by dirname exists. If a filename is specified, that file is created within the directory.
41 42 43 44 45 46 47 48 |
# File 'lib/mdss/init.rb', line 41 def self.init_dir(name, dirname, warn, file = nil) if File.exists?("#{name}/#{dirname}") helper.puts_warn("#{warn} folder exists, skipping") else Dir.mkdir("#{name}/#{dirname}") FileUtils.touch("#{name}/#{dirname}/#{file}") unless file.nil? end end |
.init_file(name, file, contents = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mdss/init.rb', line 57 def self.init_file(name, file, contents = nil) if contents.nil? FileUtils.touch("#{name}/#{file}") else File.open("#{name}/#{file}", "w+") do |file| contents.each do |line| file.write(line) end end end end |
.mdss_init(name) ⇒ Object
call-seq:
MDSSInit.mdss_init(name) => nil
Create a new simple static site in the directory specified by name. If a directory with the specified name exists, it tries to create the necessary files and directories with #init_dir.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mdss/init.rb', line 19 def self.mdss_init(name) if File.exists?(name) MDSSExtra.new.puts_warn("Directory exists") else Dir.mkdir(name) end self.init_file(name, ".mdss.cfg", ["name=#{name}"]) self.init_file(name, "index.md") self.init_dir(name, "css", "CSS", "styles.css") self.init_dir(name, "js", "JavaScript", "scripts.js") self.init_dir(name, "img", "Image") end |