Skip to content

Instantly share code, notes, and snippets.

@CNSKnight
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CNSKnight/fd136926f44710a6785e to your computer and use it in GitHub Desktop.
Save CNSKnight/fd136926f44710a6785e to your computer and use it in GitHub Desktop.
Boilerplate TODOs Includer/Scraper/Formatter using Parsedown Markdown parser ~ enjoy :)

This script will (once customized to your application root, prefered exclude directories, etc):

  • scrape your directory tree for any todo files created in Markdown - see the /regexp/
    • parse them w/Parsedown
    • print them out in the order found
  • scour your .php scripts for in-comment and in-line @todo tags
    • create a Markdown tree following paths/ as scowered
    • parse the tree w/Parsedown
    • Print it
li p + p {
font-family: monospaced;
font-size: 111%;
}
.path {
color: dimgrey;
font-weight: bold;
}
.php {
color: darkblue;
font-weight: bold;
}
.line {
}
.temp {
color: darkorange;
font-weight: bold;
}
.perm {
color: red;
font-weight: bold;
}
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" type="text/css" href="todos.css">
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<?php
/**
* This script will (once customized to your application root, etc):
* + scrape your directory tree for any todo files created in Markdown - see the /regexp/
* + parse them w/Parsedown
* + print them out in the order found
* + scour your .php scripts for in-comment and in-line @todo tags
* + create a Markdown tree following paths/ as scowered
* + parse the tree w/Parsedown
* + Print it
*/
# composer install "erusev/parsedown"
include_once 'vendor/autoload.php';
$Parsedown = new Parsedown();
try {
$fileSPLObjects = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(RELPATH),
RecursiveIteratorIterator::CHILD_FIRST
);
print '<h1>'.count($fileSPLObjects).' ToDo\'s</h1>';
foreach($fileSPLObjects as $fullFileName => $fileSPLObject ) {
if (preg_match('/^\@TODOs.*\.md$/i', $fileSPLObject->getFilename())) {
# echo Utils::_vdd($fullFileName);
print $Parsedown->text(file_get_contents($fullFileName));
}
}
} catch (UnexpectedValueException $e) {
echo $e->message;
}
$todosAry = array();
# example excludes
exec('cd '.RELPATH.' && grep --exclude-dir=ANCILLARIES --exclude-dir=\.doc\&arc --include="*.php" -Rins @todo', $todosAry);
if (count($todosAry)) {
$todosTree = array();
foreach($todosAry as $rawTodo) {
$bits = explode(':', $rawTodo, 2);
$todo = trim($bits[1], " \t\n\r\0\x0B#*"); # not strictly relevant here tho
$bits = explode('/', $bits[0]);
$backref = &$todosTree;
foreach($bits as $bit) {
if (! isset($backref[$bit])) {
$backref[$bit] = array();
}
$backref = &$backref[$bit];
}
$backref[] = $todo;
}
$root = key($todosTree);
print '<h2>In-Comment & In-Line ToDo\'s in <span class="path">'.$root.'/</span></h2>';
$mdAry = array();
writeTodo($mdAry, current($todosTree));
print $Parsedown->text(implode(PHP_EOL.PHP_EOL, $mdAry));
}
/**
* two spaces create nested branch in md tree
* 4-further indented spaces following a newline create paragraphs w/in a list item
*/
function writeTodo(&$mdAry, $branch, $mdPrefix='') {
foreach($branch as $key => $val) {
if (is_array($val)) {
$key = strpos($key, '.php') ? '<span class="php">'.$key.'</span>' : '<span class="path">'.$key.'/</span>';
$mdAry[] = $mdPrefix.'+ '.$key;
writeTodo($mdAry, $val, ' '.$mdPrefix);
} else {
$str = $val;
$str = preg_replace(array('/^([0-9]*):/', '/\s\s+/', '/(\*\s*@todo)/i', '/(\#\s*@todo)/i'), array('<span class="line">$1</span>: ', ' ', '<span class="perm">$1</span>', '<span class="temp">$1</span>'), $str);
$mdAry[] = PHP_EOL.$mdPrefix.$str;
}
}
}
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')</script>
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='//www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','UA-XXXXX-X');ga('send','pageview');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment