ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - ikeikeikeike/phoenix_html_simplified_helpers: Some helpers for phoenix html( truncate, time_ago_in_words, number_with_delimiter, url_for, current_page? )
Some helpers for phoenix html( truncate, time_ago_in_words, number_with_delimiter, url_for, current_page? )  - GitHub - ikeikeikeike/phoenix_html_simplified_helpers: Some helpers for phoenix html( ...
Visit Site

GitHub - ikeikeikeike/phoenix_html_simplified_helpers: Some helpers for phoenix html( truncate, time_ago_in_words, number_with_delimiter, url_for, current_page? )

GitHub - ikeikeikeike/phoenix_html_simplified_helpers: Some helpers for phoenix html( truncate, time_ago_in_words, number_with_delimiter, url_for, current_page? )

PhoenixHtmlSimplifiedHelpers

Build Status Hex version Hex downloads Deps Status Inline docs hex.pm

Installation

If available in Hex, the package can be installed as:

  1. Add phoenix_html_simplified_helpers to your list of dependencies in mix.exs:
def deps do
  [{:phoenix_html_simplified_helpers, "~> x.x.x"}]
end
  1. Ensure phoenix_html_simplified_helpers is started before your application:
def application do
  [applications: [:phoenix_html_simplified_helpers]]
end
  1. phoenix_html_simplified_helpers need to import(use) your Phoenix project. The following description is adding 'use syntax' into web.ex.
def view do
  quote do
    use Phoenix.View, root: "web/templates"

    # Import convenience functions from controllers
    import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1]

    # Use all HTML functionality (forms, tags, etc)
    use Phoenix.HTML
    use Phoenix.HTML.SimplifiedHelpers  # <- this line.

    import MyApp.Router.Helpers
    import MyApp.ErrorHelpers
    import MyApp.Gettext
  end
end

It is also able to import(use) in each view helper files.

defmodule MyApp.LayoutView do
  use MyApp.Web, :view
  import Phoenix.HTML.SimplifiedHelpers.Truncate        # <- this line.
  import Phoenix.HTML.SimplifiedHelpers.TimeAgoInWords  # <- this line.
end
  1. time_ago_in_words has Gettext module that is changed translation file from project's locale.
Gettext.put_locale(Phoenix.HTML.SimplifiedHelpers.Gettext, "en")
Gettext.put_locale(Phoenix.HTML.SimplifiedHelpers.Gettext, "ja")
Gettext.put_locale(Phoenix.HTML.SimplifiedHelpers.Gettext, "es")

Usage

truncate

<%= truncate entity.content %>
truncate "Once upon a time in a world far far away"
# Once upon a time in a world...
truncate "Once upon a time in a world far far away", length: 27
# Once upon a time in a wo...
truncate "And they found that many people were sleeping better.", length: 25, omission: "... (continued)"
# And they f... (continued)
truncate("Once upon a time in a world far far away", length: 17, separator: " ")
# Once upon a...

time_ago_in_words

<%= time_ago_in_words entity.published_at %> ago
time_ago_in_words :os.system_time
# less than 5 seconds
time_ago_in_words Timex.now
# less than 5 seconds
time_ago_in_words DateTime.utc_now
# less than 5 seconds
time_ago_in_words Ecto.DateTime.utc
# less than 5 seconds
time_ago_in_words NaiveDateTime.utc_now
# less than 5 seconds
time_ago_in_words ~N[2017-08-14 04:40:12.101212]
# ......

distance_of_time_in_words

from = Timex.to_datetime({{2015, 10, 31}, {0, 0, 0}})
to   = Timex.shift(from, days: 45)
distance_of_time_in_words(from, to)
# about 2 months

Gettext.put_locale(Phoenix.HTML.SimplifiedHelpers.Gettext, "ja")
from = Timex.to_datetime({{2015, 10, 31}, {0, 0, 0}})
to   = Timex.shift(from, months: 1)
distance_of_time_in_words(from, to)
# 約1ヶ月

Gettext.put_locale(Phoenix.HTML.SimplifiedHelpers.Gettext, "es")
from = Timex.to_datetime({{2015, 10, 31}, {0, 0, 0}})
to   = Timex.shift(from, months: 18)
distance_of_time_in_words(from, to)
# más de 1 año

Or uses Timex.format!("{relative}", :relative) instead, like this.

Timex.shift(datetime, hours: -3) |> Timex.format!("{relative}", :relative)
"3 hours ago"

number_with_delimiter

number_with_delimiter 1234567
# 1,234,567

url_for

Routes setting is Here.

url_for(conn, "home.index")
# /

url_for(conn, "entry.release:")
# /release/

url_for(conn, "entry.release:percent")
# /release/percent

url_for(conn, "entry.release:", some: "query")
# /release/?some=query

url_for(conn, "entry.release:", some: "query", unko: "query2")
# /release/?some=query&unko=query2

current_page?

conn = conn(:get, "/release/")

current_page?(conn, "entry.release:")
# true

current_page?(conn, "home.index")
# false

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory