rejetto forum

Software => HFS ~ HTTP File Server => HTML & templates => Topic started by: rejetto on December 20, 2007, 05:14:09 PM

Title: macros: proof of concept
Post by: rejetto on December 20, 2007, 05:14:09 PM
here is a very simple chat i made using macros, just as a proof of concept ;)

Code: [Select]
<html>
<body>
{{if| {{and|{{?name}}|{{?text}} /and}} |{{\
{{append|chat.html|<br>{{time}} --- <b>{{?name}}</b>&gt; {{?text}}
/append}}
/}} /if}}
<form name=frm>
Name <input name=name value="{{?name}}">
<p>Text <input name=text>
<p><input type=submit>
</form>
<script>document.frm.text.focus();</script>
<a href="{{get|url|text=}}">REFRESH</a>

<hr>
{{load|chat.html}}
</body>
</html>
Title: Re: macros: a simple chat
Post by: Mars on December 20, 2007, 10:36:02 PM
Extra simple but very functional, I like the idea and I think of integrating message into an iframe with a  refreshment that can be modified
Title: Re: macros: proof of concept
Post by: rejetto on December 21, 2007, 05:09:49 AM
This is a split function, splitting a string in chunks of given length.
Remember this is not meant to be actually used, it's just a proof of concept.

Code: [Select]
{{set|split|
{{\ {{if| {{or| {{not|$3}} | {{<|$3|{{length|$2}} }} /or}} |
{{\ {{cut|$3|$1|$2}} {{^split|$1|$2|{{add|$3|$1}} }} /}}
/if}}
/}} /set}}

Example:
{{^split|3|this is the string to tear apart}}
Title: Re: macros: proof of concept
Post by: Foggy on December 21, 2007, 05:42:23 AM
With the template I'm replicating right now I've had to create a couple macro's to get it Identical.

Code: [Select]
{{set| shrink |{{\{{if | {{> | {{length |$1}} | $2}} | {{cut | 1 | {{sub | $2 | {{length |$3}}}} | $1}}$3|$1</a><a>{{repeat|{{sub|$2|{{length|$1}}}}|&nbsp;}}}}/}}}}

Example:
{{^shrink|text to shrink if over X characters|X characters|..>}}
It will test if the text is longer then the allowed length, if so it will shrink it and append the 3rd parameter to the end so you can tell it has been shrunk. If it is not the correct length, it will append spaces on the end to keep everything aligned.

Code: [Select]
{{set| format_date | {{\{{replace | / | - | {{if | {{is substring | PM | $1 }} | {{if | {{is substring | / | {{cut | 1 | 2 | $1}} }} | 0{{cut | 1 | 2 | $1}}{{!month{{cut | 3 | 2 | $1}}}}{{cut | 5 | 5 | $1}}{{!pm{{cut | -11 | 2 | $1}}}}{{cut | -9 | 3 | $1}} | {{cut | 1 | 3 | $1}}{{!month{{cut | 4 | 2 | $1}}}}{{cut | 6 | 5 | $1}}{{!pm{{cut | -11 | 2 | $1}}}}{{cut | -9 | 3 | $1}}}} | {{if | {{is substring | / | {{cut | 1 | 2 | $1}} }} | 0{{cut | 1 | 2 | $1}}{{!month{{cut | 3 | 2 | $1}}}}{{cut | 5 | 5 | $1}}{{!am{{cut | -11 | 2 | $1}}}}{{cut | -9 | 3 | $1}} | {{cut | 1 | 3 | $1}}{{!month{{cut | 4 | 2 | $1}}}}{{cut | 6 | 5 | $1}}{{!am{{cut | -11 | 2 | $1}}}}{{cut | -9 | 3 | $1}}}}}}}}/}}}}

Example:
{{^format_date|%item-modified%}}

This is what I eventually ended up with for formating the date, I know it is big and complicated but surprisingly the page still builds quite fast when this is used on every file.
It returns "19-Dec-2007 15:06" instead of "19/12/2007 3:06:49 PM"
I would copy the Special:Strings section but it is too big.

Code: [Select]
{{set| size |{{\{{if|{{<=|{{length|$1}}|$2}}|{{repeat|{{sub|$2|{{length|$1}}}}|&nbsp;}}$1}}/}}}}
{{set| sizeb |{{\{{if|{{<=|{{length|$1}}|$2}}|$1{{repeat|{{sub|$2|{{length|$1}}}}|&nbsp;}}}}/}}}}
{{set| size-B |{{\{{if|{{>=|$1|1024}}|{{^size-K|{{div|$1|1024}}}}|{{^sizeb|$1|4}}}}/}}}}
{{set| size-K |{{\{{if|{{>=|$1|1024}}|{{^size-M|{{div|$1|1024}}}}|{{^size|$1K|4}}}}/}}}}
{{set| size-M |{{\{{if|{{>=|$1|1024}}|{{^size-G|{{div|$1|1024}}}}|{{^size|$1M|4}}}}/}}}}

Example:
{{^size-B|%item-size-b%}}
Its another one to format it how I want. It will take the amount of bytes an object is and work out how many MB, KB, GB, etc it is and then format it in a specific way, so if the use of {{^size}} and {{^sizeb}} are confusing don't worry about them.


Note, these come from a template that im creating which uses <pre> tag's which is why all the formatting is important.

Title: Re: macros: proof of concept
Post by: Guest on December 21, 2007, 06:25:25 PM
Proof of concept - Simple chat:
This is Great !  I hope there are plans to expand this furthur? Please.

How do I change the "Submit Query" label on the button to "Submit",
and how do I extend the length and size of the Text input field ?

Title: Re: macros: proof of concept
Post by: Unknown8063 on December 21, 2007, 06:31:14 PM
How do I change the "Submit Query" label on the button to "Submit",

Code: [Select]
<input type=submit value="Custom Name Goes Here">
and how do I extend the length and size of the Text input field ?

Code: [Select]
<input name=text size="80">

EDIT: I guess bolding doesn't work in code blocks :(
Title: Re: macros: proof of concept
Post by: Guest on December 21, 2007, 06:55:29 PM
Many thanks Unknown8063 and to Rejetto.
It works great.
I now have a message board with out 3rd party.
Something I've wanted a long time.
Title: Re: macros: proof of concept
Post by: Foggy on December 22, 2007, 01:51:24 AM
I remember some people wanted to use a poll in their template, well now they can. :P

Code: [Select]
I copied the wrong code, see the post below.
Title: Re: macros: proof of concept
Post by: rejetto on December 22, 2007, 11:31:34 PM
i don't understand how your "poll" is supposed to work, and even if it does, it doesn't use macros, so it's off topic.
are you ok?
Title: Re: macros: proof of concept
Post by: Foggy on December 23, 2007, 07:21:47 AM
Lol, I copied the wrong stuff. I was supposed to copy it from HFS instead of Dreamweaver.

Code: [Select]
[poll]
{{if|{{?poll}}|{{append|option{{?poll}}.txt|1}}/if}}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Results</h1>
<ul>
<li>Option 1: {{length|{{load|option1.txt}}}}</li>
<li>Option 2: {{length|{{load|option2.txt}}}}</li>
<li>Option 3: {{length|{{load|option3.txt}}}}</li>
</ul>
<br />
<hr />
<br />
<form id="form1" name="form1" method="get" action="/~poll">
  <input name="poll" type="radio" value="1" /><label>Option 1</label><br />
<input name="poll" type="radio" value="2" /><label>Option 2</label><br />
<input name="poll" type="radio" value="3" /><label>Option 3</label><br />
<input name="Submit" type="submit" value="Submit" />
</form>
</body>
</html>
Title: Re: macros: proof of concept
Post by: rejetto on December 23, 2007, 07:57:44 PM
your code has a problem: you didn't use the macro quoting on the append, so it will always be executed, no matter what the if says.
you will get an append on the file option.txt file for every "visitor".
Title: Re: macros: proof of concept
Post by: Foggy on December 24, 2007, 12:18:45 AM
I'll fix that and I have a couple of ideas to improve it's usability.