Skip to content

Commit

Permalink
Add namespace to partials and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
TJ Draper committed Oct 23, 2015
1 parent 3393586 commit 2d25aa1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions system/user/addons/template_sync/Controller/SyncPartials.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public function run()
$partialSyncService = ee('template_sync:SyncPartialsService');

// Get partials
$partials = $partialFileService->get('partials');
$partials = $partialFileService->get('partials', 'partial:');

// Get variables
$variables = $partialFileService->get('variables');
$variables = $partialFileService->get('variables', 'variable:');

// Sync partials
$partialSyncService->run('Snippet', $partials);
Expand Down
14 changes: 11 additions & 3 deletions system/user/addons/template_sync/Service/PartialFileTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
class PartialFileTemplates
{
private $returnTemplates = array();
private $namespace = '';

/**
* Get partial file templates from file system
*
* @return array
*/
public function get($path)
public function get($path, $namespace = '')
{
$this->namespace = $namespace;

// Set variables
$templateBasePath = SYSPATH . 'user/templates/';
$path = $templateBasePath . ee()->config->item('site_short_name') .
Expand All @@ -26,7 +29,12 @@ public function get($path)
// Recursively load files
$this->processRecursively($path);

return $this->returnTemplates;
// Reset for next use
$returnTemplates = $this->returnTemplates;
$this->returnTemplates = array();
$this->namespace = '';

return $returnTemplates;
}

/**
Expand Down Expand Up @@ -55,7 +63,7 @@ private function processRecursively($path, $prefix = '')

// Make sure hidden files (starting with .) are not included
if ($pathInfo['filename']) {
$this->returnTemplates[$prefix . $pathInfo['filename']] = $content;
$this->returnTemplates[$this->namespace . $prefix . $pathInfo['filename']] = $content;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion system/user/addons/template_sync/Service/SyncPartials.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SyncPartials
public function run($model, $data)
{
$name = $model === 'Snippet' ? 'snippet_name' : 'variable_name';
$content = $model == 'Snippet' ? 'snippet_contents' : 'variable_data';
$content = $model === 'Snippet' ? 'snippet_contents' : 'variable_data';

// Get existing partials
$partials = ee('Model')->get($model)->all();
Expand Down

0 comments on commit 2d25aa1

Please sign in to comment.