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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +10 -0
  4. data/.rubocop_todo.yml +32 -0
  5. data/.ruby-gemset +1 -0
  6. data/.travis.yml +6 -0
  7. data/CHANGELOG.md +6 -2
  8. data/Gemfile +12 -2
  9. data/Guardfile +30 -0
  10. data/README.md +5 -5
  11. data/Rakefile +9 -1
  12. data/guard-jekyll-plus.gemspec +20 -15
  13. data/lib/guard/jekyll_plus.rb +54 -0
  14. data/lib/guard/jekyll_plus/builder.rb +46 -0
  15. data/lib/guard/jekyll_plus/builder/action.rb +126 -0
  16. data/lib/guard/jekyll_plus/builder/adder.rb +23 -0
  17. data/lib/guard/jekyll_plus/builder/modifier.rb +23 -0
  18. data/lib/guard/jekyll_plus/builder/rebuilder.rb +37 -0
  19. data/lib/guard/jekyll_plus/builder/remover.rb +24 -0
  20. data/lib/guard/jekyll_plus/config.rb +131 -0
  21. data/lib/guard/jekyll_plus/server.rb +111 -0
  22. data/lib/guard/jekyll_plus/templates/Guardfile +4 -0
  23. data/lib/guard/{jekyll-plus → jekyll_plus}/version.rb +1 -1
  24. data/spec/lib/guard/jekyll-plus/builder/adder_spec.rb +94 -0
  25. data/spec/lib/guard/jekyll-plus/builder/modifier_spec.rb +113 -0
  26. data/spec/lib/guard/jekyll-plus/builder/rebuilder_spec.rb +76 -0
  27. data/spec/lib/guard/jekyll-plus/builder/remover_spec.rb +97 -0
  28. data/spec/lib/guard/jekyll-plus/builder_spec.rb +57 -0
  29. data/spec/lib/guard/jekyll-plus/config_spec.rb +138 -0
  30. data/spec/lib/guard/jekyll-plus/server_spec.rb +79 -0
  31. data/spec/lib/guard/jekyll-plus_spec.rb +114 -0
  32. data/spec/spec_helper.rb +44 -0
  33. data/test/Guardfile +3 -4
  34. metadata +70 -14
  35. data/lib/guard/jekyll-plus.rb +0 -300
  36. data/lib/guard/jekyll-plus/templates/Guardfile +0 -5
  37. data/test/Gemfile +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be72288508230bb15f897c6a90e3e3acadbfd133
4
- data.tar.gz: 5d2617be237688069afa09a0ca1e520f67ae1c63
3
+ metadata.gz: 076743d79bba521d0febc7610d79d83fff4e3e06
4
+ data.tar.gz: 32a121773ebec897e7799df0de0db78aca64710e
5
5
  SHA512:
6
- metadata.gz: 026b9320d2df6366b31badc431cf5a4f30595f7cb8ab184320354e141a7707e7390e76a2b6a7f44f80a3fecd02a7206c79d5907c3f6f7e94126855a003408ca3
7
- data.tar.gz: 1556ec62c7a9d61cecbcfb62582e3d1f605b3c4cef1101b3a67d629a7b8f4c6ffd02565d363da2aebddfd719c437a1e6a19c2778e6ae9e0f49c57703345ef6fa
6
+ metadata.gz: df7d740d999f05818c70cb31b089538f96cdec8544706905be63582917aea9964e36c49ce707a7f62eb82d5a4ad5ff9a4c65a74c168d798bd8ef26833a1be6e0
7
+ data.tar.gz: 54a1aca7708d5aeb3a0cb64c83afebd742569b688d373a5c9846d19d4e488c7e6a06353902d2b18686234e37e854d3207201c9ddce87eafd443bb659dc12cab3
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - Guardfile
6
+
7
+ Style/FileName:
8
+ Exclude:
9
+ - lib/guard/jekyll-plus.rb
10
+ - spec/lib/guard/jekyll-plus_spec.rb
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,32 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-12-15 14:17:36 +0100 using RuboCop version 0.28.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 4
9
+ Metrics/AbcSize:
10
+ Max: 34
11
+
12
+ # Offense count: 1
13
+ # Configuration parameters: CountComments.
14
+ Metrics/ClassLength:
15
+ Max: 250
16
+
17
+ # Offense count: 1
18
+ Metrics/CyclomaticComplexity:
19
+ Max: 8
20
+
21
+ # Offense count: 5
22
+ # Configuration parameters: CountComments.
23
+ Metrics/MethodLength:
24
+ Max: 25
25
+
26
+ # Offense count: 1
27
+ Metrics/PerceivedComplexity:
28
+ Max: 8
29
+
30
+ # Offense count: 2
31
+ Style/Documentation:
32
+ Enabled: false
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ guard-jekyll-plus
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.5
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ### 2.0.0
3
+ ### 2.0.1 - 12-15-2014
4
+
5
+ - Changed guard template name for better compatibility with Guard's naming scheme.
6
+
7
+ ### 2.0.0 - 12-15-2014
4
8
 
5
9
  - Updated to work with Guard 2.x
6
10
 
@@ -51,7 +55,7 @@
51
55
 
52
56
  ### 1.3.0
53
57
 
54
- - Changed guard name to jekyll-plus to help Guard properly init the Guardfile.
58
+ - Changed guard name to jekyll_plus to help Guard properly init the Guardfile.
55
59
 
56
60
  ### 1.2.3
57
61
 
data/Gemfile CHANGED
@@ -1,4 +1,14 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in guard-jekyll-plus.gemspec
4
- gemspec
3
+ # Specify your gem's dependencies in guard-jekyll_plus.gemspec
4
+ #
5
+ # NOTE: it's more convenient to use gemspec for bare-minimum test deps
6
+ # and the Gemfile for any extra dev gems
7
+ gemspec development_group: :test
8
+
9
+ group :development do
10
+ gem 'guard-rspec', require: false
11
+ gem 'guard-rubocop', require: false
12
+ gem 'pry'
13
+ gem 'pry-byebug'
14
+ end
data/Guardfile ADDED
@@ -0,0 +1,30 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %(app lib config test spec feature)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ group :bdd, halt_on_fail: true do
11
+ guard :rspec, cmd: "bundle exec rspec", all_on_start: false do
12
+ require "guard/rspec/dsl"
13
+ dsl = Guard::RSpec::Dsl.new(self)
14
+
15
+ # RSpec files
16
+ rspec = dsl.rspec
17
+ watch(rspec.spec_helper) { rspec.spec_dir }
18
+ watch(rspec.spec_support) { rspec.spec_dir }
19
+ watch(rspec.spec_files)
20
+
21
+ # Ruby files
22
+ ruby = dsl.ruby
23
+ dsl.watch_spec_files_for(ruby.lib_files)
24
+ end
25
+
26
+ guard :rubocop, all_on_start: false do
27
+ watch(%r{.+\.rb$})
28
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
29
+ end
30
+ end
data/README.md CHANGED
@@ -42,7 +42,7 @@ Navigate to your Jekyll project directory and create a Guardfile using:
42
42
  Or if you already have a Guardfile, add a Jekyll guard.
43
43
 
44
44
  ```ruby
45
- guard "jekyll-plus" do
45
+ guard "jekyll_plus" do
46
46
  watch /.*/
47
47
  ignore /^_site/
48
48
  end
@@ -66,7 +66,7 @@ If your Jekyll project has a non-standard directory stucture like this:
66
66
  You would do this instead:
67
67
 
68
68
  ```ruby
69
- guard "jekyll-plus" do
69
+ guard "jekyll_plus" do
70
70
  watch /^source/
71
71
  watch /_config.yml/
72
72
  end
@@ -97,7 +97,7 @@ This guard has these configurations.
97
97
  To use Jekyll's built-in server, simply set `:serve => true` in your rack options
98
98
 
99
99
  ```ruby
100
- guard "jekyll-plus", :serve => true do
100
+ guard "jekyll_plus", :serve => true do
101
101
  watch /.*/
102
102
  ignore /^_site/
103
103
  end
@@ -115,7 +115,7 @@ If you wish to use your own rack server configuration, simply drop a `config.ru`
115
115
  Here's how you would add `txt` to the list of file extensions which triggers a Jekyll build.
116
116
 
117
117
  ```ruby
118
- guard "jekyll-plus", :extensions => ['txt'] do
118
+ guard "jekyll_plus", :extensions => ['txt'] do
119
119
  watch /.*/
120
120
  ignore /^_site/
121
121
  end
@@ -129,7 +129,7 @@ which don't match these extensions will be simply copied over to the destination
129
129
  Here's how you might tell Jekyll to read from multiple configuration files.
130
130
 
131
131
  ```ruby
132
- guard "jekyll-plus", :config => ['settings.yml', 'override.yml'] do
132
+ guard "jekyll_plus", :config => ['settings.yml', 'override.yml'] do
133
133
  watch /.*/
134
134
  ignore /^_site/
135
135
  end
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'nenv'
3
+
4
+ require 'rspec/core/rake_task'
5
+ rspec = RSpec::Core::RakeTask.new do |t|
6
+ t.verbose = Nenv.ci?
7
+ end
8
+
9
+ task default: rspec.name
@@ -1,28 +1,33 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'guard/jekyll-plus/version'
4
+ require 'guard/jekyll_plus/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "guard-jekyll-plus"
7
+ gem.name = 'guard-jekyll-plus'
8
8
  gem.version = Guard::JekyllPlusVersion::VERSION
9
- gem.authors = ["Brandon Mathis"]
10
- gem.email = ["brandon@imathis.com"]
11
- gem.description = %q{A Guard plugin for smarter Jekyll watching}
12
- gem.summary = %q{A Guard plugin for Jekyll which intelligently handles changes to static and template files, only running a Jekyll build when necessary. }
13
- gem.homepage = "http://github.com/imathis/guard-jekyll-plus"
9
+ gem.authors = ['Brandon Mathis']
10
+ gem.email = ['brandon@imathis.com']
11
+ gem.description = 'A Guard plugin for smarter Jekyll watching'
12
+ gem.summary = 'A Guard plugin for Jekyll which intelligently handles'\
13
+ ' changes to static and template files, only running a'\
14
+ ' Jekyll build when necessary. '
15
+
16
+ gem.homepage = 'http://github.com/imathis/guard-jekyll-plus'
14
17
  gem.license = 'MIT'
15
18
 
16
- gem.files = `git ls-files`.split($/)
17
- gem.require_paths = ["lib"]
19
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
20
+ gem.require_paths = ['lib']
18
21
 
19
- gem.add_dependency 'guard', '~> 2.8'
22
+ gem.add_dependency 'guard', '~> 2.10', '>= 2.10.3'
23
+ gem.add_dependency 'guard-compat', '~> 1.1'
20
24
  gem.add_dependency 'jekyll', '>= 1.0.0'
21
25
 
22
- gem.add_development_dependency "rake"
23
- gem.add_development_dependency "pry-byebug"
26
+ # Note: we use these for test depedencies, because it's more convenient
27
+ # to use Gemfile for development deps
28
+ gem.add_development_dependency 'rake'
29
+ gem.add_development_dependency 'rspec', '~> 3.1'
30
+ gem.add_development_dependency 'nenv', '~> 0.1'
24
31
 
25
- if RUBY_VERSION >= "2"
26
- gem.add_development_dependency "bundler"
27
- end
32
+ gem.add_development_dependency 'bundler' if RUBY_VERSION >= '2'
28
33
  end
@@ -0,0 +1,54 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'pathname'
4
+
5
+ require 'jekyll'
6
+
7
+ require 'guard/compat/plugin'
8
+
9
+ require 'guard/jekyll_plus/server'
10
+ require 'guard/jekyll_plus/config'
11
+ require 'guard/jekyll_plus/builder'
12
+
13
+ module Guard
14
+ class JekyllPlus < Plugin
15
+ def initialize(options = {})
16
+ super
17
+
18
+ @config = Config.new(options)
19
+ @server = Server.new(@config)
20
+ @builder = Builder.new(@config)
21
+ end
22
+
23
+ def start
24
+ @builder.build
25
+ @server.start if @config.serve?
26
+ @config.info 'watching'
27
+ end
28
+
29
+ def reload
30
+ stop
31
+ @config.info 'Reloading Jekyll configuration!'
32
+ @config.reload
33
+ @builder.reload
34
+ start
35
+ end
36
+
37
+ def stop
38
+ @server.stop
39
+ end
40
+
41
+ def run_on_modifications(paths)
42
+ reload if paths.any? { |f| @config.config_file?(f) }
43
+ @builder.modified(paths)
44
+ end
45
+
46
+ def run_on_additions(paths)
47
+ @builder.added(paths)
48
+ end
49
+
50
+ def run_on_removals(paths)
51
+ @builder.removed(paths)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,46 @@
1
+ require 'jekyll'
2
+
3
+ require 'guard/jekyll_plus/config'
4
+
5
+ require 'guard/jekyll_plus/builder/modifier'
6
+ require 'guard/jekyll_plus/builder/adder'
7
+ require 'guard/jekyll_plus/builder/remover'
8
+ require 'guard/jekyll_plus/builder/rebuilder'
9
+
10
+ module Guard
11
+ class JekyllPlus < Plugin
12
+ class Builder
13
+ def initialize(config)
14
+ @config = config
15
+ reload
16
+ end
17
+
18
+ def reload
19
+ Jekyll.logger.log_level = :error
20
+ @site = ::Jekyll::Site.new(@config.jekyll_config)
21
+ Jekyll.logger.log_level = :info
22
+
23
+ @adder = Adder.new(@config, @site)
24
+ @modifier = Modifier.new(@config, @site)
25
+ @remover = Remover.new(@config, @site)
26
+ @rebuilder = Rebuilder.new(@config, @site)
27
+ end
28
+
29
+ def build
30
+ @rebuilder.update
31
+ end
32
+
33
+ def added(paths)
34
+ @adder.update(paths)
35
+ end
36
+
37
+ def modified(paths)
38
+ @modifier.update(paths)
39
+ end
40
+
41
+ def removed(paths)
42
+ @remover.update(paths)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,126 @@
1
+ # encoding: utf-8
2
+
3
+ require 'benchmark'
4
+ require 'jekyll'
5
+ require 'guard/compat/plugin'
6
+
7
+ require 'guard/jekyll_plus/config'
8
+
9
+ module Guard
10
+ class JekyllPlus < Plugin
11
+ class Builder
12
+ class Action
13
+ def initialize(config, site)
14
+ @config, @site = config, site
15
+ end
16
+
17
+ def jekyll_matches(paths)
18
+ paths.select { |file| file =~ @config.extensions }
19
+ end
20
+
21
+ def non_jekyll_matches(paths)
22
+ paths.select do |file|
23
+ !file.match(/^_/) && !file.match(@config.extensions)
24
+ end
25
+ end
26
+
27
+ def build(files, message, mark)
28
+ @config.info [message, 'building...'.yellow].join(' ')
29
+
30
+ if files
31
+ puts '| ' # spacing
32
+ files.each { |file| puts '|' + mark + file }
33
+ puts '| ' # spacing
34
+ end
35
+
36
+ elapsed = Benchmark.realtime { @site.process }.round(2)
37
+
38
+ change = format('%s → %s', @config.source, @config.destination)
39
+ @config.info format('build completed in %ss '.green + change, elapsed)
40
+
41
+ # rescue almost everything because Jekyll::Convertible forwards
42
+ # every plugin-specific exception it encounters
43
+ rescue StandardError => e
44
+ @config.error 'build has failed'
45
+ @config.error e.to_s
46
+ throw :task_has_failed
47
+ end
48
+
49
+ def ignore_stitch_sources(files)
50
+ return files unless (ignore = ENV['GUARD_STITCH_PLUS_FILES'])
51
+
52
+ ignore = ignore.split(',')
53
+ files.reject { |f| ignore.include? f }
54
+ end
55
+
56
+ def pluralize(word, array)
57
+ "#{word}#{array.size > 1 ? 's' : ''}"
58
+ end
59
+
60
+ def destination_path(file)
61
+ if @config.source =~ /^\./
62
+ File.join @config.destination, file
63
+ else
64
+ file.sub(/^#{@config.source}/, "#{@config.destination}")
65
+ end
66
+ end
67
+
68
+ def build_was_needed(paths)
69
+ matched = jekyll_matches(paths)
70
+ return false if matched.empty?
71
+ build(matched, @msg, @mark)
72
+ end
73
+
74
+ def update(paths)
75
+ return if build_was_needed(paths)
76
+
77
+ unmatched = non_jekyll_matches(paths)
78
+ return if unmatched.empty?
79
+ files = ignore_stitch_sources(unmatched)
80
+ return if files.empty?
81
+
82
+ do_update(files)
83
+ footer
84
+ rescue RuntimeError, SystemCallError => e
85
+ @config.error "#{@name} has failed"
86
+ @config.error e.to_s
87
+ throw :task_has_failed
88
+ end
89
+
90
+ def copy(src, dst)
91
+ if @config.excluded?(src)
92
+ puts '|' + (' ~ ' + "Ignoring excluded file: #{src}").yellow
93
+ return
94
+ end
95
+
96
+ FileUtils.mkdir_p File.dirname(dst)
97
+ FileUtils.cp src, dst
98
+ puts '|' + ' → '.green + dst
99
+ end
100
+
101
+ def remove(path)
102
+ if File.exist? path
103
+ FileUtils.rm path
104
+ puts '|' + ' → '.red + path
105
+ end
106
+
107
+ dir = File.dirname path
108
+ return if Dir[dir + '/*'].any?
109
+
110
+ FileUtils.rm_rk(dir)
111
+ puts '|' + ' x '.red + dir
112
+ end
113
+
114
+ def header(files)
115
+ plural = files.nil? ? '' : pluralize('file', files.size)
116
+ @config.info [@activity, plural].join(' ').send(@color)
117
+ puts '| ' unless files.nil? # spacing
118
+ end
119
+
120
+ def footer
121
+ puts '| ' # spacing
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end