New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template Style Dialog Plugin #1163
Changes from 17 commits
4d6524b
6ea007c
0f5e709
fb7685f
aae321f
831864d
82f9aff
e422a60
9fb9909
b1a864f
a93f9a7
d071b66
123bc81
4f2e8bf
49f1113
e4632ba
91c6cd8
23a5593
8b3eb08
418cb61
f969573
5114259
5ddba45
86c97e9
6667cd8
3e2beab
bcea9d6
c2f2ded
d634152
147d8f4
75c8c6f
8d4151d
b28801b
1dd04f9
84e76a7
cf2c8e7
0bfc8d5
ec2b4ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Config file for travis-ci.org | ||
|
||
language: php | ||
php: | ||
- "5.5" | ||
- "5.4" | ||
- "5.3" | ||
env: | ||
- DOKUWIKI=master | ||
- DOKUWIKI=stable | ||
before_install: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh | ||
install: sh travis.sh | ||
script: cd _test && phpunit --stderr --group plugin_styling |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
styling Plugin for DokuWiki | ||
|
||
Allows to edit style.ini replacements | ||
|
||
All documentation for this plugin can be found at | ||
https://www.dokuwiki.org/plugin:styling | ||
|
||
If you install this plugin manually, make sure it is installed in | ||
lib/plugins/styling/ - if the folder is called different it | ||
will not work! | ||
|
||
Please refer to http://www.dokuwiki.org/plugins for additional info | ||
on how to install plugins in DokuWiki. | ||
|
||
---- | ||
Copyright (C) Andreas Gohr <andi@splitbrain.org> | ||
|
||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; version 2 of the License | ||
|
||
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. | ||
|
||
See the COPYING file in your DokuWiki folder for details |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* General tests for the styling plugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this test make any sense at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not? it was generated by the plugin wizard There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO it is not very useful. There are other things in this plugin which are much more worth writing tests for. I can imagine it was only meant as a starting point for tests in general (as that's the only thing you can test in an otherwise yet unknown plugin) from the plugin wizard's perspective. |
||
* | ||
* @group plugin_styling | ||
* @group plugins | ||
*/ | ||
class general_plugin_styling_test extends DokuWikiTest { | ||
|
||
/** | ||
* Simple test to make sure the plugin.info.txt is in correct format | ||
*/ | ||
public function test_plugininfo() { | ||
$file = __DIR__.'/../plugin.info.txt'; | ||
$this->assertFileExists($file); | ||
|
||
$info = confToHash($file); | ||
|
||
$this->assertArrayHasKey('base', $info); | ||
$this->assertArrayHasKey('author', $info); | ||
$this->assertArrayHasKey('email', $info); | ||
$this->assertArrayHasKey('date', $info); | ||
$this->assertArrayHasKey('name', $info); | ||
$this->assertArrayHasKey('desc', $info); | ||
$this->assertArrayHasKey('url', $info); | ||
|
||
$this->assertEquals('styling', $info['base']); | ||
$this->assertRegExp('/^https?:\/\//', $info['url']); | ||
$this->assertTrue(mail_isvalid($info['email'])); | ||
$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); | ||
$this->assertTrue(false !== strtotime($info['date'])); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* DokuWiki Plugin styling (Action Component) | ||
* | ||
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html | ||
* @author Andreas Gohr <andi@splitbrain.org> | ||
*/ | ||
|
||
// must be run within Dokuwiki | ||
if(!defined('DOKU_INC')) die(); | ||
|
||
/** | ||
* Class action_plugin_styling | ||
* | ||
* This handles all the save actions and loading the interface | ||
* | ||
* All this usually would be done within an admin plugin, but we want to have this available outside | ||
* the admin interface using our floating dialog. | ||
*/ | ||
class action_plugin_styling extends DokuWiki_Action_Plugin { | ||
|
||
/** | ||
* Registers a callback functions | ||
* | ||
* @param Doku_Event_Handler $controller DokuWiki's event controller object | ||
* @return void | ||
*/ | ||
public function register(Doku_Event_Handler $controller) { | ||
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); | ||
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action'); | ||
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_header'); | ||
} | ||
|
||
/** | ||
* Adds the preview parameter to the stylesheet loading in non-js mode | ||
* | ||
* @param Doku_Event $event event object by reference | ||
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this | ||
* handler was registered] | ||
* @return void | ||
*/ | ||
public function handle_header(Doku_Event &$event, $param) { | ||
global $ACT; | ||
global $INPUT; | ||
if($ACT != 'admin' || $INPUT->str('page') != 'styling') return; | ||
if(!auth_isadmin()) return; | ||
|
||
// set preview | ||
$len = count($event->data['link']); | ||
for($i = 0; $i < $len; $i++) { | ||
if( | ||
$event->data['link'][$i]['rel'] == 'stylesheet' && | ||
strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false | ||
) { | ||
$event->data['link'][$i]['href'] .= '&preview=1&tseed='.time(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Updates the style.ini settings by passing it on to handle() of the admin component | ||
* | ||
* @param Doku_Event $event event object by reference | ||
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this | ||
* handler was registered] | ||
* @return void | ||
*/ | ||
public function handle_action(Doku_Event &$event, $param) { | ||
if($event->data != 'styling_plugin') return; | ||
if(!auth_isadmin()) return; | ||
$event->data = 'show'; | ||
|
||
/** @var admin_plugin_styling $hlp */ | ||
$hlp = plugin_load('admin', 'styling'); | ||
$hlp->handle(); | ||
} | ||
|
||
/** | ||
* Create the style form in the floating Dialog | ||
* | ||
* @param Doku_Event $event event object by reference | ||
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this | ||
* handler was registered] | ||
* @return void | ||
*/ | ||
|
||
public function handle_ajax(Doku_Event &$event, $param) { | ||
if($event->data != 'plugin_styling') return; | ||
if(!auth_isadmin()) return; | ||
$event->preventDefault(); | ||
$event->stopPropagation(); | ||
|
||
global $ID; | ||
global $INPUT; | ||
$ID = getID(); | ||
|
||
/** @var admin_plugin_styling $hlp */ | ||
$hlp = plugin_load('admin', 'styling'); | ||
if($INPUT->str('run') == 'preview') { | ||
$hlp->run_preview(); | ||
} else { | ||
$hlp->form(true); | ||
} | ||
} | ||
|
||
} | ||
|
||
// vim:ts=4:sw=4:et: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to swap the name here as well.
I personally don't like either "styler" or "styling". Those names are far too generic and sound like they would do something else. What was wrong with its original name "templatestyler"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is in spirit with "config" and "extension". There was never a "original name". I started with styler which was taken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With "original name" I mean the one I gave the prototype which you based this on. The folder was called "templatestyler".
The problem I have with calling it "styling" is that it's not clear what it is styling. And it is not even "styling" a lot. It is changing existing styles based on a handful of variables.
It is not the same as "config" or "extension".