Class: MrHyde::Site
- Inherits:
-
Object
- Object
- MrHyde::Site
- Defined in:
- lib/mr_hyde/site.rb
Class Method Summary collapse
-
.build(args = nil, 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 = nil, 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 = nil, 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
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/mr_hyde/site.rb', line 83 def build(args = nil, opts = {}) init(args, opts) # If there is no destinarion folder then will be created mk_destination(opts) unless File.exist? MrHyde.destination if not args.nil? and not args.empty? build_sites args, opts elsif opts["all"] # Build all sites and after build/rebuild the main site # so all global variables referent to nested site will be loaded build_sites sources_list, opts end # By default the main site is built build_main_site(opts) rescue Exception => e MrHyde.logger.error "cannot build site: #{e}" MrHyde.logger.error e.backtrace end |
.built?(name, opts) ⇒ Boolean
139 140 141 |
# File 'lib/mr_hyde/site.rb', line 139 def built?(name, opts) File.exist? File.join(MrHyde.destination, name) end |
.built_list ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/mr_hyde/site.rb', line 115 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
152 153 154 |
# File 'lib/mr_hyde/site.rb', line 152 def custom_config(name, opts) File.join site_path(name), opts['jekyll_config'] end |
.draft_list ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/mr_hyde/site.rb', line 125 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
135 136 137 |
# File 'lib/mr_hyde/site.rb', line 135 def exist?(name, opts) File.exist? File.join(@source, name) end |
.has_custom_config?(name, opts) ⇒ Boolean
143 144 145 |
# File 'lib/mr_hyde/site.rb', line 143 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 else File.join MrHyde.source, MrHyde.sources_sites end yield if block_given? end |
.is_main?(name) ⇒ Boolean
156 157 158 |
# File 'lib/mr_hyde/site.rb', line 156 def is_main?(name) File.directory? File.join(name) end |
.list(path) ⇒ Object
This method returns a list of nested sites
105 106 107 108 109 |
# File 'lib/mr_hyde/site.rb', line 105 def list(path) entries = Dir.entries(path) entries.reject! { |item| item == '.' or item == '..' } entries end |
.remove(args = nil, 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 |
# File 'lib/mr_hyde/site.rb', line 58 def remove(args = nil, opts = {}) init(args, opts) if not args.nil? and not args.empty? remove_sites args, opts elsif opts['all'] list(MrHyde.sources_sites).each do |sm| remove_site sm, opts end end build rescue Exception => e MrHyde.logger.error "cannot remove the site: #{e}" end |
.site_path(name) ⇒ Object
147 148 149 150 |
# File 'lib/mr_hyde/site.rb', line 147 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
111 112 113 |
# File 'lib/mr_hyde/site.rb', line 111 def sources_list list MrHyde.sources_sites end |