class YAMLFrontMatterExporter in Loft Data Grids 7.2
Class YAMLFrontMatterExporter
@link http://symfony.com/doc/current/components/yaml/introduction.html @link http://assemble.io/docs/YAML-front-matter.html
Hierarchy
- class \AKlump\LoftDataGrids\Exporter implements ExporterInterface
- class \AKlump\LoftDataGrids\YAMLFrontMatterExporter implements ExporterInterface
Expanded class hierarchy of YAMLFrontMatterExporter
File
- vendor/
aklump/ loft_data_grids/ src/ AKlump/ LoftDataGrids/ YAMLFrontMatterExporter.php, line 13
Namespace
AKlump\LoftDataGridsView source
class YAMLFrontMatterExporter extends Exporter implements ExporterInterface {
public function __construct(ExportDataInterface $data = null, $filename = '') {
parent::__construct($data, $filename);
unset($this->extension);
}
/**
* We use this magic method to have a configurable extension
*
* @param $key
*
* @return null
*/
public function __get($key) {
if ($key === 'extension') {
return $this->settings->extension;
}
return null;
}
protected function setSettingsDefault() {
parent::setSettingsDefault();
/**
* This is the data key used to fill the body of the file; every other key will be interpreted as YAML frontmatter.
*/
$this->settings->bodyKey = 'body';
$this->settings->extension = '.html';
return $this;
}
public function getInfo() {
$info = parent::getInfo();
$info = array(
'name' => 'YAML Front Matter Format',
'shortname' => 'YAML Front Matter',
'description' => 'Export data as text file with YAML Front Matter. For more information visit: http://www.yaml.org.',
) + $info;
return $info;
}
public function compile($page_id = null) {
$bodyKey = $this->settings->bodyKey;
// We will only operate on the current page.
$data = $this
->getData()
->getPage();
// We ignore all but the first row
$row = reset($data);
$build = array();
$this->output = '';
if ($data) {
$build[] = '---';
if ($build['fm'] = array_diff_key($row, array(
$bodyKey => null,
))) {
$build['fm'] = trim(Yaml::dump($build['fm']));
}
$build[] = '---';
if (empty($build['fm'])) {
$build = array();
}
$build['body'] = isset($row[$bodyKey]) ? $row[$bodyKey] : '';
$this->output = implode(PHP_EOL, $build);
}
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Exporter:: |
protected | property | ||
Exporter:: |
protected | property | ||
Exporter:: |
protected | property | ||
Exporter:: |
public | function |
Adds/Updates a single setting by name. Overrides ExporterInterface:: |
|
Exporter:: |
protected | function | ||
Exporter:: |
protected | function | Iterate over all cells and transform data as appropriate. | |
Exporter:: |
public | function |
Export data as a string Overrides ExporterInterface:: |
1 |
Exporter:: |
protected | function | Return a string as a safe filename | |
Exporter:: |
public | function |
Format a single column with format by string Overrides ExporterInterface:: |
1 |
Exporter:: |
public | function |
Return the ExportDataInterface object Overrides ExporterInterface:: |
|
Exporter:: |
protected | function | Convert ExportData to an array transforming every cell. | |
Exporter:: |
public | function |
Get the filename Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Return an array each of the keys present in the data on a page. Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Return the settings object. Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Return the showPageIds. Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Set the exporter to hide page ids. Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Stream as a file to the server with headers. Overrides ExporterInterface:: |
1 |
Exporter:: |
public | function |
Compile and and save to a filepath. Overrides ExporterInterface:: |
2 |
Exporter:: |
public | function |
Set the export data object Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Getter/Setter for the filename Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Set the settings object. Overrides ExporterInterface:: |
|
Exporter:: |
public | function |
Set a title for the exported document Overrides ExporterInterface:: |
1 |
Exporter:: |
public | function |
Set the exporter to display page ids. Overrides ExporterInterface:: |
|
YAMLFrontMatterExporter:: |
public | function |
Build the string content of $this->output and return $this for chaining. Overrides ExporterInterface:: |
|
YAMLFrontMatterExporter:: |
public | function |
Return info about this class Overrides Exporter:: |
|
YAMLFrontMatterExporter:: |
protected | function |
Setup default values on object data. Overrides Exporter:: |
|
YAMLFrontMatterExporter:: |
public | function |
Constructor Overrides Exporter:: |
|
YAMLFrontMatterExporter:: |
public | function | We use this magic method to have a configurable extension |