このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
Nitter-mod/src/views/renderutils.nim

91 行
3.0 KiB
Nim
Raw 通常表示 履歴

2019-09-18 04:01:44 +09:00
import strutils, strformat, xmltree
2019-09-06 10:37:12 +09:00
import karax/[karaxdsl, vdom]
import ../types, ../utils
proc icon*(icon: string; text=""; title=""; class=""; href=""): VNode =
var c = "icon-" & icon
if class.len > 0: c = c & " " & class
buildHtml(tdiv(class="icon-container")):
if href.len > 0:
a(class=c, title=title, href=href)
else:
span(class=c, title=title)
if text.len > 0:
text " " & text
proc linkUser*(profile: Profile, class=""): VNode =
let
isName = "username" notin class
href = "/" & profile.username
nameText = if isName: profile.fullname
else: "@" & profile.username
buildHtml(a(href=href, class=class, title=nameText)):
text nameText
if isName and profile.verified:
icon "ok", class="verified-icon", title="Verified account"
if isName and profile.protected:
text " "
icon "lock-circled", title="Protected account"
proc genImg*(url: string; class=""): VNode =
buildHtml():
img(src=getPicUrl(url), class=class, alt="Image")
2019-08-12 10:32:27 +09:00
proc linkText*(text: string; class=""): VNode =
let url = if "http" notin text: "http://" & text else: text
buildHtml():
a(href=url, class=class): text text
2019-09-18 04:01:44 +09:00
proc hiddenField*(name, value: string): VNode =
2019-09-06 05:53:23 +09:00
buildHtml():
2019-09-18 04:01:44 +09:00
verbatim "<input name=\"$1\" style=\"display: none\" value=\"$2\"/>" % [name, value]
proc refererField*(path: string): VNode =
hiddenField("referer", path)
2019-09-06 05:53:23 +09:00
proc iconReferer*(icon, action, path: string, title=""): VNode =
buildHtml(form(`method`="get", action=action, class="icon-button")):
2019-09-06 05:53:23 +09:00
refererField path
button(`type`="submit"):
icon icon, title=title
2019-09-06 05:53:23 +09:00
proc buttonReferer*(action, text, path: string; class=""; `method`="post"): VNode =
buildHtml(form(`method`=`method`, action=action, class=class)):
refererField path
button(`type`="submit"):
text text
2019-09-18 04:01:44 +09:00
proc genCheckbox*(pref, label: string; state: bool): VNode =
buildHtml(label(class="pref-group checkbox-container")):
2019-09-19 08:11:35 +09:00
text label
if state: input(name=pref, `type`="checkbox", checked="")
else: input(name=pref, `type`="checkbox")
span(class="checkbox")
2019-09-18 04:01:44 +09:00
proc genInput*(pref, label, state, placeholder: string; class=""; autofocus=false): VNode =
2019-09-18 04:01:44 +09:00
let s = xmltree.escape(state)
let p = xmltree.escape(placeholder)
let a = if autofocus: "autofocus" else: ""
2019-09-18 04:01:44 +09:00
buildHtml(tdiv(class=("pref-group pref-input " & class))):
if label.len > 0:
label(`for`=pref): text label
verbatim &"<input name={pref} type=\"text\" placeholder=\"{p}\" value=\"{s}\" {a}/>"
2019-09-18 04:01:44 +09:00
proc genSelect*(pref, label, state: string; options: seq[string]): VNode =
buildHtml(tdiv(class="pref-group")):
label(`for`=pref): text label
select(name=pref):
for opt in options:
if opt == state:
option(value=opt, selected=""): text opt
else:
option(value=opt): text opt
2019-09-20 05:11:38 +09:00
proc genDate*(pref, state: string): VNode =
buildHtml(span):
verbatim &"<input name={pref} type=\"date\" value=\"{state}\"/>"
icon "calendar"