defmodule Source do @shortdoc "Provides a macro to inspect source code rather than execute it" @moduledoc """ Provides a macro to inspect source code rather than execute it """ @doc """ This macro does not execute the code that is passed in, rather it returns the source so that it can be shown in the presentation. """ defmacro code(src) do [code: Macro.to_string(src)] end end defmodule Presentex do @shortdoc "Presentex generates HTML presentations for Elixir code" @moduledoc """ Presentex generates an index.html file that is the presentation for the slides passed in. """ @doc """ Generates the slide div element that will show the Elixir source code with syntax highlighting. """ def div([elixir: elixir]) do EEx.eval_string """

<%= elixir %>
      
""", [elixir: elixir] end @doc """ Generates the slide div element that will show the raw HTML. """ def div([html: html]) do EEx.eval_string """
<%= html %>
""", [html: html] end @doc """ Generates the slide div element that will show the Elixir source code with syntax highlighting. """ def div([code: code]) do EEx.eval_string """

<%= code %>
      
""", [code: code] end @doc """ Generates the slide div element that will show the title and subtitle. """ def div(args = [title: title, subtitle: subtitle]) do EEx.eval_string """

<%= title %>

<%= subtitle %>

""", args end @doc """ Generates the slide div element that will show a really large title. """ def div(args = [title: title]) do EEx.eval_string """

<%= title %>

""", args end @doc """ Generates the slide div element that will show a quote and attribute it. """ def div(args = [blockquote: blockquote, author: author]) do EEx.eval_string """
<%= blockquote %>
<%= author %>
""", args end @doc """ Generates the slide div element that will show a paragraph of text. """ def div(s) when is_binary(s) do EEx.eval_string """

<%= s %>

""", [s: s] end @doc """ Generates the slide div element that will show a bulleted list of items. """ def div(items) when is_list(items) do EEx.eval_string """
""", [items: items] end @doc """ Generates the content of the index.html file. """ def index(slides, style \\ "idea") do EEx.eval_string """ <%= for slide <- slides do %> <%= Presentex.div(slide) %> <% end %> """, [slides: slides, style: style] end @doc """ Generates the index.html file and copies the other JavaScript and CSS files to the destination directory. """ def gen(path, slides) do require Source content = Presentex.index(slides) File.write!(Path.join(path, "index.html"), content) File.cp_r("files", path) File.cp_r("deps/presentex/files", path) end end