Class: Hyde::Site

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Site

Returns a new instance of Site.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hyde/site.rb', line 8

def initialize(options)
  self.options = options
  
  self.pages = options['pages']
  self.posts = options['posts']

  self.source = File.expand_path(options['source'])
  self.template = File.expand_path(options['template']['directory'])
  self.dest = File.expand_path(options['intermediary']['directory'])
  
  self.reset
  self.setup
end

Instance Attribute Details

#destObject

Returns the value of attribute dest.



5
6
7
# File 'lib/hyde/site.rb', line 5

def dest
  @dest
end

#filesObject

Returns the value of attribute files.



6
7
8
# File 'lib/hyde/site.rb', line 6

def files
  @files
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/hyde/site.rb', line 4

def options
  @options
end

#pagesObject

Returns the value of attribute pages.



4
5
6
# File 'lib/hyde/site.rb', line 4

def pages
  @pages
end

#postsObject

Returns the value of attribute posts.



4
5
6
# File 'lib/hyde/site.rb', line 4

def posts
  @posts
end

#sourceObject

Returns the value of attribute source.



5
6
7
# File 'lib/hyde/site.rb', line 5

def source
  @source
end

#templateObject

Returns the value of attribute template.



5
6
7
# File 'lib/hyde/site.rb', line 5

def template
  @template
end

#timeObject

Returns the value of attribute time.



6
7
8
# File 'lib/hyde/site.rb', line 6

def time
  @time
end

Instance Method Details

#buildObject

runs Jekyll



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/hyde/site.rb', line 178

def build
  jekyll_options = Hash.new
  
  %w[safe verbose].each do |c|
    jekyll_options[c] = options[c] if options[c]
  end

  jekyll_options['destination'] = options['destination']['directory']
  jekyll_options['source'] = self.dest

  jekyll_options = Jekyll::configuration(jekyll_options)
  Jekyll::Commands::Build.process(jekyll_options)
end

#cleanupObject

cleanup



172
173
174
175
# File 'lib/hyde/site.rb', line 172

def cleanup
  self.files = Array.new
  FileUtils.rm_rf(self.dest) unless options['keep'] or options['watching'] or options['serving']
end

#copy_templateObject



124
125
126
# File 'lib/hyde/site.rb', line 124

def copy_template
  FileUtils.cp_r(Dir[File.join(template, '*')], dest, :preserve => true)
end

#directoriesObject

create the Hyde-to-Jekyll output directories



90
91
92
93
# File 'lib/hyde/site.rb', line 90

def directories
  directories_helper(pages)
  directories_helper(posts, '_posts')
end

#processObject



22
23
24
25
26
27
28
29
30
# File 'lib/hyde/site.rb', line 22

def process
  self.reset
  self.copy_template
  self.directories
  self.read
  self.write
  self.build
  self.cleanup
end

#readObject

read files



129
130
131
132
133
134
135
136
137
138
# File 'lib/hyde/site.rb', line 129

def read
  self.files ||= Array.new
  
  read_files(pages) do | source, destination |
    files << Page.new(source, File.join(self.dest, destination))
  end
  read_files(posts) do | source, destination |
    files << Post.new(source, File.join(self.dest, destination))
  end
end

#resetObject

reset the time



33
34
35
36
37
38
39
# File 'lib/hyde/site.rb', line 33

def reset
  self.time = if options['time']
                Time.parse(options['time'].to_s)
              else
                Time.now
              end
end

#setupObject

copy Jekyll source files



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hyde/site.rb', line 42

def setup
  if options['destination']['branch']
    clone_directory(options['destination'])
  else
    FileUtils.rm_rf(dest)
  end
  
  clone_directory(options['template']) if options['template']['branch']
  
  FileUtils.rm_rf(dest)
  FileUtils.mkdir_p(dest)
end

#writeObject

write jekyll files



165
166
167
168
169
# File 'lib/hyde/site.rb', line 165

def write
  files.each do |file|
    file.write
  end
end