Class: Markwiki::Init
- Inherits:
-
Jewel::Gem
- Object
- Jewel::Gem
- Markwiki::Init
- Defined in:
- lib/markwiki/init.rb
Overview
Wrapper class for Markwiki initialization
Class Method Summary collapse
-
.default_config ⇒ Hash
Get a Hash representation of a default Markwiki configuration.
-
.generate_config(name: "markwiki", files: ["index.html"], css: "css", css_files: ["styles.css"], js: "js", js_files: ["scripts.js"], img: "img", img_files: []) ⇒ Hash
Get a Hash representation of an arbitrary Markwiki configuration.
-
.generate_json_config ⇒ String
Generate a JSON String representation of a Markwiki site.
-
.generate_pretty_json_config ⇒ String
Generate a prettified JSON String representation of a Markwiki site.
-
.generate_yaml_config(config) ⇒ String
Generate a YAML representation of a configuration.
-
.init_site(site_name, config: self.load_default_config) ⇒ Object
Creates the Markwiki directory structure from a configuration.
-
.load_default_config ⇒ Hash
Load the default Markwiki configuration file.
Class Method Details
.default_config ⇒ Hash
Get a Hash representation of a default Markwiki configuration
110 111 112 |
# File 'lib/markwiki/init.rb', line 110 def self.default_config self.generate_config end |
.generate_config(name: "markwiki", files: ["index.html"], css: "css", css_files: ["styles.css"], js: "js", js_files: ["scripts.js"], img: "img", img_files: []) ⇒ Hash
Get a Hash representation of an arbitrary Markwiki configuration
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/markwiki/init.rb', line 125 def self.generate_config( name: "markwiki", files: ["index.html"], css: "css", css_files: ["styles.css"], js: "js", js_files: ["scripts.js"], img: "img", img_files: []) { "name" => name, "files".to_s => files + [".markwiki.cfg"], "css".to_s => { "dir_name" => css, "files" => css_files }, "js".to_s => { "dir_name" => js, "files" => js_files }, "img".to_s => { "dir_name" => img, "files" => img_files } } end |
.generate_json_config ⇒ String
Generate a JSON String representation of a Markwiki site.
94 95 96 |
# File 'lib/markwiki/init.rb', line 94 def self.generate_json_config CONFIG.to_json end |
.generate_pretty_json_config ⇒ String
Generate a prettified JSON String representation of a Markwiki site.
102 103 104 |
# File 'lib/markwiki/init.rb', line 102 def self.generate_pretty_json_config JSON.pretty_generate CONFIG end |
.generate_yaml_config(config) ⇒ String
Generate a YAML representation of a configuration
86 87 88 |
# File 'lib/markwiki/init.rb', line 86 def self.generate_yaml_config(config) YAML.dump(config) end |
.init_site(site_name, config: self.load_default_config) ⇒ Object
Creates the Markwiki directory structure from a configuration.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/markwiki/init.rb', line 35 def self.init_site(site_name, config: self.load_default_config) Dir.mkdir(site_name) # Create the directories config.each_key do |key| if config[key].is_a? Hash Dir.mkdir(File.join(site_name, config[key]["dir_name"])) end end # Create the files config.each_key do |key| # We have top-level files if config[key].is_a? Array and key.eql? "files" config[key].each do |file| unless file.eql? ".markwiki.cfg" #puts File.join(site_name, file) FileUtils.touch(File.join(site_name, file)) end end end # We have a subdirectory if config[key].is_a? Hash config[key].each_key do |subdiropt| if config[key][subdiropt].is_a? Array and subdiropt.eql? "files" config[key][subdiropt].each do |file| #puts File.join(site_name, config[key]["dir_name"], file) FileUtils.touch(File.join(site_name, config[key]["dir_name"], file)) end end end end end # Create the Markwiki configuration if config.eql? self.load_default_config # Path to the default configuration path = self.root.static(".markwiki.cfg").to_s FileUtils.cp(path, "#{site_name}") else File.open("#{site_name}/.markwiki.cfg", "w") do |file| file.write(self.generate_yaml_config(config)) end end end |
.load_default_config ⇒ Hash
Load the default Markwiki configuration file
155 156 157 158 159 160 161 162 |
# File 'lib/markwiki/init.rb', line 155 def self.load_default_config config = nil path = self.root.static(".markwiki.cfg").to_s file = File.open(path, "r") { |file| config = YAML.load(file) } config end |