guard-helpers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/guard/helpers/formatter.rb +91 -0
- data/lib/guard/helpers/starter.rb +133 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzQwNWRjMGNlMGQ4Mjk1MDVkYjY1ZmNhMDcwNTg0MzZhNDE3NDEwZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzI2ZGE4NmMyZTA5YmE2Mzk2NTcwMzkzNTk3YTIxMDQ1MDc3MjQ1Nw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDFiODU3MWQ1MmRjZWM5OWVlMTAyNDRkYzg2NmQzYTc4MTg1OGQ3MjI1NmNk
|
10
|
+
MmRmZjc5ZmNkNmFjYWMyYWFiMWNlMjJiYTA2ODkxMmMyZGZlZjRkM2E5YTcy
|
11
|
+
MWI0YzJhZDRlYTI3NTM0OGY5YTVmYjMyZWJhMWZjZWU0Y2NmMWM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDJlYjI5MzkwNzk2OWYxMTc1MjE3MGZlNmVmYmVmYTdmMTgwNTNmYzAyZGEx
|
14
|
+
NzljNzVjNWM1M2I4ZmFhZTY4NTNjMmUzMmM5MjM2ODE5MmE2OGUyYWViMGJj
|
15
|
+
ZmE1MjU1MDg3YWFjMWU2Y2Y5ZTVhZmU4YTA0N2E0MGE2NWNmNjE=
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'guard/guard'
|
2
|
+
|
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
|
26
|
+
|
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
|
36
|
+
|
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
|
46
|
+
|
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
|
56
|
+
|
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
|
67
|
+
|
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
|
78
|
+
|
79
|
+
private
|
80
|
+
|
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
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# 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]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
directories
|
45
|
+
end
|
46
|
+
# End of copyrighted code
|
47
|
+
|
48
|
+
# The filename of the target file
|
49
|
+
def target_filename(directory, file)
|
50
|
+
File.join(directory, File.basename(file))
|
51
|
+
end
|
52
|
+
|
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
|
+
|
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
|
64
|
+
|
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
|
75
|
+
|
76
|
+
|
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
|
82
|
+
|
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
|
+
|
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
|
103
|
+
end
|
104
|
+
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
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
if written.length > 0
|
130
|
+
notify(written)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Joseph dumol
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ! 'Helper modules to make making Guard plugins easier '
|
14
|
+
email: tim@timdumol.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/guard/helpers/formatter.rb
|
20
|
+
- lib/guard/helpers/starter.rb
|
21
|
+
homepage: https://github.com/TimDumol/guard-helpers
|
22
|
+
licenses:
|
23
|
+
- Apache 2.0
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.0.3
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Helper modules to make making Guard plugins easier
|
45
|
+
test_files: []
|