Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customization of wrapper classes #71

Open
moroz opened this issue May 27, 2018 · 2 comments
Open

Customization of wrapper classes #71

moroz opened this issue May 27, 2018 · 2 comments

Comments

@moroz
Copy link

moroz commented May 27, 2018

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
Copy link
Owner

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants