]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - doc/todo/Add_a_plugin_to_list_available_pre-processor_commands.mdwn
rename preprocessordirective to directive
[git.ikiwiki.info.git] / doc / todo / Add_a_plugin_to_list_available_pre-processor_commands.mdwn
index fd2961c2122ef1eece76d5bee9c4e8032cecdde7..b8ef2409de4e3a156995cb1c733b943c68fe0646 100644 (file)
@@ -113,8 +113,29 @@ I've found myself wanting to know which [[plugins]] are switched on so I know wh
 >>>>>>> pages get linked correctly, and missing pages get normal creation
 >>>>>>> links.  The old patch is still here if you decide you prefer that. -- [[Will]]
 
-Note that because there are double square brackets in the source, this might not
-display quite right.
+>>>>>>>> Can you explain the full/early list (why track both?) and generated parameter?
+
+>>>>>>>>> If you add in all the shortcuts you get quite a long list.  My original idea
+>>>>>>>>> was to just track the plugin commands.  This is the early list.  But then
+>>>>>>>>> I thought that it might be nice for someone looking at wiki source and
+>>>>>>>>> seeing a shortcut to know where it came from.  So I decided to make
+>>>>>>>>> displaying the full list an option, with the original concept as the default.
+
+>>>>>>>>> Another option here might be to generate the full list every time, but give
+>>>>>>>>> generated pre-processor commands (e.g. shortcuts) a different css class.
+>>>>>>>>> I'm not sure that is better than what I have though. 
+
+>>>>>>>>> I keep track of both in the page state because if a command moves from
+>>>>>>>>> a shortcut to the early list (or vice versa) it changes what should be
+>>>>>>>>> displayed in the default use of the plugin.  I thought about tracking just what
+>>>>>>>>> was actually used on the page, but I don't know in the needsbuild hook whether the `generated`
+>>>>>>>>> parameter has been supplied (or maybe the plugin is used twice on the page -
+>>>>>>>>> once in each form).  It was just easier to track both.
+
+>>>>>>>> Only code change I'd suggest is using `htmllink` rather than 
+>>>>>>>> generating a wikilink.
+
+>>>>>>>>> Yeah - that would make sense.  done. -- [[Will]]
 
     #!/usr/bin/perl
     # Ikiwiki listpreprocessors plugin.
@@ -126,8 +147,9 @@ display quite right.
     
     sub import { #{{{
        hook(type => "getsetup", id => "listpreprocessors", call => \&getsetup);
-       hook(type => "preprocess", id => "listpreprocessors", call => \&preprocess);
        hook(type => "checkconfig", id => "listpreprocessors", call => \&checkconfig);
+       hook(type => "needsbuild", id => "listpreprocessors", call => \&needsbuild);
+       hook(type => "preprocess", id => "listpreprocessors", call => \&preprocess);
     } # }}}
     
     sub getsetup () { #{{{
@@ -144,40 +166,64 @@ display quite right.
                },
     } #}}}
     
+    my @fullPluginList;
     my @earlyPluginList;
+    my $pluginString;
     
     sub checkconfig () { #{{{
+        if (!defined $config{plugin_description_dir}) {
+            $config{plugin_description_dir} = "ikiwiki/plugin/";
+        }
     
-       if (!defined $config{plugin_description_dir}) {
-               $config{plugin_description_dir} = "ikiwiki/plugin/";
-       }
-       
-       @earlyPluginList = sort( keys %{ $IkiWiki::hooks{preprocess} } );
+        @earlyPluginList = sort( keys %{ $IkiWiki::hooks{preprocess} } );
     } #}}}
     
+    sub needsbuild (@) { #{{{
+       my $needsbuild=shift;
+    
+       @fullPluginList = sort( keys %{ $IkiWiki::hooks{preprocess} } );
+       $pluginString = join (' ', @earlyPluginList) . " : ". join (' ', @fullPluginList);
+    
+       foreach my $page (keys %pagestate) {
+               if (exists $pagestate{$page}{listpreprocessors}{shown}) {
+                       if ($pagestate{$page}{listpreprocessors}{shown} ne $pluginString) {
+                               push @$needsbuild, $pagesources{$page};
+                       }
+                       if (exists $pagesources{$page} &&
+                                       grep { $_ eq $pagesources{$page} } @$needsbuild) {
+                               # remove state, will be re-added if
+                               # the [[!listpreprocessors]] is still there during the
+                               # rebuild
+                               delete $pagestate{$page}{listpreprocessors}{shown};
+                       }
+               }
+       }
+    } # }}}
+    
     sub preprocess (@) { #{{{
        my %params=@_;
        
+       $pagestate{$params{destpage}}{listpreprocessors}{shown}=$pluginString;
+       
        my @pluginlist;
        
-       if (defined $params{generated}) {
-               @pluginlist = sort( keys %{ $IkiWiki::hooks{preprocess} } );
+       if (defined $params{generated}) {
+               @pluginlist = @fullPluginList;
        } else {
                @pluginlist = @earlyPluginList;
        }
        
        my $result = '<ul class="listpreprocessors">';
-    
+       
        foreach my $plugin (@pluginlist) {
-               $result .= '<li class="listpreprocessors">[[' . $config{plugin_description_dir} . $plugin . ']]</li>';
+               $result .= '<li class="listpreprocessors">';
+               $result .= htmllink($params{page}, $params{destpage}, IkiWiki::linkpage($config{plugin_description_dir} . $plugin));
+               $result .= '</li>';
        }
-    
-       $result .= "</ul>";
-       
-       print $result;
        
-       return IkiWiki::preprocess($params{page}, $params{destpage}, 
-               IkiWiki::filter($params{page}, $params{destpage}, $result));
+       $result .= "</ul>";
+    
+       return $result;
     } # }}}
     
     1
@@ -366,3 +412,5 @@ This is what I was using for `preprocessor-description.tmpl`:
     The <TMPL_VAR plugin> preprocessor command currently has no description.
     
     Maybe you should edit this page to add one.
+
+[[tag done]]