Created
August 17, 2008 04:34
-
-
Save subtleGradient/5787 to your computer and use it in GitHub Desktop.
Yuffster's MooTools CheatSheet Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // By Yuffster | |
| function getDox($file) { | |
| $docs = file_get_contents("docs/$file.md"); | |
| $funcPatt = "/(.*?)?(Function|Method): (.*?) ?{(#.*?)}?\n/"; | |
| $argPatt = "/^[-*1-9]+.*?\(\*(.*?)\*(, optional)?/"; | |
| //This docs array will be for all the files and classes. | |
| $dox = Array(); | |
| //First, let's chop up the docs into sections. | |
| preg_match_all($funcPatt, $docs, $delims); | |
| $delims = array_shift($delims); | |
| $sections = preg_split($funcPatt, $docs); | |
| //For every function or method... | |
| foreach ($sections as $i => $txt) { | |
| $funLine = $delims[($i-1)]; | |
| preg_match_all($funcPatt, $funLine, $argh); | |
| $class = trim($argh[1][0]); | |
| if ($class == "") $class = "Window"; | |
| $funray['name'] = trim($argh[3][0]); | |
| $funray['link'] = "http://docs.mootools.net/$file".trim($argh[4][0]); | |
| // I'm pretty sure I'm going to programmer hell for these next lines. | |
| if ($funray['name']) { | |
| //Deal with the bits of the Function/Method title line | |
| //Break up the method's shit into sections. | |
| $subsecs = explode("###", $txt); | |
| //Do shit with the Arguments section. | |
| foreach ($subsecs as $subsec) { | |
| //$subsec = str_replace("\t", " ", $subsec); | |
| $args = Array(); | |
| if (preg_match("/^\sArguments/", $subsec)) { | |
| $lines = explode("\n", $subsec); | |
| $optend = null; | |
| $i = -1; | |
| foreach ($lines as $line) { | |
| //Look for standard arguments syntax. | |
| if (preg_match($argPatt, $line)) { | |
| //Now get the listed type of the arg and put that in the args array. | |
| preg_match_all($argPatt, $line, $match); | |
| list ($tmp, $type, $opt) = $match; | |
| //Stars denote optional parameters. | |
| if ($opt[0] == ", optional" && $optend == null) { | |
| $type[0] = "<span class=\"optional\">$type[0]"; | |
| $optend = "</span>"; | |
| } $args[] = $type[0]; | |
| $i++; | |
| } | |
| } //For every line in an arguments section. | |
| if ($optend) $args[$i] = $args[$i].$optend; | |
| if ($i == -1) $args[] = "*"; | |
| $funray['args'] = $args; | |
| } //Arguments section handling. | |
| } //Section handling. | |
| $dox[$class][] = $funray; | |
| }//End if $funray[name] | |
| // End programmer hell lines (sorry). | |
| }//Foreach function | |
| return $dox; | |
| } | |
| function rglob($path, $match = null) { | |
| if ($match == null) { $match = "*"; } | |
| $files = glob("$path/$match"); | |
| if (count($files) == 0) { return false; } | |
| $return = Array(); | |
| foreach ($files as $file) { | |
| if (is_dir($file)) { | |
| foreach (rglob("$file$match") as $f) $return[] = $f; | |
| } else { | |
| $return[] = $file; | |
| } | |
| } | |
| return $return; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment