Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made It possible to pass multiple input paths as option -i

  • Loading branch information...
commit e0554f268efb285f3b9ed67253a0f9b7cf294602 1 parent 88b1ed9
@troelskn authored
Showing with 48 additions and 29 deletions.
  1. +6 −1 bin/phrocco
  2. +42 −28 phrocco.php
View
7 bin/phrocco
@@ -9,7 +9,12 @@ if (count($argv)>1) {
if (!$args["i"]) die("** Error: No input file or directory specified\n");
if (!$args["o"]) echo "** No output directory specified, outputting to current directory\n";
- if (substr($args["i"], 0, 1) != "/") $args["i"] = getcwd()."/".$args["i"];
+ if (is_string($args["i"])) {
+ $args["i"] = array($args["i"]);
+ }
+ foreach ($args["i"] as $index => $path) {
+ if (substr($path, 0, 1) != "/") $args["i"][$index] = getcwd()."/".$path;
+ }
if (substr($args["o"], 0, 1) != "/") $args["o"] = getcwd()."/".$args["o"];
$group = new PhroccoGroup($args);
} else {
View
70 phrocco.php
@@ -67,10 +67,27 @@ class PhroccoGroup {
public $group = array();
public function __construct($options) {
- $this->default['i'] = dirname(__FILE__);
+ $this->default['i'] = array(dirname(__FILE__));
+ $this->default['b'] = getcwd();
$sources = array();
$this->options = $options + $this->defaults;
- $dir_iterator = new PhroccoIterator($this->options["i"]);
+
+ foreach ($options["i"] as $path) {
+ $this->addPath($path, $this->options['b']);
+ }
+ foreach($this->group as $name=>$file) {
+ $file->sources = $this->sources;
+ echo "*** Processing: ".$name."\n";
+ $file->render();
+ }
+ }
+
+ protected function addPath($path, $base_path) {
+ if (is_file($path)) {
+ $this->addFile(new SplFileInfo($path), $base_path);
+ return;
+ }
+ $dir_iterator = new PhroccoIterator($path);
$iterator = new RecursiveIteratorIterator(
$dir_iterator,
RecursiveIteratorIterator::SELF_FIRST
@@ -82,34 +99,31 @@ public function __construct($options) {
in_array($iterator->getExtension(), $this->extensions[$this->options["l"]])
)
{
- $base_path = $this->options["i"];
- $rpath = str_replace($base_path, "",$file->getPath());
- $phrocco = new Phrocco($this->options["l"], $file);
-
- if(!$this->options["o"]) $output_dir = $file->getPath();
- else $output_dir = $this->options["o"];
-
- if($rpath !=$file->getPath()) $output_dir.="/".$rpath;
- if(!is_writable($output_dir)) @mkdir($output_dir, 0777, true);
- if(!is_writable($output_dir)) throw new Exception("Invalid Output Directory - Couldn't Create Because of Permissions");
-
- $file_out = $output_dir."/".$file->getBasename($iterator->getExtension())."html";
- $phrocco->output_file = $file_out;
- $subpath = $iterator->getSubPath();
- $phrocco->path = (!empty($subpath) ? "./" : '') . $subpath;
- $this->group[$file->getBasename()] = $phrocco;
- $subpath .= (!empty($subpath) ? '/' : '');
- $this->sources[] = array(
- "url"=>$subpath.$file->getBasename($iterator->getExtension())."html",
- "name"=>$file->getBasename()
- );
+ $this->addFile($file, $base_path);
}
}
+ }
- foreach($this->group as $name=>$file) {
- $file->sources = $this->sources;
- echo "*** Processing: ".$name."\n";
- $file->render();
- }
+ protected function addFile($file, $base_path) {
+ $rpath = str_replace($base_path, "",$file->getPath());
+ $phrocco = new Phrocco($this->options["l"], $file);
+
+ if(!$this->options["o"]) $output_dir = $file->getPath();
+ else $output_dir = $this->options["o"];
+
+ if($rpath !=$file->getPath()) $output_dir.="/".$rpath;
+ if(!is_writable($output_dir)) @mkdir($output_dir, 0777, true);
+ if(!is_writable($output_dir)) throw new Exception("Invalid Output Directory - Couldn't Create Because of Permissions");
+
+ $file_out = $output_dir."/".preg_replace('/[.][^.]+$/', '.html', $file->getBasename());
+ $phrocco->output_file = $file_out;
+ $subpath = "";
+ $phrocco->path = (!empty($subpath) ? "./" : '') . $subpath;
+ $this->group[$file->getBasename()] = $phrocco;
+ $subpath .= (!empty($subpath) ? '/' : '');
+ $this->sources[] = array(
+ "url"=>$subpath.preg_replace('/[.][^.]+$/', '.html', $file->getBasename()),
+ "name"=>$file->getBasename()
+ );
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.