Skip to content

Commit d1c0d57

Browse files
committed
#82 - Improve help docs. Allow remote sources.
1 parent 20cbc09 commit d1c0d57

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

src/Console/fileconverter.drush.inc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
use FileConverter\drush_print;
23
/*
34
* This file is part of the FileConverter package.
45
*
@@ -47,6 +48,9 @@ function fileconverter_drush_command() {
4748
'optimize' => array(
4849
'description' => 'Optimize the destination file',
4950
),
51+
'allow-remote' => array(
52+
'description' => 'Allow remote paths (e.g., http://)',
53+
),
5054
'replace-string' => array(
5155
'description' => 'JSON Object: Configure text replacements',
5256
'example-value' => '{"search":"replace"}',
@@ -123,6 +127,7 @@ function drush_fileconverter_convert($source = NULL, $destination = NULL) {
123127
$fc = FileConverter\FileConverter::factory();
124128
$stdin = $stdout = FALSE;
125129
$force_conversion = trim(drush_get_option('conversion'));
130+
$is_remote = FALSE;
126131
if (preg_match('@^(.*):(.*)$@', $force_conversion, $arr)) {
127132
$force_conversion = array(
128133
$arr[1],
@@ -153,8 +158,13 @@ function drush_fileconverter_convert($source = NULL, $destination = NULL) {
153158
}
154159
}
155160
if (!is_file($source)) {
156-
drush_print(dt("Error: Unable to locate source file."));
157-
return;
161+
if (drush_get_option('allow-remote') === TRUE && strpos($source, '://') !== FALSE) {
162+
$is_remote = TRUE;
163+
}
164+
else {
165+
drush_print(dt("Error: Unable to locate source file."));
166+
return;
167+
}
158168
}
159169
}
160170
if ($destination{0} !== '/') {
@@ -183,9 +193,14 @@ function drush_fileconverter_convert($source = NULL, $destination = NULL) {
183193

184194
// Convert the file.
185195
$fc = FileConverter\FileConverter::factory();
186-
if (realpath($source) !== realpath($destination)) {
196+
if ($is_remote || realpath($source) !== realpath($destination)) {
187197
$convert_path = isset($force_conversion) ? join('->', $force_conversion) : NULL;
188-
$fc->convertFile(realpath($source), $destination, $convert_path);
198+
try {
199+
$fc->convertFile($is_remote ? $source : realpath($source), $destination, $convert_path);
200+
} catch (\Exception $e) {
201+
drush_print($e->getMessage());
202+
return;
203+
}
189204
}
190205

191206
// Further commands can work on a single file, so use a default destination.

src/Engine/Convert/PhantomJs.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getConvertFileShell($source, &$destination) {
5151
$this->cmd,
5252
Shell::argOptions($this->cmd_options, $this->configuration, 1),
5353
realpath(__DIR__ . '/Resources/PhantomJs-rasterize.js'),
54-
'file://' . $source,
54+
(strpos($source, '://') === FALSE ? 'file://' . $source : $source),
5555
$destination,
5656
$dimensions,
5757
$zoom,
@@ -65,6 +65,7 @@ protected function getHelpInstallation($os, $os_version) {
6565
'url' => 'http://phantomjs.org/',
6666
);
6767
switch ($os) {
68+
case 'Ubuntu':
6869
case 'Ubuntu (12.04 LTS)':
6970
$help['os'] = 'confirmed on Ubuntu 12.04';
7071
$help['apt-get'] = 'phantomjs xvfb';

src/Engine/EngineBase.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ public function getHelp($type = 'installation') {
135135
switch ($type) {
136136
case 'installation':
137137
$help = $this->getHelpInstallation($os, $os_version);
138-
if (isset($help) && !is_string($help)) {
139-
$help = var_export($help, 1);
138+
if (isset($help)) {
139+
if (!is_string($help)) {
140+
$help = var_export($help, 1);
141+
}
140142
}
141143
return $help;
142144
}
@@ -145,16 +147,9 @@ public function getHelp($type = 'installation') {
145147
}
146148

147149
protected function getHelpInstallation($os, $os_version) {
148-
if (isset($os)) {
149-
return array(
150-
'title' => "No installation instructions available.",
151-
);
152-
}
153-
else {
154-
return array(
155-
'title' => "No installation instructions available for your platform.",
156-
);
157-
}
150+
return array(
151+
'title' => "Unable to confirm installation instructions for OS='$os' Ver='$os_version'",
152+
);
158153
}
159154

160155
public function getTempFile($file_extension = NULL) {

0 commit comments

Comments
 (0)