XUtils

torch

Torch is a rapid admin generator for Phoenix apps. It uses generators rather than DSLs to ensure that the code remains maintainable.


Requirements

Upgrading

If you are upgrading from Torch v4 (or earlier) you can find additional documentation in the UPGRADING file.

Torch.Pagination customization

The following assumes you the above example when running torch.gen.html.

By default, the Torch generators added the following code to your Blog context module:

# blog.ex

  use Torch.Pagination,
    repo: MyApp.Repo,
    model: MyApp.Blog.Post,
    name: :posts

Please refer to the Torch.Pagination module for documentation on how to customize the pagination options for each model, or globally for your whole application.

NOTE If you want to customize the pagination functions themselves for your application, do not use the default Torch.Pagination as described above; instead you will need to define your own paginate_*/2 method that will return a Scrivener.Page object. You can also define your own pagination system and functions as well, but that will require further customization of the generated Torch controllers as well.

accounts.ex

… defp do_paginate_users(filter, params) do credential_params = Map.get(params, “credentials”) params = Map.drop(params, [“credentials”])

User |> Filtrex.query(filter) |> credential_filters(credential_params) |> order_by(^sort(params)) |> paginate(Repo, params, @pagination) end

defp credential_filters(query, nil), do: query

defp credential_filters(query, params) do search_string = “%#{params[“email”]}%”

from(u in query,

join: c in assoc(u, :credentials),
where: like(c.email, ^search_string),
group_by: u.id

) end …


2. Update form filters.

```eex
# users/index.html.heex
<div class="field">
  <label>Credential email</label>
  <%= text_input(:credentials, :email, value: maybe(@conn.params, ["credentials", "email"])) %>
</div>

Note: You’ll need to install & import Maybe into your views {:maybe, "~> 1.0.0"} for the above heex to work.

Styling

Torch generates two CSS themes you can use: base.css & theme.css. The base styles are basically bare bones, and the theme styles look like the screenshot above. Just change the stylesheet link in the torch.html.heex layout.

If you want to use the theme, but override the colors, you’ll need to include your own stylesheet with the specific overrides.

Internationalization

Torch comes with .po files for several locales. If you are using Torch and can provide us with translation files for other languages, please submit a Pull Request with the translation file. We’d love to add as many translations as possible.

If you wish to add your own customized translations, you can configure Torch to use your own custom MessagesBackend and adding it in your Torch configuration settings in config.exs. You can find the all messages that can be customized in the default i18n/backend.ex file.

If you are customizing a backend for a “standard” spoken language, please submit back a proper .po translation file for us to include in the official Torch releases so other users can take advantage.

Example

defmodule MyApp.CustomMessagesBackend do
  def message("Contains"), do: "** CUSTOM Contains **"
  def message("Equals"), do: "** CUSTOM Equals ****"
  def message("< Prev"), do: "<--"
  def message("Next >"), do: "-->"

  # You can add a fallback so it won't break with newly added messages or
  # messages you did not customize
  def message(text), do: Torch.I18n.Backend.message(text)
end
# config.exs
config :torch,
  otp_app: :my_app_name,
  i18n_backend: MyApp.CustomMessagesBackend

Development

Getting Started

Torch currently uses Node 18 to build its assets.

Building the Torch asset bundles

The JavaScript bundle is output to priv/static/torch.js, and the CSS bundles are output to priv/static/base.css and priv/static/theme.css.

To build the bundles navigate to the assets folder and run the following commands:

$ cd assets
$ npm i
$ npm run compile

Articles

  • coming soon...