fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] dw_dev2011-01-01 12:46 pm
Entry tags:

Constants Namespaces in .tt files

I'm looking for feedback on Bug 3170: Constant Namespaces in DW::Template.

Basically, right now our constants in .tt files can be found under email.*, site.*, roots.*, etc, and the more constants we have, the more likely it is that we'll accidentally have a namespace collision. So I would like to have all constants be under just the site namespace.

That is, instead of using:
email.webmaster
roots.site
site.name

We can use:
site.email.webmaster
site.root
site.name

In some cases, it's longer, but the additional clarity should be worth the extra characters. (Plus it would also make it easier to avoid mistakes -- I found several instances of dw.* in the files, which are blank, but luckily cause no issues)


site.name = $LJ::SITENAME
site.names.short = $LJ::SITENAMESHORT
site.names.abbrev = $LJ::SITENAMEABBREV

site.company = $LJ::SITECOMPANY

site.email.coppa = $LJ::COPPA_EMAIL
site.email.privacy = $LJ::PRIVACY_EMAIL

site.domain = $LJ::DOMAIN
site.domains.web = $LJ::DOMAIN_WEB

site.root = $LJ::SITEROOT
site.roots.img = $LJ::IMGPREFIX
site.roots.ssl = $LJ::SSLROOT

site.help.* = \%LJ::HELPURL





I'd like to point out, in particular,
site.name = $LJ::SITENAME
site.names.short = $LJ::SITENAMESHORT
site.names.abbrev = $LJ::SITENAMEABBREV

which suffers from inconsistency/needing to be aware of the technical limitations.

An alternative:
site.name.site = $LJ::SITENAME
site.name.short = $LJ::SITENAMESHORT
site.name.abbrev = $LJ::SITENAMEABBREV

But that suffers from the problem that the most commonly used variable, site.name, becomes long/ridiculous/redundant.
kareila: (Default)

[personal profile] kareila 2011-01-01 05:10 am (UTC)(link)
Why not:

site.name
site.nameshort
site.nameabbrev?
alierak: (Default)

[personal profile] alierak 2011-01-01 01:15 pm (UTC)(link)
Also, I'm not familiar with TT, but is there a fundamental limitation that would prevent you using

site.name
site.name.short
site.name.abbrev?
alierak: (Default)

[personal profile] alierak 2011-01-01 02:16 pm (UTC)(link)
Okay, yeah. Can't store a value and a hashref in the same place. I do see a way to create a constant with a dot in the name (since Template::Namespace::Constants->new takes a perl hashref with arbitrary hash keys), but no way to access it, since the access would be fully tokenized before trying to look things up as hash keys.
mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)

[staff profile] mark 2011-01-03 06:26 pm (UTC)(link)
In general, I'm in favor of moving everything to site.*.

In specific, I think Jen's suggestion is great.