guard-concat 0.0.2

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.
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ You can do wathever you want License and we suggest to open source your code!
data/Readme.md ADDED
@@ -0,0 +1,33 @@
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
+ guard :concat do
28
+ # This will concatenate the javascript files a.js and b.js in public/js to all.js
29
+ guard :concat, type: "js", files: %w(b a), input_dir: "public/js", output: "public/js/all"
30
+
31
+ guard :concat, type: "css", files: %w(c d), input_dir: "public/css", output: "public/css/all"
32
+ end
33
+ ```
@@ -0,0 +1,65 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'guard/watcher'
4
+
5
+ module Guard
6
+ class Concat < Guard
7
+
8
+ VERSION = '0.0.2'
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
+ # # Calls #run_all if the :all_on_start option is present.
21
+ # def start
22
+ # run_all if options[:all_on_start]
23
+ # end
24
+
25
+ # # Call #run_on_change for all files which match this guard.
26
+ # def run_all
27
+ # run_on_changes(Watcher.match_files(self, Dir.glob('{,**/}*{,.*}').uniq))
28
+ # end
29
+
30
+ def run_on_changes(paths)
31
+ concat
32
+ UI.info "Concatenated #{@output}"
33
+ end
34
+
35
+ def concat
36
+ content = ""
37
+ files = []
38
+ @opts[:files].each do |file|
39
+ files << "#{@opts[:input_dir]}/#{file}.#{@opts[:type]}"
40
+ end
41
+ files.each do |file|
42
+ content << File.read(file)
43
+ content << "\n"
44
+ end
45
+ File.open(@output, "w"){ |f| f.write content.strip }
46
+ end
47
+
48
+ # def self.concat_unix(match, dest)
49
+ # p `cat "#{match}" > #{dest}`
50
+ # end
51
+
52
+ end
53
+
54
+ class Dsl
55
+ # def concat(dest)
56
+ # p self
57
+ # watcher = self.instance_variable_get("@watchers").last
58
+ # src = watcher.pattern
59
+ # Concat.concat src, dest
60
+ # # Notifier.notify "Concat done in #{dest}"
61
+ # end
62
+ end
63
+ end
64
+
65
+ # Guard::Concat.concat %r{public/js/(?!c).+.js}, "public/js/c.js"
@@ -0,0 +1,6 @@
1
+ guard :concat do
2
+ # This will concatenate the javascript files specified in :files to public/js/all.js
3
+ guard :concat, type: "js", files: %w(), input_dir: "public/js", output: "public/js/all"
4
+
5
+ guard :concat, type: "css", files: %w(), input_dir: "public/css", output: "public/css/all"
6
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-concat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Francesco 'makevoid' Canessa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
30
+ description: ! ' Guard::Concat automatically concatenates files in one when watched
31
+ files are modified.
32
+
33
+ '
34
+ email: makevoid@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - Readme.md
40
+ - LICENSE
41
+ - lib/guard/concat.rb
42
+ - lib/guard/concat/templates/Guardfile
43
+ homepage: http://github.com/makevoid/guard-concat
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.24
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Guard gem for concatenating (js/css) files
67
+ test_files: []