Exemplo n.º 1
0
 /**
  * Handle $data, and return the results.
  *
  * @param string data The data to handle.
  * @return string
  * @access public
  */
 public function input($data, $options = array())
 {
     $result = null;
     try {
         if (strpos($data, NL) === false && is_file($data)) {
             $data = file_get_contents($data);
             if ($data === false) {
                 throw new \Exception('Could not load data: ' . $data);
             }
         }
         $data_array = explode("\n\n---\n\n", $data, 2);
         $header_handler = \Curator\Handler\Factory::getHandlerForMediaType(\Curator\Handler\YAML::getMediaType());
         $header_data = $header_handler->input($data_array[0]);
         $body_format = $header_data['format'];
         $body_handler = \Curator\Handler\Factory::getHandlerForMediaType($body_format);
         $body_data = $body_handler->input($data_array[1]);
         $result = array();
         $result['header'] = $header_data;
         $result['body'] = $body_data;
         $result['body_raw'] = $data_array[1];
     } catch (\Exception $e) {
         \Curator\Console::stderr('** Could not handle curd data:');
         \Curator\Console::stderr('   ' . $e->getMessage());
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Clean the stylesheet files from public_html/styles.
  * 
  * @access public
  */
 public function clean()
 {
     $dir = $this->project->getPublicStylesDirPath();
     $files = \Curator\FileSystem::getDirectoryContents($dir, array('directories' => false));
     foreach ($files as $path) {
         $rel_path = str_replace($this->project->getProjectDirPath() . DS, '', $path);
         if (file_exists($path)) {
             \Curator\Console::stdout('  Deleting ' . $rel_path);
             if (!unlink($path)) {
                 throw new \Exception('Could not delete: ' . $path);
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Clean the media files from public_html.
  * 
  * @access public
  */
 public function clean()
 {
     foreach ($this->config['directories'] as $dirname) {
         $dir_path = $this->project->getPublicMediaDirPath() . DS . $dirname;
         $rel_path = str_replace($this->project->getProjectDirPath() . DS, '', $dir_path);
         \Curator\Console::stdout(' Cleaning ' . $rel_path);
         $dir_contents = \Curator\FileSystem::getDirectoryContents($dir_path);
         foreach ($dir_contents as $file_path) {
             $filename = pathinfo($file_path, PATHINFO_BASENAME);
             $rel_path = str_replace($this->project->getProjectDirPath() . DS, '', $file_path);
             \Curator\Console::stdout('  Deleting ' . $rel_path);
             unlink($file_path);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Handle $data, and return the results.
  *
  * @param string data The data to handle.
  * @return string
  * @access public
  */
 public function input($data, $options = array())
 {
     include_once CURATOR_APP_DIR . DS . 'Vendors' . DS . 'php-markdown' . DS . 'dist' . DS . 'markdown.php';
     include_once CURATOR_APP_DIR . DS . 'Vendors' . DS . 'php-smartypants' . DS . 'dist' . DS . 'smartypants.php';
     $result = null;
     try {
         if (strpos($data, NL) === false && is_file($data)) {
             $data = file_get_contents($data);
             if ($data === false) {
                 throw new \Exception('Could not load file: ' . $data);
             }
         }
         $result = \SmartyPants(\Markdown($data));
     } catch (\Exception $e) {
         \Curator\Console::stderr('** Could not handle Mardkwon data:');
         \Curator\Console::stderr('   ' . $e->getMessage());
     }
     return $result;
 }
Exemplo n.º 5
0
 /**
  * Handle $data, and return the results.
  *
  * @param string data The data to handle.
  * @return string
  * @access public
  */
 public function input($data, $options = array())
 {
     $default_options = array('minify' => true);
     $result = null;
     $options = array_merge($default_options, $options);
     try {
         if (strpos($data, NL) === false && is_file($data)) {
             $data = file_get_contents($data);
             if ($data === false) {
                 throw new \Exception('Could not load CSS: ' . $data);
             }
         }
         require_once CURATOR_APP_DIR . DS . 'Vendors' . DS . 'css-compressor' . DS . 'dist' . DS . 'src' . DS . 'CSSCompression.php';
         $result = \CSSCompression::express($data, 'sane');
     } catch (\Exception $e) {
         \Curator\Console::stderr('** Could not handle CSS data:');
         \Curator\Console::stderr('  ' . $e->getMessage());
     }
     return $result;
 }
Exemplo n.º 6
0
 /**
  * Handle $data, and return the results.
  *
  * @param string data The data to handle.
  * @return string
  * @access public
  */
 public function input($data, $options = array())
 {
     $result = null;
     try {
         if (strpos($data, NL) === false && is_file($data)) {
             $data = file_get_contents($data);
             if ($data === false) {
                 throw new \Exception('Could not load data: ' . $data);
             }
         }
         foreach ($options as $key => $value) {
             $needle = '%%__' . strtoupper($key) . '__%%';
             $data = str_replace($needle, $value, $data);
         }
         $result = $data;
     } catch (\Exception $e) {
         \Curator\Console::stderr('** Could not handle basic template data:');
         \Curator\Console::stderr('   ' . $e->getMessage());
     }
     return $result;
 }
Exemplo n.º 7
0
 /**
  * Clean the data files from public_html.
  * 
  * @access public
  */
 public function clean()
 {
     // Get our cast of characters.
     $data_dir = $this->project->getDataDirPath();
     $data_files = \Curator\FileSystem::getDirectoryContents($data_dir);
     foreach ($data_files as $data_file) {
         // Gather our facts here.
         $data_info = pathinfo($data_file);
         $data_ext = $data_info['extension'];
         $data_rel = str_replace($this->project->getProjectDirPath() . DS, '', $data_file);
         // relative from the project dir.
         $data_media = \Curator\Handler\Factory::getMediaTypeForFileExtension($data_ext);
         // load the data file.
         $handler = \Curator\Handler\Factory::getHandlerForMediaType($data_media);
         $data = $handler->input($data_file);
         // See if the file specifies a special name, otherwise hack
         // together something resembling the data's filename.
         if (isset($data['header']['url'])) {
             $filename = $data['header']['url'];
         } else {
             $filename = pathinfo($data_file, PATHINFO_FILENAME) . '.html';
         }
         $output_path = $this->project->getPublicHtmlDirPath() . DS . $filename;
         if (file_exists($output_path)) {
             \Curator\Console::stdout('  Deleting public_html' . DS . $filename);
             if (!unlink($output_path)) {
                 throw new \Exception('Could not delete: ' . $output_path);
             }
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Cleans the current project.
  * 
  * @access public
  */
 public function clean()
 {
     $manifest_path = $this->getProjectDirPath() . DS . 'manifest.yml';
     if (!is_file($manifest_path)) {
         throw new \Exception('Could not locate manifest at: ' . $manifest_path);
     }
     $manifest = \Curator\Config\YAML::LoadFromFile($manifest_path);
     \Curator\Console::stdout('Project Directory: ' . $this->getProjectDirPath());
     \Curator\Console::stdout('');
     $builder = new \Curator\Builder\Styles();
     $builder->setProject($this);
     \Curator\Console::stdout(' Cleaning styles…');
     $builder->clean();
     \Curator\Console::stdout('');
     $builder = new \Curator\Builder\Scripts();
     $builder->setProject($this);
     \Curator\Console::stdout(' Cleaning scripts…');
     $builder->clean();
     \Curator\Console::stdout('');
     $builder = new \Curator\Builder\Data();
     $builder->setProject($this);
     \Curator\Console::stdout(' Cleaning data…');
     $builder->clean();
     \Curator\Console::stdout('');
     $builder = new \Curator\Builder\Media();
     $builder->setProject($this);
     \Curator\Console::stdout(' Cleaning media…');
     $builder->clean();
     \Curator\Console::stdout('');
 }
Exemplo n.º 9
0
 /**
  * Convert $data (using $options) for writing as a string.
  * 
  * @param string $data The data to convert.
  * @param array $options The options for converting data.
  * @return string
  * @access public
  */
 public function output($data, $options = array())
 {
     include_once CURATOR_APP_DIR . DS . 'Vendors' . DS . 'yaml' . DS . 'dist' . DS . 'lib' . DS . 'sfYamlDumper.php';
     $yaml = new \sfYamlDumper();
     $result = null;
     try {
         $result = $yaml->dump($data);
     } catch (\Exception $e) {
         \Curator\Console::stderr('** Unable to convert array to YAML:');
         \Curator\Console::stderr('   ', $e->getMessage());
     }
     return $result;
 }