cryptonas-branches/pythonrewrite/templates/macros.cs

87 lines
3.3 KiB
C#
Raw Normal View History

2006-08-14 17:40:12 +02:00
<?cs # $Id$ ?><?cs
# the following macro is as ugly as possible - but somehow we have to manage
to use 'normal' and 'plugin' messages in a clean way:
Lang.WarningMessage.??? - used by core functions
Lang.Plugins.PLUGINNAME.WarningMessage.??? - used by plugins ?><?cs
def:message_dispatch(mname, type, category)
?><?cs # split the message name into a (potentially existing) plugin-name prefix and the suffix (the python equivalent of the following three lines would be:
plugPrefix, PlugSuffix = mname[0:mname.find(".",8), mname[mname.find(".",8)+1:]
?><?cs loop:x = #8, #40, #1 ?><?cs if:(string.slice(mname,x,x+1) == ".") && !(?savedX) ?><?cs set:savedX = x ?><?cs /if ?><?cs /loop
?><?cs set:plugPrefix = string.slice(mname,0,savedX)
?><?cs set:plugSuffix = string.slice(mname,savedX+1,string.length(mname))
?><?cs # preparations are done - now start writing
?><div class="<?cs var:type ?>"><?cs
# check if it is a 'normal' message ?><?cs
if:?Lang[category][mname].Title ?>
<h1><?cs var:html_escape(Lang[category][mname].Title) ?></h1>
<p><?cs var:html_escape(Lang[category][mname].Text) ?></p>
<?cs # check if the mname starts with "Plugins." ... ?><?cs
elif:(string.slice(mname,0,8) == "Plugins.") && ?Lang[plugPrefix][category][plugSuffix].Title ?>
<h1><?cs var:html_escape(Lang[plugPrefix][category][plugSuffix].Title) ?></h1>
<p><?cs var:html_escape(Lang[plugPrefix][category][plugSuffix].Text) ?></p>
<?cs # the message does not seem to exist ... ?><?cs
else ?>
<h1>unknown <?cs var:type ?> message</h1>
<p>could not find <?cs var:type ?> message: '<?cs var:mname ?>'</p>
2006-08-14 17:40:12 +02:00
<?cs /if ?></div><?cs
/def ?><?cs
def:warning(mname)
?><?cs call:message_dispatch(mname, "warning", "WarningMessage") ?><?cs
2006-08-14 17:40:12 +02:00
/def ?><?cs
def:error(mname)
?><?cs call:message_dispatch(mname, "error", "ErrorMessage") ?><?cs
/def ?><?cs
def:success(mname)
?><?cs call:message_dispatch(mname, "success", "SuccessMessage") ?><?cs
2006-08-14 17:40:12 +02:00
/def ?><?cs
def:parseTree(root) ?><?cs #
# the output looks quite ugly and is not very helpful as there are
# only a few values
?><!-- data tree
<?cs each:item = root ?><?cs
name:item ?>: <?cs var:item ?><?cs
each:subitem = item ?> / <?cs name:subitem ?>=<?cs var:subitem ?><?cs /each ?>
<?cs /each ?>
--><?cs
/def ?><?cs
def:link(path, attr1, value1, attr2, value2)
2006-08-14 17:40:12 +02:00
?><?cs each:attrs = Temp
?><?cs set:attrs = ""
?><?cs /each
?><?cs each:attrs = Settings.LinkAttrs
?><?cs set:Temp[url_escape(name(attrs))] = url_escape(attrs)
?><?cs /each
?><?cs if:attr1 != "" ?><?cs set:Temp[attr1] = value1 ?><?cs /if
?><?cs if:attr2 != "" ?><?cs set:Temp[attr2] = value2 ?><?cs /if
?><?cs var:ScriptName
?>/<?cs var:path
2006-08-14 17:40:12 +02:00
?><?cs set:first_each = 1
?><?cs if:subcount(Temp) > 0
?><?cs each:attrs = Temp
?><?cs if:(name(attrs) != "") && (attrs != "")
?><?cs if:first_each == 1 ?><?cs
set:first_each = 0 ?>?<?cs
else
?>&amp;<?cs /if
?><?cs var:url_escape(name(attrs)) ?>=<?cs var:url_escape(attrs)
?><?cs /if
?><?cs /each
?><?cs /if ?><?cs
/def ?><?cs
2006-10-26 14:26:52 +02:00
def:print_form_header(form_name, action) ?><?cs #
2006-08-14 17:40:12 +02:00
# the header of a form - including Setting.LinkAttrs
2006-10-26 14:26:52 +02:00
?><form name="<?cs var:html_escape(form_name) ?>" action="<?cs call:link(action,"","","","") ?>" method="post" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"><?cs
2006-08-14 17:40:12 +02:00
/def ?>