Sha256: 3001a81e407e24dc29c7b61238bcca5a6ead0772872a157c19199a51c6cb3b0f

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require 'guard/guard'
require 'jekyll/live_site'

class Guard::Jekyll < Guard::Guard
  attr_reader :workdir

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

  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
  alias_method :start, :init_site
  alias_method :reload, :init_site
  alias_method :run_all, :init_site

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

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

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

  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

  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-reloaded-0.12.2 lib/guard/jekyll.rb
jekyll-reloaded-0.12.1 lib/guard/jekyll.rb