guard-mthaml 0.1.0 → 0.2.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 +3 -2
- data/lib/guard/mthaml/compiler/MtHaml.php +19 -7
- data/lib/guard/mthaml/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df0b052496f3e578ccba291cf4e5b0ac2cfd8d51
|
4
|
+
data.tar.gz: ba8bb2ace11c0739b1523c45e24479e45f932943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0de163ca5c2da5af1d5d102449adefc8d836fd34822e26f83be32da028d4456afa61e0500cd32459c320264ddb471f8e5fc02966e476d994ca5cc4ba5ee93bf9
|
7
|
+
data.tar.gz: f97264ceeb7c54dbc43cd4e019773fd77cfd7c177a7d7e3895288e4af77c5c22f4f22fae6fd40a907ad6e7e264044bd4711b576db6745432f2eaaf2c33a45f69
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Guard::MtHaml
|
1
|
+
# Guard::MtHaml [](http://badge.fury.io/rb/guard-mthaml)
|
2
2
|
This is a Guard wrapper to compile Haml to PHP, Twig or static HTML.
|
3
3
|
|
4
4
|
Add to your `Gemfile`:
|
@@ -17,6 +17,7 @@ $ guard init mthaml
|
|
17
17
|
```
|
18
18
|
|
19
19
|
## Usage
|
20
|
+
Requires that `php` be executable via command line.
|
20
21
|
|
21
22
|
```ruby
|
22
23
|
###
|
@@ -30,5 +31,5 @@ $ guard init mthaml
|
|
30
31
|
# :static_files (false) compile haml to static html
|
31
32
|
# :run_at_start (true) compile files when guard starts
|
32
33
|
###
|
33
|
-
guard :
|
34
|
+
guard :mthaml, :input => "views/src", :output => "views"
|
34
35
|
```
|
@@ -94,7 +94,7 @@ class MtHamlCompiler {
|
|
94
94
|
if( isset( $opts['input'] ) ) {
|
95
95
|
$this->input_file = $opts['input'];
|
96
96
|
} else {
|
97
|
-
throw new \Exception( "No input file was passed into \$opts." );
|
97
|
+
throw new \Exception( self::colorize( "No input file was passed into \$opts.", ";31" ) );
|
98
98
|
}
|
99
99
|
|
100
100
|
/**
|
@@ -103,7 +103,7 @@ class MtHamlCompiler {
|
|
103
103
|
if( isset( $opts['output'] ) ) {
|
104
104
|
$this->output_dir = $opts["output"];
|
105
105
|
} else {
|
106
|
-
throw new \Exception( "No output directory was passed into \$opts." );
|
106
|
+
throw new \Exception( self::colorize( "No output directory was passed into \$opts.", ";31" ) );
|
107
107
|
}
|
108
108
|
|
109
109
|
/**
|
@@ -112,7 +112,7 @@ class MtHamlCompiler {
|
|
112
112
|
if( isset( $opts['options'] ) ) {
|
113
113
|
$this->options = $opts['options'];
|
114
114
|
} else {
|
115
|
-
throw new \Exception( "No options were passed into \$opts." );
|
115
|
+
throw new \Exception( self::colorize( "No options were passed into \$opts.", ";31" ) );
|
116
116
|
}
|
117
117
|
|
118
118
|
/**
|
@@ -121,7 +121,7 @@ class MtHamlCompiler {
|
|
121
121
|
if( isset( $this->options['environment'] ) ) {
|
122
122
|
$this->environment = $this->options['environment'];
|
123
123
|
} else {
|
124
|
-
throw new \Exception( "No environment was passed into \$opts." );
|
124
|
+
throw new \Exception( self::colorize( "No environment was passed into \$opts.", ";31" ) );
|
125
125
|
}
|
126
126
|
|
127
127
|
// Set the MtHaml environment
|
@@ -173,7 +173,7 @@ class MtHamlCompiler {
|
|
173
173
|
"cache" => $this->output_dir . '/cache',
|
174
174
|
));
|
175
175
|
} else {
|
176
|
-
throw new \Exception("To compile static files, please set your environment to PHP. It is currently set to `$this->environment`.");
|
176
|
+
throw new \Exception(self::colorize( "To compile static files, please set your environment to PHP. It is currently set to `$this->environment`.", ";31" ) );
|
177
177
|
}
|
178
178
|
// Compile assets
|
179
179
|
return $this->executor->render( $this->input_file, array() );
|
@@ -209,7 +209,7 @@ class MtHamlCompiler {
|
|
209
209
|
}
|
210
210
|
// If dir is still not writable, throw err
|
211
211
|
if ( ! is_writable( $dir ) ) {
|
212
|
-
throw new \Exception("It looks like the directory `$dir` isn't writable.");
|
212
|
+
throw new \Exception( self::colorize( "It looks like the directory `$dir` isn't writable.", ";31" ) );
|
213
213
|
}
|
214
214
|
}
|
215
215
|
|
@@ -226,9 +226,21 @@ class MtHamlCompiler {
|
|
226
226
|
// Render output
|
227
227
|
return file_put_contents( "$this->output_dir/" . basename( $this->input_file, ".haml" ) . ".$extension", $this->output );
|
228
228
|
} else {
|
229
|
-
throw new \Exception( "It looks like `" . basename( $this->input_file ) . "` compiled without any output." );
|
229
|
+
throw new \Exception( self::colorize( "It looks like `" . basename( $this->input_file ) . "` compiled without any output.", ";33" ) );
|
230
230
|
}
|
231
231
|
}
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Colorize output messages to terminal
|
235
|
+
*
|
236
|
+
* @param {String} $message
|
237
|
+
* @param {String} $color
|
238
|
+
*
|
239
|
+
* @since 0.2.0
|
240
|
+
*/
|
241
|
+
private function colorize($message, $color) {
|
242
|
+
return "\e[0$color" . "m" . "$message\e[0m";
|
243
|
+
}
|
232
244
|
}
|
233
245
|
|
234
246
|
/**
|
data/lib/guard/mthaml/version.rb
CHANGED