guard-asciidoctor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8825b58f2bcdeb0c3f340a14ca3882c83aa9647
4
+ data.tar.gz: f569cf96d7228c06455a3189846bbad15b8ce1af
5
+ SHA512:
6
+ metadata.gz: 773dd163f498a90e6a0aeefffa99b725dfe7394263848733dbc02db610c1235d0446c9d42bb93bef9ac27e56ed4b6b524b0952aa1c3896b34f1e33f1d3b6510e
7
+ data.tar.gz: 423c2fd630641857bb49590423fe4cb168e650e148d50a53d89d52dd9b74a4930932e33c92aecd8a1edb83f8577c827808dc6c201d56f298fd67f15aced83d8b
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ guard-asciidoctor
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.0
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+
7
+ group :development do
8
+ gem 'ruby_gntp'
9
+ gem 'guard-rspec'
10
+ gem 'transpec'
11
+ end
12
+
13
+ # The test group will be
14
+ # installed on Travis CI
15
+ #
16
+ group :test do
17
+ gem 'rspec', '~> 3.1'
18
+ gem 'coveralls', require: false
19
+ gem 'rubocop', require: false
20
+ gem 'pry-byebug'
21
+ end
data/Guardfile ADDED
@@ -0,0 +1,28 @@
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 %w(app lib config test spec feature)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), the you will want to move the Guardfile
18
+ ## to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ guard :asciidcotor do
27
+ watch(*)
28
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ma Lucheng
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Guard::Asciidoctor
2
+
3
+ Watches Asciidoc files, compiles them to HTML on change.
4
+
5
+ ## Install
6
+
7
+ Please be sure to have [Guard](https://github.com/guard/guard) installed before continuing.
8
+
9
+ Add Guard::Asciidoctor to your `Gemfile`:
10
+
11
+ ```ruby
12
+ group :development do
13
+ gem 'guard-asciidoctor'
14
+ end
15
+ ```
16
+
17
+ Add guard definition to your Guardfile by running this command:
18
+
19
+ ```bash
20
+ $ guard init asciidoctor
21
+ ```
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/guard-asciidoctor/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ default_tasks = []
4
+
5
+ require 'rspec/core/rake_task'
6
+ default_tasks << RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.verbose = (ENV['CI'] == 'true')
8
+ end
9
+
10
+ if ENV['CI'] != 'true'
11
+ require 'rubocop/rake_task'
12
+ default_tasks << RuboCop::RakeTask.new(:rubocop)
13
+ end
14
+
15
+ task default: default_tasks.map(&:name)
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'guard/asciidoctor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "guard-asciidoctor"
8
+ spec.version = Guard::AsciidoctorVersion::VERSION
9
+ spec.authors = ["Ma Lucheng"]
10
+ spec.email = ["mlc880926@gmail.com"]
11
+ spec.summary = %q{asciidoctor guard}
12
+ spec.description = %q{asciidoctor guard}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency 'minitest', '~> 5.4'
24
+
25
+ spec.add_dependency 'guard', '~> 2.0'
26
+ spec.add_dependency 'guard-compat', '~> 1.1'
27
+ spec.add_dependency 'asciidoctor'
28
+
29
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'guard/asciidoctor'
4
+
5
+ module Guard
6
+ class Asciidoctor < Plugin
7
+ class Notifier
8
+ class << self
9
+ def image(result)
10
+ result ? :success : :failed
11
+ end
12
+
13
+ def notify(result, message)
14
+ Compat::UI.notify(message, title: 'Guard::Asciidoctor', image: image(result))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ # Sample guardfile block for Guard::Asciidoctor
2
+ # You can use some options to change guard-asciidoctor configuration
3
+
4
+ guard :asciidoctor do
5
+ watch(/^.+(\.asciidoc)$/)
6
+ watch(/^.+(\.adoc)$/)
7
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ class AsciidoctorVersion
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,153 @@
1
+ require 'asciidoctor'
2
+ require 'guard/compat/plugin'
3
+ require 'guard/asciidoctor/notifier'
4
+
5
+ module Guard
6
+
7
+ class Asciidoctor < Plugin
8
+
9
+ # Initializes a Guard plugin.
10
+ # Don't do any work here, especially as Guard plugins get initialized even if they are not in an active group!
11
+ #
12
+ # @param [Hash] options the custom Guard plugin options
13
+ # @option options [Array<Guard::Watcher>] watchers the Guard plugin file watchers
14
+ # @option options [Symbol] group the group this Guard plugin belongs to
15
+ # @option options [Boolean] any_return allow any object to be returned from a watcher
16
+ #
17
+ def initialize(options = {})
18
+ @patterns = []
19
+
20
+ opts = {
21
+ notifications: true,
22
+ helper_modules: []
23
+ }.merge(opts)
24
+
25
+ super(opts)
26
+ end
27
+
28
+ # Called once when Guard starts. Please override initialize method to init stuff.
29
+ #
30
+ # @raise [:task_has_failed] when start has failed
31
+ # @return [Object] the task result
32
+ #
33
+ def start
34
+ Compat::UI.info "method start"
35
+ run_all #if options[:run_at_start]
36
+ end
37
+
38
+ # Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
39
+ #
40
+ # @raise [:task_has_failed] when stop has failed
41
+ # @return [Object] the task result
42
+ #
43
+ def stop
44
+ Compat::UI.info "method stop"
45
+ true
46
+ end
47
+
48
+ # Called when `reload|r|z + enter` is pressed.
49
+ # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
50
+ #
51
+ # @raise [:task_has_failed] when reload has failed
52
+ # @return [Object] the task result
53
+ #
54
+ def reload
55
+ Compat::UI.info "method reload"
56
+ run_all
57
+ end
58
+
59
+ # Called when just `enter` is pressed
60
+ # This method should be principally used for long action like running all specs/tests/...
61
+ #
62
+ # @raise [:task_has_failed] when run_all has failed
63
+ # @return [Object] the task result
64
+ #
65
+ def run_all
66
+ Compat::UI.info "run all"
67
+ run_on_changes(Compat.matching_files(self, Dir.glob(File.join('**', '*.*'))))
68
+ end
69
+
70
+
71
+ def run_on_changes(paths)
72
+ paths.each do |file|
73
+ output_paths = _output_paths(file)
74
+ compiled_asciidoc = compile_asciidoc(file)
75
+
76
+ output_paths.each do |output_file|
77
+ FileUtils.mkdir_p File.dirname(output_file)
78
+ File.open(output_file, 'w') { |f| f.write(compiled_asciidoc) }
79
+ end
80
+
81
+ message = "Successfully compiled asciidoc!\n"
82
+ message += "# #{file} -> #{output_paths.join(', ')}".gsub("#{::Bundler.root}/", '')
83
+ Compat::UI.info message
84
+ Notifier.notify(true, message) if options[:notifications]
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def compile_asciidoc(file)
91
+ content = File.new(file).read
92
+ #engine = ::Haml::Engine.new(content, (options[:haml_options] || {}))
93
+ engine = ::Asciidoctor.convert content, safe: 'safe'
94
+ #engine.render scope_object
95
+ rescue StandardError => error
96
+ message = "Asciidoc compilation of #{file} failed!\nError: #{error.message}"
97
+ Compat::UI.error message
98
+ Notifier.notify(false, message) if options[:notifications]
99
+ throw :task_has_failed
100
+ end
101
+
102
+ def scope_object
103
+ scope = Object.new
104
+ @options[:helper_modules].each do |mod|
105
+ scope.extend mod
106
+ end
107
+ scope
108
+ end
109
+
110
+ # Get the file path to output the html based on the file being
111
+ # built. The output path is relative to where guard is being run.
112
+ #
113
+ # @param file [String, Array<String>] path to file being built
114
+ # @return [Array<String>] path(s) to file where output should be written
115
+ #
116
+ def _output_paths(file)
117
+ input_file_dir = File.dirname(file)
118
+ file_name = _output_filename(file)
119
+ input_file_dir = input_file_dir.gsub(Regexp.new("#{options[:input]}(\/){0,1}"), '') if options[:input]
120
+
121
+ if options[:output]
122
+ Array(options[:output]).map do |output_dir|
123
+ File.join(output_dir, input_file_dir, file_name)
124
+ end
125
+ else
126
+ if input_file_dir == ''
127
+ [file_name]
128
+ else
129
+ [File.join(input_file_dir, file_name)]
130
+ end
131
+ end
132
+ end
133
+
134
+ # Generate a file name based on the provided file path.
135
+ # Provide a logical extension.
136
+ #
137
+ # Examples:
138
+ # "path/foo.haml" -> "foo.html"
139
+ # "path/foo" -> "foo.html"
140
+ # "path/foo.bar" -> "foo.bar.html"
141
+ # "path/foo.bar.haml" -> "foo.bar"
142
+ #
143
+ # @param file String path to file
144
+ # @return String file name including extension
145
+ #
146
+ def _output_filename(file)
147
+ sub_strings = File.basename(file).split('.')
148
+ base_name, extensions = sub_strings.first, sub_strings[1..-1]
149
+ [base_name, extensions].flatten.join('.')
150
+ end
151
+ end
152
+
153
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ == I am title
2
+
3
+ generated by helper
4
+
5
+ My name is test
@@ -0,0 +1,5 @@
1
+ == I am title
2
+
3
+ generated by helper
4
+
5
+ My name is test3
@@ -0,0 +1,39 @@
1
+ require 'guard/asciidoctor/notifier'
2
+
3
+ RSpec.describe Guard::Asciidoctor::Notifier do
4
+ subject { described_class }
5
+
6
+ describe '#image' do
7
+ context 'when recieves true' do
8
+ # specify { expect(subject.image(true)).to be :success }
9
+ end
10
+
11
+ context 'when recieves false' do
12
+ # specify { expect(subject.image(false)).to be :failed }
13
+ end
14
+ end
15
+
16
+ describe '#notify' do
17
+ context 'when recieves true with message' do
18
+ it 'should call Guard::Notifier with success image' do
19
+ # expect(Guard::Compat::UI).to receive(:notify).with(
20
+ # 'Successful compilation!',
21
+ # title: 'Guard::Haml',
22
+ # image: :success
23
+ # )
24
+ # subject.notify(true, 'Successful compilation!')
25
+ end
26
+ end
27
+
28
+ context 'when recieves false with message' do
29
+ it 'should call Guard::Notifier with failed image' do
30
+ # expect(Guard::Compat::UI).to receive(:notify).with(
31
+ # 'Compilation failed!',
32
+ # title: 'Guard::Haml',
33
+ # image: :failed
34
+ # )
35
+ # subject.notify(false, 'Compilation failed!')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,280 @@
1
+ require 'guard/compat/test/helper'
2
+
3
+ require 'guard/asciidoctor'
4
+
5
+ RSpec.describe Guard::Asciidoctor do
6
+ let(:subject_with_options) { described_class.new(notifications: false, run_at_start: true) }
7
+ let(:subject_notifiable) { described_class.new(notifications: true) }
8
+ let(:subject_with_helper) { described_class.new(helper_modules: [TestingHelper]) }
9
+ let(:notifier) { Guard::Asciidoctor::Notifier }
10
+
11
+ before do
12
+ allow(Guard::Compat::UI).to receive(:info)
13
+ end
14
+
15
+ describe 'class' do
16
+ it 'should autoload Notifier class' do
17
+ expect { Guard::Asciidoctor::Notifier }.not_to raise_error
18
+ end
19
+ end
20
+
21
+ describe '#new' do
22
+ context 'notifications option by default' do
23
+ specify { expect(subject.options[:notifications]).to be_truthy }
24
+ end
25
+
26
+ context 'when receives options hash' do
27
+ it 'should merge it to @options instance variable' do
28
+ expect(subject_with_options.options[:notifications]).to be_falsey
29
+ expect(subject_with_options.options[:run_at_start]).to be_truthy
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#start' do
35
+ context 'by default' do
36
+ it 'should not call #run_all' do
37
+ expect(subject).not_to receive(:run_all)
38
+ subject.start
39
+ end
40
+ end
41
+
42
+ context 'when run_on_start option set to true' do
43
+ it 'should call #run_all' do
44
+ expect(subject_with_options).to receive(:run_all)
45
+ subject_with_options.start
46
+ end
47
+ end
48
+
49
+ context 'when run_on_start option set to false' do
50
+ before do
51
+ subject.options[:run_at_start] = false
52
+ end
53
+
54
+ it 'should not call #run_all' do
55
+ expect(subject).not_to receive(:run_all)
56
+ subject.start
57
+ end
58
+ end
59
+ end
60
+
61
+ describe '#stop' do
62
+ specify { expect(subject.stop).to be_truthy }
63
+ end
64
+
65
+ describe '#reload' do
66
+ it 'should call #run_all' do
67
+ expect(subject).to receive(:run_all).and_return(true)
68
+ subject.reload
69
+ end
70
+ end
71
+
72
+ describe '#run_all' do
73
+ it 'should rebuild all files being watched' do
74
+ expect(Guard::Compat).to receive(:matching_files).and_return([])
75
+ allow(subject).to receive(:run_on_changes).with([]).and_return([])
76
+ subject.run_all
77
+ end
78
+ end
79
+
80
+ describe '#_output_paths' do
81
+ context 'by default' do
82
+ it 'should return test/test/test.asciidoctor as [test/test/index.html]' do
83
+ expect(subject.send(:_output_paths, 'test/test/index.adoc')).to eq(['test/test/index.html'])
84
+ end
85
+
86
+ it 'should return test/test.sciidoctor as [test/index.htm]' do
87
+ expect(subject.send(:_output_paths, 'test/index.asciidoc')).to eq(['test/index.html'])
88
+ end
89
+
90
+ it 'should return test/test.adoc as [test/index.html]' do
91
+ expect(subject.send(:_output_paths, 'test/index.adoc'))
92
+ .to eq(['test/index.html'])
93
+ end
94
+ end
95
+
96
+ context 'when the output option is set to "demo/output"' do
97
+ before do
98
+ subject.options[:output] = 'demo/output'
99
+ end
100
+
101
+ it 'should return test/test.asciidoctor as [demo/output/test/index.html.Asciidoctor]' do
102
+ expect(subject.send(:_output_paths, 'test/index.adoc'))
103
+ .to eq(['demo/output/test/index.html'])
104
+ end
105
+ end
106
+
107
+ context 'when the output option is set to ["demo/output", "demo2/output"]' do
108
+ before do
109
+ subject.options[:output] = ['demo1/output', 'demo2/output']
110
+ end
111
+
112
+ it 'should return test/test.asciidoc as [demo1/output/test/index.html, demo2/output/test/index.html]' do
113
+ expect(subject.send(:_output_paths, 'test/index.adoc'))
114
+ .to eq(['demo1/output/test/index.html', 'demo2/output/test/index.html'])
115
+ end
116
+ end
117
+
118
+ # context 'when the default extensions is set to "txt"' do
119
+ # before do
120
+ # subject.options[:default_ext] = 'txt'
121
+ # end
122
+ #
123
+ # it 'should return test/test.asciidoc as test/index.txt' do
124
+ # expect(subject.send(:_output_paths, 'test/index.asciidoc'))
125
+ # .to eq(['test/index.txt'])
126
+ # end
127
+ #
128
+ # it 'should return test/test.adoc as test/index.txt' do
129
+ # expect(subject.send(:_output_paths, 'test/index.adoc'))
130
+ # .to eq(['test/index.txt'])
131
+ # end
132
+ # end
133
+
134
+ context 'when the exclude_base_dir option is set to "test/ignore"' do
135
+ before do
136
+ subject.options[:input] = 'test/ignore'
137
+ end
138
+
139
+ it 'should return test/ignore/test.asciidoctor as [index.html]' do
140
+ expect(subject.send(:_output_paths, 'test/ignore/index.adoc'))
141
+ .to eq(['index.html'])
142
+ end
143
+
144
+ context 'when the output option is set to "demo/output"' do
145
+ before do
146
+ subject.options[:output] = 'demo/output'
147
+ end
148
+
149
+ it 'should return test/ignore/abc/test.asciidoc as [demo/output/abc/index.html]' do
150
+ expect(subject.send(:_output_paths, 'test/ignore/abc/index.asciidoc'))
151
+ .to eq(['demo/output/abc/index.html'])
152
+ end
153
+ end
154
+ end
155
+
156
+ # context 'when the input file contains a second extension"' do
157
+ # it 'should return test/test.asciidoctor as [test/index.php]' do
158
+ # expect(subject.send(:_output_paths, 'test/index.php.Asciidoctor'))
159
+ # .to eq(['test/index.php'])
160
+ # end
161
+ # end
162
+ end
163
+
164
+ # describe '#_output_filename' do
165
+ # context 'by default (if a ".Asciidoctor" extension has been defined)' do
166
+ # it 'should return the file name with the default extension ".html"' do
167
+ # # expect(subject.send(:_output_filename, 'test/index.Asciidoctor'))
168
+ # # .to eq('index.html')
169
+ # end
170
+ # end
171
+ #
172
+ # context 'if no extension has been defined at all' do
173
+ # it 'should return the file name with the default extension ".html"' do
174
+ # # expect(subject.send(:_output_filename, 'test/index'))
175
+ # # .to eq('index.html')
176
+ # end
177
+ # end
178
+ #
179
+ # context 'if an extension other than ".Asciidoctor" has been defined' do
180
+ # it 'should return the file name with the default extension ".html"' do
181
+ # # expect(subject.send(:_output_filename, 'test/index.foo'))
182
+ # # .to eq('index.foo.html')
183
+ # end
184
+ # end
185
+ #
186
+ # context 'if multiple extensions including ".Asciidoctor" have been defined' do
187
+ # it 'should return the file name with the extension second to last' do
188
+ # # expect(subject.send(:_output_filename, 'test/index.foo.Asciidoctor'))
189
+ # # .to eq('index.foo')
190
+ # end
191
+ # end
192
+ # end
193
+
194
+ describe '#run_on_changes' do
195
+ context 'when notifications option set to true' do
196
+ let(:success_message) { "Successfully compiled asciidoc!\n" }
197
+
198
+ context 'with one output' do
199
+ after do
200
+ File.unlink "#{@fixture_path}/test.html"
201
+ end
202
+
203
+ # it 'should call Notifier.notify with 1 output' do
204
+ # message = success_message + '# spec/fixtures/test.asciidoc -> spec/fixtures/test.html'
205
+ # allow(Guard::Compat::UI).to receive(:info)
206
+ # expect(notifier).to receive(:notify).with(true, message)
207
+ # subject_notifiable.run_on_changes(["#{@fixture_path}/test.html"])
208
+ # end
209
+ end
210
+
211
+ it 'should call Notifier.notify' do
212
+ message = "Successfully compiled asciidoc!\n"
213
+ message += '# spec/fixtures/test.asciidoc -> spec/fixtures/test.html'
214
+ expect(notifier).to receive(:notify).with(true, message)
215
+ subject_notifiable.run_on_changes(["#{@fixture_path}/test.asciidoc"])
216
+ end
217
+
218
+ context 'with two outputs' do
219
+ before do
220
+ allow(subject_notifiable).to receive(:_output_paths).and_return(["#{@fixture_path}/test.html", "#{@fixture_path}/test2.html"])
221
+ end
222
+
223
+ after do
224
+ File.unlink "#{@fixture_path}/test.html"
225
+ File.unlink "#{@fixture_path}/test2.html"
226
+ end
227
+
228
+ it 'should call Notifier.notify with 2 outputs' do
229
+ message = success_message + '# spec/fixtures/test.asciidoc -> spec/fixtures/test.html, spec/fixtures/test2.html'
230
+ allow(Guard::Compat::UI).to receive(:info)
231
+ expect(notifier).to receive(:notify).with(true, message)
232
+ subject_notifiable.run_on_changes(["#{@fixture_path}/test.asciidoc"])
233
+ end
234
+ end
235
+
236
+ context 'with helper' do
237
+ before do
238
+ module TestingHelper
239
+ def output_from_helper; 'generated by helper'; end
240
+ end
241
+ end
242
+
243
+ after do
244
+ File.unlink "#{@fixture_path}/test3.html"
245
+ Object.send :remove_const, :TestingHelper
246
+ end
247
+
248
+ it 'should call Notifier.notify with 1 output' do
249
+ message = success_message + '# spec/fixtures/test3.asciidoc -> spec/fixtures/test3.html'
250
+ allow(Guard::Compat::UI).to receive(:error)
251
+ allow(Guard::Compat::UI).to receive(:info)
252
+ expect(notifier).to receive(:notify).with(true, message)
253
+ subject_with_helper.run_on_changes(["#{@fixture_path}/test3.asciidoc"])
254
+ expect(File.new("#{@fixture_path}/test3.html").read).to match(/generated by helper/)
255
+ end
256
+ end
257
+ end
258
+ end
259
+
260
+ describe '#compile_Asciidoctor' do
261
+ it 'throws :task_has_failed when an error occurs' do
262
+ allow(Guard::Compat::UI).to receive(:error)
263
+ allow(Guard::Compat::UI).to receive(:notify)
264
+ expect { subject.send(:compile_asciidoc, "#{@fixture_path}/fail_test.asciidoc") }
265
+ .to throw_symbol :task_has_failed
266
+ end
267
+
268
+ # context 'when notifications option set to true' do
269
+ # it 'should call Notifier.notify when an error occurs' do
270
+ # message = "Asciidoctor compilation of #{@fixture_path}/fail_test.asciidoctor failed!\n"
271
+ # message += "Error: Illegal nesting: content can't be both given on the same line as %p and nested within it."
272
+ # expect(notifier).to receive(:notify).with(false, message)
273
+ # allow(Guard::Compat::UI).to receive(:error)
274
+ # expect(catch(:task_has_failed) do
275
+ # subject_notifiable.send(:compile_Asciidoctor, "#{@fixture_path}/fail_test.asciidoctor")
276
+ # end.to be_nil
277
+ # end
278
+ # end
279
+ end
280
+ end
@@ -0,0 +1,34 @@
1
+ require 'bundler'
2
+ require 'rake/ext/pathname'
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec do |expectations|
8
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
+ end
10
+
11
+ config.mock_with :rspec do |mocks|
12
+ mocks.verify_partial_doubles = true
13
+ end
14
+
15
+ config.filter_run :focus
16
+ config.run_all_when_everything_filtered = true
17
+
18
+ config.disable_monkey_patching!
19
+
20
+ # config.warnings = true
21
+
22
+ config.default_formatter = 'doc' if config.files_to_run.one?
23
+
24
+ # config.profile_examples = 10
25
+
26
+ config.order = :random
27
+
28
+ Kernel.srand config.seed
29
+
30
+ config.before(:each) do
31
+ @fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__))
32
+ @lib_path = Pathname.new(File.expand_path('../../lib/', __FILE__))
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-asciidoctor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ma Lucheng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-compat
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: asciidoctor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: asciidoctor guard
98
+ email:
99
+ - mlc880926@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".ruby-gemset"
107
+ - ".ruby-version"
108
+ - Gemfile
109
+ - Guardfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - guard-asciidoctor.gemspec
114
+ - lib/guard/asciidoctor.rb
115
+ - lib/guard/asciidoctor/notifier.rb
116
+ - lib/guard/asciidoctor/templates/Guardfile
117
+ - lib/guard/asciidoctor/version.rb
118
+ - spec/fixtures/test.adoc
119
+ - spec/fixtures/test.asciidoc
120
+ - spec/fixtures/test3.asciidoc
121
+ - spec/guard/asciidoctor/notifier_spec.rb
122
+ - spec/guard/asciidoctor_spec.rb
123
+ - spec/spec_helper.rb
124
+ homepage: ''
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.4.5
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: asciidoctor guard
148
+ test_files:
149
+ - spec/fixtures/test.adoc
150
+ - spec/fixtures/test.asciidoc
151
+ - spec/fixtures/test3.asciidoc
152
+ - spec/guard/asciidoctor/notifier_spec.rb
153
+ - spec/guard/asciidoctor_spec.rb
154
+ - spec/spec_helper.rb
155
+ has_rdoc: