[GoLUG] DRY in my 444domains.com system
Steve Litt
slitt at troubleshooters.com
Thu Dec 12 01:50:07 EST 2024
Hi all,
In my December GoLUG presentation I spoke up for DRY: "Don't Repeat
Yourself", and mentioned it as related to database normalization.
Things you say in code are a lot like things you say with your voice:
If you have only one version of the story it's easy to remember it.
With multiple versions, you need to remember to whom you told each
version, and things inevitably get messed up.
My 444domains.com website will soon refer people to actual websites of
my domains for sale. 444domains.com is a static HTML site that is built
from a data file listing lines, with each line containing three triple
colon separated fields: 1) The domain, 2) The price, and 3) A comment.
But now I need to have some of the domains say things like "See
Moretime.Com" (with "Moretime.Com" being a link). Yet I still need the
price in the conversion script in order to sort by price.
Of course, the easy way would have been to make a fourth column with an
(optional) URL. But then there would have been a price in the
Moretime.Com website and in the 444domains.com data file, and they
would have needed to be kept in sync, and I'm just not careful enough
to be trusted to remember to do so. I need each domain's price in
exactly one place, either in the 444domains.Com data file or in the
Moretime.Com website (and in the future there will be several other
such websites). Having it in the data file would have necessitated my
remembering to run Moretime.Com's index.html through the script every
time I changed the price, and I didn't like it.
So what I plan to do is have the possibility of a URL instead of a
price in the URL field. Then my 444domains builder script will look
inside Moretime.Com's index.html file for the price, and use it to sort.
Which isn't so simple, because I plan on displaying the price in
different ways and different places in the index.html's for many of my
for-sale domains. So I need the price in exactly one place in
index.html, and stated in a way that it can easily be parsed out. So I
used the technique displayed in the following short example program:
====================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width,
initial-scale=1.0"/>
<title>Testing CSS Custom
Properties (Variables)</title>
<style>
span.bux::before{content: "$54,321.00";}
body{
font-family: sans-serif;
background-color: #ffffff;
}
@media (max-width: 650px) {
body{background-color: #ccf0ff;}
}
</style>
</head>
<body>
<p>This is a test of
custom properties (variables)</p>
<h2 id="by_price">The
price is
<span class="bux"></span>
USD.</h2>
</body>
</html>
====================================================
So the one and only place the price is quantified is in the line:
span.bux::before{content: "$54,321.00";}
Once the preceding CSS line is stated, anywhere I want to put the price
can be displayed simply by the following HTML tag sequence:
<span class="bux"></span>
And as far as the 444domains.com builder script, all it needs to do is
look in the Moretime.Com (or whatever domain I'm selling with a website)
index.html for "span.bux::before{content:", and then capture the string
that follows. In the 444domains.com builder script I can strip out the
dollar sign and commas and turn it into a number for sorting.
Kinda slick, huh?
SteveT
PS: I don't use Javascript except where it's needed, like for
calculations and such.
Steve Litt
http://444domains.com
More information about the GoLUG
mailing list