在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:mgwidmann/scrivener_html开源软件地址:https://github.com/mgwidmann/scrivener_html开源编程语言:Elixir 100.0%开源软件介绍:Scrivener.HtmlHelpers built to work with Scrivener's page struct to easily build HTML output for various CSS frameworks. SetupAdd to # add :scrivener_html to deps
defp deps do
[
# ...
{:scrivener_html, "~> 1.8"}
# ...
]
end
# add :scrivener_html to applications list
defp application do
[
# ...
applications: [ ..., :scrivener_html, ... ]
# ...
]
end For use with Phoenix.HTML, configure the config :scrivener_html,
routes_helper: MyApp.Router.Helpers,
# If you use a single view style everywhere, you can configure it here. See View Styles below for more info.
view_style: :bootstrap Import to your view. defmodule MyApp.UserView do
use MyApp.Web, :view
import Scrivener.HTML
end Example UsageUse in your template. <%= for user <- @page do %>
...
<% end %>
<%= pagination_links @page %> Where # params = %{"page" => _page}
def index(conn, params) do
page = MyApp.User
# Other query conditions can be done here
|> MyApp.Repo.paginate(params)
render conn, "index.html", page: page
end Scopes and URL ParametersIf your resource has any url parameters to be supplied, you should provide them as the 3rd parameter. For example, given a scope like: scope "/:locale", App do
pipe_through [:browser]
get "/page", PageController, :index, as: :pages
get "/pages/:id", PageController, :show, as: :page
end You would need to pass in the (this would generate links like "/en/page?page=1") <%= pagination_links @conn, @page, ["en"], path: &pages_path/4 %> With a nested resource, simply add it to the list: (this would generate links like "/en/pages/1?page=1") <%= pagination_links @conn, @page, ["en", @page_id], path: &page_path/4, action: :show %> Query String ParametersAny additional query string parameters can be passed in as well. <%= pagination_links @conn, @page, ["en"], some_parameter: "data" %>
# Or if there are no URL parameters
<%= pagination_links @conn, @page, some_parameter: "data" %> Custom ActionsIf you need to hit a different action other than <%= pagination_links @conn, @page, action: :show %> Customizing OutputBelow are the defaults which are used without passing in any options. <%= pagination_links @conn, @page, [], distance: 5, next: ">>", previous: "<<", first: true, last: true, view_style: :bootstrap %>
# Which is the same as
<%= pagination_links @conn, @page %> To prevent HTML escaping (i.e. seeing things like <%= pagination_links @conn, @page, previous: Phoenix.HTML.raw("←"), next: Phoenix.HTML.raw("→") %> To show icons instead of text, simply render custom html templates, like: (this example uses materialize icons) # Using Phoenix.HTML's sigil_E for EEx
<%= pagination_links @conn, @page, previous: ~E(<i class="material-icons">chevron_left</i>), next: ~E(<i class="material-icons">chevron_right</i>) %>
# Or by calling render
<%= pagination_links @conn, @page, previous: render("pagination.html", direction: :prev), next: render("pagination.html", direction: :next)) %> The same can be done for first/last links as well ( (this example uses materialize icons) <%= pagination_links @conn, @page, first: ~E(<i class="material-icons">chevron_left</i>), last: ~E(<i class="material-icons">chevron_right</i>) %> View StylesThere are six view styles currently supported:
ExtendingFor custom HTML output, see See Scrivener.HTML can be included in your view and then just used with a simple call to iex> Scrivener.HTML.pagination_links(%Scrivener.Page{total_pages: 10, page_number: 5}) |> Phoenix.HTML.safe_to_string()
"<nav>
<ul class=\"pagination\">
<li class=\"\"><a class=\"\" href=\"?page=4\"><<</a></li>
<li class=\"\"><a class=\"\" href=\"?page=1\">1</a></li>
<li class=\"\"><a class=\"\" href=\"?page=2\">2</a></li>
<li class=\"\"><a class=\"\" href=\"?page=3\">3</a></li>
<li class=\"\"><a class=\"\" href=\"?page=4\">4</a></li>
<li class=\"active\"><a class=\"\" href=\"?page=5\">5</a></li>
<li class=\"\"><a class=\"\" href=\"?page=6\">6</a></li>
<li class=\"\"><a class=\"\" href=\"?page=7\">7</a></li>
<li class=\"\"><a class=\"\" href=\"?page=8\">8</a></li>
<li class=\"\"><a class=\"\" href=\"?page=9\">9</a></li>
<li class=\"\"><a class=\"\" href=\"?page=10\">10</a></li>
<li class=\"\"><a class=\"\" href=\"?page=6\">>></a></li>
</ul>
</nav>" SEOSEO attributes like See |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论