Skip to content
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

Merged
merged 38 commits into from Jul 26, 2015
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4d6524b
allow preview style replacements
splitbrain May 16, 2015
6ea007c
a first very basic implementation of the preview mechanism
splitbrain May 16, 2015
0f5e709
we have working save and revert buttons
splitbrain May 16, 2015
fb7685f
more improvements
splitbrain May 16, 2015
aae321f
make styler plugin work without javascript as well (partly done)
splitbrain May 17, 2015
831864d
make styler work without JS as well
splitbrain May 17, 2015
82f9aff
started to localize the styler plugin
splitbrain May 17, 2015
e422a60
added color picker support
splitbrain May 17, 2015
9fb9909
added more localization
splitbrain May 17, 2015
b1a864f
fix keeping the current page
splitbrain May 17, 2015
a93f9a7
allow resizing the dialog
splitbrain May 17, 2015
d071b66
autopreview in styler plugin
splitbrain May 17, 2015
123bc81
renamed plugin from styler to styling
splitbrain May 23, 2015
4f2e8bf
fixed ajax endpoint for styling plugin
splitbrain May 23, 2015
49f1113
avoid double ampersand in url
splitbrain May 23, 2015
e4632ba
Scrutinizer Auto-Fixes
scrutinizer-auto-fixer May 23, 2015
91c6cd8
Merge pull request #1168 from splitbrain/scrutinizer-patch-2
dom-mel May 24, 2015
23a5593
improved copy for styler plugin
selfthinker May 24, 2015
8b3eb08
adjusted gitignore for adjusted plugin name
splitbrain May 25, 2015
418cb61
removed unused class
splitbrain May 25, 2015
f969573
removed debuggin output
splitbrain May 25, 2015
5114259
removed accidental checkin
splitbrain May 25, 2015
5ddba45
Merge branch 'master' into styler
splitbrain Jun 26, 2015
86c97e9
fixes various probelms mentioned in #1163
splitbrain Jun 26, 2015
6667cd8
changed the whole thing to a real popup
splitbrain Jun 26, 2015
3e2beab
added a simple loading screen for the JavaScript preview
splitbrain Jun 26, 2015
bcea9d6
removed no longer needed ajax action components
splitbrain Jun 26, 2015
c2f2ded
reset page back to normal on closing dialog
splitbrain Jun 26, 2015
d634152
improved various minor frontend issues in styling plugin
selfthinker Jul 7, 2015
147d8f4
added labels to form entries
selfthinker Jul 7, 2015
75c8c6f
readded cookie to styling plugin
splitbrain Jul 18, 2015
8d4151d
added styler into default plugin section
splitbrain Jul 18, 2015
b28801b
added plugin to list of bundled extensions
splitbrain Jul 18, 2015
1dd04f9
fixed styling preview in IE
splitbrain Jul 24, 2015
84e76a7
make personal style ini to cause cache reloads
splitbrain Jul 24, 2015
cf2c8e7
changed input submits to buttons, fixed small RTL issue
selfthinker Jul 25, 2015
0bfc8d5
Merge remote-tracking branch 'origin/master' into styler
selfthinker Jul 25, 2015
ec2b4ba
fix problem with IE11
splitbrain Jul 26, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -47,6 +47,7 @@
!/lib/plugins/popularity
!/lib/plugins/revert
!/lib/plugins/safefnrecode
!/lib/plugins/styler
Copy link
Collaborator

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"?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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".

!/lib/plugins/testing
!/lib/plugins/usermanager
!/lib/plugins/action.php
Expand Down
23 changes: 20 additions & 3 deletions lib/exe/css.php
Expand Up @@ -37,7 +37,7 @@ function css_out(){
if(!$tpl) $tpl = $conf['template'];

// load style.ini
$styleini = css_styleini($tpl);
$styleini = css_styleini($tpl, $INPUT->bool('preview'));

// find mediatypes
if ($INPUT->str('s') == 'feed') {
Expand All @@ -49,7 +49,7 @@ function css_out(){
}

// The generated script depends on some dynamic options
$cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tpl.$type,'.css');
$cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].$INPUT->int('preview').DOKU_BASE.$tpl.$type,'.css');

// if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility
if (isset($config_cascade['userstyle']['default'])) {
Expand All @@ -63,6 +63,7 @@ function css_out(){
$cache_files[] = $tplinc.'style.local.ini'; // @deprecated
$cache_files[] = DOKU_CONF."tpl/$tpl/style.ini";
$cache_files[] = __FILE__;
if($INPUT->bool('preview')) $cache_files[] = $conf['cachedir'].'/preview.ini';

// Array of needed files and their web locations, the latter ones
// are needed to fix relative paths in the stylesheets
Expand Down Expand Up @@ -262,9 +263,12 @@ function css_applystyle($css, $replacements) {
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param string $tpl the used template
* @param bool $preview load preview replacements
* @return array with keys 'stylesheets' and 'replacements'
*/
function css_styleini($tpl) {
function css_styleini($tpl, $preview=false) {
global $conf;

$stylesheets = array(); // mode, file => base
$replacements = array(); // placeholder => value

Expand Down Expand Up @@ -321,6 +325,19 @@ function css_styleini($tpl) {
}
}

// allow replacement overwrites in preview mode
if($preview) {
$webbase = DOKU_BASE;
$ini = $conf['cachedir'].'/preview.ini';
if(file_exists($ini)) {
$data = parse_ini_file($ini, true);
// replacements
if(is_array($data['replacements'])) {
$replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'], $webbase));
}
}
}

return array(
'stylesheets' => $stylesheets,
'replacements' => $replacements
Expand Down
13 changes: 13 additions & 0 deletions lib/plugins/styling/.travis.yml
@@ -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
27 changes: 27 additions & 0 deletions lib/plugins/styling/README
@@ -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
33 changes: 33 additions & 0 deletions lib/plugins/styling/_test/general.test.php
@@ -0,0 +1,33 @@
<?php
/**
* General tests for the styling plugin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test make any sense at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not? it was generated by the plugin wizard

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
The plugin wizard also generates the plugin.info.txt, so testing for it makes even less sense.

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']));
}
}
108 changes: 108 additions & 0 deletions lib/plugins/styling/action.php
@@ -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: