guard-concat 0.0.3 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Readme.md +27 -1
- data/lib/guard/concat.rb +83 -27
- data/lib/guard/concat/templates/Guardfile +3 -0
- data/lib/guard/concat/version.rb +5 -0
- metadata +16 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aab079ba7fa104c1eb4b72240de8ba89ba54de77
|
4
|
+
data.tar.gz: 3fe2f2958b10bb0d50412b5276450c97f85f2d8f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 19a5e0b8260075458c866495623cabff8b7d65a302e58b14f20ff6c3c91536517d0fa5dfed2206d4e9e6ec909a1d3e9f800bb90b4d98788a777f5883f1b030a2
|
7
|
+
data.tar.gz: 86a962b27c8b7b65ef2361d0565d605485dd23539c455d53ebcc6c91165a0617d40860894914e672b7925ddee4879d29fd1444db074681827b95c770a90e27df
|
data/Readme.md
CHANGED
@@ -29,4 +29,30 @@ guard :concat, type: "js", files: %w(b a), input_dir: "public/js", output: "publ
|
|
29
29
|
|
30
30
|
# analog css example
|
31
31
|
guard :concat, type: "css", files: %w(c d), input_dir: "public/css", output: "public/css/all"
|
32
|
-
|
32
|
+
|
33
|
+
# js example with *
|
34
|
+
|
35
|
+
guard :concat, type: "js", files: %w(vendor/* b a), input_dir: "public/js", output: "public/js/all"
|
36
|
+
# will concatenate all files in the vendor dir, then b then a (watch out of dependencies)
|
37
|
+
```
|
38
|
+
|
39
|
+
Advanced usage:
|
40
|
+
|
41
|
+
``` ruby
|
42
|
+
# this is a recommended file structure when using *
|
43
|
+
# plugins usually need libraries so put libraries like jquery in the libs directory, then your jquery (or another library) plugin(s) in the plugins dir and at the end your main file(s)
|
44
|
+
guard :concat, type: "js", files: %w(libs/* plugins/* main), input_dir: "public/js", output: "public/js/all"
|
45
|
+
```
|
46
|
+
|
47
|
+
it's not possible to use * or ./* alone, you have to use * after a directory name, like this: `dir/*`
|
48
|
+
|
49
|
+
## Versions changelog
|
50
|
+
- 0.8.1 - add guard runtime dependency correctly (with ~>)
|
51
|
+
- 0.8.0 - add debug messages, add support for newer guard, add all_on_start option [yanked from rubygems]
|
52
|
+
- 0.0.4 - add star (*) support to load multiple files
|
53
|
+
- 0.0.3 - basic version
|
54
|
+
|
55
|
+
## Contributors
|
56
|
+
|
57
|
+
- [@ezekg](https://github.com/ezekg)
|
58
|
+
- [@mikz](https://github.com/mikz)
|
data/lib/guard/concat.rb
CHANGED
@@ -1,48 +1,104 @@
|
|
1
1
|
require 'guard'
|
2
|
-
require 'guard/
|
2
|
+
require 'guard/plugin'
|
3
3
|
require 'guard/watcher'
|
4
4
|
|
5
5
|
module Guard
|
6
|
-
class Concat <
|
6
|
+
class Concat < Plugin
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
regex = %r{^#{opts[:input_dir]}/(#{files})\.#{opts[:type]}$}
|
14
|
-
watcher = ::Guard::Watcher.new regex
|
15
|
-
watchers << watcher
|
16
|
-
@watchers, @opts = watchers, opts
|
17
|
-
super watchers, opts
|
8
|
+
def initialize(opts={})
|
9
|
+
@opts = opts
|
10
|
+
opts[:watchers] = [] unless opts[:watchers]
|
11
|
+
opts[:watchers] << ::Guard::Watcher.new(matcher_regex)
|
12
|
+
super(opts)
|
18
13
|
end
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
# end
|
15
|
+
def start
|
16
|
+
run_all if all_on_start?
|
17
|
+
end
|
24
18
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
# end
|
19
|
+
def run_all
|
20
|
+
concat
|
21
|
+
end
|
29
22
|
|
30
23
|
def run_on_changes(paths)
|
31
24
|
concat
|
32
|
-
UI.info "Concatenated #{@output}"
|
33
25
|
end
|
34
26
|
|
27
|
+
# The actual concat method
|
28
|
+
#
|
29
|
+
# scans the :files passed as options
|
30
|
+
# supports * and expands them requiring all files in that path/folder
|
31
|
+
|
35
32
|
def concat
|
36
|
-
|
37
|
-
|
38
|
-
@opts[:files].each do |file|
|
39
|
-
files << "#{@opts[:input_dir]}/#{file}.#{@opts[:type]}"
|
33
|
+
file_names = files.map do |file|
|
34
|
+
single?(file) ? full_path(file) : expand(file)
|
40
35
|
end
|
41
|
-
|
36
|
+
|
37
|
+
content = file_names.flatten.reduce("") do |content, file|
|
42
38
|
content << File.read(file)
|
43
39
|
content << "\n"
|
44
40
|
end
|
45
|
-
|
41
|
+
|
42
|
+
if writes content
|
43
|
+
if @opts[:verbose]
|
44
|
+
UI.info "concat: #{file_names.join(', ')} to #{output_file}"
|
45
|
+
else
|
46
|
+
UI.info "concat: #{output_file}"
|
47
|
+
end
|
48
|
+
else
|
49
|
+
if @opts[:verbose]
|
50
|
+
UI.error "concat: error: #{file_names.join(', ')} to #{output_file} - message: Error, "
|
51
|
+
else
|
52
|
+
UI.error "concat: Error concatenating files to #{output_file}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def full_path(file)
|
58
|
+
path = "#{input_dir}/#{file}"
|
59
|
+
path << ".#{type}" unless path =~ /\.#{type}$/
|
60
|
+
path
|
61
|
+
end
|
62
|
+
|
63
|
+
def matcher_regex
|
64
|
+
all_files = files.map{|f| f.sub(/\*$/, '.+') }.join("|")
|
65
|
+
%r|^#{input_dir}/(#{all_files})\.#{type}$|
|
66
|
+
end
|
67
|
+
|
68
|
+
def files
|
69
|
+
@opts.fetch(:files)
|
70
|
+
end
|
71
|
+
|
72
|
+
def input_dir
|
73
|
+
@opts.fetch(:input_dir)
|
74
|
+
end
|
75
|
+
|
76
|
+
def type
|
77
|
+
@opts.fetch(:type)
|
78
|
+
end
|
79
|
+
|
80
|
+
def output_file
|
81
|
+
@output_file ||= "#{@opts.fetch(:output)}.#{type}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def all_on_start?
|
85
|
+
!!@opts[:all_on_start]
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def writes(content)
|
91
|
+
File.open(output_file, "w"){ |f| f.write content.strip }
|
92
|
+
end
|
93
|
+
|
94
|
+
# handle the star option (*)
|
95
|
+
|
96
|
+
def single?(file)
|
97
|
+
file !~ /\*/
|
98
|
+
end
|
99
|
+
|
100
|
+
def expand(file)
|
101
|
+
Dir.glob full_path(file)
|
46
102
|
end
|
47
103
|
|
48
104
|
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
# This will concatenate the javascript files specified in :files to public/js/all.js
|
2
|
+
#
|
3
|
+
# Specifying every single file in the array like %w(a b c) to maintain the loading order is suggested - See https://github.com/makevoid/guard-concat for more info
|
4
|
+
#
|
2
5
|
guard :concat, type: "js", files: %w(), input_dir: "public/js", output: "public/js/all"
|
3
6
|
|
4
7
|
guard :concat, type: "css", files: %w(), input_dir: "public/css", output: "public/css/all"
|
metadata
CHANGED
@@ -1,67 +1,62 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-concat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.8.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Francesco 'makevoid' Canessa
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: guard
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: '2.0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
description:
|
31
|
-
|
32
|
-
|
33
|
-
'
|
26
|
+
version: '2.0'
|
27
|
+
description: |2
|
28
|
+
Guard::Concat automatically concatenates files in one when watched files are modified.
|
34
29
|
email: makevoid@gmail.com
|
35
30
|
executables: []
|
36
31
|
extensions: []
|
37
32
|
extra_rdoc_files: []
|
38
33
|
files:
|
39
|
-
- Readme.md
|
40
34
|
- LICENSE
|
41
|
-
-
|
35
|
+
- Readme.md
|
42
36
|
- lib/guard/concat.rb
|
37
|
+
- lib/guard/concat/templates/Guardfile
|
38
|
+
- lib/guard/concat/version.rb
|
43
39
|
homepage: http://github.com/makevoid/guard-concat
|
44
40
|
licenses: []
|
41
|
+
metadata: {}
|
45
42
|
post_install_message:
|
46
43
|
rdoc_options: []
|
47
44
|
require_paths:
|
48
45
|
- lib
|
49
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
47
|
requirements:
|
52
|
-
- -
|
48
|
+
- - ">="
|
53
49
|
- !ruby/object:Gem::Version
|
54
50
|
version: '0'
|
55
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
52
|
requirements:
|
58
|
-
- -
|
53
|
+
- - ">="
|
59
54
|
- !ruby/object:Gem::Version
|
60
55
|
version: '0'
|
61
56
|
requirements: []
|
62
57
|
rubyforge_project:
|
63
|
-
rubygems_version:
|
58
|
+
rubygems_version: 2.2.2
|
64
59
|
signing_key:
|
65
|
-
specification_version:
|
60
|
+
specification_version: 4
|
66
61
|
summary: Guard gem for concatenating (js/css) files
|
67
62
|
test_files: []
|