"""
- doc.renderPlans["bigText"] = doc.renderPlans["nbText"]
+proc revealTheme*(nb: var Nb) =
+ nb.backend.funcs["NbDoc"] = revealNbDocToHtml
+ nb.backend.partials["head"] = revealHeadToHtml
+
+ nb.populateNimiSlidesBlockPartials()
- doc.context["slidesTheme"] = "black"
- doc.context["nb_style"] = ""
- doc.context["reveal_version"] = reveal_version
+ nb.doc.context["slidesTheme"] = %"black"
+ nb.doc.context["nb_style"] = %""
+ nb.doc.context["reveal_version"] = %reveal_version
try:
- let slidesConfig = loadTomlSection(doc.rawCfg, "nimislides", NimiSlidesConfig)
+ let slidesConfig = loadTomlSection(nb.doc.rawCfg, "nimislides", NimiSlidesConfig)
if slidesConfig.localReveal != "":
echo "Using local Reveal.js installation specified in nimib.toml "
- doc.useLocalReveal(slidesConfig.localReveal)
+ nb.useLocalReveal(slidesConfig.localReveal)
except CatchableError:
discard # if it doesn't exists, just let it be
var currentFragment*, currentSlideNumber*: int
-proc slideOptionsToAttributes*(options: SlideOptions): string =
- result.add """data-nimib-slide-number="$1" """ % [$currentSlideNumber]
- if options.autoAnimate:
- result.add "data-auto-animate "
- if options.colorBackground.len > 0:
- result.add """data-background-color="$1" """ % [options.colorBackground]
- elif options.imageBackground.len > 0:
- result.add """data-background-image="$1" """ % [options.imageBackground]
- elif options.videoBackground.len > 0:
- result.add """data-background-video="$1" """ % [options.videoBackground]
- elif options.iframeBackground.len > 0:
- result.add """data-background-iframe="$1" """ % [options.iframeBackground]
- if options.iframeInteractive:
- result.add "data-background-interactive "
- elif options.gradientBackground.len > 0:
- result.add """data-background-gradient="$1" """ % [options.gradientBackground]
-
-template slide*(options: untyped, body: untyped): untyped =
+template slide*(toptions: untyped, body: untyped): untyped =
currentSlideNumber += 1
-
- nbRawHtml: "" % [slideOptionsToAttributes(options)]
+ let blk = newNbSlide(slideNumber=currentSlideNumber, options=toptions)
+
when declaredInScope(CountVarNimiSlide):
when CountVarNimiSlide < 2:
static: inc CountVarNimiSlide
- body
+ nb.withContainer(blk):
+ body
static: dec CountVarNimiSlide
else:
{.error: "You can only nest slides once!".}
else:
var CountVarNimiSlide {.inject, compileTime.} = 1 # we just entered the first level
- body
+ nb.withContainer(blk):
+ body
static: dec CountVarNimiSlide
- nbRawHtml: ""
+ nb.add blk
template slide*(body: untyped) =
slide(slideOptions()):
@@ -257,6 +341,23 @@ template slideAutoAnimate*(body: untyped) =
slide(slideOptions(autoAnimate=true)):
body
+template fragmentCoreOld*(animations: openArray[seq[FragmentAnimation]], endAnimations: openArray[seq[FragmentAnimation]], indexOffset: untyped, incrementCounter: untyped, body: untyped) =
+ ## Creates a fragment of the content of body. Nesting works.
+ ## animations: each seq in animations are animations that are to be applied at the same time. The first seq's animations
+ ## are applied on the first button click, and the second seq's animations on the second click etc.
+ ## endAnimations: animations that should be applied AT THE END of block.
+ ## Example:
+ ## `fragment(@[@[fadeIn, highlightBlue], @[shrinks, semiFadeOut]]): block` will at the first click of a button fadeIn and highlightBlue
+ ## the content of the block. At the second click the same content will shrink and semiFadeOut. This code is also equivilent with
+ ## `fragment(@[@[fadeIn, highlightBlue]]): fragment(@[@[shrinks, semiFadeOut]]): block`.
+ ## `fragment(@[@[fadeIn]], @[@[fadeOut]]): block` will first fadeIn the entire block and perform eventual animations in nested fragments. Once
+ ## all of those are finished, it will run fadeOut on the entire block and its subfragments.
+ var fragments: seq[Table[string, string]]
+ fragmentStartBlock(fragments, animations, endAnimations, indexOffset, incrementCounter)
+ var startBlock = nb.blk # this *should* be the block created by fragmentStartBlock
+ body
+ fragmentEndBlock(fragments, animations, endAnimations, startBlock)
+
template fragmentStartBlock(fragments: seq[Table[string, string]], animations: openArray[seq[FragmentAnimation]], endAnimations: openArray[seq[FragmentAnimation]], indexOffset: int, incrementCounter: bool) =
newNbSlimBlock("fragmentStart"):
for level in animations:
@@ -296,11 +397,21 @@ template fragmentCore*(animations: openArray[seq[FragmentAnimation]], endAnimati
## `fragment(@[@[fadeIn, highlightBlue]]): fragment(@[@[shrinks, semiFadeOut]]): block`.
## `fragment(@[@[fadeIn]], @[@[fadeOut]]): block` will first fadeIn the entire block and perform eventual animations in nested fragments. Once
## all of those are finished, it will run fadeOut on the entire block and its subfragments.
- var fragments: seq[Table[string, string]]
- fragmentStartBlock(fragments, animations, endAnimations, indexOffset, incrementCounter)
- var startBlock = nb.blk # this *should* be the block created by fragmentStartBlock
- body
- fragmentEndBlock(fragments, animations, endAnimations, startBlock)
+ let blk = newNbFragment()
+ for level in animations:
+ if level.len > 1 and fadeIn in level:
+ # Add a fadeIn fragment at the same frame
+ blk.fragments.add FragmentItem(classStr: "", fragIndex: currentFragment + indexOffset)
+ blk.fragments.add FragmentItem(classStr: level.join(" "), fragIndex: currentFragment + indexOffset)
+ if incrementCounter:
+ currentFragment += 1
+
+ withContainer(nb, blk):
+ body
+
+ for level in endAnimations:
+ blk.fragments.add FragmentItem(classStr: level.join(" "), fragIndex: currentFragment)
+ nb.add blk
template fragmentCore*(animations: openArray[seq[FragmentAnimation]], endAnimations: openArray[seq[FragmentAnimation]], body: untyped) =
fragmentCore(animations, endAnimations, 0, true, body)
@@ -400,12 +511,6 @@ template listItem*(animation: FragmentAnimation, body: untyped) =
template listItem*(body: untyped) =
listItem(fadeInThenSemiOut, body)
-template animateCode*(lines: string, body: untyped) =
- newNbCodeBlock("animateCode", body):
- nb.blk.context["highlightLines"] = lines
- captureStdout(nb.blk.output):
- body
-
template animateCode*(lines: varargs[set[range[0..65535]], toSet], body: untyped) =
## Shows code and its output just like nbCode, but highlights different lines of the code in the order specified in `lines`.
## lines: Specify which lines to highlight and in which order. The lines can be specified using either:
@@ -417,39 +522,39 @@ template animateCode*(lines: varargs[set[range[0..65535]], toSet], body: untyped
## animateCode(1, 2..3, {4, 6}): body
## ```
## This will first highlight line 1, then lines 2 and 3, and lastly line 4 and 6.
- newNbCodeBlock("animateCode", body):
- var linesString: string
- if lines.len > 0:
- linesString &= "|"
- for lineBundle in lines:
- for line in lineBundle:
- linesString &= $line & ","
- linesString &= "|"
- if lines.len > 0:
- linesString = linesString[0 .. ^3]
- nb.blk.context["highlightLines"] = linesString
- captureStdout(nb.blk.output):
+ var highlightedLines: seq[seq[int]]
+ for line in lines:
+ var lineSeq: seq[int]
+ for l in line:
+ lineSeq.add l
+ highlightedLines.add lineSeq
+ let blk = newNbAnimateCode(highlightedLines=highlightedLines)
+ blk.code = getCode(body)
+ nb.withContainer(blk):
+ captureStdout(blk.output):
body
+ nb.add blk
-template newAnimateCodeBlock*(cmd: untyped, impl: untyped) =
- const cmdStr = astToStr(cmd)
-
- template `cmd`*(lines: varargs[set[range[0..65535]], toSet], body: untyped) =
- newNbCodeBlock(cmdStr, body):
- var linesString: string
- if lines.len > 0:
- linesString &= "|"
- for lineBundle in lines:
- for line in lineBundle:
- linesString &= $line & ","
- linesString &= "|"
- if lines.len > 0:
- linesString = linesString[0 .. ^3]
- nb.blk.context["highlightLines"] = linesString
- impl(body)
-
- nb.partials[cmdStr] = nb.partials["animateCode"]
- nb.renderPlans[cmdStr] = nb.renderPlans["animateCode"]
+template animateCodeSkip*(lines: varargs[set[range[0..65535]], toSet], body: untyped) =
+ ## Shows code and its output just like nbCode, but highlights different lines of the code in the order specified in `lines`.
+ ## lines: Specify which lines to highlight and in which order. The lines can be specified using either:
+ ## - An `int` (highlight single line)
+ ## - A slice `x..y` (highlight a range of consequative lines)
+ ## - A set {x, y..z} (highlight any combination of lines)
+ ## Ex:
+ ## ```nim
+ ## animateCode(1, 2..3, {4, 6}): body
+ ## ```
+ ## This will first highlight line 1, then lines 2 and 3, and lastly line 4 and 6.
+ var highlightedLines: seq[seq[int]]
+ for line in lines:
+ var lineSeq: seq[int]
+ for l in line:
+ lineSeq.add l
+ highlightedLines.add lineSeq
+ let blk = newNbAnimateCode(highlightedLines=highlightedLines)
+ blk.code = getCode(body)
+ nb.add blk
template typewriter*(textMessage: string, typeSpeed = 50, alignment = "center") =
let localText = textMessage
@@ -458,23 +563,29 @@ template typewriter*(textMessage: string, typeSpeed = 50, alignment = "center")
# HTML and add eventlistener
# check what we get back from reveal's event
let fragIndex = currentFragment # important it is before fragmentFadeIn!
- let id = "typewriter" & $nb.newId()
+ let id = "typewriter" & $nb.doc.newId()
fragmentFadeIn:
- nbKaraxCode(id, localText, fragIndex, speed, align):
+ nbRawHtml: hlHTml"""
+
$3
+ """ % [id, align, localText]
+ nbJsFromCodeOwnFile(id, localText, fragIndex, speed, align):
+ import std / [dom]
import nimiSlides/revealFFI
- import karax / vstyles
var i = 0
var timeout: Timeout
proc typewriterLocal() =
echo "Typing ", fragindex
var el = getElementById(id.cstring)
if i < localText.len:
- el.innerHtml &= $localText[i]
+ var c = localText[i]
+ let s =
+ if c == '\n':
+ " "
+ else:
+ $c
+ el.innerHtml &= s
inc i
timeout = setTimeout(typewriterLocal, speed)
- karaxHtml:
- p(id = id, style=style(textAlign, align.kstring)):
- text localText.cstring
window.addEventListener("load", proc (event: Event) =
echo "Loading ", fragIndex
@@ -504,9 +615,9 @@ template typewriter*(textMessage: string, typeSpeed = 50, alignment = "center")
discard
))
-template bigText*(text: string) =
- newNbSlimBlock("bigText"):
- nb.blk.output = text
+template bigText*(ttext: string) =
+ let blk = newNbBigText(text=ttext)
+ nb.add blk
template fitImage*(src: string) =
nbRawHtml: hlHtml"""""" % [src]
@@ -519,47 +630,40 @@ template speakerNote*(text: string) =
""" % [markdown(text)]
template align*(text: string, body: untyped) =
- nbRawHtml: """
-
-""" % text
- body
- nbRawHtml: "
"
+ nbDiv(styles="text-align: $1;" % text, classes=""):
+ body
#templates can't have default args and untyped args at the same time
#so we use overloading to get the same effect
template columns*(columnGap: float, body: untyped) =
#tempted to use fmt"", but strformat doesn't support template args in the format string
- nbRawHtml: """