guard-helpers 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzQwNWRjMGNlMGQ4Mjk1MDVkYjY1ZmNhMDcwNTg0MzZhNDE3NDEwZg==
4
+ ODVhMmIyOThjMDE5MGY0ZWVlMDNiMjhiMmE0NDE4OTBlMWQyYmU1Zg==
5
5
  data.tar.gz: !binary |-
6
- YzI2ZGE4NmMyZTA5YmE2Mzk2NTcwMzkzNTk3YTIxMDQ1MDc3MjQ1Nw==
6
+ YmY3N2MxYWM3N2E3OGY0ZmI4MWQ0YmQyZDE0NWZlOTkyMzRkMjU1Yw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDFiODU3MWQ1MmRjZWM5OWVlMTAyNDRkYzg2NmQzYTc4MTg1OGQ3MjI1NmNk
10
- MmRmZjc5ZmNkNmFjYWMyYWFiMWNlMjJiYTA2ODkxMmMyZGZlZjRkM2E5YTcy
11
- MWI0YzJhZDRlYTI3NTM0OGY5YTVmYjMyZWJhMWZjZWU0Y2NmMWM=
9
+ NzhiODg0YTBlZjUxY2Y2MjQ0MTBhNTc5ZjlmMzNhMTE2NTgxZmQ3MjdmYjA4
10
+ NDE4YTkxMGJkMjMyNzU4ODQzYmJkZmUzZjA1MDMzNDlhOWQ0NWM2MGI0ODBi
11
+ ZWRhMTY1Y2IwMThhMmE0OGE4ZmVjZDViMDUzYmY3ZDEyMTQxYWU=
12
12
  data.tar.gz: !binary |-
13
- ZDJlYjI5MzkwNzk2OWYxMTc1MjE3MGZlNmVmYmVmYTdmMTgwNTNmYzAyZGEx
14
- NzljNzVjNWM1M2I4ZmFhZTY4NTNjMmUzMmM5MjM2ODE5MmE2OGUyYWViMGJj
15
- ZmE1MjU1MDg3YWFjMWU2Y2Y5ZTVhZmU4YTA0N2E0MGE2NWNmNjE=
13
+ ZDlkZDgyM2I5OWUwNjgyMDMwN2MwNDAzOTZiMGI4MGU1YzVmMDVkYWY5OGU2
14
+ OWIxNWVmYTBlNjdhOWYzNmRhM2RjNzFiYTMzMTVlZWY2MWIwYzc5ODk5NDJk
15
+ MmQyYTBkNThiMmFiYWQ5MzhkYzA1MTFmZWM2ODQzZmY2NmFiMmM=
@@ -1,91 +1,96 @@
1
+ require 'guard'
1
2
  require 'guard/guard'
3
+ module ::Guard
4
+ module Helpers
5
+ module Formatter
6
+ class << self
7
+ # Copyright (c) 2010-2012 Michael Kessler
8
+ #
9
+ # Permission is hereby granted, free of charge, to any person obtaining
10
+ # a copy of this software and associated documentation files (the
11
+ # "Software"), to deal in the Software without restriction, including
12
+ # without limitation the rights to use, copy, modify, merge, publish,
13
+ # distribute, sublicense, and/or sell copies of the Software, and to
14
+ # permit persons to whom the Software is furnished to do so, subject to
15
+ # the following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be
18
+ # included in all copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ # Collects console and system notification methods and enhances them with
28
+ # some color information.
2
29
 
3
- # Copyright (c) 2010-2012 Michael Kessler
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.
23
- # Collects console and system notification methods and enhances them with
24
- # some color information.
25
- module ::Guard::Helpers::Formatter class << self
30
+ # Print an info message to the console.
31
+ #
32
+ # @param [String] message the message to print
33
+ # @param [Hash] options the output options
34
+ # @option options [Boolean] :reset reset the UI
35
+ #
36
+ def info(message, options = { })
37
+ ::Guard::UI.info(message, options)
38
+ end
26
39
 
27
- # Print an info message to the console.
28
- #
29
- # @param [String] message the message to print
30
- # @param [Hash] options the output options
31
- # @option options [Boolean] :reset reset the UI
32
- #
33
- def info(message, options = { })
34
- ::Guard::UI.info(message, options)
35
- end
40
+ # Print a debug message to the console.
41
+ #
42
+ # @param [String] message the message to print
43
+ # @param [Hash] options the output options
44
+ # @option options [Boolean] :reset reset the UI
45
+ #
46
+ def debug(message, options = { })
47
+ ::Guard::UI.debug(message, options)
48
+ end
36
49
 
37
- # Print a debug message to the console.
38
- #
39
- # @param [String] message the message to print
40
- # @param [Hash] options the output options
41
- # @option options [Boolean] :reset reset the UI
42
- #
43
- def debug(message, options = { })
44
- ::Guard::UI.debug(message, options)
45
- end
50
+ # Print a red error message to the console.
51
+ #
52
+ # @param [String] message the message to print
53
+ # @param [Hash] options the output options
54
+ # @option options [Boolean] :reset reset the UI
55
+ #
56
+ def error(message, options = { })
57
+ ::Guard::UI.error(color(message, ';31'), options)
58
+ end
46
59
 
47
- # Print a red error message to the console.
48
- #
49
- # @param [String] message the message to print
50
- # @param [Hash] options the output options
51
- # @option options [Boolean] :reset reset the UI
52
- #
53
- def error(message, options = { })
54
- ::Guard::UI.error(color(message, ';31'), options)
55
- end
60
+ # Print a green success message to the console.
61
+ #
62
+ # @param [String] message the message to print
63
+ # @param [Hash] options the output options
64
+ # @option options [Boolean] :reset reset the UI
65
+ #
66
+ def success(message, options = { })
67
+ stamped_message = "#{Time.now.strftime('%r')} #{message}"
68
+ ::Guard::UI.info(color(stamped_message, ';32'), options)
69
+ end
56
70
 
57
- # Print a green success message to the console.
58
- #
59
- # @param [String] message the message to print
60
- # @param [Hash] options the output options
61
- # @option options [Boolean] :reset reset the UI
62
- #
63
- def success(message, options = { })
64
- stamped_message = "#{Time.now.strftime('%r')} #{message}"
65
- ::Guard::UI.info(color(stamped_message, ';32'), options)
66
- end
71
+ # Outputs a system notification.
72
+ #
73
+ # @param [String] message the message to print
74
+ # @param [Hash] options the output options
75
+ # @option options [Symbol, String] :image the image to use, either :failed, :pending or :success, or an image path
76
+ # @option options [String] :title the title of the system notification
77
+ #
78
+ def notify(message, options = { })
79
+ ::Guard::Notifier.notify(message, options)
80
+ end
67
81
 
68
- # Outputs a system notification.
69
- #
70
- # @param [String] message the message to print
71
- # @param [Hash] options the output options
72
- # @option options [Symbol, String] :image the image to use, either :failed, :pending or :success, or an image path
73
- # @option options [String] :title the title of the system notification
74
- #
75
- def notify(message, options = { })
76
- ::Guard::Notifier.notify(message, options)
77
- end
82
+ private
78
83
 
79
- private
84
+ # Print a info message to the console.
85
+ #
86
+ # @param [String] text the text to colorize
87
+ # @param [String] color_code the color code
88
+ #
89
+ def color(text, color_code)
90
+ ::Guard::UI.send(:color_enabled?) ? "\e[0#{ color_code }m#{ text }\e[0m" : text
91
+ end
80
92
 
81
- # Print a info message to the console.
82
- #
83
- # @param [String] text the text to colorize
84
- # @param [String] color_code the color code
85
- #
86
- def color(text, color_code)
87
- ::Guard::UI.send(:color_enabled?) ? "\e[0#{ color_code }m#{ text }\e[0m" : text
93
+ end
94
+ end
88
95
  end
89
-
90
96
  end
91
- end
@@ -1,133 +1,144 @@
1
+ require 'guard/guard'
2
+ require 'guard/helpers/formatter'
1
3
  # Starter code that can be included into a Guard plugin
2
- module ::Guard::Helpers::Starter
3
-
4
- ## Helper methods
5
-
6
- # Copyright (c) 2010-2012 Michael Kessler
7
- #
8
- # Permission is hereby granted, free of charge, to any person obtaining
9
- # a copy of this software and associated documentation files (the
10
- # "Software"), to deal in the Software without restriction, including
11
- # without limitation the rights to use, copy, modify, merge, publish,
12
- # distribute, sublicense, and/or sell copies of the Software, and to
13
- # permit persons to whom the Software is furnished to do so, subject to
14
- # the following conditions:
15
- #
16
- # The above copyright notice and this permission notice shall be
17
- # included in all copies or substantial portions of the Software.
18
- # Detects the output directory for each CoffeeScript file. Builds
19
- # the product of all watchers and assigns to each directory
20
- # the files to which it belongs to.
21
- #
22
- # @param [Array<Guard::Watcher>] watchers the Guard watchers in the block
23
- # @param [Array<String>] files the CoffeeScript files
24
- # @param [Hash] options the options for the execution
25
- # @option options [String] :output the output directory
26
- # @option options [Boolean] :shallow do not create nested directories
27
- #
28
- def detect_nested_directories(watchers, files, options)
29
- return { options[:output] => files } if options[:shallow]
30
-
31
- directories = { }
32
-
33
- watchers.product(files).each do |watcher, file|
34
- if matches = file.match(watcher.pattern)
35
- target = matches[1] ? File.join(options[:output], File.dirname(matches[1])).gsub(/\/\.$/, '') : options[:output] || File.dirname(file)
36
- if directories[target]
37
- directories[target] << file
38
- else
39
- directories[target] = [file]
4
+ module ::Guard
5
+ module Helpers
6
+ module Starter
7
+
8
+ ## Helper methods
9
+
10
+ # Copyright (c) 2010-2012 Michael Kessler
11
+ #
12
+ # Permission is hereby granted, free of charge, to any person obtaining
13
+ # a copy of this software and associated documentation files (the
14
+ # "Software"), to deal in the Software without restriction, including
15
+ # without limitation the rights to use, copy, modify, merge, publish,
16
+ # distribute, sublicense, and/or sell copies of the Software, and to
17
+ # permit persons to whom the Software is furnished to do so, subject to
18
+ # the following conditions:
19
+ #
20
+ # The above copyright notice and this permission notice shall be
21
+ # included in all copies or substantial portions of the Software.
22
+ # Detects the output directory for each CoffeeScript file. Builds
23
+ # the product of all watchers and assigns to each directory
24
+ # the files to which it belongs to.
25
+ #
26
+ # @param [Array<Guard::Watcher>] watchers the Guard watchers in the block
27
+ # @param [Array<String>] files the CoffeeScript files
28
+ # @param [Hash] options the options for the execution
29
+ # @option options [String] :output the output directory
30
+ # @option options [Boolean] :shallow do not create nested directories
31
+ #
32
+ def detect_nested_directories(watchers, files, options)
33
+ return { options[:output] => files } if options[:shallow]
34
+
35
+ directories = { }
36
+
37
+ watchers.product(files).each do |watcher, file|
38
+ if matches = file.match(watcher.pattern)
39
+ target = matches[1] ? File.join(options[:output], File.dirname(matches[1])).gsub(/\/\.$/, '') : options[:output] || File.dirname(file)
40
+ if directories[target]
41
+ directories[target] << file
42
+ else
43
+ directories[target] = [file]
44
+ end
45
+ end
40
46
  end
41
- end
42
- end
43
47
 
44
- directories
45
- end
46
- # End of copyrighted code
48
+ directories
49
+ end
50
+ # End of copyrighted code
47
51
 
48
- # The filename of the target file
49
- def target_filename(directory, file)
50
- File.join(directory, File.basename(file))
51
- end
52
+ # The filename of the target file
53
+ def target_filename(directory, file)
54
+ File.join(directory, File.basename(file))
55
+ end
52
56
 
53
- # The action to be performed on a file (e.g., compilation)
54
- def act_on(directory, file)
55
- raise NotImplementedError.new('act_on not implemented')
56
- end
57
+ # The action to be performed on a file (e.g., compilation)
58
+ def act_on(directory, file)
59
+ raise NotImplementedError.new('act_on not implemented')
60
+ end
57
61
 
58
- # Informs the user of an error
59
- def error(message, path)
60
- message = "#{self.class.name} ERROR: #{path} with error '#{message}'"
61
- Formatter.error message
62
- Formatter.notify message, :image => :failed
63
- end
62
+ # Informs the user of an error
63
+ def error(message, path)
64
+ message = "#{self.class.name} ERROR: #{path} with error '#{message}'"
65
+ ::Guard::Helpers::Formatter.error message
66
+ ::Guard::Helpers::Formatter.notify message, :image => :failed
67
+ end
64
68
 
65
- # Informs the user that an action has succeeded.
66
- def notify(path, action="COMPILED")
67
- message = if paths.length <= 8
68
- "#{self.class.name} #{action}: #{paths.join(', ')}"
69
- else
70
- "#{self.class.name} #{action}: #{paths[0..7].join(', ')}, and others."
71
- end
72
- Formatter.success message
73
- Formatter.notify message, :image => :success
74
- end
69
+ # Informs the user that an action has succeeded.
70
+ def notify(paths, action="COMPILED")
71
+ message = if paths.length <= 8
72
+ "#{self.class.name} #{action}: #{paths.join(', ')}"
73
+ else
74
+ "#{self.class.name} #{action}: #{paths[0..7].join(', ')}, and others."
75
+ end
76
+ ::Guard::Helpers::Formatter.success message
77
+ ::Guard::Helpers::Formatter.notify message, :image => :success
78
+ end
75
79
 
76
80
 
77
- ## Defaults
78
- # Calls #run_all if the :all_on_start option is present.
79
- def start
80
- run_all if options[:all_on_start]
81
- end
81
+ ## Defaults
82
+ # Calls #run_all if the :all_on_start option is present.
83
+ def start
84
+ run_all if options[:all_on_start]
85
+ end
82
86
 
83
- # Call #run_on_change for all files which match this guard.
84
- def run_all
85
- run_on_changes(Watcher.match_files(self, Dir.glob('**{,/*/**}/*').uniq.compact))
86
- end
87
+ # Call #run_on_change for all files which match this guard.
88
+ def run_all
89
+ run_on_changes(Watcher.match_files(self, Dir.glob('**{,/*/**}/*').uniq.compact))
90
+ end
87
91
 
88
- # The default action when a path is removed is to remove the matching
89
- # compiled file
90
- def run_on_removals(paths)
91
- paths = paths.select {|path| not options[:exclude] =~ path and File.file? path}
92
-
93
- directories = detect_nested_directories(watchers, paths, options)
94
- removed = []
95
-
96
- directories.each do |directory, files|
97
- files.each do |file|
98
- begin
99
- File.delete file
100
- removed << file
101
- rescue Error::ENOENT
102
- # Ignore
92
+ # The default action when a path is removed is to remove the matching
93
+ # compiled file
94
+ def run_on_removals(paths)
95
+ paths = paths.select {|path| not options[:exclude] =~ path and File.file? path}
96
+
97
+ directories = detect_nested_directories(watchers, paths, options)
98
+ removed = []
99
+
100
+ directories.each do |directory, files|
101
+ files.each do |file|
102
+ begin
103
+ File.delete file
104
+ removed << file
105
+ rescue Error::ENOENT
106
+ # Ignore
107
+ end
108
+ end
109
+ end
110
+ if removed.length > 0
111
+ notify(removed, "REMOVED")
103
112
  end
104
113
  end
105
- end
106
- if removed.length > 0
107
- notify(removed, "REMOVED")
108
- end
109
- end
110
-
111
- # Run `act_on` on each file that is watched
112
- def run_on_changes(paths)
113
- paths = paths.select {|path| not options[:exclude] =~ path and File.file? path}
114
-
115
- directories = detect_nested_directories(watchers, paths, options)
116
- written = []
117
-
118
- directories.each do |directory, files|
119
- files.each do |file|
120
- begin
121
- act_on(directory, file)
122
- written << file
123
- rescue Exception => e
124
- error(e.message, file)
125
- throw :task_has_failed
114
+
115
+ # Run `act_on` on each file that is watched
116
+ def run_on_changes(paths)
117
+ if options[:all_on_change]
118
+ paths = Watcher.match_files(self, Dir.glob('**{,/*/**}/*').uniq.compact)
119
+ end
120
+ paths = paths.select {|path| not options[:exclude] =~ path and File.file? path}
121
+
122
+ directories = detect_nested_directories(watchers, paths, options)
123
+ written = []
124
+
125
+ directories.each do |directory, files|
126
+ files.each do |file|
127
+ begin
128
+ act_on(directory, file)
129
+ puts 'Wrote!'
130
+ written << file
131
+ rescue Exception => e
132
+ puts 'Error!'
133
+ error(e.message, file)
134
+ throw :task_has_failed
135
+ end
136
+ end
137
+ end
138
+ if written.length > 0
139
+ notify(written)
126
140
  end
127
141
  end
128
142
  end
129
- if written.length > 0
130
- notify(written)
131
- end
132
143
  end
133
144
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Joseph dumol