Class: MrHyde::Site
- Inherits:
-
Object
- Object
- MrHyde::Site
- Defined in:
- lib/mr_hyde/site.rb
Class Method Summary collapse
-
.build(args, opts = {}) ⇒ Object
Builds the site Params: :name String => builds the concrete site Array => builds the correspondings site names empty => builds all sites with option ‘all’ opts Hash ‘all’ => ‘all’ Builds all built sites.
- .built?(name, opts) ⇒ Boolean
- .built_list ⇒ Object
-
.create(args, opts = {}) ⇒ Object
Creates the directory and necessary files for the site Params: args String => creates the concrete site Array => creates the correspondings site names opts Hash ‘force’ => ‘force’ Install the new site over an exiting path ‘blank’ => ‘blank’ Creates a blank site.
- .custom_config(name, opts) ⇒ Object
- .draft_list ⇒ Object
- .exist?(name, opts) ⇒ Boolean
- .has_custom_config?(name, opts) ⇒ Boolean
- .init(args, opts) ⇒ Object
- .is_main?(name) ⇒ Boolean
-
.list(path) ⇒ Object
This method returns a list of nested sites.
-
.remove(args, opts = {}) ⇒ Object
Removes the site directory Params: args String => removes the concrete site Array => removes the correspondings site names empty => remove all sites with the option ‘all’ opts Hash ‘all’ => ‘all’ Removes all built sites ‘full’ => ‘full’ Removes built and source site/s.
- .site_path(name) ⇒ Object
- .sources_list ⇒ Object
Class Method Details
.build(args, opts = {}) ⇒ Object
Builds the site Params:
:name
String => builds the concrete site
Array[String] => builds the correspondings site names
empty => builds all sites with option 'all'
opts
Hash
'all' => 'all' Builds all built sites
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mr_hyde/site.rb', line 86 def build(args, opts = {}) init(args, opts) unless opts.delete('main') # If there is no main site then it is built build_main_site(opts) unless File.exist? MrHyde.destination if opts["all"] build_sites sources_list, opts elsif args.kind_of? Array build_sites args, opts elsif args.kind_of? String build_site args, opts end else if opts["all"] build_main_site(opts) build_sites sources_list, opts else # Fetching the list of built sites to rebuild again once the main site has been built if File.exist? MrHyde.destination nested_sites = built_list build_main_site(opts) build_sites nested_sites, opts else build_main_site(opts) end end end rescue Exception => e MrHyde.logger.error "cannot build site: #{e}" MrHyde.logger.error e.backtrace end |
.built?(name, opts) ⇒ Boolean
156 157 158 |
# File 'lib/mr_hyde/site.rb', line 156 def built?(name, opts) File.exist? File.join(MrHyde.destination, name) end |
.built_list ⇒ Object
132 133 134 135 136 137 138 139 140 |
# File 'lib/mr_hyde/site.rb', line 132 def built_list return [] unless File.exist? MrHyde.destination sources = sources_list builts = list(MrHyde.destination) builts.select do |site| site if sources.include?(site) end end |
.create(args, opts = {}) ⇒ Object
Creates the directory and necessary files for the site Params:
args
String => creates the concrete site
Array[String] => creates the correspondings site names
opts
Hash
'force' => 'force' Install the new site over an exiting path
'blank' => 'blank' Creates a blank site
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mr_hyde/site.rb', line 29 def create(args, opts = {}) init(args, opts) if args.kind_of? Array and not args.empty? args.each do |bn| begin create_site(bn, opts) rescue Exception => e raise e unless e.class == SystemExit end end elsif args.kind_of? String create_site args, opts end rescue Exception => e MrHyde.logger.error "cannot create site: #{e}" end |
.custom_config(name, opts) ⇒ Object
169 170 171 |
# File 'lib/mr_hyde/site.rb', line 169 def custom_config(name, opts) File.join site_path(name), opts['jekyll_config'] end |
.draft_list ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/mr_hyde/site.rb', line 142 def draft_list return sources_list unless File.exist? MrHyde.destination sources = sources_list builts = built_list sources.reject do |site| site if builts.include?(site) end end |
.exist?(name, opts) ⇒ Boolean
152 153 154 |
# File 'lib/mr_hyde/site.rb', line 152 def exist?(name, opts) File.exist? File.join(@source, name) end |
.has_custom_config?(name, opts) ⇒ Boolean
160 161 162 |
# File 'lib/mr_hyde/site.rb', line 160 def has_custom_config?(name, opts) File.exist? custom_config(name, opts) end |
.init(args, opts) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/mr_hyde/site.rb', line 9 def init(args, opts) opts = MrHyde.configuration(opts) @source = if opts['main'] File.join MrHyde.source, MrHyde.sources else File.join MrHyde.source, MrHyde.sources_sites end yield if block_given? end |
.is_main?(name) ⇒ Boolean
173 174 175 |
# File 'lib/mr_hyde/site.rb', line 173 def is_main?(name) File.directory? File.join(MrHyde.sources, name) end |
.list(path) ⇒ Object
This method returns a list of nested sites
122 123 124 125 126 |
# File 'lib/mr_hyde/site.rb', line 122 def list(path) entries = Dir.entries(path) entries.reject! { |item| item == '.' or item == '..' } entries end |
.remove(args, opts = {}) ⇒ Object
Removes the site directory Params:
args
String => removes the concrete site
Array[String] => removes the correspondings site names
empty => remove all sites with the option 'all'
opts
Hash
'all' => 'all' Removes all built sites
'full' => 'full' Removes built and source site/s
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mr_hyde/site.rb', line 58 def remove(args, opts = {}) init(args, opts) if opts['all'] list(MrHyde.sources_sites).each do |sm| remove_site sm, opts end elsif args.kind_of? Array args.each do |sm| remove_site sm, opts end else remove_site args, opts end rescue Exception => e MrHyde.logger.error "cannot remove the site: #{e}" end |
.site_path(name) ⇒ Object
164 165 166 167 |
# File 'lib/mr_hyde/site.rb', line 164 def site_path(name) source = is_main?(name) ? @source : File.join(MrHyde.source, MrHyde.sources_sites) Jekyll.sanitized_path(source , name) end |
.sources_list ⇒ Object
128 129 130 |
# File 'lib/mr_hyde/site.rb', line 128 def sources_list list MrHyde.sources_sites end |