Skip to content

Commit

Permalink
Put notes on slides from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
zkayser committed May 15, 2020
1 parent 8d9c14c commit c95c03e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
21 changes: 20 additions & 1 deletion lib/live_deck/presentations/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule LiveDeck.Presentations.Config do
Use this Configuration to adjust Presentation settings, including position, background color, and title of slides.
"""

@default_theme "live-deck-theme"
@default_slides [
%{filename: "template_4_col.html", title: "overridden title"},
%{filename: "template_3_col.html", background_color: "overridden color"},
Expand All @@ -17,6 +18,24 @@ defmodule LiveDeck.Presentations.Config do
%{filename: "template_full_image.html"},
%{filename: "template_left_aside.html"}
]
# This is for testing purposes
@dummy List.first(@default_slides).filename

def slides, do: @default_slides
def slides do
@default_slides
|> insert_notes()
end

def insert_notes(slides) do
slides
|> Enum.map(fn %{filename: filename} = config ->
Map.put(config, :notes, notes(for: filename))
end)
end

defp notes(for: @dummy) do
"Hi. I am your notes."
end

defp notes(_), do: ""
end
6 changes: 4 additions & 2 deletions lib/live_deck/presentations/slide.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defmodule LiveDeck.Presentations.Slide do
:filename,
:background_color,
:title,
:position
:position,
:notes
]

@type title :: String.t()
Expand All @@ -22,7 +23,8 @@ defmodule LiveDeck.Presentations.Slide do
%__MODULE__{
struct
| title: format_title(slide[:title] || slide.filename),
position: position
position: position,
notes: slide.notes
}
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/live_deck/presentations/config_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule LiveDeck.Presentations.ConfigTest do
use ExUnit.Case
alias LiveDeck.Presentations.Config

describe "notes/2" do
test "returns slide config with notes added in" do
slides = Config.slides() |> Config.insert_notes()

assert List.first(slides).notes == "Hi. I am your notes."
end
end
end
4 changes: 4 additions & 0 deletions test/live_deck/presentations_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ defmodule LiveDeck.PresentationsTest do
assert first_slide.position == 0
assert last_slide.position == length(presentation.slides) - 1
end

test "inserts notes on slides", %{presentation: presentation} do
assert Enum.all?(presentation.slides, fn slide -> slide.notes end)
end
end

describe "next_slide/1" do
Expand Down

0 comments on commit c95c03e

Please sign in to comment.