Class: MrHyde::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/mr_hyde/site.rb

Class Method Summary collapse

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


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/mr_hyde/site.rb', line 84

def build(args = nil, opts = {})
  init(args, opts)

  # If there is no destination 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

Returns:

  • (Boolean)


140
141
142
# File 'lib/mr_hyde/site.rb', line 140

def built?(name, opts)
  File.exist? File.join(MrHyde.destination, name)
end

.built_listObject



116
117
118
119
120
121
122
123
124
# File 'lib/mr_hyde/site.rb', line 116

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


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mr_hyde/site.rb', line 30

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



153
154
155
# File 'lib/mr_hyde/site.rb', line 153

def custom_config(name, opts)
  File.join site_path(name), opts['config']
end

.draft_listObject



126
127
128
129
130
131
132
133
134
# File 'lib/mr_hyde/site.rb', line 126

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

Returns:

  • (Boolean)


136
137
138
# File 'lib/mr_hyde/site.rb', line 136

def exist?(name, opts)
  File.exist? File.join(@source, name)
end

.has_custom_config?(name, opts) ⇒ Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/mr_hyde/site.rb', line 144

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
18
# 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?
  opts
end

.is_main?(name) ⇒ Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/mr_hyde/site.rb', line 157

def is_main?(name)
  File.directory? File.join(name)
end

.keep_files(files, conf) ⇒ Object

Receives an array of files don’t want to be removed



162
163
164
165
# File 'lib/mr_hyde/site.rb', line 162

def keep_files(files, conf)
  conf['keep_files'] = [] unless conf['keep_files']
  conf['keep_files'] = conf['keep_files'].concat(files).uniq
end

.list(path) ⇒ Object

This method returns a list of nested sites



106
107
108
109
110
# File 'lib/mr_hyde/site.rb', line 106

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


59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/mr_hyde/site.rb', line 59

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



148
149
150
151
# File 'lib/mr_hyde/site.rb', line 148

def site_path(name)
  source = is_main?(name) ? @source : File.join(MrHyde.source, MrHyde.sources_sites)
  Jekyll.sanitized_path(source , name)
end

.sources_listObject



112
113
114
# File 'lib/mr_hyde/site.rb', line 112

def sources_list
  list MrHyde.sources_sites
end