Skip to content

Commit

Permalink
Navigation, fuerers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Matiushkin committed Jun 21, 2017
1 parent 1994b6e commit 06a907c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 19 deletions.
2 changes: 1 addition & 1 deletion assets/brunch-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ exports.config = {

modules: {
autoRequire: {
"js/app.js": ["js/app"]
"js/app.js": []
}
},

Expand Down
36 changes: 23 additions & 13 deletions lib/eblox/content.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule Eblox.Content.Nav do
@moduledoc false

@typedoc """
Navigation as by web page navigation.
"""
Expand All @@ -7,23 +9,20 @@ defmodule Eblox.Content.Nav do
def fields, do: @fields
defstruct @fields

def new(list, key, acc \\ nil)
def new([], _key, _acc), do: nil
def new([h | _] = list, nil, _acc), do: new(list, h)
def new([h | t], key, acc) do
case h do
^key ->
next = case t do
[] -> nil
[th | _] -> th
end
%Eblox.Content.Nav{prev: acc, this: key, next: next}
prev -> new(t, key, prev)
end
@spec new(List.t, String.t, String.t) :: Eblox.Content.Nav.t
def new(list, key, next \\ nil)
def new([], _key, _next), do: nil
def new([key], key, _next), do: nil
def new([h | _] = list, nil, _next), do: new(list, h)
def new([key | [prev | _]], key, next) do
%Eblox.Content.Nav{prev: prev, this: key, next: next}
end
def new([next | t], key, _next), do: new(t, key, next)
end

defmodule Eblox.Content do
@moduledoc false

@typedoc """
Content is the whole lazily cached content of the blog.
"""
Expand All @@ -40,10 +39,14 @@ defmodule Eblox.Content do
def fields, do: @fields
defstruct @fields

require Logger

@spec new(String.t, List.t) :: Eblox.Content.t
def new(file, list) do
with {timestamp, _} <- to_date_number(file),
raw <- File.read!(Path.join(Eblox.GenEblox.content_dir, file)),
{ast, collected} <- Markright.to_ast(raw, Eblox.Markright.Collector),
ast <- fuererize(ast, collected[Markright.Collectors.Fuerer]),
html <- XmlBuilder.generate(ast) do
%Eblox.Content{
type: collected[Markright.Collectors.Type],
Expand All @@ -58,6 +61,12 @@ defmodule Eblox.Content do
end
end

@spec fuererize({:article, Map.t, List.t}, Keyword.t) :: {:article, Map.t, List.t}
defp fuererize({:article, %{}, [{:p, %{}, title} | rest]}, {:h2, %{}, title}),
do: {:article, %{}, [{:h2, %{}, title} | rest]}
defp fuererize(ast, _), do: ast

@spec to_date_number(String.t) :: {Date.t, Integer.t}
@doc """
Converts any arbitrary file name to a tuple `{Date.t, Integer.t}`.
Used for sorting the entries as well as for extracting the date from the url.
Expand Down Expand Up @@ -111,6 +120,7 @@ defmodule Eblox.Content do
end
end

@spec to_number_text(String.t) :: {Integer.t, String.t}
def to_number_text(file) when is_binary(file) do
with [[num, text]] <- Regex.scan(~r/\A(\d*)(.*)\z/, file, capture: :all_but_first),
do: {num, text}
Expand Down
2 changes: 2 additions & 0 deletions lib/eblox/markright/collector.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
defmodule Eblox.Markright.Collector do
@moduledoc false
use Markright.Collector, collectors: [
Markright.Collectors.Fuerer,
Markright.Collectors.OgpTwitter,
Markright.Collectors.Type,
Markright.Collectors.Tag]
Expand Down
2 changes: 1 addition & 1 deletion lib/eblox/web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Eblox.Web.PageController do

defp generic_route(conn, _opts) do
conn
|> put_flash(:info, "You must be logged in")
# TODO |> put_flash(:info, "You must be logged in")
|> assign(:title, @title)
|> assign(:description, @description)
|> assign(:author, @author)
Expand Down
24 changes: 21 additions & 3 deletions lib/eblox/web/templates/page/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,25 @@
</div>

<div class="row">
<div class="col s1"><a href="<%= @content.nav.prev %>"><%= @prev_title %></a></div>
<div class="col s10"></div>
<div class="col s1"><a href="<%= @content.nav.next %>"><%= @next_title %></a></div>
<div class="col s12 m12 center">
<%= if @content.nav.prev do %>
<a class="btn btn-floating teal"
href="<%= @content.nav.prev %>"
title="<%= @prev_title %>"><i class="material-icons medium"><%= @prev_title %></i></a>
<% else %>
<a class="btn btn-floating disabled"><i class="material-icons medium">⇐</i></a>
<% end %>
&nbsp;&nbsp;&nbsp;
<a class="btn btn-floating teal"
href="/"
title="🏠"><i class="material-icons medium">🏠</i></a>
&nbsp;&nbsp;&nbsp;
<%= if @content.nav.next do %>
<a class="btn btn-floating teal"
href="<%= @content.nav.next %>"
title="<%= @next_title %>"><i class="material-icons medium"><%= @next_title %></i></a>
<% else %>
<a class="btn btn-floating disabled"><i class="material-icons medium">⇒</i></a>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], []},
"gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [:mix], []},
"markright": {:hex, :markright, "0.3.2", "786308d1f4e71e2e02f3cf6d869945417cf07a4c0fccd10242881f64cba02e47", [:mix], []},
"markright": {:hex, :markright, "0.3.3", "06281aaa10841607bfe74c3504abd7be66f3835c83bbe917cfdb08b56e82a857", [:mix], []},
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], []},
"phoenix": {:hex, :phoenix, "1.3.0-rc.0", "4ecd69b1a421157b1de3109c9531396e847df483c86fe2be8ad188c3b9b1f447", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, optional: false]}, {:plug, "~> 1.3.2 or ~> 1.4", [hex: :plug, optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: false]}]},
"phoenix_html": {:hex, :phoenix_html, "2.9.3", "1b5a2122cbf743aa242f54dced8a4f1cc778b8bd304f4b4c0043a6250c58e258", [:mix], [{:plug, "~> 1.0", [hex: :plug, optional: false]}]},
Expand Down

0 comments on commit 06a907c

Please sign in to comment.