forked from vufind-org/vufind
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "mix-ins" capability to theme system. (#963)
- Includes example, tests and generator tool
- Loading branch information
1 parent
35aebdd
commit 97d15fe
Showing
15 changed files
with
284 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Class to generate a new mixin from a template. | ||
* | ||
* PHP version 5 | ||
* | ||
* Copyright (C) Villanova University 2017. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* @category VuFind | ||
* @package Theme | ||
* @author Chris Hallberg <challber@villanova.edu> | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org Main Site | ||
*/ | ||
namespace VuFindTheme; | ||
use Zend\Console\Console; | ||
|
||
/** | ||
* Class to generate a new mixin from a template. | ||
* | ||
* @category VuFind | ||
* @package Theme | ||
* @author Chris Hallberg <challber@villanova.edu> | ||
* @author Demian Katz <demian.katz@villanova.edu> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org Main Site | ||
*/ | ||
class MixinGenerator extends AbstractThemeUtility | ||
{ | ||
/** | ||
* Generate a new mixin from a template. | ||
* | ||
* @param string $name Name of mixin to generate. | ||
* @param string $template Name of template mixin directory | ||
* | ||
* @return bool | ||
*/ | ||
public function generate($name, $template = 'local_mixin_example') | ||
{ | ||
// Check for existing theme | ||
$baseDir = $this->info->getBaseDir() . '/'; | ||
if (realpath($baseDir . $name)) { | ||
return $this->setLastError('Mixin "' . $name . '" already exists'); | ||
} | ||
Console::writeLine('Creating new mixin: "' . $name . '"'); | ||
$source = $baseDir . $template; | ||
$dest = $baseDir . $name; | ||
Console::writeLine("\tCopying $template"); | ||
Console::writeLine("\t\tFrom: " . $source); | ||
Console::writeLine("\t\tTo: " . $dest); | ||
return $this->copyDir($source, $dest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
module/VuFindTheme/tests/unit-tests/fixtures/themes/mixin/js/hello.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alert('hello, mixin'); |
1 change: 1 addition & 0 deletions
1
module/VuFindTheme/tests/unit-tests/fixtures/themes/mixin/js/mixin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// no code in demo file |
4 changes: 4 additions & 0 deletions
4
module/VuFindTheme/tests/unit-tests/fixtures/themes/mixin/mixin.config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
return [ | ||
'js' => ['mixin.js'], | ||
]; |
5 changes: 5 additions & 0 deletions
5
module/VuFindTheme/tests/unit-tests/fixtures/themes/mixin_user/theme.config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
return [ | ||
'extends' => 'child', | ||
'mixins' => ['mixin'], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alert('Your mixin is loaded; please customize it to remove this annoying example script.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
return [ | ||
'js' => ['mixin-popup.js'], | ||
]; |