guard-concatfilter 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ You can do wathever you want License and we suggest to open source your code!
@@ -0,0 +1,52 @@
1
+ # Guard::Concat
2
+
3
+ This little guard allows you to concatenate js/css (or other) files in one.
4
+
5
+
6
+ ## Install
7
+
8
+ Make sure you have [guard](http://github.com/guard/guard) installed.
9
+
10
+ Install the gem with:
11
+
12
+ gem install guard-concat
13
+
14
+ Or add it to your Gemfile:
15
+
16
+ gem 'guard-concat'
17
+
18
+ And then add a basic setup to your Guardfile:
19
+
20
+ guard init concat
21
+
22
+
23
+ ## Usage
24
+
25
+
26
+ ``` ruby
27
+ # This will concatenate the javascript files a.js and b.js in public/js to all.js
28
+ guard :concat, type: "js", files: %w(b a), input_dir: "public/js", output: "public/js/all"
29
+
30
+ # analog css example
31
+ guard :concat, type: "css", files: %w(c d), input_dir: "public/css", output: "public/css/all"
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
+
51
+ - 0.0.4 - add star (*) support to load multiple files
52
+ - 0.0.3 - basic version
@@ -0,0 +1,82 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'guard/watcher'
4
+
5
+ module Guard
6
+ class ConcatFilter < Guard
7
+
8
+ VERSION = '0.0.6'
9
+
10
+ def initialize(watchers=[], opts={})
11
+ @output = "#{opts[:output]}.#{opts[:type]}"
12
+ files = opts[:files].join("|")
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
18
+ end
19
+
20
+ def run_on_changes(paths)
21
+ concat
22
+ end
23
+
24
+ # The actual concat method
25
+ #
26
+ # scans the :files passed as options
27
+ # supports * and expands them requiring all files in that path/folder
28
+
29
+ def concat
30
+ content = ""
31
+ files = []
32
+ @opts[:files].each do |file|
33
+ files += if single? file
34
+ ["#{@opts[:input_dir]}/#{file}.#{@opts[:type]}"]
35
+ else
36
+ expand file
37
+ end
38
+ end
39
+ files.each do |file|
40
+ content << File.read(file)
41
+ content << "\n"
42
+ end
43
+
44
+ if @opts[:outputs]
45
+ @opts[:outputs].each do |name|
46
+ output = "#{name}.#{@opts[:type]}"
47
+ local = content
48
+ local = @opts[:filter].call(output, local) if @opts[:filter]
49
+ File.open(output, "w"){ |f| f.write local.strip }
50
+ UI.info "Concatenated #{output}"
51
+ end
52
+ else
53
+ content = @opts[:filter].call(@output, content) if @opts[:filter]
54
+ File.open(@output, "w"){ |f| f.write content.strip }
55
+ UI.info "Concatenated #{@output}"
56
+ end
57
+ end
58
+
59
+ def input_dir
60
+ @opts[:input_dir]
61
+ end
62
+
63
+ def type
64
+ @opts[:type]
65
+ end
66
+
67
+
68
+ private
69
+
70
+ # handle the star option (*)
71
+
72
+ def single?(file)
73
+ file !~ /\*/
74
+ end
75
+
76
+ def expand(file)
77
+ path = "#{input_dir}/#{file}.#{type}"
78
+ Dir.glob path
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,4 @@
1
+ # This will concatenate the javascript files specified in :files to public/js/all.js
2
+ guard :concatfilter, type: "js", files: %w(), input_dir: "public/js", output: "public/js/all"
3
+
4
+ guard :concatfilter, type: "css", files: %w(), input_dir: "public/css", output: "public/css/all"
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-concatfilter
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 6
10
+ version: 0.0.6
11
+ platform: ruby
12
+ authors:
13
+ - Geoff Youngs
14
+ - Francesco 'makevoid' Canessa
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2013-12-20 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: guard
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 1
32
+ - 1
33
+ - 0
34
+ version: 1.1.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: " Guard::ConcatFilter automatically concatenates files in one when watched files are modified.\n"
38
+ email: github@intersect-uk.co.uk
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - Readme.md
47
+ - LICENSE
48
+ - lib/guard/concatfilter.rb
49
+ - lib/guard/concatfilter/templates/Guardfile
50
+ homepage: http://github.com/geoffyoungs/guard-concat
51
+ licenses:
52
+ - Unspecified
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.15
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Guard gem for concatenating (js/css) files
83
+ test_files: []
84
+
85
+ has_rdoc: