guard-haml-ext 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +19 -0
- data/README.md +100 -0
- data/lib/guard/haml.rb +125 -0
- data/lib/guard/haml/notifier.rb +20 -0
- data/lib/guard/haml/templates/Guardfile +11 -0
- data/lib/guard/haml/version.rb +5 -0
- 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 +259 -0
- data/spec/spec_helper.rb +14 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c511c716e07156432d4acd997e324a962566214
|
4
|
+
data.tar.gz: ef7ddbc18f417cba46571264eb48ba761efeaf20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81954ecbe85cf06ecf05a56ec8dd5a2805852b6db336d2a5c720afa4914dea354c53dc407f85e04a7854acb176529675fd7dd19221db47a0366e88de94a7353a
|
7
|
+
data.tar.gz: 81f47a0c8a3301049b8d2d1d57e4e638dc424451ca5d7b7cc1226df766a62a04d516737e0a2f443ae53ebd0d4e7ceea9b69c6039e7c9a3c0ab2ebae79ff8fe9b
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 by Immanuel Häussermann
|
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,100 @@
|
|
1
|
+
# Guard::Haml
|
2
|
+
|
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
|
+
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
As the gem name suggests this is a guard extension. Make sure you get [guard](https://github.com/guard/guard) first.
|
11
|
+
|
12
|
+
Install the gem:
|
13
|
+
|
14
|
+
gem install guard-haml
|
15
|
+
|
16
|
+
Add it to your Gemfile if you're using bundler (you should)
|
17
|
+
|
18
|
+
gem 'guard-haml'
|
19
|
+
|
20
|
+
Add a basic guard setup:
|
21
|
+
|
22
|
+
guard init haml
|
23
|
+
|
24
|
+
## Options
|
25
|
+
|
26
|
+
### Configuring the output destination
|
27
|
+
|
28
|
+
If you want to change the output directory use the `output` option in your
|
29
|
+
Guardfile, e.g.:
|
30
|
+
|
31
|
+
guard 'haml', :output => 'public' do
|
32
|
+
watch %r{^src/.+(\.html\.haml)}
|
33
|
+
end
|
34
|
+
|
35
|
+
This output is relative to the Guardfile.
|
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
|
+
|
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.:
|
46
|
+
|
47
|
+
guard 'haml', :output => 'public', :input => 'src' do
|
48
|
+
watch %r{^src/.+(\.html\.haml)}
|
49
|
+
end
|
50
|
+
|
51
|
+
So when you edit a file `src/partials/_partial.html.haml`
|
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
|
+
"foo.haml" -> "foo.html"
|
59
|
+
"foo" -> "foo.html"
|
60
|
+
"foo.txt" -> "foo.txt.html"
|
61
|
+
"foo.php.haml" -> "foo.php"
|
62
|
+
|
63
|
+
You can override the default extension (`html`) using the `default_ext` option:
|
64
|
+
|
65
|
+
guard 'haml', :default_ext => 'txt' do
|
66
|
+
watch %r{^src/.+(\.html\.haml)}
|
67
|
+
end
|
68
|
+
|
69
|
+
### Compile when starting guard
|
70
|
+
|
71
|
+
If you want to compile haml files on guard start you can use `run_at_start` option.
|
72
|
+
|
73
|
+
guard 'haml', :output => 'public', :input => 'src', :run_at_start => true do
|
74
|
+
watch %r{^src/.+(\.html\.haml)}
|
75
|
+
end
|
76
|
+
|
77
|
+
### Guard notifications
|
78
|
+
|
79
|
+
Also you can configure guard notifications (to Growl/lib-notify/Notifu) by setting `notifications` option to `true`
|
80
|
+
|
81
|
+
guard 'haml', :output => 'public', :input => 'src', :notifications => true do
|
82
|
+
watch %r{^src/.+(\.html\.haml)}
|
83
|
+
end
|
84
|
+
|
85
|
+
### Configuring HAML
|
86
|
+
|
87
|
+
If you want to pass options to the Haml engine, you can set the `haml_options` option, e.g.:
|
88
|
+
|
89
|
+
guard 'haml', :output => 'public', :input => 'src', :haml_options => { :ugly => true } do
|
90
|
+
watch %r{^src/.+(\.html\.haml)}
|
91
|
+
end
|
92
|
+
|
93
|
+
This will produce compressed HTML. See [Haml Reference](http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#options) for more details.
|
94
|
+
|
95
|
+
## Development
|
96
|
+
|
97
|
+
* Source is hosted on [Github: guard-haml](https://github.com/manufaktor/guard-haml)
|
98
|
+
* Report issues/questions/feature requests on the [Github Issue tracker for guard-haml](https://github.com/manufaktor/guard-haml/issues)
|
99
|
+
|
100
|
+
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
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'guard/watcher'
|
4
|
+
require 'haml'
|
5
|
+
|
6
|
+
module Guard
|
7
|
+
class Haml < Guard
|
8
|
+
autoload :Notifier, 'guard/haml/notifier'
|
9
|
+
|
10
|
+
def initialize(watchers = [], options = {})
|
11
|
+
@options = {
|
12
|
+
:notifications => true,
|
13
|
+
:default_ext => 'html'
|
14
|
+
}.merge options
|
15
|
+
super(watchers, @options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def start
|
19
|
+
run_all if @options[:run_at_start]
|
20
|
+
end
|
21
|
+
|
22
|
+
def stop
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def reload
|
27
|
+
run_all
|
28
|
+
end
|
29
|
+
|
30
|
+
def run_all
|
31
|
+
run_on_changes(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
|
32
|
+
end
|
33
|
+
|
34
|
+
def run_on_changes(paths)
|
35
|
+
paths.each do |file|
|
36
|
+
output_files = get_output(file)
|
37
|
+
compiled_haml = compile_haml(file)
|
38
|
+
output_files.each do |output_file|
|
39
|
+
FileUtils.mkdir_p File.dirname(output_file)
|
40
|
+
File.open(output_file, 'w') { |f| f.write(compiled_haml) }
|
41
|
+
end
|
42
|
+
message = "Successfully compiled haml to html!\n"
|
43
|
+
message += "# #{file} -> #{output_files.join(', ')}".gsub("#{Bundler.root.to_s}/", '')
|
44
|
+
::Guard::UI.info message
|
45
|
+
Notifier.notify( true, message ) if @options[:notifications]
|
46
|
+
end
|
47
|
+
notify paths
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def compile_haml file
|
53
|
+
begin
|
54
|
+
content = File.new(file).read
|
55
|
+
engine = ::Haml::Engine.new(content, (@options[:haml_options] || {}))
|
56
|
+
engine.render
|
57
|
+
rescue StandardError => error
|
58
|
+
message = "HAML compilation failed!\nError: #{error.message}"
|
59
|
+
::Guard::UI.error message
|
60
|
+
Notifier.notify( false, message ) if @options[:notifications]
|
61
|
+
throw :task_has_failed
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Get the file path to output the html based on the file being
|
66
|
+
# built. The output path is relative to where guard is being run.
|
67
|
+
#
|
68
|
+
# @param file [String, Array<String>] path to file being built
|
69
|
+
# @return [Array<String>] path(s) to file where output should be written
|
70
|
+
#
|
71
|
+
def get_output(file)
|
72
|
+
input_file_dir = File.dirname(file)
|
73
|
+
|
74
|
+
file_name = get_file_name(file)
|
75
|
+
|
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
|
89
|
+
|
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]
|
105
|
+
|
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
|
113
|
+
else
|
114
|
+
[base_name, extensions, @options[:default_ext]].flatten.join('.')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def notify(changed_files)
|
119
|
+
::Guard.guards.reject{ |guard| guard == self }.each do |guard|
|
120
|
+
paths = Watcher.match_files(guard, changed_files)
|
121
|
+
guard.run_on_changes paths unless paths.empty?
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
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
|
@@ -0,0 +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
|
+
|
9
|
+
guard 'haml' do
|
10
|
+
watch(/^.+(\.html\.haml)/)
|
11
|
+
end
|
@@ -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
|
@@ -0,0 +1,259 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Guard::Haml do
|
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
|
69
|
+
it 'should rebuild all files being watched' do
|
70
|
+
Guard::Haml.stub(:run_on_change).with([]).and_return([])
|
71
|
+
Guard.stub(:guards).and_return([subject])
|
72
|
+
subject.run_all
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#get_output' do
|
77
|
+
context 'by default' do
|
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'])
|
81
|
+
end
|
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'])
|
86
|
+
end
|
87
|
+
|
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'])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when the output option is set to "demo/output"' do
|
95
|
+
before do
|
96
|
+
subject.options[:output] = 'demo/output'
|
97
|
+
end
|
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'])
|
102
|
+
end
|
103
|
+
end
|
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
|
+
|
134
|
+
context 'when the exclude_base_dir option is set to "test/ignore"' do
|
135
|
+
before do
|
136
|
+
subject.options[:input] = 'test/ignore'
|
137
|
+
end
|
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'])
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when the output option is set to "demo/output"' do
|
145
|
+
before do
|
146
|
+
subject.options[:output] = 'demo/output'
|
147
|
+
end
|
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'])
|
152
|
+
end
|
153
|
+
end
|
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
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#run_on_changes' do
|
195
|
+
it 'should notify other guards upon completion' do
|
196
|
+
subject.should_receive(:notify).with([])
|
197
|
+
subject.run_on_changes([])
|
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
|
239
|
+
end
|
240
|
+
|
241
|
+
describe '#compile_haml' do
|
242
|
+
it 'throws :task_has_failed when an error occurs' do
|
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
|
257
|
+
end
|
258
|
+
end
|
259
|
+
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 "#{Bundler.root}/spec/fixtures"
|
12
|
+
@lib_path = Pathname.new "#{Bundler.root}/lib"
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-haml-ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.6'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Immanuel Häussermann
|
8
|
+
- Florian Plank
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: guard
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: haml
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: Fork of @manufaktor’s guard-haml with support for file extension detection.
|
71
|
+
Compiles file.html.haml into file.html
|
72
|
+
email:
|
73
|
+
- haeussermann@gmail.com
|
74
|
+
- florian@polarblau.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- lib/guard/haml/notifier.rb
|
80
|
+
- lib/guard/haml/templates/Guardfile
|
81
|
+
- lib/guard/haml/version.rb
|
82
|
+
- lib/guard/haml.rb
|
83
|
+
- LICENSE
|
84
|
+
- README.md
|
85
|
+
- Gemfile
|
86
|
+
- spec/fixtures/fail_test.html.haml
|
87
|
+
- spec/fixtures/test.html.haml
|
88
|
+
- spec/fixtures/test2.html.haml
|
89
|
+
- spec/guard/haml/notifier_spec.rb
|
90
|
+
- spec/guard/haml_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: ''
|
93
|
+
licenses: []
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project: guard-haml-ext
|
111
|
+
rubygems_version: 2.0.3
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Guard gem for Haml
|
115
|
+
test_files:
|
116
|
+
- spec/fixtures/fail_test.html.haml
|
117
|
+
- spec/fixtures/test.html.haml
|
118
|
+
- spec/fixtures/test2.html.haml
|
119
|
+
- spec/guard/haml/notifier_spec.rb
|
120
|
+
- spec/guard/haml_spec.rb
|
121
|
+
- spec/spec_helper.rb
|