{"id":13508033,"url":"https://github.com/ikeikeikeike/phoenix_html_simplified_helpers","last_synced_at":"2025-04-09T17:54:06.477Z","repository":{"id":51065302,"uuid":"52363999","full_name":"ikeikeikeike/phoenix_html_simplified_helpers","owner":"ikeikeikeike","description":"Some helpers for phoenix html( truncate, time_ago_in_words, number_with_delimiter, url_for, current_page? ) ","archived":false,"fork":false,"pushed_at":"2021-05-25T08:13:18.000Z","size":59,"stargazers_count":31,"open_issues_count":4,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T20:01:36.948Z","etag":null,"topics":["elixir","helper","html","phoenix"],"latest_commit_sha":null,"homepage":"https://github.com/ikeikeikeike/phoenix_html_simplified_helpers","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ikeikeikeike.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-23T14:16:51.000Z","updated_at":"2023-08-20T23:35:38.000Z","dependencies_parsed_at":"2022-09-19T18:23:46.184Z","dependency_job_id":null,"html_url":"https://github.com/ikeikeikeike/phoenix_html_simplified_helpers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikeikeikeike%2Fphoenix_html_simplified_helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikeikeikeike%2Fphoenix_html_simplified_helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikeikeikeike%2Fphoenix_html_simplified_helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikeikeikeike%2Fphoenix_html_simplified_helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ikeikeikeike","download_url":"https://codeload.github.com/ikeikeikeike/phoenix_html_simplified_helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248083558,"owners_count":21045122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","helper","html","phoenix"],"created_at":"2024-08-01T02:00:46.247Z","updated_at":"2025-04-09T17:54:06.450Z","avatar_url":"https://github.com/ikeikeikeike.png","language":"Elixir","funding_links":[],"categories":["Framework Components"],"sub_categories":[],"readme":"# PhoenixHtmlSimplifiedHelpers\n\n[![Build Status](http://img.shields.io/travis/ikeikeikeike/phoenix_html_simplified_helpers.svg?style=flat-square)](http://travis-ci.org/ikeikeikeike/phoenix_html_simplified_helpers)\n[![Hex version](https://img.shields.io/hexpm/v/phoenix_html_simplified_helpers.svg \"Hex version\")](https://hex.pm/packages/phoenix_html_simplified_helpers)\n[![Hex downloads](https://img.shields.io/hexpm/dt/phoenix_html_simplified_helpers.svg \"Hex downloads\")](https://hex.pm/packages/phoenix_html_simplified_helpers)\n[![Deps Status](https://beta.hexfaktor.org/badge/all/github/ikeikeikeike/phoenix_html_simplified_helpers.svg)](https://beta.hexfaktor.org/github/ikeikeikeike/phoenix_html_simplified_helpers)\n[![Inline docs](https://inch-ci.org/github/ikeikeikeike/phoenix_html_simplified_helpers.svg)](http://inch-ci.org/github/ikeikeikeike/phoenix_html_simplified_helpers)\n[![hex.pm](https://img.shields.io/hexpm/l/ltsv.svg)](https://github.com/ikeikeikeike/phoenix_html_simplified_helpers/blob/master/LICENSE)\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed as:\n\n  1. Add phoenix_html_simplified_helpers to your list of dependencies in `mix.exs`:\n\n  ```elixir\n  def deps do\n    [{:phoenix_html_simplified_helpers, \"~\u003e x.x.x\"}]\n  end\n  ```\n\n  2. Ensure phoenix_html_simplified_helpers is started before your application:\n\n  ```elixir\n  def application do\n    [applications: [:phoenix_html_simplified_helpers]]\n  end\n  ```\n\n  3. phoenix_html_simplified_helpers need to import(use) your Phoenix project. The following description is adding 'use syntax' into web.ex.\n\n  ```elixir\n  def view do\n    quote do\n      use Phoenix.View, root: \"web/templates\"\n\n      # Import convenience functions from controllers\n      import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1]\n\n      # Use all HTML functionality (forms, tags, etc)\n      use Phoenix.HTML\n      use Phoenix.HTML.SimplifiedHelpers  # \u003c- this line.\n\n      import MyApp.Router.Helpers\n      import MyApp.ErrorHelpers\n      import MyApp.Gettext\n    end\n  end\n  ```\n\n  It is also able to import(use) in each view helper files.\n\n  ```elixir\n  defmodule MyApp.LayoutView do\n    use MyApp.Web, :view\n    import Phoenix.HTML.SimplifiedHelpers.Truncate        # \u003c- this line.\n    import Phoenix.HTML.SimplifiedHelpers.TimeAgoInWords  # \u003c- this line.\n  end\n  ```\n\n  4. time_ago_in_words has Gettext module that is changed translation file from project's locale.\n\n  ```elixir\n  Gettext.put_locale(Phoenix.HTML.SimplifiedHelpers.Gettext, \"en\")\n  Gettext.put_locale(Phoenix.HTML.SimplifiedHelpers.Gettext, \"ja\")\n  Gettext.put_locale(Phoenix.HTML.SimplifiedHelpers.Gettext, \"es\")\n  ```\n\n\n# Usage\n\n## truncate\n\n```elixir\n\u003c%= truncate entity.content %\u003e\n```\n```elixir\ntruncate \"Once upon a time in a world far far away\"\n# Once upon a time in a world...\ntruncate \"Once upon a time in a world far far away\", length: 27\n# Once upon a time in a wo...\ntruncate \"And they found that many people were sleeping better.\", length: 25, omission: \"... (continued)\"\n# And they f... (continued)\ntruncate(\"Once upon a time in a world far far away\", length: 17, separator: \" \")\n# Once upon a...\n```\n\n## time_ago_in_words\n\n```elixir\n\u003c%= time_ago_in_words entity.published_at %\u003e ago\n```\n\n```elixir\ntime_ago_in_words :os.system_time\n# less than 5 seconds\ntime_ago_in_words Timex.now\n# less than 5 seconds\ntime_ago_in_words DateTime.utc_now\n# less than 5 seconds\ntime_ago_in_words Ecto.DateTime.utc\n# less than 5 seconds\ntime_ago_in_words NaiveDateTime.utc_now\n# less than 5 seconds\ntime_ago_in_words ~N[2017-08-14 04:40:12.101212]\n# ......\n```\n\n### distance_of_time_in_words\n\n```elixir\nfrom = Timex.to_datetime({{2015, 10, 31}, {0, 0, 0}})\nto   = Timex.shift(from, days: 45)\ndistance_of_time_in_words(from, to)\n# about 2 months\n\nGettext.put_locale(Phoenix.HTML.SimplifiedHelpers.Gettext, \"ja\")\nfrom = Timex.to_datetime({{2015, 10, 31}, {0, 0, 0}})\nto   = Timex.shift(from, months: 1)\ndistance_of_time_in_words(from, to)\n# 約1ヶ月\n\nGettext.put_locale(Phoenix.HTML.SimplifiedHelpers.Gettext, \"es\")\nfrom = Timex.to_datetime({{2015, 10, 31}, {0, 0, 0}})\nto   = Timex.shift(from, months: 18)\ndistance_of_time_in_words(from, to)\n# más de 1 año\n```\n\nOr uses `Timex.format!(\"{relative}\", :relative)` instead, like this.\n\n```elixir\nTimex.shift(datetime, hours: -3) |\u003e Timex.format!(\"{relative}\", :relative)\n\"3 hours ago\"\n```\n\n## number_with_delimiter\n\n```elixir\nnumber_with_delimiter 1234567\n# 1,234,567\n```\n\n## url_for\n\nRoutes setting is [Here](https://github.com/ikeikeikeike/phoenix_html_simplified_helpers/blob/master/test/test_helper.exs).\n\n```elixir\nurl_for(conn, \"home.index\")\n# /\n\nurl_for(conn, \"entry.release:\")\n# /release/\n\nurl_for(conn, \"entry.release:percent\")\n# /release/percent\n\nurl_for(conn, \"entry.release:\", some: \"query\")\n# /release/?some=query\n\nurl_for(conn, \"entry.release:\", some: \"query\", unko: \"query2\")\n# /release/?some=query\u0026unko=query2\n```\n\n## current_page?\n\n```elixir\nconn = conn(:get, \"/release/\")\n\ncurrent_page?(conn, \"entry.release:\")\n# true\n\ncurrent_page?(conn, \"home.index\")\n# false\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikeikeikeike%2Fphoenix_html_simplified_helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fikeikeikeike%2Fphoenix_html_simplified_helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikeikeikeike%2Fphoenix_html_simplified_helpers/lists"}