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

97 行
2.9 KiB
Nim
Raw 通常表示 履歴

2021-12-27 10:37:38 +09:00
# SPDX-License-Identifier: AGPL-3.0-only
2020-06-01 09:22:22 +09:00
import strutils
2019-11-12 18:57:28 +09:00
import karax/[karaxdsl, vdom, vstyles]
2020-06-01 09:22:22 +09:00
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*(user: User, class=""): VNode =
let
isName = "username" notin class
href = "/" & user.username
nameText = if isName: user.fullname
else: "@" & user.username
buildHtml(a(href=href, class=class, title=nameText)):
text nameText
if isName and user.verified:
icon "ok", class="verified-icon", title="Verified account"
if isName and user.protected:
text " "
icon "lock", title="Protected account"
2019-08-12 10:32:27 +09:00
proc linkText*(text: string; class=""): VNode =
2021-12-30 12:18:40 +09:00
let url = if "http" notin text: https & text else: text
2019-08-12 10:32:27 +09:00
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-11-12 18:57:28 +09:00
input(name=name, style={display: "none"}, value=value)
2019-09-18 04:01:44 +09:00
proc refererField*(path: string): VNode =
hiddenField("referer", path)
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
2019-11-14 15:32:11 +09:00
proc genInput*(pref, label, state, placeholder: string; class=""): VNode =
2019-11-26 13:45:05 +09:00
let p = placeholder
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
2019-11-26 13:45:05 +09:00
if state.len == 0:
input(name=pref, `type`="text", placeholder=p, value=state, autofocus="")
2019-11-14 15:32:11 +09:00
else:
2019-11-26 13:45:05 +09:00
input(name=pref, `type`="text", placeholder=p, value=state)
2019-09-18 04:01:44 +09:00
proc genSelect*(pref, label, state: string; options: seq[string]): VNode =
2019-10-23 19:05:08 +09:00
buildHtml(tdiv(class="pref-group pref-input")):
2019-09-18 04:01:44 +09:00
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 =
2019-09-20 06:36:21 +09:00
buildHtml(span(class="date-input")):
2019-11-12 18:57:28 +09:00
input(name=pref, `type`="date", value=state)
2019-09-20 05:11:38 +09:00
icon "calendar"
2019-09-21 08:08:30 +09:00
proc genImg*(url: string; class=""): VNode =
buildHtml():
2020-06-17 07:20:34 +09:00
img(src=getPicUrl(url), class=class, alt="")
2019-09-21 08:08:30 +09:00
proc getTabClass*(query: Query; tab: QueryKind): string =
result = "tab-item"
if query.kind == tab:
result &= " active"
2022-01-14 11:16:09 +09:00
proc getAvatarClass*(prefs: Prefs): string =
if prefs.squareAvatars:
"avatar"
else:
"avatar round"