hackability of the homepage

2 views
Skip to first unread message

simon mcmanus

unread,
Jul 14, 2009, 4:02:47 AM7/14/09
to tidd...@googlegroups.com
hi,

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.

Could this be turned into a config variable which can point to a static html page? Maybe using Jinja for dynamic content?

Thanks

--
Simon McManus

simon mcmanus

unread,
Jul 14, 2009, 6:21:01 AM7/14/09
to tidd...@googlegroups.com
btw :

this is now working as a plugin which can be seen here :

http://pastebin.com/f59874daa

2009/7/14 simon mcmanus <mcmanu...@gmail.com>



--
Simon McManus

blog : http://simonmcmanus.com

Chris Dent

unread,
Jul 14, 2009, 6:35:33 AM7/14/09
to tidd...@googlegroups.com

On Jul 14, 2009, at 9:02 AM, simon mcmanus wrote:

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

Chris Dent

unread,
Jul 14, 2009, 6:47:14 AM7/14/09
to tidd...@googlegroups.com

Comments on the plugin directly within

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)

simon mcmanus

unread,
Jul 14, 2009, 7:05:51 AM7/14/09
to tidd...@googlegroups.com
Thanks for the responses Chris,

embarrassingly I pasted the wrong file into pastebin.  The link previously posted will NOT work.

The right code for the plugin is here :

http://gist.github.com/146894

ps : While this one actually works I'm sure many of the previous comments still apply

2009/7/14 Chris Dent <chris...@gmail.com>

simon mcmanus

unread,
Jul 17, 2009, 5:17:16 AM7/17/09
to tidd...@googlegroups.com
Hi,

I have made various changes to my homepage plugin. I think I have incorporated all the suggestions Chris made in his previous mail.

Despite the fact that I am not loading any content dynamically I decided to use Jinja.  This was so that I could use the same template for the homepage and the other dynamic pages.

http://gist.github.com/148961

Any feedback/comments welcome.

Thanks

Simon



Chris Dent

unread,
Jul 17, 2009, 7:36:15 AM7/17/09
to tidd...@googlegroups.com

On Jul 17, 2009, at 10:17 AM, simon mcmanus wrote:


http://gist.github.com/148961

Any feedback/comments welcome. 

I forked your gist to http://gist.github.com/149012 and made some changes:

* I got rid of an unused import.

* I switched the template handling to use template.generate() rather than render so that the content can be returned as a generator, which can be useful if your template is long.

FND

unread,
Jul 17, 2009, 8:00:34 AM7/17/09
to tidd...@googlegroups.com
>> 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)


-- F.

simon mcmanus

unread,
Jul 17, 2009, 8:57:19 AM7/17/09
to tidd...@googlegroups.com
Thank you both. 

Simon

2009/7/17 FND <FN...@gmx.net>

Chris Dent

unread,
Jul 17, 2009, 9:31:18 AM7/17/09
to tidd...@googlegroups.com

On Jul 17, 2009, at 1:00 PM, FND wrote:

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)

While I agree with this for things that handlers, for some reason I can't break my habit of putting it at the end.

b) ensure consistent use of quotes (chose double quotes here)

Curious, I generally prefer single, easier on the eyes.

c) whitespace adjustments, of course (chose tabs for indentation)

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

FND

unread,
Jul 18, 2009, 3:02:47 AM7/18/09
to tidd...@googlegroups.com
[OT]

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

FND

unread,
Jul 21, 2009, 8:46:09 AM7/21/09
to tidd...@googlegroups.com
[OT]

> 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

Reply all
Reply to author
Forward
0 new messages