guard-jekyll-plus 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.rubocop.yml +10 -0
- data/.rubocop_todo.yml +32 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +6 -2
- data/Gemfile +12 -2
- data/Guardfile +30 -0
- data/README.md +5 -5
- data/Rakefile +9 -1
- data/guard-jekyll-plus.gemspec +20 -15
- data/lib/guard/jekyll_plus.rb +54 -0
- data/lib/guard/jekyll_plus/builder.rb +46 -0
- data/lib/guard/jekyll_plus/builder/action.rb +126 -0
- data/lib/guard/jekyll_plus/builder/adder.rb +23 -0
- data/lib/guard/jekyll_plus/builder/modifier.rb +23 -0
- data/lib/guard/jekyll_plus/builder/rebuilder.rb +37 -0
- data/lib/guard/jekyll_plus/builder/remover.rb +24 -0
- data/lib/guard/jekyll_plus/config.rb +131 -0
- data/lib/guard/jekyll_plus/server.rb +111 -0
- data/lib/guard/jekyll_plus/templates/Guardfile +4 -0
- data/lib/guard/{jekyll-plus → jekyll_plus}/version.rb +1 -1
- data/spec/lib/guard/jekyll-plus/builder/adder_spec.rb +94 -0
- data/spec/lib/guard/jekyll-plus/builder/modifier_spec.rb +113 -0
- data/spec/lib/guard/jekyll-plus/builder/rebuilder_spec.rb +76 -0
- data/spec/lib/guard/jekyll-plus/builder/remover_spec.rb +97 -0
- data/spec/lib/guard/jekyll-plus/builder_spec.rb +57 -0
- data/spec/lib/guard/jekyll-plus/config_spec.rb +138 -0
- data/spec/lib/guard/jekyll-plus/server_spec.rb +79 -0
- data/spec/lib/guard/jekyll-plus_spec.rb +114 -0
- data/spec/spec_helper.rb +44 -0
- data/test/Guardfile +3 -4
- metadata +70 -14
- data/lib/guard/jekyll-plus.rb +0 -300
- data/lib/guard/jekyll-plus/templates/Guardfile +0 -5
- data/test/Gemfile +0 -3
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'guard/jekyll_plus/server'
|
2
|
+
|
3
|
+
# stub for tests to avoid requiring
|
4
|
+
unless Object.const_defined?(:Rack)
|
5
|
+
module Rack
|
6
|
+
class Handler
|
7
|
+
class Thin
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Server
|
12
|
+
def initialize(_options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def server
|
16
|
+
end
|
17
|
+
|
18
|
+
def start
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec.describe Guard::JekyllPlus::Server do
|
25
|
+
let(:config) { instance_double(Guard::JekyllPlus::Config) }
|
26
|
+
subject { described_class.new(config) }
|
27
|
+
|
28
|
+
before do
|
29
|
+
allow(Thread).to receive(:new) do |&block|
|
30
|
+
block.call
|
31
|
+
end
|
32
|
+
|
33
|
+
allow(Process).to receive(:fork) do |&block|
|
34
|
+
block.call
|
35
|
+
end
|
36
|
+
|
37
|
+
allow(Process).to receive(:wait)
|
38
|
+
allow(Process).to receive(:kill)
|
39
|
+
|
40
|
+
allow_any_instance_of(Rack::Server).to receive(:start)
|
41
|
+
allow(Jekyll::Commands::Serve).to receive(:process)
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#start' do
|
45
|
+
before do
|
46
|
+
allow(config).to receive(:host)
|
47
|
+
allow(config).to receive(:baseurl)
|
48
|
+
allow(config).to receive(:port)
|
49
|
+
allow(config).to receive(:info)
|
50
|
+
allow(config).to receive(:jekyll_serve_options)
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when Rack is available' do
|
54
|
+
before do
|
55
|
+
allow(Kernel).to receive(:require)
|
56
|
+
allow(config).to receive(:server_root)
|
57
|
+
allow(config).to receive(:rack_config)
|
58
|
+
allow(config).to receive(:rack_environment)
|
59
|
+
allow(File).to receive(:exist?).with('config.ru').and_return(false)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'starts the Rack server' do
|
63
|
+
expect_any_instance_of(Rack::Server).to receive(:start)
|
64
|
+
subject.start
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when Rack is not available' do
|
69
|
+
before do
|
70
|
+
allow(Kernel).to receive(:require).and_raise(LoadError)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'starts the Jekyll server' do
|
74
|
+
expect(Jekyll::Commands::Serve).to receive(:process)
|
75
|
+
subject.start
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'guard/compat/test/helper'
|
2
|
+
require 'guard/jekyll_plus'
|
3
|
+
|
4
|
+
RSpec.describe Guard::JekyllPlus do
|
5
|
+
let(:server) { instance_double(Guard::JekyllPlus::Server) }
|
6
|
+
let(:config) { instance_double(Guard::JekyllPlus::Config) }
|
7
|
+
let(:builder) { instance_double(Guard::JekyllPlus::Builder) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
allow(Guard::Compat::UI).to receive(:info)
|
11
|
+
|
12
|
+
allow(Guard::JekyllPlus::Config).to receive(:new).and_return(config)
|
13
|
+
allow(Guard::JekyllPlus::Server).to receive(:new).and_return(server)
|
14
|
+
allow(Guard::JekyllPlus::Builder).to receive(:new).and_return(builder)
|
15
|
+
|
16
|
+
allow(config).to receive(:info)
|
17
|
+
allow(config).to receive(:source)
|
18
|
+
allow(config).to receive(:destination)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#initialize' do
|
22
|
+
it 'sets up the configuration' do
|
23
|
+
options = double('options')
|
24
|
+
expect(Guard::JekyllPlus::Config).to receive(:new).with(options)
|
25
|
+
described_class.new(options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#start' do
|
30
|
+
before do
|
31
|
+
allow(config).to receive(:serve?)
|
32
|
+
allow(builder).to receive(:build)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'processes the site' do
|
36
|
+
expect(builder).to receive(:build)
|
37
|
+
subject.start
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when not serving' do
|
41
|
+
before do
|
42
|
+
allow(config).to receive(:serve?).and_return(false)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'does not start the server' do
|
46
|
+
expect(server).to_not receive(:start)
|
47
|
+
subject.start
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when serving' do
|
52
|
+
before do
|
53
|
+
allow(config).to receive(:serve?).and_return(true)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'starts the server' do
|
57
|
+
expect(server).to receive(:start)
|
58
|
+
subject.start
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#run_on_modifications' do
|
64
|
+
before do
|
65
|
+
allow(builder).to receive(:modified)
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'with normal modifications' do
|
69
|
+
before do
|
70
|
+
allow(config).to receive(:config_file?).and_return(false)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'updates based on given paths' do
|
74
|
+
paths = [double('paths')]
|
75
|
+
expect(builder).to receive(:modified).with(paths)
|
76
|
+
subject.run_on_modifications(paths)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'with changed config' do
|
81
|
+
before do
|
82
|
+
allow(config).to receive(:config_file?).and_return(true)
|
83
|
+
|
84
|
+
# after config changes
|
85
|
+
allow(builder).to receive(:build)
|
86
|
+
allow(server).to receive(:stop)
|
87
|
+
allow(config).to receive(:reload)
|
88
|
+
allow(config).to receive(:serve?).and_return(false)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'reloads config' do
|
92
|
+
paths = [double('paths')]
|
93
|
+
expect(builder).to receive(:reload)
|
94
|
+
subject.run_on_modifications(paths)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#run_on_additions' do
|
100
|
+
it 'updates based on given paths' do
|
101
|
+
paths = [double('paths')]
|
102
|
+
expect(builder).to receive(:added).with(paths)
|
103
|
+
subject.run_on_additions(paths)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#run_on_removals' do
|
108
|
+
it 'updates based on given paths' do
|
109
|
+
paths = [double('paths')]
|
110
|
+
expect(builder).to receive(:removed).with(paths)
|
111
|
+
subject.run_on_removals(paths)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.expect_with :rspec do |expectations|
|
3
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
4
|
+
end
|
5
|
+
|
6
|
+
config.mock_with :rspec do |mocks|
|
7
|
+
mocks.verify_partial_doubles = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.filter_run :focus
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
|
13
|
+
config.disable_monkey_patching!
|
14
|
+
|
15
|
+
# config.warnings = true
|
16
|
+
|
17
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
18
|
+
|
19
|
+
# config.profile_examples = 10
|
20
|
+
|
21
|
+
config.order = :random
|
22
|
+
|
23
|
+
Kernel.srand config.seed
|
24
|
+
|
25
|
+
config.before do
|
26
|
+
%w(cp rm_r rm mkdir mkdir_p).each do |meth|
|
27
|
+
allow(FileUtils).to receive(meth) do |*args|
|
28
|
+
fail "stub me: FileUtils.#{meth}(#{args.map(&:inspect).join(', ')})"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
%w(exist?).each do |meth|
|
33
|
+
allow(File).to receive(meth) do |*args|
|
34
|
+
fail "stub me: File.#{meth}(#{args.map(&:inspect).join(', ')})"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
%w([]).each do |meth|
|
39
|
+
allow(Dir).to receive(meth) do |*args|
|
40
|
+
fail "stub me: Dir.#{meth}(#{args.map(&:inspect).join(', ')})"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/test/Guardfile
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# A sample Guardfile
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
ignore(/^_site/)
|
5
|
+
guard 'jekyll_plus', config: ['_config.yml', '_override.yml'], serve: true do
|
6
|
+
watch(/.*/)
|
7
7
|
end
|
8
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-jekyll-plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|
@@ -16,14 +16,34 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.10'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.10.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.10'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.10.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: guard-compat
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.1'
|
20
40
|
type: :runtime
|
21
41
|
prerelease: false
|
22
42
|
version_requirements: !ruby/object:Gem::Requirement
|
23
43
|
requirements:
|
24
44
|
- - "~>"
|
25
45
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
46
|
+
version: '1.1'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: jekyll
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,19 +73,33 @@ dependencies:
|
|
53
73
|
- !ruby/object:Gem::Version
|
54
74
|
version: '0'
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
76
|
+
name: rspec
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
58
78
|
requirements:
|
59
|
-
- - "
|
79
|
+
- - "~>"
|
60
80
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
81
|
+
version: '3.1'
|
62
82
|
type: :development
|
63
83
|
prerelease: false
|
64
84
|
version_requirements: !ruby/object:Gem::Requirement
|
65
85
|
requirements:
|
66
|
-
- - "
|
86
|
+
- - "~>"
|
67
87
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
88
|
+
version: '3.1'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: nenv
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.1'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.1'
|
69
103
|
- !ruby/object:Gem::Dependency
|
70
104
|
name: bundler
|
71
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,19 +122,41 @@ extensions: []
|
|
88
122
|
extra_rdoc_files: []
|
89
123
|
files:
|
90
124
|
- ".gitignore"
|
125
|
+
- ".rspec"
|
126
|
+
- ".rubocop.yml"
|
127
|
+
- ".rubocop_todo.yml"
|
128
|
+
- ".ruby-gemset"
|
129
|
+
- ".travis.yml"
|
91
130
|
- CHANGELOG.md
|
92
131
|
- Gemfile
|
132
|
+
- Guardfile
|
93
133
|
- LICENSE.txt
|
94
134
|
- README.md
|
95
135
|
- Rakefile
|
96
136
|
- guard-jekyll-plus.gemspec
|
97
|
-
- lib/guard/
|
98
|
-
- lib/guard/
|
99
|
-
- lib/guard/
|
137
|
+
- lib/guard/jekyll_plus.rb
|
138
|
+
- lib/guard/jekyll_plus/builder.rb
|
139
|
+
- lib/guard/jekyll_plus/builder/action.rb
|
140
|
+
- lib/guard/jekyll_plus/builder/adder.rb
|
141
|
+
- lib/guard/jekyll_plus/builder/modifier.rb
|
142
|
+
- lib/guard/jekyll_plus/builder/rebuilder.rb
|
143
|
+
- lib/guard/jekyll_plus/builder/remover.rb
|
144
|
+
- lib/guard/jekyll_plus/config.rb
|
145
|
+
- lib/guard/jekyll_plus/server.rb
|
146
|
+
- lib/guard/jekyll_plus/templates/Guardfile
|
147
|
+
- lib/guard/jekyll_plus/version.rb
|
100
148
|
- lib/rack/config.ru
|
149
|
+
- spec/lib/guard/jekyll-plus/builder/adder_spec.rb
|
150
|
+
- spec/lib/guard/jekyll-plus/builder/modifier_spec.rb
|
151
|
+
- spec/lib/guard/jekyll-plus/builder/rebuilder_spec.rb
|
152
|
+
- spec/lib/guard/jekyll-plus/builder/remover_spec.rb
|
153
|
+
- spec/lib/guard/jekyll-plus/builder_spec.rb
|
154
|
+
- spec/lib/guard/jekyll-plus/config_spec.rb
|
155
|
+
- spec/lib/guard/jekyll-plus/server_spec.rb
|
156
|
+
- spec/lib/guard/jekyll-plus_spec.rb
|
157
|
+
- spec/spec_helper.rb
|
101
158
|
- test/.gitignore
|
102
159
|
- test/404.html
|
103
|
-
- test/Gemfile
|
104
160
|
- test/Guardfile
|
105
161
|
- test/Testfile
|
106
162
|
- test/_config.yml
|
@@ -135,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
191
|
version: '0'
|
136
192
|
requirements: []
|
137
193
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
194
|
+
rubygems_version: 2.2.2
|
139
195
|
signing_key:
|
140
196
|
specification_version: 4
|
141
197
|
summary: A Guard plugin for Jekyll which intelligently handles changes to static and
|
data/lib/guard/jekyll-plus.rb
DELETED
@@ -1,300 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'benchmark'
|
4
|
-
require 'guard/plugin'
|
5
|
-
require 'jekyll'
|
6
|
-
|
7
|
-
begin
|
8
|
-
require 'rack'
|
9
|
-
rescue LoadError
|
10
|
-
end
|
11
|
-
|
12
|
-
module Guard
|
13
|
-
class Jekyllplus < Plugin
|
14
|
-
def initialize(options = {})
|
15
|
-
super
|
16
|
-
|
17
|
-
default_extensions = ['md','mkd','mkdn','markdown','textile','html','haml','slim','xml','yml','sass','scss']
|
18
|
-
|
19
|
-
@options = {
|
20
|
-
:extensions => [],
|
21
|
-
:config => ['_config.yml'],
|
22
|
-
:serve => false,
|
23
|
-
:rack_config => nil,
|
24
|
-
:drafts => false,
|
25
|
-
:future => false,
|
26
|
-
:config_hash => nil,
|
27
|
-
:silent => false,
|
28
|
-
:msg_prefix => 'Jekyll'
|
29
|
-
}.merge(options)
|
30
|
-
|
31
|
-
@config = load_config(@options)
|
32
|
-
@source = local_path @config['source']
|
33
|
-
@destination = local_path @config['destination']
|
34
|
-
@msg_prefix = @options[:msg_prefix]
|
35
|
-
|
36
|
-
# Convert array of extensions into a regex for matching file extensions eg, /\.md$|\.markdown$|\.html$/i
|
37
|
-
#
|
38
|
-
extensions = @options[:extensions].concat(default_extensions).flatten.uniq
|
39
|
-
@extensions = Regexp.new extensions.map { |e| (e << '$').gsub('\.', '\\.') }.join('|'), true
|
40
|
-
|
41
|
-
# set Jekyll server thread to nil
|
42
|
-
@server_thread = nil
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def load_config(options)
|
47
|
-
config = jekyll_config(options)
|
48
|
-
|
49
|
-
# Override configuration with guard option values
|
50
|
-
config['show_drafts'] ||= options[:drafts]
|
51
|
-
config['future'] ||= options[:future]
|
52
|
-
config
|
53
|
-
end
|
54
|
-
|
55
|
-
def reload_config!
|
56
|
-
UI.info "Reloading Jekyll configuration!"
|
57
|
-
@config = load_config(@options)
|
58
|
-
end
|
59
|
-
|
60
|
-
def start
|
61
|
-
if @options[:serve]
|
62
|
-
build
|
63
|
-
start_server
|
64
|
-
UI.info "#{@msg_prefix} " + "watching and serving at #{@config['host']}:#{@config['port']}#{@config['baseurl']}" unless @config[:silent]
|
65
|
-
else
|
66
|
-
build
|
67
|
-
UI.info "#{@msg_prefix} " + "watching" unless @config[:silent]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def reload
|
72
|
-
stop if !@server_thread.nil? and @server_thread.alive?
|
73
|
-
reload_config!
|
74
|
-
start
|
75
|
-
end
|
76
|
-
|
77
|
-
def reload_server
|
78
|
-
stop_server
|
79
|
-
start_server
|
80
|
-
end
|
81
|
-
|
82
|
-
def stop
|
83
|
-
stop_server
|
84
|
-
end
|
85
|
-
|
86
|
-
def run_on_modifications(paths)
|
87
|
-
# At this point we know @options[:config] is going to be an Array
|
88
|
-
# thanks to the call the jekyll_config earlier.
|
89
|
-
reload_config! if @options[:config].map { |f| paths.include?(f) }.any?
|
90
|
-
matched = jekyll_matches paths
|
91
|
-
unmatched = non_jekyll_matches paths
|
92
|
-
if matched.size > 0
|
93
|
-
build(matched, "Files changed: ", " ~ ".yellow)
|
94
|
-
elsif unmatched.size > 0
|
95
|
-
copy(unmatched)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def run_on_additions(paths)
|
100
|
-
matched = jekyll_matches paths
|
101
|
-
unmatched = non_jekyll_matches paths
|
102
|
-
|
103
|
-
if matched.size > 0
|
104
|
-
build(matched, "Files added: ", " + ".green)
|
105
|
-
elsif unmatched.size > 0
|
106
|
-
copy(unmatched)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def run_on_removals(paths)
|
111
|
-
matched = jekyll_matches paths
|
112
|
-
unmatched = non_jekyll_matches paths
|
113
|
-
|
114
|
-
if matched.size > 0
|
115
|
-
build(matched, "Files removed: ", " x ".red)
|
116
|
-
elsif unmatched.size > 0
|
117
|
-
remove(unmatched)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
private
|
123
|
-
|
124
|
-
def build(files = nil, message = '', mark = nil)
|
125
|
-
begin
|
126
|
-
UI.info "#{@msg_prefix} #{message}" + "building...".yellow unless @config[:silent]
|
127
|
-
if files
|
128
|
-
puts '| ' # spacing
|
129
|
-
files.each { |file| puts '|' + mark + file }
|
130
|
-
puts '| ' # spacing
|
131
|
-
end
|
132
|
-
elapsed = Benchmark.realtime { build_site(@config) }
|
133
|
-
UI.info "#{@msg_prefix} " + "build completed in #{elapsed.round(2)}s ".green + "#{@source} → #{@destination}" unless @config[:silent]
|
134
|
-
rescue Exception
|
135
|
-
UI.error "#{@msg_prefix} build has failed" unless @config[:silent]
|
136
|
-
stop_server
|
137
|
-
throw :task_has_failed
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# Copy static files to destination directory
|
142
|
-
#
|
143
|
-
def copy(files=[])
|
144
|
-
files = ignore_stitch_sources files
|
145
|
-
if files.size > 0
|
146
|
-
begin
|
147
|
-
message = 'copied file'
|
148
|
-
message += 's' if files.size > 1
|
149
|
-
UI.info "#{@msg_prefix} #{message.green}" unless @config[:silent]
|
150
|
-
puts '| ' #spacing
|
151
|
-
files.each do |file|
|
152
|
-
if(!check_jekyll_exclude(file))
|
153
|
-
path = destination_path file
|
154
|
-
FileUtils.mkdir_p File.dirname(path)
|
155
|
-
FileUtils.cp file, path
|
156
|
-
puts '|' + " → ".green + path
|
157
|
-
else
|
158
|
-
puts '|' + " ~ ".yellow + "Jekyll exclude: Ignoring changes to #{file}".yellow
|
159
|
-
end
|
160
|
-
end
|
161
|
-
puts '| ' #spacing
|
162
|
-
|
163
|
-
rescue Exception
|
164
|
-
UI.error "#{@msg_prefix} copy has failed" unless @config[:silent]
|
165
|
-
UI.error e
|
166
|
-
stop_server
|
167
|
-
throw :task_has_failed
|
168
|
-
end
|
169
|
-
true
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def ignore_stitch_sources(files)
|
174
|
-
if ENV['GUARD_STITCH_PLUS_FILES']
|
175
|
-
ignore = ENV['GUARD_STITCH_PLUS_FILES'].split(',')
|
176
|
-
files.reject {|f| ignore.include? f }
|
177
|
-
else
|
178
|
-
files
|
179
|
-
end
|
180
|
-
|
181
|
-
end
|
182
|
-
|
183
|
-
# Remove deleted source file/directories from destination
|
184
|
-
#
|
185
|
-
def remove(files=[])
|
186
|
-
files = ignore_stitch_sources files
|
187
|
-
# Ensure at least one file still exists (other scripts may clean up too)
|
188
|
-
if files.select {|f| File.exist? f }.size > 0
|
189
|
-
begin
|
190
|
-
message = 'removed file'
|
191
|
-
message += 's' if files.size > 1
|
192
|
-
UI.info "#{@msg_prefix} #{message.red}" unless @config[:silent]
|
193
|
-
puts '| ' #spacing
|
194
|
-
|
195
|
-
files.each do |file|
|
196
|
-
path = destination_path file
|
197
|
-
if File.exist? path
|
198
|
-
FileUtils.rm path
|
199
|
-
puts '|' + " x ".red + path
|
200
|
-
end
|
201
|
-
|
202
|
-
dir = File.dirname path
|
203
|
-
if Dir[dir+'/*'].empty?
|
204
|
-
FileUtils.rm_r(dir)
|
205
|
-
puts '|' + " x ".red + dir
|
206
|
-
end
|
207
|
-
end
|
208
|
-
puts '| ' #spacing
|
209
|
-
|
210
|
-
rescue Exception
|
211
|
-
UI.error "#{@msg_prefix} remove has failed" unless @config[:silent]
|
212
|
-
UI.error e
|
213
|
-
stop_server
|
214
|
-
throw :task_has_failed
|
215
|
-
end
|
216
|
-
true
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
def jekyll_matches(paths)
|
221
|
-
paths.select { |file| file =~ @extensions }
|
222
|
-
end
|
223
|
-
|
224
|
-
def non_jekyll_matches(paths)
|
225
|
-
paths.select { |file| !file.match(/^_/) and !file.match(@extensions) }
|
226
|
-
end
|
227
|
-
|
228
|
-
def jekyll_config(options)
|
229
|
-
if options[:config_hash]
|
230
|
-
config = options[:config_hash]
|
231
|
-
elsif options[:config]
|
232
|
-
options[:config] = [options[:config]] unless options[:config].is_a? Array
|
233
|
-
config = options
|
234
|
-
end
|
235
|
-
Jekyll.configuration(config)
|
236
|
-
end
|
237
|
-
|
238
|
-
def check_jekyll_exclude(path)
|
239
|
-
return @config['exclude'].any? {|f| File.fnmatch?(path, f)}
|
240
|
-
end
|
241
|
-
|
242
|
-
def rack_config(root)
|
243
|
-
ENV['RACK_ROOT'] = root
|
244
|
-
default_config = File.expand_path("../rack/config.ru", File.dirname(__FILE__))
|
245
|
-
local_config = File.exist?('config.ru') ? 'config.ru' : nil
|
246
|
-
|
247
|
-
config = (@config['rack_config'] || local_config || default_config)
|
248
|
-
{ :config => config, :Port => @config['port'], :Host => @config['host'], :environment => 'development' }
|
249
|
-
end
|
250
|
-
|
251
|
-
def local_path(path)
|
252
|
-
Dir.chdir('.')
|
253
|
-
current = Dir.pwd
|
254
|
-
path = path.sub current, ''
|
255
|
-
if path == ''
|
256
|
-
'./'
|
257
|
-
else
|
258
|
-
path.sub(/^\//, '')
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
def build_site(options)
|
263
|
-
Jekyll.logger.log_level = :error
|
264
|
-
site = Jekyll::Site.new(options)
|
265
|
-
Jekyll.logger.log_level = :info
|
266
|
-
site.process
|
267
|
-
end
|
268
|
-
|
269
|
-
|
270
|
-
def destination_path(file)
|
271
|
-
if @source =~ /^\./
|
272
|
-
File.join @destination, file
|
273
|
-
else
|
274
|
-
file.sub(/^#{@source}/, "#{@destination}")
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
def server(config)
|
279
|
-
if defined? ::Rack
|
280
|
-
Thread.new { ::Rack::Server.start(rack_config(@destination)) }
|
281
|
-
UI.info "#{@msg_prefix} running Rack" unless @config[:silent]
|
282
|
-
else
|
283
|
-
Thread.new { Jekyll::Commands::Serve.process(config) }
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
def start_server
|
288
|
-
if @server_thread.nil?
|
289
|
-
@server_thread = server(@config)
|
290
|
-
else
|
291
|
-
UI.warning "#{@msg_prefix} using an old server thread!"
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
def stop_server
|
296
|
-
@server_thread.kill unless @server_thread.nil?
|
297
|
-
@server_thread = nil
|
298
|
-
end
|
299
|
-
end
|
300
|
-
end
|