guard-haml 0.2.0 → 0.3.0
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/README.md +18 -1
- data/lib/guard/haml.rb +27 -15
- data/lib/guard/haml/version.rb +5 -0
- data/spec/guard/haml_spec.rb +64 -0
- data/spec/spec_helper.rb +14 -0
- metadata +37 -18
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Guard yo Haml, guard yo html cuz they compilin errybody out here.
|
|
4
4
|
|
5
5
|
## Install
|
6
6
|
|
7
|
-
As the gem name suggests this is a guard extension. Make sure you get [guard](
|
7
|
+
As the gem name suggests this is a guard extension. Make sure you get [guard](https://github.com/guard/guard) first.
|
8
8
|
|
9
9
|
Install the gem:
|
10
10
|
|
@@ -28,3 +28,20 @@ Guardfile, e.g.:
|
|
28
28
|
end
|
29
29
|
|
30
30
|
This output is relative to the Guardfile.
|
31
|
+
|
32
|
+
If you maintain your haml files in a directory that should not be part of the output path, you can set the `input` option, e.g.:
|
33
|
+
|
34
|
+
guard 'haml', :output => 'public', :input => 'src' do
|
35
|
+
watch %r{^src/.+(\.html\.haml)}
|
36
|
+
end
|
37
|
+
|
38
|
+
So when you edit a file `src/partials/_partial.html.haml`
|
39
|
+
it will be outputted in `public/partials/_partial.html` without the `src`.
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
* Source is hosted on [Github: guard-haml](https://github.com/manufaktor/guard-haml)
|
44
|
+
* Report issues/questions/feature requests on the [Github Issue tracker for guard-haml](https://github.com/manufaktor/guard-haml/issues)
|
45
|
+
|
46
|
+
Pull requests are welcome.
|
47
|
+
Specs are very welcome, make sure you support both ruby 1.8.7 and ruby 1.9.2.
|
data/lib/guard/haml.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
require 'guard'
|
2
2
|
require 'guard/guard'
|
3
|
+
require 'guard/watcher'
|
3
4
|
require 'haml'
|
4
5
|
|
5
6
|
module Guard
|
6
7
|
class Haml < Guard
|
7
8
|
|
8
|
-
VERSION = '0.2.0'
|
9
|
-
|
10
9
|
def initialize(watchers = [], options = {})
|
10
|
+
super(watchers, {
|
11
|
+
:notifications => true
|
12
|
+
}.merge(options))
|
11
13
|
@watchers, @options = watchers, options
|
12
|
-
@haml_options = options.delete(:haml_options) || {}
|
13
14
|
end
|
14
15
|
|
15
16
|
def compile_haml file
|
16
17
|
content = File.new(file).read
|
17
|
-
engine = ::Haml::Engine.new(content, @haml_options)
|
18
|
+
engine = ::Haml::Engine.new(content, (@options[:haml_options] || {}))
|
18
19
|
engine.render
|
19
20
|
end
|
20
21
|
|
@@ -25,29 +26,40 @@ module Guard
|
|
25
26
|
# @return [String] path to file where output should be written
|
26
27
|
#
|
27
28
|
def get_output(file)
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
file_dir = File.dirname(file)
|
30
|
+
file_name = File.basename(file).split('.')[0..-2].join('.')
|
31
|
+
|
32
|
+
file_dir = file_dir.gsub(Regexp.new("#{@options[:input]}(\/){0,1}"), '') if @options[:input]
|
33
|
+
file_dir = File.join(@options[:output], file_dir) if @options[:output]
|
34
|
+
|
35
|
+
if file_dir == ''
|
36
|
+
file_name
|
31
37
|
else
|
32
|
-
|
38
|
+
File.join(file_dir, file_name)
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
36
42
|
def run_all
|
37
|
-
|
38
|
-
files = Dir.glob('**/*.*')
|
39
|
-
paths = files.map do |file|
|
40
|
-
patterns.map { |pattern| file if file.match(Regexp.new(pattern)) }
|
41
|
-
end
|
42
|
-
run_on_change(paths.flatten.compact)
|
43
|
+
run_on_change(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
|
43
44
|
end
|
44
45
|
|
45
46
|
def run_on_change(paths)
|
46
47
|
paths.each do |file|
|
47
48
|
output_file = get_output(file)
|
49
|
+
FileUtils.mkdir_p File.dirname(output_file)
|
48
50
|
File.open(output_file, 'w') { |f| f.write(compile_haml(file)) }
|
49
|
-
|
51
|
+
::Guard::UI.info "# compiled haml in '#{file}' to html in '#{output_file}'"
|
52
|
+
::Guard::Notifier.notify("# compiled haml in #{file}", :title => "Guard::Haml", :image => :success) if @options[:notifications]
|
50
53
|
end
|
54
|
+
notify paths
|
51
55
|
end
|
56
|
+
|
57
|
+
def notify(changed_files)
|
58
|
+
::Guard.guards.reject{ |guard| guard == self }.each do |guard|
|
59
|
+
paths = Watcher.match_files(guard, changed_files)
|
60
|
+
guard.run_on_change paths unless paths.empty?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
52
64
|
end
|
53
65
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::Haml do
|
4
|
+
subject { Guard::Haml.new }
|
5
|
+
|
6
|
+
describe 'run all' do
|
7
|
+
it 'should rebuild all files being watched' do
|
8
|
+
Guard::Haml.stub(:run_on_change).with([]).and_return([])
|
9
|
+
Guard.stub(:guards).and_return([subject])
|
10
|
+
subject.run_all
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#get_output' do
|
15
|
+
context 'by default' do
|
16
|
+
it 'should return test/index.html.haml as test/index.html' do
|
17
|
+
subject.get_output('test/index.html.haml').should eq('test/index.html')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should return test/index.htm.haml as test/index.htm' do
|
21
|
+
subject.get_output('test/index.htm.haml').should eq('test/index.htm')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when the output option is set to "demo/output"' do
|
26
|
+
before do
|
27
|
+
subject.options[:output] = 'demo/output'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return test/index.html.haml as demo/output/test/index.html.haml' do
|
31
|
+
subject.get_output('test/index.html.haml').should eq('demo/output/test/index.html')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when the exclude_base_dir option is set to "test/ignore"' do
|
36
|
+
before do
|
37
|
+
subject.options[:input] = 'test/ignore'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return test/ignore/index.html.haml as index.html' do
|
41
|
+
subject.get_output('test/ignore/index.html.haml').should eq('index.html')
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when the output option is set to "demo/output"' do
|
45
|
+
before do
|
46
|
+
subject.options[:output] = 'demo/output'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return test/ignore/abc/index.html.haml as demo/output/abc/index.html' do
|
50
|
+
subject.get_output('test/ignore/abc/index.html.haml').should eq('demo/output/abc/index.html')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'building haml to html' do
|
57
|
+
it 'should notify other guards upon completion' do
|
58
|
+
other_guard = mock('guard')
|
59
|
+
other_guard.should_receive(:watchers).and_return([])
|
60
|
+
Guard.stub(:guards).and_return([subject, other_guard])
|
61
|
+
subject.notify([])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'guard/haml'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.color_enabled = true
|
6
|
+
config.filter_run :focus => true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
|
9
|
+
config.before(:each) do
|
10
|
+
ENV["GUARD_ENV"] = 'test'
|
11
|
+
@fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__))
|
12
|
+
@lib_path = Pathname.new(File.expand_path('../../lib/', __FILE__))
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Immanuel H\xC3\xA4ussermann"
|
@@ -15,29 +15,31 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-18 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
name: guard
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
25
|
none: false
|
24
26
|
requirements:
|
25
|
-
- -
|
27
|
+
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
27
|
-
hash:
|
29
|
+
hash: 3
|
28
30
|
segments:
|
29
31
|
- 0
|
30
|
-
-
|
31
|
-
version: "0.
|
32
|
+
- 4
|
33
|
+
version: "0.4"
|
32
34
|
type: :runtime
|
33
|
-
|
34
|
-
prerelease: false
|
35
|
-
name: guard
|
35
|
+
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
|
37
|
+
name: haml
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
40
|
none: false
|
39
41
|
requirements:
|
40
|
-
- -
|
42
|
+
- - ">="
|
41
43
|
- !ruby/object:Gem::Version
|
42
44
|
hash: 7
|
43
45
|
segments:
|
@@ -45,9 +47,21 @@ dependencies:
|
|
45
47
|
- 0
|
46
48
|
version: "3.0"
|
47
49
|
type: :runtime
|
48
|
-
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rspec
|
49
53
|
prerelease: false
|
50
|
-
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
51
65
|
description: Compiles file.html.haml into file.html
|
52
66
|
email:
|
53
67
|
- haeussermann@gmail.com
|
@@ -59,9 +73,13 @@ extra_rdoc_files: []
|
|
59
73
|
|
60
74
|
files:
|
61
75
|
- lib/guard/haml/templates/Guardfile
|
76
|
+
- lib/guard/haml/version.rb
|
62
77
|
- lib/guard/haml.rb
|
63
78
|
- LICENSE
|
64
79
|
- README.md
|
80
|
+
- Gemfile
|
81
|
+
- spec/guard/haml_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
65
83
|
has_rdoc: true
|
66
84
|
homepage: ""
|
67
85
|
licenses: []
|
@@ -96,5 +114,6 @@ rubygems_version: 1.6.2
|
|
96
114
|
signing_key:
|
97
115
|
specification_version: 3
|
98
116
|
summary: Guard gem for Haml
|
99
|
-
test_files:
|
100
|
-
|
117
|
+
test_files:
|
118
|
+
- spec/guard/haml_spec.rb
|
119
|
+
- spec/spec_helper.rb
|