Diffs
WikiHub/trunk/build.conf
@@ -0,0 +1,51 @@
+[project]
+src_dir = src
+release_dir = release
+
+[document]
+doc_dir = doc
+tutorial_file = tutorial.txt
+;; if stylesheet_file is "@http://...". it download file.
+;stylesheet_file = @http://d.hatena.ne.jp/theme/hatena/hatena.css
+stylesheet_file =
+
+[package]
+package_name = WikiHub
+package_type = php
+baseinstalldir = /
+channel = __uri
+summary = WikiHub service commnad
+;description = #
+;notes = #
+;summary_file = <filepath>
+description_file = desc.txt
+notes_file = notes.txt
+
+[role]
+;; role value is <php|data|doc|test|script|src>
+;sh = script
+
+[version]
+release_ver = 1.0.0
+release_stab = stable
+api_ver = 1.0.0
+api_stab = beta
+php_min = 5.1.0
+pear_min = 1.8.0
+
+[license]
+name =The MIT License
+uri =http://www.opensource.org/licenses/mit-license.php
+
+[maintainer://sotarok]
+name = Sotarok Karasawa
+email = sotaro.k@gmail.com
+role = lead
+
+[file://bin/whprev]
+commandscript = whprev
+role = script
+
+[dep://HatenaSyntax]
+type = required
+channel = openpear.org
WikiHub/trunk/src/WikiHub/Exception.php
@@ -0,0 +1,9 @@
+<?php
+/**
+ *
+ *
+ */
+
+class WikiHub_Exception extends Exception
+{
+}
属性に変更があったパス: WikiHub/trunk/src/WikiHub/Exception.php
___________________________________________________________________
名前: svn:keywords
+ Id
名前: svn:eol-style
+ native
WikiHub/trunk/src/WikiHub.php
@@ -0,0 +1,105 @@
+<?php
+
+require_once 'WikiHub/Exception.php';
+require_once 'HatenaSyntax.php';
+
+class WikiHub {
+
+ const VERSION = "1.0.0";
+ const URL = "http://openpear.org/package/WikiHub";
+
+ protected $_dir;
+
+ public $browser = 'w3m';
+ public $browser_option = array(
+ 'w3m' => '-T "text/html"',
+ );
+
+ public function __construct($dir, $browser = "w3m")
+ {
+ $this->_dir = $dir;
+
+ exec('which ' . $browser, $output, $status);
+ if ($status) {
+ throw new WikiHub_Exception("$browser does not installed!\n");
+ }
+
+ $this->browser = $browser;
+ $this->browser_cmd = trim($output[0]);
+ }
+
+ protected function getPath($path)
+ {
+ $path = ltrim($path, "/");
+ return $this->_dir . "/" . $path;
+ }
+
+ public static function getHeader()
+ {
+ return '<h1>Wikihub :: preview</h1>
+ <p> (This is only a preview, it is little different from web view. Inner link doe\'s not work.)</p><hr />';
+ }
+
+ public static function getFooter()
+ {
+ return '<hr /><em> -- powererd by nequal.</em>';
+ }
+
+ public static function runCommand($args)
+ {
+ $o = new self(getcwd());
+ $path = $o->getPath($args);
+ if (!file_exists($path)) {
+ throw new WikiHub_Exception('file is not exists.');
+ }
+
+ $txt = file_get_contents($path);
+
+ $html = self::getHeader();
+ $html .= HatenaSyntax::render($o->getTocIfSectionsCount(3, $txt) . $txt, array(
+ 'headerlevel' => 3,
+ 'htmlescape' => true,
+ 'keywordlinkhandler' => array($o, 'keywordLinkHandler'),
+ )
+ );
+ $html .= self::getFooter();
+
+ $w = popen(join(" ", array($o->browser_cmd, $o->browser_option[$o->browser],)), "w");
+ fwrite($w, $html);
+ pclose($w);
+ }
+
+ public function getTocIfSectionsCount($count, $txt)
+ {
+ $c = preg_match_all('!\n\*+?!', "\n" . $txt, $m);
+ if ($c >= $count) {
+ return "[:contents]\n";
+ }
+ return "";
+ }
+
+ public function keywordlinkhandler($path)
+ {
+ return $path;
+ }
+
+ public static function getUsage()
+ {
+ $version = self::VERSION;
+ $url = self::URL;
+
+ return <<<EEE
+usage: whprev <path>
+
+example:
+ % whprev hoge.html
+ % whprev hoge/fuga.html
+
+whprev - WikiHub preview command.
+ version $version
+ url $url
+ author Sotaro Karasawa
+
+EEE;
+ }
+}
属性に変更があったパス: WikiHub/trunk/src/WikiHub.php
___________________________________________________________________
名前: svn:keywords
+ Id
名前: svn:eol-style
+ native
WikiHub/trunk/src/bin/whprev
@@ -0,0 +1,30 @@
+#!@php_bin@
+<?php
+/**
+#!/usr/bin/env php
+ * whprev
+ *
+ * @package WikiHub
+ * @author sotarok
+ * @license The MIT License
+ * @id $Id$
+ */
+
+require_once 'WikiHub.php';
+
+try {
+ if (!isset($argv)) {
+ throw new WikiHub_Exception('variable $argv is not setted. please check your setting of "register_argc_argv".');
+ }
+ array_shift($argv);
+
+ if (empty($argv)) {
+ echo WikiHub::getUsage();
+ throw new WikiHub_Exception('--');
+ }
+
+ WikiHub::runCommand(array_shift($argv));
+}
+catch (WikiHub_Exception $e) {
+ echo "Error: ", $e->getMessage(), PHP_EOL;
+}