guard-haml 0.5 → 1.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/LICENSE +2 -2
- data/README.md +75 -37
- data/lib/guard/haml.rb +9 -8
- data/lib/guard/haml/notifier.rb +2 -2
- data/lib/guard/haml/templates/Guardfile +6 -6
- data/lib/guard/haml/version.rb +1 -1
- metadata +19 -29
- data/Gemfile +0 -4
- data/spec/fixtures/fail_test.html.haml +0 -10
- data/spec/fixtures/test.html.haml +0 -9
- data/spec/fixtures/test2.html.haml +0 -9
- data/spec/guard/haml/notifier_spec.rb +0 -39
- data/spec/guard/haml_spec.rb +0 -259
- data/spec/spec_helper.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf3007a54edba5584940b2812d793e1e6bc3ecd1
|
4
|
+
data.tar.gz: a961d482a52ffb5a15c1a8f4a782be9fa653118e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3104170be4cfcba41ed1b2a6f984a3ea9461b2a4b0451e38f4ac98c712ac15b431680e0e83baa368afb24c78a7b71d4245115fadb7d60ade4b0269d2d68f8d6b
|
7
|
+
data.tar.gz: b2e3d6789f279448fdd064152f44152c69e83b07d1fb7ad0046b259e3b0cab5811d07bec076793827a4a2a6fac612760a0a080bafb48747e5ba7cde2df612095
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Moved to [GitHub releases](https://github.com/guard/guard-haml/releases) page.
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (C)
|
1
|
+
Copyright (C) 2013 Immanuel Häussermann, Rémy Coutable
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
19
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,25 +1,29 @@
|
|
1
1
|
# Guard::Haml
|
2
2
|
|
3
|
-
|
3
|
+
[](http://badge.fury.io/rb/guard-haml) [](https://travis-ci.org/guard/guard-haml) [](https://gemnasium.com/guard/guard-haml) [](https://codeclimate.com/github/guard/guard-haml) [](https://coveralls.io/r/guard/guard-haml)
|
4
4
|
|
5
|
-
|
5
|
+
Watches HAML files, compiles them to HTML on change.
|
6
6
|
|
7
|
+
* Compatible with HAML >= 3.
|
8
|
+
* Tested against Ruby 1.9.3, 2.0.0, Rubinius & JRuby (1.9 mode only).
|
7
9
|
|
8
10
|
## Install
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
Install the gem:
|
12
|
+
Please be sure to have [Guard](https://github.com/guard/guard) installed before continuing.
|
13
13
|
|
14
|
-
|
14
|
+
Add Guard::Haml to your `Gemfile`:
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
```ruby
|
17
|
+
group :development do
|
18
|
+
gem 'guard-haml'
|
19
|
+
end
|
20
|
+
```
|
19
21
|
|
20
|
-
Add
|
22
|
+
Add guard definition to your Guardfile by running this command:
|
21
23
|
|
22
|
-
|
24
|
+
```bash
|
25
|
+
$ guard init haml
|
26
|
+
```
|
23
27
|
|
24
28
|
## Options
|
25
29
|
|
@@ -28,9 +32,11 @@ Add a basic guard setup:
|
|
28
32
|
If you want to change the output directory use the `output` option in your
|
29
33
|
Guardfile, e.g.:
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
```ruby
|
36
|
+
guard :haml, output: 'public' do
|
37
|
+
watch %r{^src/.+(\.html\.haml)}
|
38
|
+
end
|
39
|
+
```
|
34
40
|
|
35
41
|
This output is relative to the Guardfile.
|
36
42
|
|
@@ -38,16 +44,19 @@ This output is relative to the Guardfile.
|
|
38
44
|
|
39
45
|
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
46
|
|
41
|
-
|
42
|
-
|
43
|
-
|
47
|
+
```ruby
|
48
|
+
guard :haml, { input: 'markup', output: ['public/dev', 'public/build'] } do
|
49
|
+
watch(%r{^.+(\.haml)$})
|
50
|
+
end
|
51
|
+
```
|
44
52
|
|
45
53
|
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
54
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
```ruby
|
56
|
+
guard :haml, output: 'public', input: 'src' do
|
57
|
+
watch %r{^src/.+(\.html\.haml)}
|
58
|
+
end
|
59
|
+
```
|
51
60
|
So when you edit a file `src/partials/_partial.html.haml`
|
52
61
|
it will be saved to `public/partials/_partial.html` without the `src`.
|
53
62
|
|
@@ -55,7 +64,7 @@ it will be saved to `public/partials/_partial.html` without the `src`.
|
|
55
64
|
|
56
65
|
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
66
|
|
58
|
-
```
|
67
|
+
```ruby
|
59
68
|
"foo.haml" -> "foo.html"
|
60
69
|
"foo" -> "foo.html"
|
61
70
|
"foo.txt" -> "foo.txt.html"
|
@@ -64,39 +73,68 @@ The guard extension will try to add the correct extension based off the input fi
|
|
64
73
|
|
65
74
|
You can override the default extension (`html`) using the `default_ext` option:
|
66
75
|
|
67
|
-
|
68
|
-
|
69
|
-
|
76
|
+
```ruby
|
77
|
+
guard :haml, default_ext: 'txt' do
|
78
|
+
watch %r{^src/.+(\.html\.haml)}
|
79
|
+
end
|
80
|
+
```
|
70
81
|
|
71
82
|
### Compile when starting guard
|
72
83
|
|
73
84
|
If you want to compile haml files on guard start you can use `run_at_start` option.
|
74
85
|
|
75
|
-
|
76
|
-
|
77
|
-
|
86
|
+
```ruby
|
87
|
+
guard :haml, output: 'public', input: 'src', run_at_start: true do
|
88
|
+
watch %r{^src/.+(\.html\.haml)}
|
89
|
+
end
|
90
|
+
```
|
78
91
|
|
79
92
|
### Guard notifications
|
80
93
|
|
81
94
|
Also you can configure guard notifications (to Growl/lib-notify/Notifu) by setting `notifications` option to `true`
|
82
95
|
|
83
|
-
|
84
|
-
|
85
|
-
|
96
|
+
```ruby
|
97
|
+
guard 'haml', output: 'public', input: 'src', notifications: true do
|
98
|
+
watch %r{^src/.+(\.html\.haml)}
|
99
|
+
end
|
100
|
+
```
|
86
101
|
|
87
102
|
### Configuring HAML
|
88
103
|
|
89
104
|
If you want to pass options to the Haml engine, you can set the `haml_options` option, e.g.:
|
90
105
|
|
91
|
-
|
92
|
-
|
93
|
-
|
106
|
+
```ruby
|
107
|
+
guard :haml, output: 'public', input: 'src', haml_options: { ugly: true } do
|
108
|
+
watch %r{^src/.+(\.html\.haml)}
|
109
|
+
end
|
110
|
+
```
|
94
111
|
|
95
112
|
This will produce compressed HTML. See [Haml Reference](http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#options) for more details.
|
96
113
|
|
97
114
|
## Development
|
98
115
|
|
99
|
-
*
|
100
|
-
*
|
116
|
+
* Documentation hosted at [RubyDoc](http://rubydoc.info/gems/guard-haml/frames).
|
117
|
+
* Source hosted at [GitHub](https://github.com/guard/guard-haml).
|
118
|
+
|
119
|
+
Pull requests are very welcome! Please try to follow these simple rules if applicable:
|
120
|
+
|
121
|
+
* Please create a topic branch for every separate change you make.
|
122
|
+
* Make sure your patches are well tested. All specs must pass on [Travis CI](https://travis-ci.org/guard/guard-haml).
|
123
|
+
* Update the [Yard](http://yardoc.org/) documentation.
|
124
|
+
* Update the [README](https://github.com/guard/guard-haml/blob/master/README.md).
|
125
|
+
* Please **do not change** the version number.
|
126
|
+
|
127
|
+
For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
|
128
|
+
`#guard` (irc.freenode.net).
|
129
|
+
|
130
|
+
## Author
|
131
|
+
|
132
|
+
[Immanuel Häussermann](https://github.com/manufaktor) ([@manufaktor](http://twitter.com/manufaktor), [manufaktor.com](http://manufaktor.com))
|
133
|
+
|
134
|
+
## Maintainer
|
135
|
+
|
136
|
+
[Rémy Coutable](https://github.com/rymai) ([@rymai](http://twitter.com/rymai), [rym.ai](http://rym.ai))
|
137
|
+
|
138
|
+
## Contributors
|
101
139
|
|
102
|
-
|
140
|
+
[https://github.com/guard/guard-haml/graphs/contributors](https://github.com/guard/guard-haml/graphs/contributors)
|
data/lib/guard/haml.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'guard'
|
2
|
-
require 'guard/
|
2
|
+
require 'guard/plugin'
|
3
3
|
require 'guard/watcher'
|
4
4
|
require 'haml'
|
5
5
|
|
6
6
|
module Guard
|
7
|
-
class Haml <
|
7
|
+
class Haml < Plugin
|
8
8
|
autoload :Notifier, 'guard/haml/notifier'
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(options = {})
|
11
11
|
@options = {
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
12
|
+
notifications: true,
|
13
|
+
default_ext: 'html',
|
14
|
+
auto_append_file_ext: false
|
15
15
|
}.merge options
|
16
|
-
|
16
|
+
|
17
|
+
super(@options)
|
17
18
|
end
|
18
19
|
|
19
20
|
def start
|
@@ -41,7 +42,7 @@ module Guard
|
|
41
42
|
File.open(output_file, 'w') { |f| f.write(compiled_haml) }
|
42
43
|
end
|
43
44
|
message = "Successfully compiled haml to html!\n"
|
44
|
-
message += "# #{file} -> #{output_files.join(', ')}".gsub("#{Bundler.root.to_s}/", '')
|
45
|
+
message += "# #{file} -> #{output_files.join(', ')}".gsub("#{::Bundler.root.to_s}/", '')
|
45
46
|
::Guard::UI.info message
|
46
47
|
Notifier.notify( true, message ) if @options[:notifications]
|
47
48
|
end
|
data/lib/guard/haml/notifier.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Sample guardfile block for Guard::Haml
|
2
2
|
# You can use some options to change guard-haml configuration
|
3
|
-
# :
|
4
|
-
# :
|
5
|
-
# :
|
6
|
-
# :
|
7
|
-
# :
|
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
8
|
|
9
9
|
guard 'haml' do
|
10
|
-
watch(/^.+(\.html\.haml)
|
10
|
+
watch(/^.+(\.html\.haml)$/)
|
11
11
|
end
|
data/lib/guard/haml/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Immanuel Häussermann
|
8
|
+
- Rémy Coutable
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
+
date: 2013-10-05 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: guard
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- -
|
18
|
+
- - ~>
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
+
version: '2.0'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- -
|
25
|
+
- - ~>
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
+
version: '2.0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: haml
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +40,7 @@ dependencies:
|
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '3.0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
43
|
+
name: bundler
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
46
|
- - '>='
|
@@ -53,7 +54,7 @@ dependencies:
|
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '0'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
+
name: rspec
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
60
|
- - '>='
|
@@ -68,7 +69,7 @@ dependencies:
|
|
68
69
|
version: '0'
|
69
70
|
description: Compiles file.html.haml into file.html
|
70
71
|
email:
|
71
|
-
-
|
72
|
+
- remy@rymai.me
|
72
73
|
executables: []
|
73
74
|
extensions: []
|
74
75
|
extra_rdoc_files: []
|
@@ -77,17 +78,12 @@ files:
|
|
77
78
|
- lib/guard/haml/templates/Guardfile
|
78
79
|
- lib/guard/haml/version.rb
|
79
80
|
- lib/guard/haml.rb
|
81
|
+
- CHANGELOG.md
|
80
82
|
- LICENSE
|
81
83
|
- README.md
|
82
|
-
-
|
83
|
-
|
84
|
-
-
|
85
|
-
- spec/fixtures/test2.html.haml
|
86
|
-
- spec/guard/haml/notifier_spec.rb
|
87
|
-
- spec/guard/haml_spec.rb
|
88
|
-
- spec/spec_helper.rb
|
89
|
-
homepage: ''
|
90
|
-
licenses: []
|
84
|
+
homepage: https://rubygems.org/gems/guard-haml
|
85
|
+
licenses:
|
86
|
+
- MIT
|
91
87
|
metadata: {}
|
92
88
|
post_install_message:
|
93
89
|
rdoc_options: []
|
@@ -97,22 +93,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
93
|
requirements:
|
98
94
|
- - '>='
|
99
95
|
- !ruby/object:Gem::Version
|
100
|
-
version:
|
96
|
+
version: 1.9.2
|
101
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
98
|
requirements:
|
103
99
|
- - '>='
|
104
100
|
- !ruby/object:Gem::Version
|
105
101
|
version: '0'
|
106
102
|
requirements: []
|
107
|
-
rubyforge_project:
|
108
|
-
rubygems_version: 2.0.
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.0.7
|
109
105
|
signing_key:
|
110
106
|
specification_version: 4
|
111
|
-
summary: Guard
|
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
|
117
|
-
- spec/guard/haml_spec.rb
|
118
|
-
- spec/spec_helper.rb
|
107
|
+
summary: Guard plugin for Haml
|
108
|
+
test_files: []
|
data/Gemfile
DELETED
@@ -1,39 +0,0 @@
|
|
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
DELETED
@@ -1,259 +0,0 @@
|
|
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
DELETED
@@ -1,14 +0,0 @@
|
|
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
|