• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
  • This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Unix scripts to clarify template diffs

#1
Knowing that eventually I'd have to merge my template changes to new versions of XenForo, I create these scripts. They're useful for guys who prefer to do development on unix (as opposed to web forms), or want an easier way to diff different versions of templates. They can also ensure that you do not forget or omit any changes to new templates that were obsoleted in an upgrade.

I've attached four files. They will need a tweak or two out of the box to run with your setup. Specifically, change the site name in xf-check(in|out) and xf-list to your site, with the correct path to admindav.php. You'll want to change the default style number in those same files to be the style you want to edit by default (mine is #2). Otherwise you can override it with the environment variable TEMPLATE (note this is really more "style", but I meant it as an overall template-library ID). You'll need the cadaver package installed (command line webdav client) and a .netrc file setup per cadaver's man page, and to have followed the XF instructions to enable WebDav.

Usage:
xf-checkout template1 template2 ...
Give it one or more template names and it will download them from your xen installation, using the given style ID (see above paragraph), and leave them in the corresponding filenames in the local directory.

xf-checkin template1
Will check in "template1" to your xen install, using the style number specified in the prior paragraph

xf-list
lists all templates/css's in the specified style

xf-diff
You'll need to edit this to specify the list of style ID's you want it to dump. For each style ID listed (i), it will create subdirectory i from the current directory, and that subdir will contain files for all the templates/css's. Note that this gets everything, and is somewhat overkill if you're just dealing one or two templates. But, it's very handy to have versions of all the templates on disk to locate what you're looking for. Just make sure to always check out a new version before editing it, in case you've made a later change via acp.

So... typically when I do changes, if I know the template name, I just do
xf-checkout PAGE_CONTAINER (or appropriate template name)
emacs PAGE_CONTAINER
xf-checkin PAGE_CONTAINER
If you run export TEMPLATE=4 before this, it'll default to style 4.

If I want to tell how my version of PAGE_CONTAINER differs from the base/default one. First I run xf-diff. It creates a library of all the versions of everything. Next I run

diff 0/PAGE_CONTAINER 2/PAGE_CONTAINER
(you can use sdiff or the diff of your choice)

So when faced with obsolete templates after an upgrade, you can do this:

First, run xf-diff to create a library of the current/old versions of the templates. Ideally do this before the upgrade. Make sure you have directories for style 0 (base) and the ID of your default style (in my case 2).

Now, when you have the list of obsolete templates from the xf acp, for each of them, run the diff command as listed above. This will tell you the exact changes you made from the base version. Next, revert the template in acp. Then use the xf-checkout-edit-xf-checkin flow to apply the diffs (I do it manually) to the now-reverted template.

This method pretty much ensures you won't miss any changes you've made since by diffing 0 vs. your default style over the full dump of all old template files from each style, you get all the changes listed out.

xf-list
Code:
#!/bin/sh
if [ -z "$TEMPLATE" ]; then
    TEMPLATE=2
fi

(
echo cd Public_Templates
echo cd $TEMPLATE
echo ls
) | cadaver http://thunderbeastarms.com/forum/admindav.php  | \
    grep -v '^dav:' | grep -v 'Listing' | grep -v 'Connection to' | \
    sed 's/^Error:\s*//g' | cut -d' ' -f1
xf-diff
Code:
#!/bin/sh

#for a in 0 1 2 3; do
for a in 0 1 2 3 4 5; do
    export TEMPLATE=$a
    mkdir $a || true
    ( 
    cd $a
    export TEMPLATE=$a
    list=`xf-list |sed 's/\.html//' `
    xf-checkout $list
    )
done
xf-checkout
Code:
#!/bin/sh
if [ -z "$TEMPLATE" ]; then
    TEMPLATE=2
fi

(
echo cd Public_Templates
echo cd $TEMPLATE

until [ -z "$1" ]  # Until all parameters used up . . .
do
  echo get $1
  shift
done

) | cadaver http://thunderbeastarms.com/forum/admindav.php
xf-checkin
Code:
#!/bin/sh
if [ -z "$TEMPLATE" ]; then
    TEMPLATE=2
fi


(
echo cd Public_Templates
echo cd $TEMPLATE
echo put $1
) | cadaver http://thunderbeastarms.com/forum/admindav.php

PS- It would be helpful if we could upload .tar.gz files. Standard packaging for unix systems.
 

Attachments

#2
So here's how one of the diffs looked
Code:
$ diff 0/thread_watch 2/thread_watch
30c30
<<input type="radio" name="email_subscribe" value="1" id="ctrl_email_subscribe_1" />
---
><input type="radio" name="email_subscribe" value="1" id="ctrl_email_subscribe_1" checked="checked" autofocus="true" />
36c36
<<input type="radio" name="email_subscribe" value="0" id="ctrl_email_subscribe_0" checked="checked" autofocus="true" />
---
><input type="radio" name="email_subscribe" value="0" id="ctrl_email_subscribe_0"  />