mgwidmann / scrivener_html

HTML view helpers for Scrivener
MIT License
125 stars 208 forks source link

Customization of wrapper classes #71

Open moroz opened 6 years ago

moroz commented 6 years ago

Hi there, First of all thank you for your work, I will use this library in my next pet project. However, I noticed that there is no easy way to change wrapper classes for pagination_links. For example, the templates for Bulma CSS are centered "by default", which means the classes are hard-coded in private functions. I ended up rewriting the functions like this:

  def pagination_links(paginator, conn) do
    %{page_number: current_page} = paginator
    path_fn = fn number -> Routes.post_path(conn, :index, %{"page" => number}) end

    content_tag :nav, class: "pagination" do
      content_tag :ul, class: "pagination-list" do
        Scrivener.HTML.raw_pagination_links(paginator)
        |> Enum.map(fn content -> page(content, current_page, path_fn) end)
      end
    end
  end

  defp page({number, number}, number, path_fn),
    do: link(Integer.to_string(number), to: path_fn.(number), class: "pagination-link is-current")

  defp page({number, number}, _, path_fn),
    do: link(Integer.to_string(number), to: path_fn.(number), class: "pagination-link")

  defp page({text, number}, _, path_fn) when is_bitstring(text),
    do: link(text, to: path_fn.(number), class: "pagination-link")

  defp page({:ellipsis, safe}, _, _) do
    content_tag :li do
      content_tag(:span, safe, class: "pagination-ellipsis")
    end
  end

  defp page(anything, _, _), do: inspect(anything)

Do you think it would be possible to add options to change wrapper classes for each separate element? Or maybe add a simple API that one could use to define own renderer modules, a bit like HTTPoison.Base? Technically, I'm still a newbie, but I'm open to implement and open a PR if you point me in the right direction. Regards, KM

mgwidmann commented 5 years ago

I was unaware that it automatically made the links centered. The best workaround for now seems it would be to override it with CSS, however thats not ideal.

Would allowing an override to classes work? I don't think I have time for something like that, but I'd be willing to accept a PR if you did.

mgwidmann commented 5 years ago

I know I didn't respond super quick but if anyone knows what should be done with this CSS framework, help would be appreciated.