guard-haml 1.0.0 → 1.1.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/README.md +46 -11
- data/lib/guard/haml.rb +37 -28
- data/lib/guard/haml/templates/Guardfile +1 -1
- data/lib/guard/haml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13cf52ae3f88496081c0f7f37ff2d1697d61c803
|
4
|
+
data.tar.gz: ed755bd3436951a0118a97cc6aa1f57877b122aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0a370863ba296d0d830f2bcbf951858d4bbc259c7d8cc9d903578910eec613402c0690d81d20833b4f7f347ffd533c1f0275adf6af911a7d3f81986d20d1a2c
|
7
|
+
data.tar.gz: 8764f1887b544fbb2ee99261635c819e2ce962a654957879470792dd2c5b8e4e488b3c87d3afa64641323bc5bc3789c5fb749db4249b5195cffe8ce81556fe9e
|
data/README.md
CHANGED
@@ -27,9 +27,30 @@ $ guard init haml
|
|
27
27
|
|
28
28
|
## Options
|
29
29
|
|
30
|
+
### Configuring the input folder + automatic watchers generation
|
31
|
+
|
32
|
+
Use the `:input` option to define the folder where your HAML files are stored.
|
33
|
+
This options also ensure the input folder won't be part of the output path.
|
34
|
+
|
35
|
+
If you set the `:input` option and don't define any watchers, Guard::Haml will
|
36
|
+
automatically generates watchers with the pattern
|
37
|
+
`%r{^#{options[:input]}/(.+(\.html)?\.haml)$}`. For instance:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
guard :haml, input: 'markup'
|
41
|
+
```
|
42
|
+
|
43
|
+
is equivalent to:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
guard :haml, input: 'markup' do
|
47
|
+
watch %r{^markup/(.+(\.html)?\.haml)$}
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
30
51
|
### Configuring the output destination
|
31
52
|
|
32
|
-
If you want to change the output directory use the
|
53
|
+
If you want to change the output directory use the `:output` option in your
|
33
54
|
Guardfile, e.g.:
|
34
55
|
|
35
56
|
```ruby
|
@@ -42,18 +63,20 @@ This output is relative to the Guardfile.
|
|
42
63
|
|
43
64
|
### Multiple output option
|
44
65
|
|
45
|
-
This lets you compile to two (or more) html files from one haml file. This
|
66
|
+
This lets you compile to two (or more) html files from one haml file. This
|
67
|
+
comes in handy if you want to compile to both a dev and prod build directory,
|
68
|
+
for instance:
|
46
69
|
|
47
70
|
```ruby
|
48
|
-
guard :haml,
|
49
|
-
watch
|
71
|
+
guard :haml, input: 'markup', output: ['public/dev', 'public/build'] do
|
72
|
+
watch %r{^.+(\.haml)$}
|
50
73
|
end
|
51
74
|
```
|
52
75
|
|
53
|
-
If you maintain your haml files in a directory that should not be part of the output path, you can set the
|
76
|
+
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.:
|
54
77
|
|
55
78
|
```ruby
|
56
|
-
guard :haml,
|
79
|
+
guard :haml, input: 'src', output: 'public' do
|
57
80
|
watch %r{^src/.+(\.html\.haml)}
|
58
81
|
end
|
59
82
|
```
|
@@ -62,7 +85,7 @@ it will be saved to `public/partials/_partial.html` without the `src`.
|
|
62
85
|
|
63
86
|
### File extensions
|
64
87
|
|
65
|
-
|
88
|
+
Guard::Haml will try to add the correct extension based on the input file name. You can provide multiple extensions to control the file name.
|
66
89
|
|
67
90
|
```ruby
|
68
91
|
"foo.haml" -> "foo.html"
|
@@ -71,7 +94,7 @@ The guard extension will try to add the correct extension based off the input fi
|
|
71
94
|
"foo.php.haml" -> "foo.php"
|
72
95
|
```
|
73
96
|
|
74
|
-
You can override the default extension (`html`) using the
|
97
|
+
You can override the default extension (`html`) using the `:default_ext` option:
|
75
98
|
|
76
99
|
```ruby
|
77
100
|
guard :haml, default_ext: 'txt' do
|
@@ -81,7 +104,7 @@ end
|
|
81
104
|
|
82
105
|
### Compile when starting guard
|
83
106
|
|
84
|
-
If you want to compile haml files
|
107
|
+
If you want to compile haml files when Guard starts you can use `:run_at_start` option.
|
85
108
|
|
86
109
|
```ruby
|
87
110
|
guard :haml, output: 'public', input: 'src', run_at_start: true do
|
@@ -91,7 +114,7 @@ end
|
|
91
114
|
|
92
115
|
### Guard notifications
|
93
116
|
|
94
|
-
|
117
|
+
You can disable Guard notifications by setting `:notifications` option to `false`:
|
95
118
|
|
96
119
|
```ruby
|
97
120
|
guard 'haml', output: 'public', input: 'src', notifications: true do
|
@@ -101,7 +124,7 @@ end
|
|
101
124
|
|
102
125
|
### Configuring HAML
|
103
126
|
|
104
|
-
If you want to pass options to the Haml engine, you can set the
|
127
|
+
If you want to pass options to the Haml engine, you can set the `:haml_options` option, e.g.:
|
105
128
|
|
106
129
|
```ruby
|
107
130
|
guard :haml, output: 'public', input: 'src', haml_options: { ugly: true } do
|
@@ -111,6 +134,18 @@ end
|
|
111
134
|
|
112
135
|
This will produce compressed HTML. See [Haml Reference](http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#options) for more details.
|
113
136
|
|
137
|
+
### List of available options
|
138
|
+
|
139
|
+
``` ruby
|
140
|
+
input: 'markup' # define the folder where your HAML files are stored
|
141
|
+
output: ['public/dev', 'public/build'] # define the output folder where conpiled HAML files are saved
|
142
|
+
default_ext: 'txt' # override the default extension (`html`)
|
143
|
+
run_at_start: false # compile haml files when Guard starts, default: false
|
144
|
+
notifications: false # enable/disable Guard notifications, default: true
|
145
|
+
haml_options: { ugly: true } # HAML options (passed directly to HAML), default: {}
|
146
|
+
auto_append_file_ext: false # automatically append `.html` to the generated files, default: true
|
147
|
+
```
|
148
|
+
|
114
149
|
## Development
|
115
150
|
|
116
151
|
* Documentation hosted at [RubyDoc](http://rubydoc.info/gems/guard-haml/frames).
|
data/lib/guard/haml.rb
CHANGED
@@ -7,18 +7,22 @@ module Guard
|
|
7
7
|
class Haml < Plugin
|
8
8
|
autoload :Notifier, 'guard/haml/notifier'
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
|
10
|
+
def initialize(opts = {})
|
11
|
+
opts = {
|
12
12
|
notifications: true,
|
13
13
|
default_ext: 'html',
|
14
14
|
auto_append_file_ext: false
|
15
|
-
}.merge
|
15
|
+
}.merge(opts)
|
16
16
|
|
17
|
-
super(
|
17
|
+
super(opts)
|
18
|
+
|
19
|
+
if options[:input]
|
20
|
+
watchers << ::Guard::Watcher.new(%r{^#{options[:input]}/(.+(\.html)?\.haml)$})
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
def start
|
21
|
-
run_all if
|
25
|
+
run_all if options[:run_at_start]
|
22
26
|
end
|
23
27
|
|
24
28
|
def stop
|
@@ -35,31 +39,34 @@ module Guard
|
|
35
39
|
|
36
40
|
def run_on_changes(paths)
|
37
41
|
paths.each do |file|
|
38
|
-
|
42
|
+
output_paths = _output_paths(file)
|
39
43
|
compiled_haml = compile_haml(file)
|
40
|
-
|
44
|
+
|
45
|
+
output_paths.each do |output_file|
|
41
46
|
FileUtils.mkdir_p File.dirname(output_file)
|
42
47
|
File.open(output_file, 'w') { |f| f.write(compiled_haml) }
|
43
48
|
end
|
49
|
+
|
44
50
|
message = "Successfully compiled haml to html!\n"
|
45
|
-
message += "# #{file} -> #{
|
51
|
+
message += "# #{file} -> #{output_paths.join(', ')}".gsub("#{::Bundler.root.to_s}/", '')
|
46
52
|
::Guard::UI.info message
|
47
|
-
Notifier.notify(
|
53
|
+
Notifier.notify(true, message) if options[:notifications]
|
48
54
|
end
|
49
|
-
|
55
|
+
|
56
|
+
_notify_other_guard_plugins(paths)
|
50
57
|
end
|
51
58
|
|
52
59
|
private
|
53
60
|
|
54
|
-
def compile_haml
|
61
|
+
def compile_haml(file)
|
55
62
|
begin
|
56
63
|
content = File.new(file).read
|
57
|
-
engine = ::Haml::Engine.new(content, (
|
64
|
+
engine = ::Haml::Engine.new(content, (options[:haml_options] || {}))
|
58
65
|
engine.render
|
59
66
|
rescue StandardError => error
|
60
67
|
message = "HAML compilation failed!\nError: #{error.message}"
|
61
68
|
::Guard::UI.error message
|
62
|
-
Notifier.notify(
|
69
|
+
Notifier.notify(false, message) if options[:notifications]
|
63
70
|
throw :task_has_failed
|
64
71
|
end
|
65
72
|
end
|
@@ -70,13 +77,14 @@ module Guard
|
|
70
77
|
# @param file [String, Array<String>] path to file being built
|
71
78
|
# @return [Array<String>] path(s) to file where output should be written
|
72
79
|
#
|
73
|
-
def
|
80
|
+
def _output_paths(file)
|
74
81
|
input_file_dir = File.dirname(file)
|
75
|
-
file_name =
|
76
|
-
file_name = "#{file_name}.html" if
|
77
|
-
input_file_dir = input_file_dir.gsub(Regexp.new("#{
|
78
|
-
|
79
|
-
|
82
|
+
file_name = _output_filename(file)
|
83
|
+
file_name = "#{file_name}.html" if _append_html_ext_to_output_path?(file_name)
|
84
|
+
input_file_dir = input_file_dir.gsub(Regexp.new("#{options[:input]}(\/){0,1}"), '') if options[:input]
|
85
|
+
|
86
|
+
if options[:output]
|
87
|
+
Array(options[:output]).map do |output_dir|
|
80
88
|
File.join(output_dir, input_file_dir, file_name)
|
81
89
|
end
|
82
90
|
else
|
@@ -100,31 +108,32 @@ module Guard
|
|
100
108
|
# @param file String path to file
|
101
109
|
# @return String file name including extension
|
102
110
|
#
|
103
|
-
def
|
111
|
+
def _output_filename(file)
|
104
112
|
sub_strings = File.basename(file).split('.')
|
105
113
|
base_name, extensions = sub_strings.first, sub_strings[1..-1]
|
106
114
|
|
107
115
|
if extensions.last == 'haml'
|
108
116
|
extensions.pop
|
109
117
|
if extensions.empty?
|
110
|
-
[base_name,
|
118
|
+
[base_name, options[:default_ext]].join('.')
|
111
119
|
else
|
112
120
|
[base_name, extensions].flatten.join('.')
|
113
121
|
end
|
114
122
|
else
|
115
|
-
[base_name, extensions,
|
123
|
+
[base_name, extensions, options[:default_ext]].flatten.join('.')
|
116
124
|
end
|
117
125
|
end
|
118
126
|
|
119
|
-
def
|
120
|
-
return unless
|
121
|
-
|
127
|
+
def _append_html_ext_to_output_path?(filename)
|
128
|
+
return unless options[:auto_append_file_ext]
|
129
|
+
|
130
|
+
filename.match("\.html?").nil?
|
122
131
|
end
|
123
132
|
|
124
|
-
def
|
125
|
-
::Guard.guards.reject{ |guard| guard == self }.each do |guard|
|
133
|
+
def _notify_other_guard_plugins(changed_files)
|
134
|
+
::Guard.guards.reject { |guard| guard == self }.each do |guard|
|
126
135
|
paths = Watcher.match_files(guard, changed_files)
|
127
|
-
guard.run_on_changes
|
136
|
+
guard.run_on_changes(paths) unless paths.empty?
|
128
137
|
end
|
129
138
|
end
|
130
139
|
end
|
data/lib/guard/haml/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Immanuel Häussermann
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard
|