guard-haml 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +56 -9
- data/lib/guard/haml.rb +90 -32
- data/lib/guard/haml/notifier.rb +20 -0
- data/lib/guard/haml/templates/Guardfile +9 -1
- data/lib/guard/haml/version.rb +1 -1
- data/spec/fixtures/fail_test.html.haml +10 -0
- data/spec/fixtures/test.html.haml +9 -0
- data/spec/fixtures/test2.html.haml +9 -0
- data/spec/guard/haml/notifier_spec.rb +39 -0
- data/spec/guard/haml_spec.rb +212 -25
- data/spec/spec_helper.rb +2 -2
- metadata +51 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b3f56d6c5009f06294948811c117837430f48c1
|
4
|
+
data.tar.gz: 3571aed2a9923238a869162cdef9654fab29d949
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a052a15124ba7591ce3e91232a6883864b4b98ef189fe9d1bb4ab939d01e8177ddb3fa548dc1738beadb75fa628db31faf2f27d6dc7d33d66a48177169defb7f
|
7
|
+
data.tar.gz: b20b540d3bc4cbfc62e042612dbf708b31f5e5e9825093316915087882bd7574f247110f56a3787b3cdb215d2147e730e3e5799d3df4b45671207c517dc926de
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Guard::Haml
|
2
2
|
|
3
|
-
|
3
|
+
Watches HAML files, compiles them to HTML on change.
|
4
|
+
|
5
|
+
[![Build Status](https://secure.travis-ci.org/manufaktor/guard-haml.png?branch=development)](http://travis-ci.org/manufaktor/guard-haml)
|
6
|
+
|
4
7
|
|
5
8
|
## Install
|
6
9
|
|
@@ -9,17 +12,19 @@ As the gem name suggests this is a guard extension. Make sure you get [guard](ht
|
|
9
12
|
Install the gem:
|
10
13
|
|
11
14
|
gem install guard-haml
|
12
|
-
|
15
|
+
|
13
16
|
Add it to your Gemfile if you're using bundler (you should)
|
14
|
-
|
17
|
+
|
15
18
|
gem 'guard-haml'
|
16
|
-
|
19
|
+
|
17
20
|
Add a basic guard setup:
|
18
|
-
|
21
|
+
|
19
22
|
guard init haml
|
20
23
|
|
21
24
|
## Options
|
22
25
|
|
26
|
+
### Configuring the output destination
|
27
|
+
|
23
28
|
If you want to change the output directory use the `output` option in your
|
24
29
|
Guardfile, e.g.:
|
25
30
|
|
@@ -29,6 +34,14 @@ Guardfile, e.g.:
|
|
29
34
|
|
30
35
|
This output is relative to the Guardfile.
|
31
36
|
|
37
|
+
### Multiple output option
|
38
|
+
|
39
|
+
This lets you compile to two (or more) html files from one haml file. This comes in handy if you want to compile to both a dev and prod build directory, for example:
|
40
|
+
|
41
|
+
guard 'haml', { :input => 'markup', :output => ['public/dev', 'public/build'] } do
|
42
|
+
watch(%r{^.+(\.haml)$})
|
43
|
+
end
|
44
|
+
|
32
45
|
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
46
|
|
34
47
|
guard 'haml', :output => 'public', :input => 'src' do
|
@@ -36,7 +49,42 @@ If you maintain your haml files in a directory that should not be part of the ou
|
|
36
49
|
end
|
37
50
|
|
38
51
|
So when you edit a file `src/partials/_partial.html.haml`
|
39
|
-
it will be
|
52
|
+
it will be saved to `public/partials/_partial.html` without the `src`.
|
53
|
+
|
54
|
+
### File extensions
|
55
|
+
|
56
|
+
The guard extension will try to add the correct extension based off the input file name. You can provide multiple extensions to control the file name.
|
57
|
+
|
58
|
+
```
|
59
|
+
"foo.haml" -> "foo.html"
|
60
|
+
"foo" -> "foo.html"
|
61
|
+
"foo.txt" -> "foo.txt.html"
|
62
|
+
"foo.php.haml" -> "foo.php"
|
63
|
+
```
|
64
|
+
|
65
|
+
You can override the default extension (`html`) using the `default_ext` option:
|
66
|
+
|
67
|
+
guard 'haml', :default_ext => 'txt' do
|
68
|
+
watch %r{^src/.+(\.html\.haml)}
|
69
|
+
end
|
70
|
+
|
71
|
+
### Compile when starting guard
|
72
|
+
|
73
|
+
If you want to compile haml files on guard start you can use `run_at_start` option.
|
74
|
+
|
75
|
+
guard 'haml', :output => 'public', :input => 'src', :run_at_start => true do
|
76
|
+
watch %r{^src/.+(\.html\.haml)}
|
77
|
+
end
|
78
|
+
|
79
|
+
### Guard notifications
|
80
|
+
|
81
|
+
Also you can configure guard notifications (to Growl/lib-notify/Notifu) by setting `notifications` option to `true`
|
82
|
+
|
83
|
+
guard 'haml', :output => 'public', :input => 'src', :notifications => true do
|
84
|
+
watch %r{^src/.+(\.html\.haml)}
|
85
|
+
end
|
86
|
+
|
87
|
+
### Configuring HAML
|
40
88
|
|
41
89
|
If you want to pass options to the Haml engine, you can set the `haml_options` option, e.g.:
|
42
90
|
|
@@ -44,12 +92,11 @@ If you want to pass options to the Haml engine, you can set the `haml_options` o
|
|
44
92
|
watch %r{^src/.+(\.html\.haml)}
|
45
93
|
end
|
46
94
|
|
47
|
-
This will produce compressed HTML. See [Haml Reference](http://haml
|
95
|
+
This will produce compressed HTML. See [Haml Reference](http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#options) for more details.
|
48
96
|
|
49
97
|
## Development
|
50
98
|
|
51
99
|
* Source is hosted on [Github: guard-haml](https://github.com/manufaktor/guard-haml)
|
52
100
|
* Report issues/questions/feature requests on the [Github Issue tracker for guard-haml](https://github.com/manufaktor/guard-haml/issues)
|
53
101
|
|
54
|
-
Pull requests are welcome.
|
55
|
-
Specs are very welcome, make sure you support both ruby 1.8.7 and ruby 1.9.2.
|
102
|
+
Pull requests are welcome. If you are adding something new that is worth documenting, please do not forget to note it in the README.
|
data/lib/guard/haml.rb
CHANGED
@@ -5,60 +5,119 @@ require 'haml'
|
|
5
5
|
|
6
6
|
module Guard
|
7
7
|
class Haml < Guard
|
8
|
-
|
8
|
+
autoload :Notifier, 'guard/haml/notifier'
|
9
|
+
|
9
10
|
def initialize(watchers = [], options = {})
|
10
11
|
@options = {
|
11
|
-
:notifications => true
|
12
|
-
|
12
|
+
:notifications => true,
|
13
|
+
:default_ext => 'html',
|
14
|
+
:auto_append_file_ext => false
|
15
|
+
}.merge options
|
13
16
|
super(watchers, @options)
|
14
17
|
end
|
15
|
-
|
18
|
+
|
19
|
+
def start
|
20
|
+
run_all if @options[:run_at_start]
|
21
|
+
end
|
22
|
+
|
23
|
+
def stop
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def reload
|
28
|
+
run_all
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_all
|
32
|
+
run_on_changes(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
|
33
|
+
end
|
34
|
+
|
35
|
+
def run_on_changes(paths)
|
36
|
+
paths.each do |file|
|
37
|
+
output_files = get_output(file)
|
38
|
+
compiled_haml = compile_haml(file)
|
39
|
+
output_files.each do |output_file|
|
40
|
+
FileUtils.mkdir_p File.dirname(output_file)
|
41
|
+
File.open(output_file, 'w') { |f| f.write(compiled_haml) }
|
42
|
+
end
|
43
|
+
message = "Successfully compiled haml to html!\n"
|
44
|
+
message += "# #{file} -> #{output_files.join(', ')}".gsub("#{Bundler.root.to_s}/", '')
|
45
|
+
::Guard::UI.info message
|
46
|
+
Notifier.notify( true, message ) if @options[:notifications]
|
47
|
+
end
|
48
|
+
notify paths
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
16
53
|
def compile_haml file
|
17
54
|
begin
|
18
55
|
content = File.new(file).read
|
19
56
|
engine = ::Haml::Engine.new(content, (@options[:haml_options] || {}))
|
20
57
|
engine.render
|
21
58
|
rescue StandardError => error
|
22
|
-
|
59
|
+
message = "HAML compilation failed!\nError: #{error.message}"
|
60
|
+
::Guard::UI.error message
|
61
|
+
Notifier.notify( false, message ) if @options[:notifications]
|
23
62
|
throw :task_has_failed
|
24
63
|
end
|
25
64
|
end
|
26
65
|
|
27
66
|
# Get the file path to output the html based on the file being
|
28
|
-
# built.
|
67
|
+
# built. The output path is relative to where guard is being run.
|
29
68
|
#
|
30
|
-
# @param file [String] path to file being built
|
31
|
-
# @return [String] path to file where output should be written
|
69
|
+
# @param file [String, Array<String>] path to file being built
|
70
|
+
# @return [Array<String>] path(s) to file where output should be written
|
32
71
|
#
|
33
72
|
def get_output(file)
|
34
|
-
|
35
|
-
file_name =
|
36
|
-
|
37
|
-
|
73
|
+
input_file_dir = File.dirname(file)
|
74
|
+
file_name = get_file_name(file)
|
75
|
+
file_name = "#{file_name}.html" if append_file_ext_to_output_path?(file_name)
|
76
|
+
input_file_dir = input_file_dir.gsub(Regexp.new("#{@options[:input]}(\/){0,1}"), '') if @options[:input]
|
77
|
+
if @options[:output]
|
78
|
+
Array(@options[:output]).map do |output_dir|
|
79
|
+
File.join(output_dir, input_file_dir, file_name)
|
80
|
+
end
|
81
|
+
else
|
82
|
+
if input_file_dir == ''
|
83
|
+
[file_name]
|
84
|
+
else
|
85
|
+
[File.join(input_file_dir, file_name)]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
38
89
|
|
39
|
-
|
40
|
-
|
90
|
+
# Generate a file name based on the provided file path.
|
91
|
+
# Provide a logical extension.
|
92
|
+
#
|
93
|
+
# Examples:
|
94
|
+
# "path/foo.haml" -> "foo.html"
|
95
|
+
# "path/foo" -> "foo.html"
|
96
|
+
# "path/foo.bar" -> "foo.bar.html"
|
97
|
+
# "path/foo.bar.haml" -> "foo.bar"
|
98
|
+
#
|
99
|
+
# @param file String path to file
|
100
|
+
# @return String file name including extension
|
101
|
+
#
|
102
|
+
def get_file_name(file)
|
103
|
+
sub_strings = File.basename(file).split('.')
|
104
|
+
base_name, extensions = sub_strings.first, sub_strings[1..-1]
|
41
105
|
|
42
|
-
if
|
43
|
-
|
106
|
+
if extensions.last == 'haml'
|
107
|
+
extensions.pop
|
108
|
+
if extensions.empty?
|
109
|
+
[base_name, @options[:default_ext]].join('.')
|
110
|
+
else
|
111
|
+
[base_name, extensions].flatten.join('.')
|
112
|
+
end
|
44
113
|
else
|
45
|
-
|
114
|
+
[base_name, extensions, @options[:default_ext]].flatten.join('.')
|
46
115
|
end
|
47
116
|
end
|
48
|
-
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
def run_on_changes(paths)
|
54
|
-
paths.each do |file|
|
55
|
-
output_file = get_output(file)
|
56
|
-
FileUtils.mkdir_p File.dirname(output_file)
|
57
|
-
File.open(output_file, 'w') { |f| f.write(compile_haml(file)) }
|
58
|
-
::Guard::UI.info "# compiled haml in '#{file}' to html in '#{output_file}'"
|
59
|
-
::Guard::Notifier.notify("# compiled haml in #{file}", :title => "Guard::Haml", :image => :success) if @options[:notifications]
|
60
|
-
end
|
61
|
-
notify paths
|
117
|
+
|
118
|
+
def append_file_ext_to_output_path?(file_name)
|
119
|
+
return unless @options[:auto_append_file_ext]
|
120
|
+
file_name.match("\.html?").nil?
|
62
121
|
end
|
63
122
|
|
64
123
|
def notify(changed_files)
|
@@ -67,6 +126,5 @@ module Guard
|
|
67
126
|
guard.run_on_changes paths unless paths.empty?
|
68
127
|
end
|
69
128
|
end
|
70
|
-
|
71
129
|
end
|
72
130
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Guard
|
4
|
+
class Haml
|
5
|
+
class Notifier
|
6
|
+
class << self
|
7
|
+
def image result
|
8
|
+
result ? :success : :failed
|
9
|
+
end
|
10
|
+
|
11
|
+
def notify( result, message )
|
12
|
+
::Guard::Notifier.notify( message,
|
13
|
+
:title => 'Guard::Haml',
|
14
|
+
:image => image( result )
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,3 +1,11 @@
|
|
1
|
+
# Sample guardfile block for Guard::Haml
|
2
|
+
# You can use some options to change guard-haml configuration
|
3
|
+
# :output => 'public' set output directory for compiled files
|
4
|
+
# :input => 'src' set input directory with haml files
|
5
|
+
# :run_at_start => true compile files when guard starts
|
6
|
+
# :notifications => true send notifictions to Growl/libnotify/Notifu
|
7
|
+
# :haml_options => { :ugly => true } pass options to the Haml engine
|
8
|
+
|
1
9
|
guard 'haml' do
|
2
10
|
watch(/^.+(\.html\.haml)/)
|
3
|
-
end
|
11
|
+
end
|
data/lib/guard/haml/version.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::Haml::Notifier do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
describe '#image' do
|
7
|
+
context 'when recieves true' do
|
8
|
+
specify { subject.image(true).should be :success }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when recieves false' do
|
12
|
+
specify { subject.image(false).should be :failed }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#notify' do
|
17
|
+
context 'when recieves true with message' do
|
18
|
+
it 'should call Guard::Notifier with success image' do
|
19
|
+
::Guard::Notifier.should_receive(:notify).with(
|
20
|
+
'Successful compilation!',
|
21
|
+
:title => 'Guard::Haml',
|
22
|
+
:image => :success
|
23
|
+
)
|
24
|
+
subject.notify(true, 'Successful compilation!')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when recieves false with message' do
|
29
|
+
it 'should call Guard::Notifier with failed image' do
|
30
|
+
::Guard::Notifier.should_receive(:notify).with(
|
31
|
+
'Compilation failed!',
|
32
|
+
:title => 'Guard::Haml',
|
33
|
+
:image => :failed
|
34
|
+
)
|
35
|
+
subject.notify(false, 'Compilation failed!')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/guard/haml_spec.rb
CHANGED
@@ -1,72 +1,259 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Guard::Haml do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
let(:subject_with_options) { described_class.new( [],
|
5
|
+
:notifications => false,
|
6
|
+
:run_at_start => true) }
|
7
|
+
let(:subject_notifiable) { described_class.new( [],
|
8
|
+
:notifications => true ) }
|
9
|
+
let(:notifier) { Guard::Haml::Notifier }
|
10
|
+
|
11
|
+
describe "class" do
|
12
|
+
it 'should autoload Notifier class' do
|
13
|
+
expect { Guard::Haml::Notifier }.not_to raise_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#new' do
|
18
|
+
context 'notifications option by default' do
|
19
|
+
specify { subject.options[:notifications].should be_true }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when recieves options hash" do
|
23
|
+
it 'should merge it to @options instance variable' do
|
24
|
+
subject_with_options.options[:notifications].should be_false
|
25
|
+
subject_with_options.options[:run_at_start].should be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#start' do
|
31
|
+
context 'by default' do
|
32
|
+
it 'should not call #run_all' do
|
33
|
+
subject.should_not_receive(:run_all).and_return(true)
|
34
|
+
subject.start
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when run_on_start option set to true' do
|
39
|
+
it 'should call #run_all' do
|
40
|
+
subject_with_options.should_receive(:run_all).and_return(true)
|
41
|
+
subject_with_options.start
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when run_on_start option set to false' do
|
46
|
+
before do
|
47
|
+
subject.options[:run_at_start] = false
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should not call #run_all' do
|
51
|
+
subject.should_not_receive(:run_all).and_return(true)
|
52
|
+
subject.start
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#stop' do
|
58
|
+
specify { subject.stop.should be_true }
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#reload' do
|
62
|
+
it 'should call #run_all' do
|
63
|
+
subject.should_receive(:run_all).and_return(true)
|
64
|
+
subject.reload
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#run_all' do
|
7
69
|
it 'should rebuild all files being watched' do
|
8
70
|
Guard::Haml.stub(:run_on_change).with([]).and_return([])
|
9
71
|
Guard.stub(:guards).and_return([subject])
|
10
72
|
subject.run_all
|
11
73
|
end
|
12
74
|
end
|
13
|
-
|
75
|
+
|
14
76
|
describe '#get_output' do
|
15
77
|
context 'by default' do
|
16
|
-
it 'should return test/index.html.haml as test/index.html' do
|
17
|
-
subject.get_output
|
78
|
+
it 'should return test/index.html.haml as [test/index.html]' do
|
79
|
+
subject.send(:get_output, 'test/index.html.haml').
|
80
|
+
should eq(['test/index.html'])
|
18
81
|
end
|
19
|
-
|
20
|
-
it 'should return test/index.htm.haml as test/index.htm' do
|
21
|
-
subject.get_output
|
82
|
+
|
83
|
+
it 'should return test/index.htm.haml as [test/index.htm]' do
|
84
|
+
subject.send(:get_output, 'test/index.htm.haml').
|
85
|
+
should eq(['test/index.htm'])
|
22
86
|
end
|
23
87
|
|
24
|
-
it 'should return test/index.haml as test/index.html' do
|
25
|
-
subject.get_output
|
88
|
+
it 'should return test/index.haml as [test/index.html]' do
|
89
|
+
subject.send(:get_output, 'test/index.haml').
|
90
|
+
should eq(['test/index.html'])
|
26
91
|
end
|
27
92
|
end
|
28
|
-
|
93
|
+
|
29
94
|
context 'when the output option is set to "demo/output"' do
|
30
95
|
before do
|
31
96
|
subject.options[:output] = 'demo/output'
|
32
97
|
end
|
33
|
-
|
34
|
-
it 'should return test/index.html.haml as demo/output/test/index.html.haml' do
|
35
|
-
subject.get_output
|
98
|
+
|
99
|
+
it 'should return test/index.html.haml as [demo/output/test/index.html.haml]' do
|
100
|
+
subject.send(:get_output, 'test/index.html.haml').
|
101
|
+
should eq(['demo/output/test/index.html'])
|
36
102
|
end
|
37
103
|
end
|
38
|
-
|
104
|
+
|
105
|
+
context 'when the output option is set to ["demo/output", "demo2/output"]' do
|
106
|
+
before do
|
107
|
+
subject.options[:output] = ['demo1/output', 'demo2/output']
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should return test/index.html.haml as [demo1/output/test/index.html.haml, demo2/output/test/index.html.haml]' do
|
111
|
+
subject.send(:get_output, 'test/index.html.haml').
|
112
|
+
should eq(['demo1/output/test/index.html', 'demo2/output/test/index.html'])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when the default extensions is set to "txt"' do
|
117
|
+
before do
|
118
|
+
subject.options[:default_ext] = 'txt'
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should return test/index.haml as test/index.txt' do
|
122
|
+
subject.send(:get_output, 'test/index.haml').
|
123
|
+
should eq(['test/index.txt'])
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should return test/index.php.haml as test/index.php due to the second extension' do
|
127
|
+
subject.send(:get_output, 'test/index.php.haml').
|
128
|
+
should eq(['test/index.php'])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
|
39
134
|
context 'when the exclude_base_dir option is set to "test/ignore"' do
|
40
135
|
before do
|
41
136
|
subject.options[:input] = 'test/ignore'
|
42
137
|
end
|
43
|
-
|
44
|
-
it 'should return test/ignore/index.html.haml as index.html' do
|
45
|
-
subject.get_output
|
138
|
+
|
139
|
+
it 'should return test/ignore/index.html.haml as [index.html]' do
|
140
|
+
subject.send(:get_output, 'test/ignore/index.html.haml').
|
141
|
+
should eq(['index.html'])
|
46
142
|
end
|
47
|
-
|
143
|
+
|
48
144
|
context 'when the output option is set to "demo/output"' do
|
49
145
|
before do
|
50
146
|
subject.options[:output] = 'demo/output'
|
51
147
|
end
|
52
|
-
|
53
|
-
it 'should return test/ignore/abc/index.html.haml as demo/output/abc/index.html' do
|
54
|
-
subject.get_output
|
148
|
+
|
149
|
+
it 'should return test/ignore/abc/index.html.haml as [demo/output/abc/index.html]' do
|
150
|
+
subject.send(:get_output, 'test/ignore/abc/index.html.haml').
|
151
|
+
should eq(['demo/output/abc/index.html'])
|
55
152
|
end
|
56
153
|
end
|
57
154
|
end
|
155
|
+
|
156
|
+
context 'when the input file contains a second extension"' do
|
157
|
+
it 'should return test/index.php.haml as [test/index.php]' do
|
158
|
+
subject.send(:get_output, 'test/index.php.haml').
|
159
|
+
should eq(['test/index.php'])
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#get_file_name' do
|
165
|
+
context 'by default (if a ".haml" extension has been defined)' do
|
166
|
+
it 'should return the file name with the default extension ".html"' do
|
167
|
+
subject.send(:get_file_name, 'test/index.haml').
|
168
|
+
should eq('index.html')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'if no extension has been defined at all' do
|
173
|
+
it 'should return the file name with the default extension ".html"' do
|
174
|
+
subject.send(:get_file_name, 'test/index').
|
175
|
+
should eq('index.html')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'if an extension other than ".haml" has been defined' do
|
180
|
+
it 'should return the file name with the default extension ".html"' do
|
181
|
+
subject.send(:get_file_name, 'test/index.foo').
|
182
|
+
should eq('index.foo.html')
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context 'if multiple extensions including ".haml" have been defined' do
|
187
|
+
it 'should return the file name with the extension second to last' do
|
188
|
+
subject.send(:get_file_name, 'test/index.foo.haml').
|
189
|
+
should eq('index.foo')
|
190
|
+
end
|
191
|
+
end
|
58
192
|
end
|
59
|
-
|
193
|
+
|
60
194
|
describe '#run_on_changes' do
|
61
195
|
it 'should notify other guards upon completion' do
|
62
196
|
subject.should_receive(:notify).with([])
|
63
197
|
subject.run_on_changes([])
|
64
198
|
end
|
199
|
+
|
200
|
+
context 'when notifications option set to true' do
|
201
|
+
let(:success_message) { "Successfully compiled haml to html!\n" }
|
202
|
+
|
203
|
+
context 'with one output' do
|
204
|
+
after do
|
205
|
+
File.unlink "#{@fixture_path}/test.html"
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should call Notifier.notify with 1 output' do
|
209
|
+
message = success_message + "# spec/fixtures/test.html.haml -> spec/fixtures/test.html"
|
210
|
+
notifier.should_receive(:notify).with(true, message)
|
211
|
+
subject_notifiable.run_on_changes(["#{@fixture_path}/test.html.haml"])
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should call Notifier.notify' do
|
216
|
+
message = "Successfully compiled haml to html!\n"
|
217
|
+
message += "# spec/fixtures/test.html.haml -> spec/fixtures/test.html"
|
218
|
+
notifier.should_receive(:notify).with(true, message)
|
219
|
+
subject_notifiable.run_on_changes(["#{@fixture_path}/test.html.haml"])
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'with two outputs' do
|
223
|
+
before do
|
224
|
+
subject_notifiable.stub(:get_output).and_return(["#{@fixture_path}/test.html", "#{@fixture_path}/test2.html"])
|
225
|
+
end
|
226
|
+
|
227
|
+
after do
|
228
|
+
File.unlink "#{@fixture_path}/test.html"
|
229
|
+
File.unlink "#{@fixture_path}/test2.html"
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should call Notifier.notify with 2 outputs' do
|
233
|
+
message = success_message + "# spec/fixtures/test.html.haml -> spec/fixtures/test.html, spec/fixtures/test2.html"
|
234
|
+
notifier.should_receive(:notify).with(true, message)
|
235
|
+
subject_notifiable.run_on_changes(["#{@fixture_path}/test.html.haml"])
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
65
239
|
end
|
66
240
|
|
67
241
|
describe '#compile_haml' do
|
68
242
|
it 'throws :task_has_failed when an error occurs' do
|
69
|
-
expect { subject.compile_haml
|
243
|
+
expect { subject.send(:compile_haml, "#{@fixture_path}/fail_test.html.haml") }.
|
244
|
+
to throw_symbol :task_has_failed
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'when notifications option set to true' do
|
248
|
+
it 'should call Notifier.notify when an error occurs' do
|
249
|
+
message = "HAML compilation failed!\n"
|
250
|
+
message += "Error: Illegal nesting: content can't be both given on the same line as %p and nested within it."
|
251
|
+
notifier.should_receive(:notify).with(false, message)
|
252
|
+
catch(:task_has_failed) do
|
253
|
+
subject_notifiable.send(:compile_haml, "#{@fixture_path}/fail_test.html.haml")
|
254
|
+
end.should be_nil
|
255
|
+
|
256
|
+
end
|
70
257
|
end
|
71
258
|
end
|
72
259
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,7 +8,7 @@ RSpec.configure do |config|
|
|
8
8
|
|
9
9
|
config.before(:each) do
|
10
10
|
ENV["GUARD_ENV"] = 'test'
|
11
|
-
@fixture_path = Pathname.new
|
12
|
-
@lib_path = Pathname.new
|
11
|
+
@fixture_path = Pathname.new "#{Bundler.root}/spec/fixtures"
|
12
|
+
@lib_path = Pathname.new "#{Bundler.root}/lib"
|
13
13
|
end
|
14
14
|
end
|
metadata
CHANGED
@@ -1,49 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
5
|
-
prerelease:
|
4
|
+
version: '0.5'
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Immanuel Häussermann
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: guard
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.1'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: haml
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '3.0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rspec
|
38
|
-
requirement:
|
39
|
-
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
51
|
requirements:
|
41
|
-
- -
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
42
60
|
- !ruby/object:Gem::Version
|
43
61
|
version: '0'
|
44
62
|
type: :development
|
45
63
|
prerelease: false
|
46
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
47
69
|
description: Compiles file.html.haml into file.html
|
48
70
|
email:
|
49
71
|
- haeussermann@gmail.com
|
@@ -51,38 +73,46 @@ executables: []
|
|
51
73
|
extensions: []
|
52
74
|
extra_rdoc_files: []
|
53
75
|
files:
|
76
|
+
- lib/guard/haml/notifier.rb
|
54
77
|
- lib/guard/haml/templates/Guardfile
|
55
78
|
- lib/guard/haml/version.rb
|
56
79
|
- lib/guard/haml.rb
|
57
80
|
- LICENSE
|
58
81
|
- README.md
|
59
82
|
- Gemfile
|
83
|
+
- spec/fixtures/fail_test.html.haml
|
84
|
+
- spec/fixtures/test.html.haml
|
85
|
+
- spec/fixtures/test2.html.haml
|
86
|
+
- spec/guard/haml/notifier_spec.rb
|
60
87
|
- spec/guard/haml_spec.rb
|
61
88
|
- spec/spec_helper.rb
|
62
89
|
homepage: ''
|
63
90
|
licenses: []
|
91
|
+
metadata: {}
|
64
92
|
post_install_message:
|
65
93
|
rdoc_options: []
|
66
94
|
require_paths:
|
67
95
|
- lib
|
68
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
97
|
requirements:
|
71
|
-
- -
|
98
|
+
- - '>='
|
72
99
|
- !ruby/object:Gem::Version
|
73
100
|
version: '0'
|
74
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
102
|
requirements:
|
77
|
-
- -
|
103
|
+
- - '>='
|
78
104
|
- !ruby/object:Gem::Version
|
79
105
|
version: '0'
|
80
106
|
requirements: []
|
81
107
|
rubyforge_project: guard-haml
|
82
|
-
rubygems_version:
|
108
|
+
rubygems_version: 2.0.3
|
83
109
|
signing_key:
|
84
|
-
specification_version:
|
110
|
+
specification_version: 4
|
85
111
|
summary: Guard gem for Haml
|
86
112
|
test_files:
|
113
|
+
- spec/fixtures/fail_test.html.haml
|
114
|
+
- spec/fixtures/test.html.haml
|
115
|
+
- spec/fixtures/test2.html.haml
|
116
|
+
- spec/guard/haml/notifier_spec.rb
|
87
117
|
- spec/guard/haml_spec.rb
|
88
118
|
- spec/spec_helper.rb
|