Class: Guard::Jekyllplus

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Jekyllplus.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/guard/jekyll-plus.rb', line 16

def initialize (watchers=[], options={})
  super

  default_extensions = ['md','mkd','mkdn','markdown','textile','html','haml','slim','xml','yml']

  @options = {
    :extensions     => [], 
    :config         => ['_config.yml'],
    :serve          => false,
    :rack_config    => nil,
    :drafts         => false,
    :future         => false,
    :config_hash    => nil,
    :silent         => false,
    :msg_prefix     => 'Jekyll'
  }.merge(options)

  # The config_hash option should be a hash ready to be consumed by Jekyll's Site class.
  #
  @config = jekyll_config(@options)

  # Override configuration with guard option values
  #
  @config['show_drafts'] ||= @options[:drafts]
  @config['future']      ||= @options[:future]

  # Store vars for easy internal access
  #
  @source = local_path @config['source']
  @destination = local_path @config['destination']
  @msg_prefix = @options[:msg_prefix]
 
  # Convert array of extensions into a regex for matching file extensions eg, /\.md$|\.markdown$|\.html$/i
  #
  extensions  = @options[:extensions].concat(default_extensions).flatten.uniq
  @extensions = Regexp.new extensions.map { |e| (e << '$').gsub('\.', '\\.') }.join('|'), true

  # set Jekyll server process id to nil
  #
  @pid = nil

  # Create a Jekyll site
  #
  @site = ::Jekyll::Site.new @config
  @rack = ::Rack::Server.new(rack_config(@destination)) if @use_rack

end

Instance Method Details

#restartObject



75
76
77
78
# File 'lib/guard/jekyll-plus.rb', line 75

def restart
  stop if alive?
  start
end

#run_on_additions(paths) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'lib/guard/jekyll-plus.rb', line 96

def run_on_additions(paths)
  matched = jekyll_matches paths
  unmatched = non_jekyll_matches paths

  if matched.size > 0
    build(matched, "Files added: ", "  + ".green)
  elsif unmatched.size > 0
    copy(unmatched)
  end
end

#run_on_modifications(paths) ⇒ Object



85
86
87
88
89
90
91
92
93
94
# File 'lib/guard/jekyll-plus.rb', line 85

def run_on_modifications(paths)
  matched = jekyll_matches paths
  unmatched = non_jekyll_matches paths

  if matched.size > 0
    build(matched, "Files changed: ", "  ~ ".yellow)
  elsif unmatched.size > 0
    copy(unmatched)
  end
end

#run_on_removals(paths) ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'lib/guard/jekyll-plus.rb', line 107

def run_on_removals(paths)
  matched = jekyll_matches paths
  unmatched = non_jekyll_matches paths

  if matched.size > 0
    build(matched, "Files removed: ", "  x ".red)
  elsif unmatched.size > 0
    remove(unmatched)
  end
end

#startObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/guard/jekyll-plus.rb', line 64

def start
  if @options[:serve]
    start_server
    build
    UI.info "#{@msg_prefix} " + "watching and serving at #{@config['host']}:#{@config['port']}#{@config['baseurl']}" unless @config[:silent]
  else
    build
    UI.info "#{@msg_prefix} " + "watching" unless @config[:silent]
  end
end

#stopObject



81
82
83
# File 'lib/guard/jekyll-plus.rb', line 81

def stop
  stop_server
end