Commit 4be69b42 authored by Alexandre Bourget's avatar Alexandre Bourget
Browse files

Add function to include the asciidoc.conf file while compiling.

parent 6b46ac68
...@@ -87,18 +87,32 @@ function check_cache_path() { ...@@ -87,18 +87,32 @@ function check_cache_path() {
* @return mixed NULL or the content of the cache * @return mixed NULL or the content of the cache
*/ */
function get_cache_hash($hash) { function get_cache_hash($hash) {
$fn = get_cache_hash_filename($hash);
if ($fn) {
return file_get_contents($fn);
}
return NULL;
}
/**
* Return the local filename (.cache) in the cache path if it exists
*
* @return string/null Filename of the locally cached file.
*/
function get_cache_hash_filename($hash) {
global $CACHE_PATH; global $CACHE_PATH;
$fn = $CACHE_PATH.'/'.$hash.'.cache'; $fn = $CACHE_PATH.'/'.$hash.'.cache';
if (file_exists($fn)) { if (file_exists($fn)) {
return file_get_contents($fn); return $fn;
} }
return NULL; return NULL;
} }
/** /**
* Write content to cache (identified by $hash) * Write content to cache (identified by $hash)
*/ */
...@@ -119,12 +133,16 @@ function put_cache_hash($hash, $content) { ...@@ -119,12 +133,16 @@ function put_cache_hash($hash, $content) {
* @return string Content of the compiled page. * @return string Content of the compiled page.
*/ */
function compile_page($hash, $page) { function compile_page($hash, $page) {
global $GIT_REPOS; global $GIT_REPOS, $CACHE_PATH;
$output = ''; $output = '';
// Grab the asciidoc.conf file, and put it into cache.
// keep return the hash
$fnconf = bring_local_file('asciidoc.conf');
// -d book so we can render H1s // -d book so we can render H1s
$p = popen("GIT_DIR=".$GIT_REPOS." git-show $hash | asciidoc -d book --no-header-footer -", 'r'); $p = popen("GIT_DIR=".$GIT_REPOS." git-show $hash | asciidoc -f \"".$fnconf."\"-d book --no-header-footer -", 'r');
if (!$p) { if (!$p) {
return "Unable to compile file: $page ($hash)\n"; return "Unable to compile file: $page ($hash)\n";
...@@ -140,34 +158,32 @@ function compile_page($hash, $page) { ...@@ -140,34 +158,32 @@ function compile_page($hash, $page) {
/** /**
* Retrieve the page (without compilation) * Bring a file in the .git repository into a local .cache file
* and return the filename (as $CACHE_PATH/hash.cache)
* *
* This function is just like compile_page(), but it doesn't call asciidoc on it. * This function will prepend the PREFIX to the given git filename ($gitfile)
* @param hash The hash for the required content *
* @param file The filename (only for error reporting) * @param string Gitfile is a filename in the repository (without the PREFIX)
* @return string Original content of the file. * @return string Filename of the local copy of that file (cache/lsakdjflakdj.cache)
*/ */
/* function bring_local_file($gitfile) {
//DUPLICATES get_git_file_content()
function retr_file($hash, $file) {
global $GIT_REPOS;
$output = ''; $hash = get_git_hash($gitfile);
$p = popen("GIT_DIR=".$GIT_REPOS." git-show $hash", 'r'); $fn = get_cache_hash_filename($hash);
if (!$p) { if (!$fn) {
return "Unable to retrieve: $file ($hash)\n"; $cnt = get_git_hash_content($hash);
}
while (!feof($p)) { put_cache_hash($hash, $cnt);
$output .= fread($p, 1024);
// Might return an error, but that's all we can do.
return get_cache_hash_filename($hash);
} }
pclose($p);
return $output; return $fn;
} }
*/
/** /**
* Retrieve file from git's object-ocean * Retrieve file from git's object-ocean
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment