Class: Guard::Jekyll

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/jekyll.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ Jekyll

Returns a new instance of Jekyll.



7
8
9
10
11
# File 'lib/guard/jekyll.rb', line 7

def initialize(watchers = [], options = {})
  super
  @site = nil
  @workdir = Dir.pwd
end

Instance Attribute Details

#workdirObject (readonly)

Returns the value of attribute workdir.



5
6
7
# File 'lib/guard/jekyll.rb', line 5

def workdir
  @workdir
end

Instance Method Details

#filter_files(paths) ⇒ Object



31
32
33
# File 'lib/guard/jekyll.rb', line 31

def filter_files paths
  paths.reject { |path| in_destination? path }
end

#in_destination?(path) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/guard/jekyll.rb', line 35

def in_destination? path
  File.expand_path(path, workdir).index(@destination) == 0
end

#init_siteObject Also known as: start, reload, run_all



13
14
15
16
17
18
19
20
# File 'lib/guard/jekyll.rb', line 13

def init_site
  jekyll_options = ::Jekyll::configuration(@options)
  @site = ::Jekyll::LiveSite.new(jekyll_options)
  @destination = File.join(File.expand_path(jekyll_options['destination'], @workdir), '')
  print "Rebuilding Jekyll site... "
  @site.process
  puts "done."
end

#notify(changed_files) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/guard/jekyll.rb', line 50

def notify changed_files
  ::Guard.guards.each do |guard|
    next if self.class === guard
    paths = ::Guard::Watcher.match_files(guard, changed_files)
    guard.run_on_change(paths) unless paths.empty?
  end
end

#render_files(paths) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/guard/jekyll.rb', line 39

def render_files paths
  changed = []
  @site.process_files filter_files(paths) do |processed|
    relative = processed.sub("#{workdir}/", '')
    puts "Jekyll: #{relative}"
    changed << relative
  end

  notify changed if changed.any?
end

#run_on_change(paths) ⇒ Object



25
26
27
28
29
# File 'lib/guard/jekyll.rb', line 25

def run_on_change paths
  init_site if paths.include? '_config.yml'
  return if @site.nil?
  render_files paths
end