Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fitVideo() #51

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docsrc/nimconf2022.nim
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ slide:
nbCodeDontRunAnimate(1, 2, 3, 4..7, 9, 10, 11):
for n in [50, 100, 1000, 10000]:
let filename = &"images/gauss-{n}.png"
let samples = newSeqWith[float](n, gauss(0.0, 1.0))
let samples = newSeqWith(n, gauss(0.0, 1.0))
let df = toDf(samples)
ggplot(df, aes("samples")) +
geom_histogram(fillColor="green") +
Expand All @@ -714,7 +714,7 @@ slide:
slide:
for n in [50, 100, 1000, 10000]:
let filename = &"images/gauss-{n}.png"
let samples = newSeqWith[float](n, gauss(0.0, 1.0))
let samples = newSeqWith(n, gauss(0.0, 1.0))
let df = toDf(samples)
ggplot(df, aes("samples")) +
geom_histogram(fillColor="green") +
Expand All @@ -738,4 +738,4 @@ slide:
nbText: "Thanks for watching 😄"
nbText: "Have a great day!"

nbSave()
nbSave()
28 changes: 26 additions & 2 deletions src/nimiSlides.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,28 @@ type
SlidesTheme* = enum
Black, Beige, Blood, Dracula, League, Moon, Night, Serif, Simple, Sky, Solarized, White

SlideTransition* {.pure.} = enum
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the enum to be pure, i.e. that you have to write SlideTransition.convex?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of the {.pure.} pragma was the opposite. I wanted to avoid calling the full name and just use 'convex.' I tried to compile my test code without the pragma, and it wouldn't compile.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that's weird 🤔

According to the manual it should be the opposite:

An enum type can be marked as pure. Then access of its fields always requires full qualification.

I'll try running your code without it and see if I can find something

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also getting an error without it so something fishy is going on. But as it seems to work, we can keep the pure pragma for now :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't even work when doing SlideTransition.convex without the pure pragma, really strange 🤯

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that's weird 🤔

According to the manual it should be the opposite:

An enum type can be marked as pure. Then access of its fields always requires full qualification.

I'll try running your code without it and see if I can find something

I see, the manual is a little bit confusing to me. I tried to understand the pragma based on this example.
https://nim-by-example.github.io/types/enums/

My guess was that the {.pure.} pragma does two things.

  1. It forces you to be explicit when there are overlapping names among all the declared enums.
  2. It allows you to refer to enums without qualification if there is no ambiguity.

none = "none"
slide = "slide" # default
fade = "fade"
convex = "convex"
concave = "concave"
zoom = "zoom"

SlideTransitionSpeed* {.pure.} = enum
fast = "fast"
slow = "slow"

Corner* = enum
UpperLeft, UpperRight, LowerLeft, LowerRight

NimiSlidesConfig* = object
localReveal*: string

SlideOptions* = object
transition*: SlideTransition
outTransition*: SlideTransition
transitionSpeed*: SlideTransitionSpeed
autoAnimate*: bool
colorBackground*: string
imageBackground*: string
Expand All @@ -46,12 +61,12 @@ type
iframeInteractive*: bool
gradientBackground*: string

proc slideOptions*(autoAnimate = false, iframeInteractive = true, colorBackground, imageBackground, videoBackground, iframeBackground, gradientBackground: string = ""): SlideOptions =
proc slideOptions*(autoAnimate = false, iframeInteractive = true, colorBackground, imageBackground, videoBackground, iframeBackground, gradientBackground: string = "", transition = SlideTransition.slide, outTransition = transition, transitionSpeed = SlideTransitionSpeed.fast ): SlideOptions =
SlideOptions(
autoAnimate: autoAnimate, iframeInteractive: iframeInteractive, colorBackground: colorBackground,
imageBackground: imageBackground, videoBackground: videoBackground,
iframeBackground: iframeBackground,
gradientBackground: gradientBackground,
gradientBackground: gradientBackground, transition: transition, outTransition: outTransition, transitionSpeed: transitionSpeed
)

const reveal_version* = "5.0.4"
Expand Down Expand Up @@ -217,6 +232,8 @@ var currentFragment*, currentSlideNumber*: int

proc slideOptionsToAttributes*(options: SlideOptions): string =
result.add """data-nimib-slide-number="$1" """ % [$currentSlideNumber]
result.add """data-transition="$1-in $2-out" """ % [$options.transition, $options.outTransition]
result.add """data-transition-speed="$1" """ % [$options.transitionSpeed]
if options.autoAnimate:
result.add "data-auto-animate "
if options.colorBackground.len > 0:
Expand Down Expand Up @@ -511,6 +528,13 @@ template bigText*(text: string) =
template fitImage*(src: string) =
nbRawHtml: hlHtml"""<img data-src="$1" class="r-stretch">""" % [src]

template fitVideo*(src: string) =
nbRawHtml: """
<video controls class="r-stretch">
<source src="$1" type="video/mp4">
<source src="$1" type="video/webm">
</video>""" % [src]

template speakerNote*(text: string) =
nbRawHtml: """
<aside class="notes">
Expand Down
Loading