summaryrefslogtreecommitdiffhomepage
path: root/lib.m4
blob: a4cb49eb39e2a83cd4531a56ac47cbeaf0508282 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
m4_changecom()
m4_changequote([,])

m4_dnl Output ‘$2’ if the country code matches ‘$1’
m4_define(__ifcode, [m4_ifelse(__code, [$1], [$2])])

m4_dnl Execute the script ‘$1’ in the ‘scripts/’ directory
m4_define(__esyscmd, [m4_esyscmd([scripts/$1])])

m4_dnl Include the file ‘$1’ in the ‘src/’ directory, while also keeping track
m4_dnl of who called ‘__include’.  This is required sometimes when expanding
m4_dnl macros in included files.
m4_define(__include, [
	m4_define([__caller], m4___file__)
	m4_include([src/$1])
])

m4_dnl A setup file for ‘src/euro/index.dcoins.gsp’.  It converts ‘__denom’ from
m4_dnl something unhelpful like ‘10c’ to something helpful like ‘0.10’.
m4_define(__dcoins_denom, [m4_define([__denom], m4_ifelse(
	[0], m4_regexp(__denom, [^\([0-9]\)c]),
		m4_regexp(__denom, [^\([0-9]\)c], [0.0\1]),
	[0], m4_regexp(__denom, [^\([0-9]+\)c]),
		m4_regexp(__denom, [^\([0-9]+\)c], [0.\1]),
	[0], m4_regexp(__denom, [^\([0-9]\)e]),
		m4_regexp(__denom, [^\([0-9]\)e], [\1.00]),
	[Something went wrong… check ‘init.m4’]
))])

m4_dnl Create a link to ‘$1’ with the text ‘$2’.  This does some checks with the
m4_dnl caller to mark some nav-bar buttons as ‘selected’.  Dynamically generated
m4_dnl pages can work with this API by hijacking ‘m4___file__’ via ‘__hijack’.
m4_define(__link, [
	m4_ifelse(
		[$1], m4_regexp(__caller, [src\(/\)index\.gsp], [\1]),
			[div .selected {-$2}],
		[$1], m4_regexp(__caller, [src\(/.+\)/index\.gsp], [\1]),
			[div .selected {-$2}],
		[a href="$1" {-$2}]
	)
])

m4_dnl Hijack ‘m4___file__’ by setting it to ‘src/$1/index.gsp’
m4_define(__hijack, [m4_define([m4___file__], src/$1/index.gsp)])

m4_dnl Add an entry in the site changelog for the date ‘$1’ with the body ‘$2’
m4_define(__entry, [
	section #$1 .cl-section .slant-down {
		div {
			h2 {=m4_esyscmd(echo $1 | scripts/changelog-dates.sed)}
			$2
		}
	}
])