guard-handlebars 0.0.1
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/Gemfile +4 -0
- data/LICENSE +19 -0
- data/README.md +18 -0
- data/lib/guard/handlebars/templates/Guardfile +3 -0
- data/lib/guard/handlebars/version.rb +5 -0
- data/lib/guard/handlebars.rb +67 -0
- metadata +73 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2012 by Chris Homer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Guard::Handlebars
|
2
|
+
|
3
|
+
## Install
|
4
|
+
|
5
|
+
As the gem name suggests this is a guard extension. Make sure you get [guard](https://github.com/guard/guard) first.
|
6
|
+
|
7
|
+
Install the gem:
|
8
|
+
|
9
|
+
gem install guard-handlebars
|
10
|
+
|
11
|
+
Add it to your Gemfile if you're using bundler (you should)
|
12
|
+
|
13
|
+
gem 'guard-handlebars'
|
14
|
+
|
15
|
+
Add a basic guard setup:
|
16
|
+
|
17
|
+
guard init handlebars
|
18
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'guard/watcher'
|
4
|
+
|
5
|
+
module Guard
|
6
|
+
class Handlebars < Guard
|
7
|
+
|
8
|
+
def initialize(watchers = [], options = {})
|
9
|
+
@options = {
|
10
|
+
:notifications => true
|
11
|
+
}.merge(options)
|
12
|
+
super(watchers, @options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def compile_handlebars file
|
16
|
+
content = File.new(file).read
|
17
|
+
begin
|
18
|
+
`handlebars #{file} -f #{get_output(file)}`
|
19
|
+
rescue StandardError => error
|
20
|
+
puts "ERROR COMPILING #{file}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get the file path to output the js based on the file being
|
25
|
+
# built. The output path is relative to where guard is being run.
|
26
|
+
#
|
27
|
+
# @param file [String] path to file being built
|
28
|
+
# @return [String] path to file where output should be written
|
29
|
+
#
|
30
|
+
def get_output(file)
|
31
|
+
file_dir = File.dirname(file)
|
32
|
+
file_name = File.basename(file).split('.')[0..-2].join('.')
|
33
|
+
|
34
|
+
file_dir = file_dir.gsub(Regexp.new("#{@options[:input]}(\/){0,1}"), '') if @options[:input]
|
35
|
+
file_dir = File.join(@options[:output], file_dir) if @options[:output]
|
36
|
+
|
37
|
+
if file_dir == ''
|
38
|
+
file_name
|
39
|
+
else
|
40
|
+
File.join(file_dir, file_name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def run_all
|
45
|
+
run_on_change(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
|
46
|
+
end
|
47
|
+
|
48
|
+
def run_on_change(paths)
|
49
|
+
paths.each do |file|
|
50
|
+
output_file = get_output(file)
|
51
|
+
FileUtils.mkdir_p File.dirname(output_file)
|
52
|
+
File.open(output_file, 'w') { |f| f.write(compile_handlebars(file)) }
|
53
|
+
::Guard::UI.info "# compiled handlebars in '#{file}' to js in '#{output_file}'"
|
54
|
+
::Guard::Notifier.notify("# compiled handlebars in #{file}", :title => "Guard::Handlebars", :image => :success) if @options[:notifications]
|
55
|
+
end
|
56
|
+
notify paths
|
57
|
+
end
|
58
|
+
|
59
|
+
def notify(changed_files)
|
60
|
+
::Guard.guards.reject{ |guard| guard == self }.each do |guard|
|
61
|
+
paths = Watcher.match_files(guard, changed_files)
|
62
|
+
guard.run_on_change paths unless paths.empty?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-handlebars
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Homer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-30 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: guard
|
16
|
+
requirement: &70357579103560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.4'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70357579103560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70357579103140 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70357579103140
|
36
|
+
description: Compiles file.handlebars into file.js
|
37
|
+
email:
|
38
|
+
- chris@thredup.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- lib/guard/handlebars/templates/Guardfile
|
44
|
+
- lib/guard/handlebars/version.rb
|
45
|
+
- lib/guard/handlebars.rb
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Gemfile
|
49
|
+
homepage: http://labs.thredup.com
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project: guard-handlebars
|
69
|
+
rubygems_version: 1.8.10
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Guard gem for Handlebars precompiled js files
|
73
|
+
test_files: []
|