~mika/www.m1kadev.nl

1c5e50a88b88ab1d2e500cdec0ab3257da2dce11 — m1kadev 6 months ago 4d656d6
kethel: start stage 1 of build api: collect
R bricks/base-header.html => bricks/base-header.thtml +0 -0
R bricks/extended-footer.html => bricks/extended-footer.thtml +0 -0
R bricks/footer.html => bricks/footer.thtml +0 -0
R bricks/highlight.html => bricks/highlight.thtml +0 -0
R bricks/navbar.html => bricks/navbar.thtml +0 -0
M kethel/lib/bricks.ex => kethel/lib/bricks.ex +5 -5
@@ 1,17 1,17 @@
defmodule Bricks do
  @typedoc "A path, relative to mix.exs"
  @type relative_path() :: String.t()
  @type relative_path() :: binary()

  @typedoc "The name of the brick"
  @type brick_name() :: String.t()
  @type brick_name() :: binary()

  @typedoc "A valid mustache template"
  @type mustache() :: String.t()
  @type mustache() :: binary()

  @spec collect(relative_path()) :: %{brick_name() => mustache()}
  @spec collect(relative_path()) :: [ { brick_name(), mustache() } ]
  def collect(folder) do
    Path.wildcard(folder <> "/bricks/*.thtml")
      |> Enum.map(fn brick -> { brick, File.read!(brick) } end) 
      |> Enum.map(fn { brick, contents } -> { Path.basename(brick) |> Path.rootname(), contents } end) # "../bricks/base_header.html" would beccome just "base_header"
      |> Enum.map(fn { brick, contents } -> { FileX.trimmed_filename(brick), contents } end) # "../bricks/base_header.html" would beccome just "base_header"
  end
 end 

A kethel/lib/compilers.ex => kethel/lib/compilers.ex +12 -0
@@ 0,0 1,12 @@
defmodule Compilers do
  # TODO
  @doc "Creates a random file in /tmp/kethel-TIME/, which functions as a pipe writing the given `data`"
  @spec tempdata(binary()) :: binary()
  defp tempdata(data) do
  end


  @doc "Invokes the fxg compiler on `data`. provides the output as a binary"
  def fxg(path) do
  end
end

A kethel/lib/filex.ex => kethel/lib/filex.ex +9 -0
@@ 0,0 1,9 @@
defmodule FileX do
  @typedoc "Any path"
  @type path() :: binary()

  @spec trimmed_filename(path()) :: binary()
  def trimmed_filename(path) do
    Path.basename(path) |> Path.rootname()
  end
end

A kethel/lib/kernelx.ex => kethel/lib/kernelx.ex +8 -0
@@ 0,0 1,8 @@
defmodule KernelX do

  @doc "Returns all bytes from `binary`, excluding those before `from`"
  @spec binary_slice_from(binary(), pos_integer()) :: binary()
  def binary_slice_from(binary, from) do
    binary_part(binary, from, byte_size(binary) - from)
  end
end

A kethel/lib/pages.ex => kethel/lib/pages.ex +8 -0
@@ 0,0 1,8 @@
defmodule Pages do
  def collect(context) do
    pages_root = context.project_root <> "/pages"
    pages = Path.wildcard(pages_root <> "/**/*.fxg")
      |> Enum.map(fn path -> { path, File.read!(path) } end)
      |> Enum.map(fn { path, data } -> { KernelX.binary_slice_from(path, byte_size(pages_root)), data } end)
  end
end

M kethel/main.exs => kethel/main.exs +6 -3
@@ 3,9 3,12 @@ args = System.argv()
folder = Enum.at(args, 1)

if folder != nil do
  IO.inspect(folder)
  bricks = Bricks.collect(folder)
  IO.inspect(bricks)
  project_root = Path.expand(folder) 
  context = %{
   project_root: project_root,
   bricks: Bricks.collect(project_root)
  }
  pages = Pages.collect(context)
else
  IO.puts(:stderr, "The root project folder should be provided on the command line")
end