Exemplo n.º 1
0
 /**
  * Creates any templates that do not exist yet, unless the "force" parameter is specified
  *
  * @see "silversmith help"	 
  * @param The parameters, e.g. from the command line
  */
 public static function build_templates($params = array())
 {
     $theme_dir = isset($params['theme']) ? "themes/" . $params['theme'] : false;
     $force = isset($params['force']);
     $specificTemplates = isset($params['list']) ? explode(',', $params['list']) : false;
     if (!$theme_dir) {
         if (self::$project_dir == project()) {
             if (SSViewer::current_theme()) {
                 $theme_dir = "themes/" . SSViewer::current_theme();
             } else {
                 $theme_dir = project();
             }
         } else {
             $theme_dir = self::$project_dir;
         }
     }
     say("Using theme directory {$theme_dir}");
     if (!file_exists($theme_dir)) {
         fail("The theme directory {$theme_dir} does not exist");
     }
     if (!is_dir($theme_dir . "/templates")) {
         mkdir($theme_dir . "/templates");
     }
     $layout_dir = "{$theme_dir}/templates/Layout";
     if (!is_dir($layout_dir)) {
         mkdir($layout_dir);
     }
     $source = "Page.ss";
     if (isset($params['source'])) {
         $source = $params['source'];
     }
     if (!file_exists("{$layout_dir}/{$source}")) {
         fail("Source template {$layout_dir}/{$source} does not exist.");
     }
     if (!file_exists(self::$yaml_path)) {
         fail("File " . self::$yaml_path . " does not exist.");
     }
     SilverSmithProject::load(self::$yaml_path);
     $created = 0;
     say(cell("Status", 11, true, "grey", "on_white") . cell("File", 30, true, "grey", "on_white") . cell("Result", 40, true, "grey", "on_white"));
     line();
     foreach (SilverSmithProject::get_page_types() as $node) {
         if ($node->getKey() == "SiteConfig") {
             continue;
         }
         if ($specificTemplates && !in_array($node->getKey(), $specificTemplates)) {
             continue;
         }
         if (!file_exists("{$layout_dir}/{$node->getKey()}.ss") || $force) {
             $stock = file_get_contents("{$layout_dir}/{$source}");
             $fh = fopen("{$layout_dir}/{$node->getKey()}.ss", "w");
             $created++;
             $notes = "Copied from {$source}";
             if (isset($params['autofill'])) {
                 if (!preg_match('/\\$Content[^A-Za-z0-9_]/', $stock)) {
                     say(cell("Skipped", 2, "white", "on_red") . cell($node->getKey() . ".ss", 30) . cell("Varible \$Content is not in the template.", 40));
                     continue;
                 }
                 $notes .= " [Auto-filled]";
                 $template = new BedrockTemplate(file_get_contents(self::$script_dir . "/code/lib/structures/AutoFill.bedrock"));
                 $template->bind($node);
                 $autofill = $template->render();
                 $filled = preg_replace('/\\$Content([^A-Za-z0-9_])/', "\$Content\n\n{$autofill}\n\n\$1", $stock);
                 fwrite($fh, $filled);
             } else {
                 fwrite($fh, $stock);
             }
             fclose($fh);
             say(cell("Created", 10, true, "white", "on_green") . cell($node->getKey() . ".ss", 30) . cell($notes, 40));
         } else {
             say(cell("Bypassed", 11, true, "grey", "on_yellow") . cell($node->getKey() . ".ss", 30) . cell("File exists. Use --force to override", 40));
         }
     }
     line();
     say("{$created} templates created.");
 }
Exemplo n.º 2
0
         say("Connection error: {$conn->connect_error}");
     }
 }
 DB::connect($databaseConfig);
 say("done");
 $project_dir = isset($PARAMS['module']) ? $PARAMS['module'] : project();
 SilverSmith::set_project_dir($project_dir);
 if ($action != "init") {
     $yml_file = isset($PARAMS['file']) ? $PARAMS['file'] : "_project.yml";
     $yml_path = SilverSmith::get_project_dir() . "/{$yml_file}";
     if (!file_exists($yml_path)) {
         fail("File {$yml_path} does not exist. Use 'silversmith init' to create it.");
     }
     state("Bootstrapping SilverSmith...");
     SilverSmith::set_yaml_path($yml_path);
     SilverSmithProject::load($yml_path);
     SilverSmith::load_field_manifest();
     SilverSmith::load_class_manifest();
     SilverSmith::load_interface_manifest();
     // Check for an upgrade every hour
     $time = time();
     $stamp = @file_get_contents($script_dir . "/upgrade");
     if (!$stamp) {
         $stamp = $time;
     }
     $diff = $time - (int) $stamp;
     if ($diff > 3600) {
         say("Checking for upgrade...");
         SilverSmith::upgrade();
     }
     say("done");