All Projects → ikeikeikeike → phoenix_html_simplified_helpers

ikeikeikeike / phoenix_html_simplified_helpers

Licence: MIT license
Some helpers for phoenix html( truncate, time_ago_in_words, number_with_delimiter, url_for, current_page? )

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to phoenix html simplified helpers

SQLServerTools
This repo is the home of various SQL-Server-Tools
Stars: ✭ 28 (-3.45%)
Mutual labels:  helper
stub on web
Create stub urls to test external API integration
Stars: ✭ 54 (+86.21%)
Mutual labels:  phoenix
phoenix meta tags
Phoenix library helps generating meta tags for website.
Stars: ✭ 25 (-13.79%)
Mutual labels:  phoenix
live dj
💿 Join or create video playlists to share a real-time experience with others! 🎧
Stars: ✭ 19 (-34.48%)
Mutual labels:  phoenix
sms blitz
Send SMS messages through multiple different providers
Stars: ✭ 29 (+0%)
Mutual labels:  phoenix
algoliax
Algolia integration to elixir application
Stars: ✭ 38 (+31.03%)
Mutual labels:  phoenix
phoenix passwordless login
Phoenix Passwordless Login
Stars: ✭ 28 (-3.45%)
Mutual labels:  phoenix
vkhelpers
Vulkan c helper library
Stars: ✭ 25 (-13.79%)
Mutual labels:  helper
alternate
Plug and Phoenix helpers to localize your web app via the URL
Stars: ✭ 26 (-10.34%)
Mutual labels:  phoenix
elixir ravelry
Elixir API using Neo4j database for ElixirConf 2017 talk
Stars: ✭ 21 (-27.59%)
Mutual labels:  phoenix
phoenix-queryserver
Apache Phoenix Query Server
Stars: ✭ 33 (+13.79%)
Mutual labels:  phoenix
background-service-lib
Essential classes for reliable background services.
Stars: ✭ 24 (-17.24%)
Mutual labels:  helper
radiopush
Create communities and share songs with Spotify users (https://radiopush.app)
Stars: ✭ 89 (+206.9%)
Mutual labels:  phoenix
laravel-cache
An improved helper for working with cache
Stars: ✭ 64 (+120.69%)
Mutual labels:  helper
phoenix pagination
Simple pagination for Ecto and Phoenix that uses plain EEx templates.
Stars: ✭ 20 (-31.03%)
Mutual labels:  phoenix
Android-SharedPreferences-Helper
This Shared Preferences Helper library (Library size = ~15kb only) Simplifies usage of the default Android SharedPreferences Class. The developer can do in a few lines of code which otherwise would have required several. Simple to understand as compared to the default Shared Preferences class and easy to use. Can be used by simply adding the dep…
Stars: ✭ 15 (-48.28%)
Mutual labels:  helper
gringotts payment
Demo Phoenix app showing gringotts payment library integrations.
Stars: ✭ 24 (-17.24%)
Mutual labels:  phoenix
uncharted
No description or website provided.
Stars: ✭ 31 (+6.9%)
Mutual labels:  phoenix
phoenix.webui.framework
基于WebDriver的WebUI自动化测试框架
Stars: ✭ 118 (+306.9%)
Mutual labels:  phoenix
Country
Country gives a list of countries with all their flags.
Stars: ✭ 26 (-10.34%)
Mutual labels:  helper

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].