guard-haml 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf3007a54edba5584940b2812d793e1e6bc3ecd1
4
- data.tar.gz: a961d482a52ffb5a15c1a8f4a782be9fa653118e
3
+ metadata.gz: 13cf52ae3f88496081c0f7f37ff2d1697d61c803
4
+ data.tar.gz: ed755bd3436951a0118a97cc6aa1f57877b122aa
5
5
  SHA512:
6
- metadata.gz: 3104170be4cfcba41ed1b2a6f984a3ea9461b2a4b0451e38f4ac98c712ac15b431680e0e83baa368afb24c78a7b71d4245115fadb7d60ade4b0269d2d68f8d6b
7
- data.tar.gz: b2e3d6789f279448fdd064152f44152c69e83b07d1fb7ad0046b259e3b0cab5811d07bec076793827a4a2a6fac612760a0a080bafb48747e5ba7cde2df612095
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 `output` option in your
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 comes in handy if you want to compile to both a dev and prod build directory, for example:
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, { input: 'markup', output: ['public/dev', 'public/build'] } do
49
- watch(%r{^.+(\.haml)$})
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 `input` option, e.g.:
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, output: 'public', input: 'src' do
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
- 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.
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 `default_ext` option:
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 on guard start you can use `run_at_start` option.
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
- Also you can configure guard notifications (to Growl/lib-notify/Notifu) by setting `notifications` option to `true`
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 `haml_options` option, e.g.:
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).
@@ -7,18 +7,22 @@ module Guard
7
7
  class Haml < Plugin
8
8
  autoload :Notifier, 'guard/haml/notifier'
9
9
 
10
- def initialize(options = {})
11
- @options = {
10
+ def initialize(opts = {})
11
+ opts = {
12
12
  notifications: true,
13
13
  default_ext: 'html',
14
14
  auto_append_file_ext: false
15
- }.merge options
15
+ }.merge(opts)
16
16
 
17
- super(@options)
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 @options[:run_at_start]
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
- output_files = get_output(file)
42
+ output_paths = _output_paths(file)
39
43
  compiled_haml = compile_haml(file)
40
- output_files.each do |output_file|
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} -> #{output_files.join(', ')}".gsub("#{::Bundler.root.to_s}/", '')
51
+ message += "# #{file} -> #{output_paths.join(', ')}".gsub("#{::Bundler.root.to_s}/", '')
46
52
  ::Guard::UI.info message
47
- Notifier.notify( true, message ) if @options[:notifications]
53
+ Notifier.notify(true, message) if options[:notifications]
48
54
  end
49
- notify paths
55
+
56
+ _notify_other_guard_plugins(paths)
50
57
  end
51
58
 
52
59
  private
53
60
 
54
- def compile_haml file
61
+ def compile_haml(file)
55
62
  begin
56
63
  content = File.new(file).read
57
- engine = ::Haml::Engine.new(content, (@options[:haml_options] || {}))
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( false, message ) if @options[:notifications]
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 get_output(file)
80
+ def _output_paths(file)
74
81
  input_file_dir = File.dirname(file)
75
- file_name = get_file_name(file)
76
- file_name = "#{file_name}.html" if append_file_ext_to_output_path?(file_name)
77
- input_file_dir = input_file_dir.gsub(Regexp.new("#{@options[:input]}(\/){0,1}"), '') if @options[:input]
78
- if @options[:output]
79
- Array(@options[:output]).map do |output_dir|
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 get_file_name(file)
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, @options[:default_ext]].join('.')
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, @options[:default_ext]].flatten.join('.')
123
+ [base_name, extensions, options[:default_ext]].flatten.join('.')
116
124
  end
117
125
  end
118
126
 
119
- def append_file_ext_to_output_path?(file_name)
120
- return unless @options[:auto_append_file_ext]
121
- file_name.match("\.html?").nil?
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 notify(changed_files)
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 paths unless paths.empty?
136
+ guard.run_on_changes(paths) unless paths.empty?
128
137
  end
129
138
  end
130
139
  end
@@ -6,6 +6,6 @@
6
6
  # notifications: true send notifictions to Growl/libnotify/Notifu
7
7
  # haml_options: { ugly: true } pass options to the Haml engine
8
8
 
9
- guard 'haml' do
9
+ guard :haml do
10
10
  watch(/^.+(\.html\.haml)$/)
11
11
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  class HamlVersion
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
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.0.0
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-05 00:00:00.000000000 Z
12
+ date: 2013-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard