> Ive recently been trying to change the html at the root of tiddlyweb
> (http://127.0.0.1:8080). I started writing a custom plugin but that
> seemed excessive.
The handling of / in the core TiddlyWeb is intentionally very basic.
It's basically just there to have something at / at all. Writing a
custom plugin is _not_ excessive according to the TiddlyWeb way:
customizations and complexity are supposed to go in plugins and
plugins are intentionally easy to write to do most of anything. It's
OK to write code.
> Could this be turned into a config variable which can point to a
> static html page? Maybe using Jinja for dynamic content?
You've got several options for changing how root is handled.
* You can override the wsgi application at tiddlyweb.web.handler.root
with one of your own.
* You can override the static string contained by tiddlyweb.web.handler.ROOT
_PAGE.
* You can write a plugin to do whatever you want, including deliver a
static page or use jinja for sending content.
I'll comment on the plugin itself in response to the other message.
On Jul 14, 2009, at 11:21 AM, simon mcmanus wrote:
def homepage(environ, start_response):
# you should have a 'return' before this generate_response
generate_response('bong', environ, start_response);
def _generate_response(content, environ, start_response):
# As you've guessed getting the serialize type is not requried
# if you are only going to be sending html from this handler
serialize_type, mime_type = web.get_serialize_type(environ) #
XXX: not suitable here!?
# You should avoid setting no-cache wherever possible, and
# instead set valid Etag and Last-Modified headers on your
# content. Otherwise you're ignoring the most powerful part
# of the web.
cache_header = ("Cache-Control", "no-cache") # ensure accessing
latest HEAD revision
# Make sure your content is marked as being UTF-8
# ('Content-Type', 'text/html; charset=UTF-8')
content_header = ("Content-Type", 'text/html') # XXX: should be
determined by diff format
# If you set environ['tiddlyweb.title'] to something, upstream
Middleware will
# wrap any HTML content you have with the header and footer
provided by
# HTMLPresenter. If you don't want that don't set tiddlyweb.title
in the environ.
response = [cache_header, content_header]
start_response("200 OK", response)
return [content]
def init(config):
# Since you are replacing an existing handler at /
# rather adding a new one, you need to use different
# syntax here. If it is working now, that is just the luck of
# the draw in the sequence handling that is present in
# the data structure Selector is using. Instead do this.
# replace_handler(config['selector'], '/', dict(GET=homepage))
# replace_handler can be imported from the tiddlywebplugins
# package, which is can be installed with easy_install. It has
# a few other handy little methods for making plugins easier to
# deal with.
config['selector'].add('/', GET=homepage)
http://gist.github.com/148961
Any feedback/comments welcome.
So did I:
http://gist.github.com/149019
a) moved init function to top (makes plugins more readable I think)
b) ensure consistent use of quotes (chose double quotes here)
c) whitespace adjustments, of course (chose tabs for indentation)
-- F.
Any feedback/comments welcome.I forked your gist to http://gist.github.com/149012 and made some changes
So did I:
http://gist.github.com/149019
a) moved init function to top (makes plugins more readable I think)
b) ensure consistent use of quotes (chose double quotes here)
c) whitespace adjustments, of course (chose tabs for indentation)
For new projects, spaces-only are strongly recommended over tabs.
>> a) moved init function to top (makes plugins more readable I think)
>
> While I agree with this for things that handlers, for some reason I
> can't break my habit of putting it at the end.
I'll take that as a license to gradually migrate init functions to the
top in tiddlyweb-plugins.
>> b) ensure consistent use of quotes (chose double quotes here)
>
> Curious, I generally prefer single, easier on the eyes.
I don't like single quotes because they're ambiguous.
> From PEP8:
>> For new projects, spaces-only are strongly recommended over tabs.
> While I don't always follow it, I do try to make TiddlyWeb code
> eventually hew to PEP8. You should too. :P
While I generally try to adhere to PEP8, I've explained to you why it's
simply wrong (*wrong*, WRONG!) in this regard (meaning > presentation).
Having said that, I do agree with PEP8 that consistency within a project
is paramount, which is why I use spaces and single quotes when working
on the TiddlyWeb repositories.
However, for my own projects - and that includes my personal TiddlyWeb
plugins repository - I take the liberty of ignoring those few misguided
aspects of PEP8.
As you were.
-- F.
> I don't like single quotes because they're ambiguous.
Also, JSON prescribes double quotes.
In TiddlyWeb, that surfaces via the policy files (in the default text
store, anyway), which leads to a certain inconsistency (especially WRT
the default* tiddlywebconfig.py).
-- F.
* now only created by TiddlyWebWiki's twanager instance