Class: Guard::Jekyll
- Inherits:
-
Guard
- Object
- Guard
- Guard::Jekyll
- Defined in:
- lib/guard/jekyll.rb
Instance Attribute Summary collapse
-
#workdir ⇒ Object
readonly
Returns the value of attribute workdir.
Instance Method Summary collapse
- #filter_files(paths) ⇒ Object
- #in_destination?(path) ⇒ Boolean
- #init_site ⇒ Object (also: #start, #reload, #run_all)
-
#initialize(watchers = [], options = {}) ⇒ Jekyll
constructor
A new instance of Jekyll.
- #notify(changed_files) ⇒ Object
- #render_files(paths) ⇒ Object
- #run_on_change(paths) ⇒ Object
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 = [], = {}) super @site = nil @workdir = Dir.pwd end |
Instance Attribute Details
#workdir ⇒ Object (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
35 36 37 |
# File 'lib/guard/jekyll.rb', line 35 def in_destination? path File.(path, workdir).index(@destination) == 0 end |
#init_site ⇒ Object 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::configuration(@options) @site = ::Jekyll::LiveSite.new() @destination = File.join(File.(['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 |