|
14 | 14 |
|
15 | 15 | use \PatternLab\Config;
|
16 | 16 | use \PatternLab\Data;
|
| 17 | +use \PatternLab\Parsers\Documentation; |
17 | 18 | use \PatternLab\PatternData\Exporters\NavItemsExporter;
|
18 | 19 | use \PatternLab\PatternData\Exporters\PatternPartialsExporter;
|
19 | 20 | use \PatternLab\PatternData\Exporters\PatternPathDestsExporter;
|
@@ -73,6 +74,70 @@ protected function gatherMQs() {
|
73 | 74 |
|
74 | 75 | }
|
75 | 76 |
|
| 77 | + protected function generateAnnotations() { |
| 78 | + |
| 79 | + $annotations = array(); |
| 80 | + $annotations["comments"] = array(); |
| 81 | + |
| 82 | + // iterate over all of the files in the annotations dir |
| 83 | + $directoryIterator = new \RecursiveDirectoryIterator(Config::$options["sourceDir"]."/_annotations"); |
| 84 | + $objects = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST); |
| 85 | + |
| 86 | + // make sure dots are skipped |
| 87 | + $objects->setFlags(\FilesystemIterator::SKIP_DOTS); |
| 88 | + |
| 89 | + foreach ($objects as $name => $object) { |
| 90 | + |
| 91 | + // if it's an .md file parse and generate the proper info |
| 92 | + if ($object->isFile() && ($object->getExtension() == "md")) { |
| 93 | + |
| 94 | + $data = array(); |
| 95 | + $data[0] = array(); |
| 96 | + |
| 97 | + $text = file_get_contents($object->getPathname()); |
| 98 | + list($yaml,$markdown) = Documentation::parse($text); |
| 99 | + |
| 100 | + if (isset($yaml["el"]) || isset($yaml["selector"])) { |
| 101 | + $data[0]["el"] = (isset($yaml["el"])) ? $yaml["el"] : $yaml["selector"]; |
| 102 | + } else { |
| 103 | + $data[0]["el"] = "#someimpossibleselector"; |
| 104 | + } |
| 105 | + $data[0]["title"] = isset($yaml["title"]) ? $yaml["title"] : ""; |
| 106 | + $data[0]["comment"] = $markdown; |
| 107 | + |
| 108 | + $annotations["comments"] = array_merge($annotations["comments"],$data); |
| 109 | + |
| 110 | + } |
| 111 | + |
| 112 | + } |
| 113 | + |
| 114 | + // read in the old style annotations.js, modify the data and generate JSON array to merge |
| 115 | + if (file_exists(Config::$options["sourceDir"]."/_annotations/annotations.js")) { |
| 116 | + $text = file_get_contents(Config::$options["sourceDir"]."/_annotations/annotations.js"); |
| 117 | + $text = str_replace("var comments = ","",$text); |
| 118 | + $text = rtrim($text,";"); |
| 119 | + $data = json_decode($text,true); |
| 120 | + if ($jsonErrorMessage = JSON::hasError()) { |
| 121 | + JSON::lastErrorMsg("_annotations/annotations.js",$jsonErrorMessage,$data); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + // merge in any data from the old file |
| 126 | + $annotations["comments"] = array_merge($annotations["comments"],$data["comments"]); |
| 127 | + |
| 128 | + // encode the content so it can be written out |
| 129 | + $json = json_encode($annotations); |
| 130 | + |
| 131 | + // make sure annotations/ exists |
| 132 | + if (!is_dir(Config::$options["publicDir"]."/annotations")) { |
| 133 | + mkdir(Config::$options["publicDir"]."/annotations"); |
| 134 | + } |
| 135 | + |
| 136 | + // write out the new annotations.js file |
| 137 | + file_put_contents(Config::$options["publicDir"]."/annotations/annotations.js","var comments = ".$json.";"); |
| 138 | + |
| 139 | + } |
| 140 | + |
76 | 141 | /**
|
77 | 142 | * Generates the index page and style guide
|
78 | 143 | */
|
|
0 commit comments