nitter/src/views/renderutils.nim

40 lines
1.2 KiB
Nim
Raw Normal View History

import karax/[karaxdsl, vdom, vstyles]
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=url.getSigUrl("pic"), class=class, alt="Image")
2019-08-12 01:32:27 +00: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