langf now works in transpiled templates, albeit a little inefficiently.

Removed the quick_topic.add_poll_option phrase.
Added the quick_topic.add_poll_option_first phrase.
Changed the topic.reply_add_poll_option phrase.
Added the topic.reply_add_poll_option_first phrase.
This commit is contained in:
Azareal 2019-06-17 09:36:31 +10:00
parent 89c8f4e775
commit 89ca5ee823
9 changed files with 94 additions and 36 deletions

View File

@ -179,6 +179,7 @@ type TopicCAttachItem struct {
}
type TopicCPollInput struct {
Index int
Place string
}
type TopicPage struct {

View File

@ -49,6 +49,11 @@ func (con *CContext) PushPhrase(langIndex int) (index int) {
return con.LastBufIndex()
}
func (con *CContext) PushPhrasef(langIndex int, args string) (index int) {
*con.OutBuf = append(*con.OutBuf, OutBufferFrame{args, "langf", con.TemplateName, langIndex, nil})
return con.LastBufIndex()
}
func (con *CContext) StartLoop(body string) (index int) {
con.LoopDepth++
return con.Push("startloop", body)

View File

@ -11,6 +11,7 @@ import (
"runtime/debug"
"strconv"
"strings"
"unicode"
"text/template/parse"
"time"
)
@ -106,7 +107,7 @@ func NewCTemplateSet(in string) *CTemplateSet {
"hasWidgets": true,
"elapsed": true,
"lang": true,
//"langf":true,
"langf":true,
"level": true,
"bunit": true,
"abstime": true,
@ -1109,7 +1110,56 @@ ArgLoop:
notident = true
con.PushPhrase(len(c.langIndexToName) - 1)
break ArgLoop
// TODO: Implement langf
case "langf":
// TODO: Implement string literals properly
leftOperand := node.Args[pos+1].String()
if len(leftOperand) == 0 {
panic("The left operand for the language string cannot be left blank")
}
if leftOperand[0] != '"' {
panic("Phrase names cannot be dynamic")
}
var olist []string
for i := pos+2; i < len(node.Args); i++ {
op := node.Args[i].String()
if op != "" {
if op[0] == '.' || op[0] == '$' {
panic("langf args cannot be dynamic")
}
if op[0] != '"' && !unicode.IsDigit(rune(op[0])) {
break
}
olist = append(olist,op)
}
}
if len(olist) == 0 {
panic("You must provide parameters for langf")
}
var ob = ","
for _, op := range olist {
allNum := true
for _, o := range op {
if !unicode.IsDigit(o) {
allNum = false
}
}
if allNum {
ob += strings.Replace(op,"\"","\\\"",-1) + ","
} else {
ob += ob + ","
}
}
if ob != "" {
ob = ob[:len(ob)-1]
}
// TODO: Implement string literals properly
// ! Slightly crude but it does the job
litString("phrases.GetTmplPhrasef("+leftOperand+ob+")", false)
c.importMap[langPkg] = langPkg
break ArgLoop
case "level":
// TODO: Implement level literals
leftOperand := node.Args[pos+1].String()

View File

@ -546,7 +546,7 @@
"quick_topic.avatar_alt":"Your Avatar",
"quick_topic.whatsup":"What's up?",
"quick_topic.content_placeholder":"Insert post here",
"quick_topic.add_poll_option":"Poll option",
"quick_topic.add_poll_option_first":"Poll option #0",
"quick_topic.create_topic_button":"Create Topic",
"quick_topic.create_topic_button_short":"New Topic",
"quick_topic.add_poll_button":"Add Poll",
@ -653,7 +653,8 @@
"topic.reply_aria":"The quick reply form",
"topic.reply_content":"Insert reply here",
"topic.reply_content_alt":"What do you think?",
"topic.reply_add_poll_option":"Poll option",
"topic.reply_add_poll_option":"Poll option #%d",
"topic.reply_add_poll_option_first":"Poll option #0",
"topic.reply_button":"Create Reply",
"topic.reply_add_poll_button":"Add Poll",
"topic.reply_add_file_button":"Add File",

View File

@ -286,6 +286,7 @@
if(dataPollInput != (pollInputIndex-1)) return;
$(".poll_content_row .formitem").append(Template_topic_c_poll_input({
Index: pollInputIndex,
Place: phraseBox["topic"]["topic.reply_add_poll_option"].replace("%d",pollInputIndex),
}));
pollInputIndex++;
console.log("new pollInputIndex: ", pollInputIndex);

View File

@ -82,10 +82,10 @@
</div>
<div class="formrow poll_content_row auto_hide">
<div class="formitem">
<div class="pollinput" data-pollinput="0">
<div class="pollinput" data-pollinput=0>
<input type="checkbox" disabled />
<label class="pollinputlabel"></label>
<input form="quick_post_form" name="pollinputitem[0]" class="pollinputinput" type="text" placeholder="{{lang "topic.reply_add_poll_option"}}" />
<input form="quick_post_form" name="pollinputitem[0]" class="pollinputinput" type="text" placeholder="{{lang "topic.reply_add_poll_option_first"}}" />
</div>
</div>
</div>

View File

@ -1,6 +1,6 @@
<div class="rowblock topic_reply_container">
<div class="userinfo" aria-label="{{lang "topic.your_information"}}">
<div class="avatar_item" style="background-image: url({{.CurrentUser.Avatar}}), url(/static/white-dot.jpg);background-position: 0px -10px;">&nbsp;</div>
<div class="avatar_item" style="background-image:url({{.CurrentUser.Avatar}}), url(/static/white-dot.jpg);background-position:0px -10px;">&nbsp;</div>
<div class="user_meta">
<a href="{{.CurrentUser.Link}}" class="the_name" rel="author">{{.CurrentUser.Name}}</a>
{{if .CurrentUser.Tag}}<div class="tag_block"><div class="tag_pre"></div><div class="post_tag">{{.CurrentUser.Tag}}</div><div class="tag_post"></div></div>{{else}}<div class="tag_block"><div class="tag_pre"></div><div class="post_tag post_level">{{level .CurrentUser.Level}}</div><div class="tag_post"></div></div>{{end}}
@ -17,10 +17,10 @@
</div>
<div class="formrow poll_content_row auto_hide">
<div class="formitem">
<div class="pollinput" data-pollinput="0">
<div class="pollinput" data-pollinput=0>
<input type="checkbox" disabled />
<label class="pollinputlabel"></label>
<input form="quick_post_form" name="pollinputitem[0]" class="pollinputinput" type="text" placeholder="{{lang "topic.reply_add_poll_option"}}" />
<input form="quick_post_form" name="pollinputitem[0]" class="pollinputinput" type="text" placeholder="{{lang "topic.reply_add_poll_option_first"}}" />
</div>
</div>
</div>

View File

@ -1,5 +1,5 @@
<div class='pollinput' data-pollinput='{{.Index}}'>
<div class='pollinput' data-pollinput={{.Index}}>
<input type='checkbox' disabled />
<label class='pollinputlabel'></label>
<input form='quick_post_form' name='pollinputitem[{{.Index}}]' class='pollinputinput' type='text' placeholder='{{lang "topic.reply_add_poll_option"}}' />
<input form='quick_post_form' name='pollinputitem[{{.Index}}]' class='pollinputinput' type='text' placeholder='{{.Place}}' />
</div>

View File

@ -1,26 +1,26 @@
<input form="quick_post_form" id="has_poll_input" name="has_poll" value="0" type="hidden" />
<div class="formrow topic_content_row">
<div class="formitem">
<textarea form="quick_post_form" id="input_content" name="topic-content" placeholder="{{lang "quick_topic.content_placeholder"}}" required></textarea>
</div>
<input form="quick_post_form" id="has_poll_input" name="has_poll" value="0" type="hidden" />
<div class="formrow topic_content_row">
<div class="formitem">
<textarea form="quick_post_form" id="input_content" name="topic-content" placeholder="{{lang "quick_topic.content_placeholder"}}" required></textarea>
</div>
</div>
<div class="formrow poll_content_row auto_hide">
<div class="formitem">
<div class="pollinput" data-pollinput=0>
<input type="checkbox" disabled />
<label class="pollinputlabel"></label>
<input form="quick_post_form" name="pollinputitem[0]" class="pollinputinput" type="text" placeholder="{{lang "quick_topic.add_poll_option_first"}}" />
</div>
<div class="formrow poll_content_row auto_hide">
<div class="formitem">
<div class="pollinput" data-pollinput="0">
<input type="checkbox" disabled />
<label class="pollinputlabel"></label>
<input form="quick_post_form" name="pollinputitem[0]" class="pollinputinput" type="text" placeholder="{{lang "quick_topic.add_poll_option"}}" />
</div>
</div>
</div>
<div class="formrow quick_button_row">
<div class="formitem">
<button form="quick_post_form" class="formbutton">{{lang "quick_topic.create_topic_button"}}</button>
<button form="quick_post_form" class="formbutton" id="add_poll_button">{{lang "quick_topic.add_poll_button"}}</button>
{{if .CurrentUser.Perms.UploadFiles}}
<input name="upload_files" form="quick_post_form" id="upload_files" multiple type="file" class="auto_hide" />
<label for="upload_files" class="formbutton add_file_button">{{lang "quick_topic.add_file_button"}}</label>
<div id="upload_file_dock"></div>{{end}}
<button class="formbutton close_form">{{lang "quick_topic.cancel_button"}}</button>
</div>
</div>
</div>
</div>
<div class="formrow quick_button_row">
<div class="formitem">
<button form="quick_post_form" class="formbutton">{{lang "quick_topic.create_topic_button"}}</button>
<button form="quick_post_form" class="formbutton" id="add_poll_button">{{lang "quick_topic.add_poll_button"}}</button>
{{if .CurrentUser.Perms.UploadFiles}}
<input name="upload_files" form="quick_post_form" id="upload_files" multiple type="file" class="auto_hide" />
<label for="upload_files" class="formbutton add_file_button">{{lang "quick_topic.add_file_button"}}</label>
<div id="upload_file_dock"></div>{{end}}
<button class="formbutton close_form">{{lang "quick_topic.cancel_button"}}</button>
</div>
</div>