Skip to content

Instantly share code, notes, and snippets.

@dumblob dumblob/config.dao
Created Sep 24, 2014

Embed
What would you like to do?
#!/usr/bin/env dao
load time
load os.fs
namespace configuration { conf, partners, curdir, check_path }
invar curdir = fs.dir('.').path
type Partner = tuple<name:string, img:string, uri:string>
# all paths have to be full or non-relative URIs! Do not worry,
# they'll be changed to relative ones in the end if needed.
invar conf = (
time_from = time.make(2014, 11, 1),
time_to = time.make(2014, 11, 2),
coord_gps = '49.2263872°N, 16.5963531°E',
lang = 'cs',
base_uri = '',
meta_description = 'some short human readable description in english of the content of the web page',
rootdir = curdir,
uri = (
# shared between all pages (no exceptions)
css = curdir + '/style.css',
rss = 'https://rss',
twitter = 'https://twitter',
fb = 'https://facebook',
),
favicon = (mime='image/x-svg', path=curdir + '/img/favicon.svg',
sizes='any'),
img = (
rss = curdir + '/img/icon-clock.png',
twitter = curdir + '/img/icon-clock.png',
fb = curdir + '/img/icon-clock.png',
location = curdir + '/img/map_fit_vutbr.jpg',
# FIXME use SVG everywhere!
audio = curdir + '/img/icon-audio.png',
clock = curdir + '/img/icon-clock.png',
door = curdir + '/img/icon-door.png',
on_in_circle = curdir + '/img/icon-on_in_circle.png',
pdf = curdir + '/img/icon-pdf.png',
video = curdir + '/img/icon-video.png',
logo_big = curdir + '/img/logo-openalt-conference-far-305px.png',
),
)
invar partners: list<Partner> = {
('', curdir + '/img/partners/partner00.png', 'http://some_nice_circle0.com/about'),
('', curdir + '/img/partners/partner00.png', 'http://some_nice_circle1.com/about'),
('', curdir + '/img/partners/partner00.png', 'http://some_nice_circle2.com/about'),
}
# testing
routine check_path(invar uri: string) {
if (uri[0] != '/'[0] && uri.match('^[^:/]+') == none)
std.error('"' + uri + '" is not a full path nor non-relative URI')
}
check_path(conf.rootdir)
for (t in conf.uri) check_path(t[1])
check_path(conf.favicon.path)
if ('svg' in conf.favicon.mime) {
if (conf.favicon.sizes != 'any')
std.error('scalable favicons demand "any" in the `sizes\' attribute')
}
else {
conf.favicon.sizes.split(' ').iterate {
if (X.match('^[0-9]+x[0-9]+$') == none)
std.error('bitmap favicons demand "NxM N2xM2 ..." in the `sizes\' attribute')
}
}
for (t in conf.img) check_path(t[1])
for (p in partners) check_path(p.img)
#!/usr/bin/env dao
load os.fs
load 'config.dao' import configuration
load 'translations.dao' import translation
routine mkrel(from: string, invar target: string) => string {
if (from [0] != '/'[0]) std.error('"from" is not a full path')
if (from [-1] != '/'[0]) from += '/'
if (target[0] != '/'[0]) {
if (target.match('^[^:/]+') == none)
std.error('"target" is not a full path nor URI')
else
return target
}
shared = 1 # /
while (1) {
x = target[shared:].fetch('[^/]+')
y = from[shared:].fetch('[^/]+')
if (%x && x == y)
shared += %x +1 # +1 for /
else
break
}
return from[shared:].change('[^/]+', '..') + target[shared:]
}
# FIXME temporary for testing
routine html_main (a){}
routine html_about (a){}
routine html_thanks (a){}
routine html_gallery (a){}
routine html_downloads(a){}
routine html_contact (a){}
routine gen_pages(invar trans: string) {
d = fs.dir(conf.rootdir)
if (! d.exists(trans)) d.mkdir(trans)
invar dst = conf.rootdir + '/' + trans
rel = routine(invar target: string) { return mkrel(dst, target) }
invar pages = (
main = ('main.html', html_main),
about = ('about.html', html_about),
thanks = ('thanks.html', html_thanks),
gallery = ('gallery.html', html_gallery),
downloads = ('downloads.html', html_downloads),
contact = ('contact.html', html_contact),
)
for (p in pages) {
html5 = io.open(dst + '/' + p[1][0], 'w')
defer { html5.close() }
#fut = html5.write(p[1][1](trans, dst, rel, pages)) !!
fut = html5.write(p[1][1](trans)) !!
defer { fut.value() }
}
}
# USAGE: generate.dao [<translation>]...
# if no translations given, generate all
routine main(invar ...: string as args) {
invar chosen_trs = std.exec {
if (%args)
return ((list<string>)args).associate(1) { (X, translations[X]) }
else
return translations
}
for (invar trans in chosen_trs) {
fut = gen_pages(trans[0]) !!
defer { fut.value() }
}
css = io.open(conf.uri.css, 'w')
defer { css.close() }
invar red = 'red'
invar font = ''
css.write(
@[]html {
background-color: white;
color: black;
font: "";
}
@[])
}
#!/usr/bin/env dao
load 'config.dao' import configuration . { conf, curdir, check_path }
load time
namespace translation { translations, participants }
type Event = tuple<
kind:enum<talk, workshop, internal>,
from:time.DateTime,
to:time.DateTime,
trans:map<string, tuple<
name:string,
requirements:string,
description:string,
place:string,
>>
>
type Participant = tuple<
name:string,
photo:string,
note:string,
events:list<Event>
>
# FIXME use some existing format supporting plurals
# http://docs.transifex.com/developer/formats/
var translations = {
'en' -> {
'_locale' -> 'en_US',
'title' -> 'OpenAlt conference ' + (string)conf.time_from.year,
'logo_big' -> 'a big logo of the OpenAlt conference',
'rss' -> 'RSS channel for conference news and changes on this web',
'twitter' -> 'official twitter stream for OpenAlt conference',
'fb' -> 'official Facebook page for OpenAlt conference',
'motivation' -> 'Become a part of the ninth anniversary proceeding of a Brno open-source, open-hardware and open-mind conference!',
'home' -> 'Home',
'about' -> 'About',
'thanks' -> 'Thanks',
'gallery' -> 'Gallery',
'downloads' -> 'Downloads',
'contact' -> 'Contact',
'speakers' -> 'Speakers',
'partners' -> 'Partners',
'footer' -> 'last updated on ' + time.now().format(),
'talks' -> 'Talks',
'talk' -> 'Talk',
'workshops' -> 'Workshops',
'workshop' -> 'Workshop',
'schedule' -> 'Schedule',
'location' -> 'Location',
'participation_reqs' -> 'Requirements for participation:',
},
'sk' -> {
'_locale' -> 'sk_SK',
'motivation' -> 'Staňte sa aj Vy súčasťou už deviateho pokračovania brnenskej open-source, open-hardware a open-mind konferencie!',
},
'de' -> {
'_locale' -> 'de_DE',
},
'cs' -> {
'_locale' -> 'cs_CZ',
'title' -> 'Konference OpenAlt ' + (string)conf.time_from.year,
'logo_big' -> 'velké logo konference OpenAlt',
'rss' -> 'kanál RSS s konferenčními aktualitami a změnami na tomto webu',
'twitter' -> 'oficiální stránka konference OpenAlt na Twitter',
'fb' -> 'oficiální stránka konference OpenAlt na Facebook',
'motivation' -> 'Staňte sa i Vy součástí již devátého pokračování brněnské open-source, open-hardware a open-mind konference!',
'home' -> 'Domů',
'about' -> 'O nás',
'thanks' -> 'Poděkování',
'gallery' -> 'Fotogalerie', # Fotografie
'downloads' -> 'Ke stažení',
'contact' -> 'Kontakt',
'speakers' -> 'Přednášející',
'partners' -> 'Partneři',
'footer' -> 'Poslední aktualizace ' + time.now().format(),
'talks' -> 'Přednášky',
'talk' -> 'Přednáška',
'workshops' -> 'Dílny',
'workshop' -> 'Dílna',
'schedule' -> 'Rozvrh',
'location' -> 'Místo konání',
'participation_reqs' -> 'Požadavky pro účast:',
},
}
var participants: list<Participant> = {
('organizers',
curdir + '/img/participants/miroslav_suchy.png',
'Tvrde jadro OpenAlt z.s.',
events = {
($internal,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 7, 00),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 7, 30),
trans = {
'en' -> ('zahajeni',
'',
'popis zahajeni',
'D105',),
}
),
($internal,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 11, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 12, 30),
trans = {
'en' -> ('obed',
'',
'popis obeda',
'',),
}
),
($internal,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day, 11, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day, 12, 30),
trans = {
'en' -> ('obed2',
'',
'popis obeda',
'',),
}
),
($internal,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day, 17, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day, 18, 80),
trans = {
'en' -> ('zakonceni',
'',
'popis zakonceni',
'D105',),
}
),
}),
('Miroslav Suchy',
curdir + '/img/participants/miroslav_suchy.png',
'Vzrustove vypadam jak velky medved a v praci si rikam lopata.',
events = {
($talk,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 15, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 16, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum T',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'D105',),
}
),
($workshop,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 14, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 15, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum W',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'C304',),
}
),
($talk,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 12, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 13, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum T',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'D105',),
}
),
($workshop,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 10, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 11, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum W',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'C304',),
}
),
($talk,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 8, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 9, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum T',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'D105',),
}
),
($workshop,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 9, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 10, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum W',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'C304',),
}
),
}),
('Nekdo Jiny0',
curdir + '/img/participants/miroslav_suchy.png',
'Jiny nepovinny popisek.',
events = {
}),
('Nekdo Jiny1',
curdir + '/img/participants/miroslav_suchy.png',
'Jiny nepovinny popisek.',
events = {
}),
('Nekdo Jiny2',
curdir + '/img/participants/miroslav_suchy.png',
'Jiny nepovinny popisek.',
events = {
}),
('Nekdo Jiny3',
curdir + '/img/participants/miroslav_suchy.png',
'Jiny nepovinny popisek.',
events = {
($talk,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 5, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 6, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum T',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'D105',),
}
),
($workshop,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 1, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 2, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum W',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'C304',),
}
),
($talk,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 11, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 12, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum T',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'D105',),
}
),
($workshop,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 12, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 13, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum W',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'C304',),
}
),
($talk,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 13, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 14, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum T',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'D105',),
}
),
($workshop,
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 14, 30),
time.make(conf.time_to.year, conf.time_to.month, conf.time_to.day -1, 19, 30),
trans = {
'en' -> ('Stare dobre Lorem ipsum W',
'sami chytri lide',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."',
'C304',),
}
),
}),
}
# fill empty translations with english terms (if not existing in en,
# raise exception)
translations.iterate { [k, v]
if ('_locale' not in v)
io.stderr.writeln('ERR _locale not specified for ' + k)
if (k != 'en') {
translations['en'].iterate { [k2, v2]
if (k2 not in v) {
io.stderr.writeln('WARN missing translation [' + k + ']: ' + k2)
v[k2] = v2
}
}
participants.iterate { [p]
# blackbox testing
check_path(p.photo)
p.events.iterate { [e]
if (k not in e.trans) {
io.stderr.writeln('WARN missing translation [' + k + '] in ' +
e.trans['en'].name + ' in ' + p.name)
e.trans[k] = e.trans['en']
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.