forked from mojotech/torch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize repo as a lib with example, rather than an umbrella app (m…
…ojotech#33) * Reorganize repo as a lib with example, rather than an umbrella app In the original configuration, this project was an umbrella app, with one app being the torch lib itself, and the other app being the example. This proved problemmatic for a number of reason, so this rather sizeable commit reorganizes the repo so that the torch lib is at the top level, and the example app is in the apps dir. * Restore CHANGELOG * Fix CI script
- Loading branch information
1 parent
ddfb4c5
commit 8b37449
Showing
77 changed files
with
275 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,154 @@ | ||
# Torch | ||
|
||
[](https://semaphoreci.com/ir/torch) | ||
Torch is a rapid admin generator for Phoenix apps. It uses generators rather than DSLs to ensure that the code remains maintainable. | ||
|
||
 | ||
## Installation | ||
|
||
A rapid admin generator for Phoenix apps. See more details in the [README](/apps/torch/README.md). | ||
To install Torch, perform the following steps: | ||
|
||
## Development | ||
1. Add `torch` to your list of dependencies in `mix.exs`. Then, run `mix deps.get`: | ||
|
||
Because Torch relies on generators, the development environment needs to let you see the generated code in action. Accordingly, this repo is a Mix [umbrella app](http://elixir-lang.org/getting-started/mix-otp/dependencies-and-umbrella-apps.html). | ||
```elixir | ||
def deps do | ||
[{:torch, "~> 1.0.0-rc.5"}] | ||
end | ||
``` | ||
|
||
- **apps/torch**: The actual Torch Hex package, including the generators. | ||
- **apps/example**: A sample Phoenix app, using Torch. By running the Phoenix app, you can see Torch-generated code in action. | ||
2. Ensure `:torch` is started in your applications list in `mix.exs`: | ||
|
||
Follow these steps to set up your environment: | ||
```elixir | ||
def application do | ||
[applications: [:torch]] | ||
end | ||
``` | ||
|
||
1. Run `bin/setup`. | ||
2. In one terminal tab, `cd apps/torch` and run `./node_modules/brunch/bin/brunch watch --production`. | ||
3. In another terminal tab, `cd apps/example` and run `mix phoenix.server`. | ||
3. Add `torch` to your `package.json` dependencies. Then, run `npm install`. | ||
|
||
You can then visit `localhost:4000/admin/posts` and see a Torch-generated admin. | ||
```diff | ||
"dependencies": { | ||
"phoenix": "file:deps/phoenix", | ||
"phoenix_html": "file:deps/phoenix_html", | ||
+ "torch": "file:deps/torch" | ||
}, | ||
``` | ||
|
||
If you make a change to one of the generators, you can run `mix regenerate (eex|slim)` inside `apps/example` to regenerate the Torch code. | ||
4. Import `torch.js` in your `app.js`: | ||
|
||
```js | ||
import "torch" | ||
``` | ||
|
||
5. Run `mix torch.install (eex|slim)` to install the relevant Torch files. You can choose between `eex` templates and `slim` templates. If you choose to use `slim` templates, you will need to [install Phoenix Slim](https://github.com/slime-lang/phoenix_slime). | ||
|
||
6. Set up CSS as described below. | ||
|
||
## Setting up CSS | ||
|
||
Torch provides its CSS in two ways: | ||
|
||
1. A precompiled css file in `priv/static/css/torch.css`. | ||
2. SASS styles in `web/static/css/torch.sass` | ||
|
||
### Customization Using Sass Variables | ||
|
||
If you want to customize the look and feel of your admin, you should use the SASS styles. Update your `app.scss` file to look like this: | ||
|
||
```css | ||
@import "admin_variables"; | ||
@import "../../../node_modules/torch/web/static/css/torch"; | ||
``` | ||
|
||
Then, update your `brunch-config.js` sass settings to make Brunch watch your node_modules directory: | ||
|
||
```js | ||
plugins: { | ||
sass: { | ||
mode: 'native', | ||
includePaths: ['node_modules'] | ||
} | ||
} | ||
``` | ||
|
||
Then, simply uncomment and customize the variables in `web/static/css/_admin_variables.scss` to change how Torch is styled. | ||
|
||
### Using Precompiled CSS | ||
|
||
If you're not using SASS, then you will need to configure your asset pipeline to compile the precompiled `torch.css`. Brunch can be configured to do this like so: | ||
|
||
1. Add `node_modules` to the watched directories for `stylesheets`. | ||
|
||
```js | ||
stylesheets: { | ||
joinTo: { | ||
'css/app.css': /^(web|node_modules)/ | ||
} | ||
} | ||
``` | ||
|
||
2. Add `torch` to the npm configuration: | ||
|
||
```js | ||
npm: { | ||
enabled: true | ||
styles: { | ||
torch: [ | ||
'priv/static/torch.css' | ||
] | ||
} | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
Run `mix torch.gen (eex|slim)` to generate admin controllers and views for a given Ecto schema module. Torch expects you to have already defined the schema in your project. | ||
|
||
For example, if we wanted to generate an admin area for a `Post` model we already have using `eex` templates, we could run this command: | ||
|
||
```bash | ||
$ mix torch.gen eex Admin Post posts title:string body:text inserted_at:date | ||
``` | ||
|
||
And the output would be: | ||
|
||
```bash | ||
Success! | ||
|
||
You should now add a route to the new controller to your `router.ex`, within the `:admin` scope: | ||
|
||
scope "/admin", Example.Admin, as: :admin do | ||
pipe_through :browser | ||
|
||
resources "/posts", PostController | ||
end | ||
|
||
And update the `layout/admin.html.eex` navigation: | ||
|
||
<header id="main-header"> | ||
<nav> | ||
<h1>Torch Admin</h1> | ||
<ul> | ||
<li><%= Torch.NavigationView.nav_link @conn, "Posts", admin_post_path(@conn, :index) %></a> | ||
</ul> | ||
</nav> | ||
</header> | ||
``` | ||
|
||
The command created the following files for us: | ||
|
||
``` | ||
web/templates/admin/post/index.html.eex | ||
web/templates/admin/post/edit.html.eex | ||
web/templates/admin/post/new.html.eex | ||
web/templates/admin/post/_form.html.eex | ||
web/templates/admin/post/_filters.html.eex | ||
web/controllers/admin/post_controller.ex | ||
web/views/admin/post_view.ex | ||
``` | ||
|
||
If you hook up the routes as described above, you'll see a fully featured CRUD interface for posts, including sophisticated filtering, sorting and search at <http://localhost:4000/admin/posts>. | ||
|
||
To learn more about the `torch.gen` task, run: | ||
|
||
``` | ||
mix help torch.gen | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
%{"certifi": {:hex, :certifi, "0.7.0", "861a57f3808f7eb0c2d1802afeaae0fa5de813b0df0979153cbafcd853ababaf", [:rebar3], []}, | ||
"combine": {:hex, :combine, "0.9.2", "cd3c8721f378ebe032487d8a4fa2ced3181a456a3c21b16464da8c46904bb552", [:mix], []}, | ||
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []}, | ||
"cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [:make, :rebar], [{:cowlib, "~> 1.0.0", [hex: :cowlib, optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, optional: false]}]}, | ||
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], []}, | ||
"db_connection": {:hex, :db_connection, "1.0.0", "63c03e520d54886a66104d34e32397ba960db6e74b596ce221592c07d6a40d8d", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]}, | ||
"decimal": {:hex, :decimal, "1.2.0", "462960fd71af282e570f7b477f6be56bf8968e68277d4d0b641a635269bf4b0d", [:mix], []}, | ||
"ecto": {:hex, :ecto, "2.0.5", "7f4c79ac41ffba1a4c032b69d7045489f0069c256de606523c65d9f8188e502d", [:mix], [{:db_connection, "~> 1.0-rc.4", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.1.2 or ~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.7.7", [hex: :mariaex, optional: true]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.12.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0-beta", [hex: :sbroker, optional: true]}]}, | ||
"filtrex": {:hex, :filtrex, "0.3.0", "72023423f44e7b833e761ffa2079de761421f7c91fe9ad139f1b16de2e05a211", [:mix], [{:ecto, ">= 1.1.0", [hex: :ecto, optional: false]}, {:timex, "~> 2.1.4", [hex: :timex, optional: false]}]}, | ||
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], []}, | ||
"gettext": {:hex, :gettext, "0.12.1", "c0624f52763469ef7a3674919ae28b8286d88195b90fa1516180f31bbbd26d14", [:mix], []}, | ||
"hackney": {:hex, :hackney, "1.6.3", "d489d7ca2d4323e307bedc4bfe684323a7bf773ecfd77938f3ee8074e488e140", [:mix, :rebar3], [{:certifi, "0.7.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]}, | ||
"idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []}, | ||
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []}, | ||
"mime": {:hex, :mime, "1.0.1", "05c393850524767d13a53627df71beeebb016205eb43bfbd92d14d24ec7a1b51", [:mix], []}, | ||
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []}, | ||
"phoenix": {:hex, :phoenix, "1.2.1", "6dc592249ab73c67575769765b66ad164ad25d83defa3492dc6ae269bd2a68ab", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, optional: false]}, {:plug, "~> 1.1", [hex: :plug, optional: false]}, {:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: false]}]}, | ||
"phoenix_ecto": {:hex, :phoenix_ecto, "3.0.1", "42eb486ef732cf209d0a353e791806721f33ff40beab0a86f02070a5649ed00a", [:mix], [{:ecto, "~> 2.0", [hex: :ecto, optional: false]}, {:phoenix_html, "~> 2.6", [hex: :phoenix_html, optional: true]}, {:plug, "~> 1.0", [hex: :plug, optional: false]}]}, | ||
"phoenix_html": {:hex, :phoenix_html, "2.7.0", "19e12e2044340c2e43df206a06d059677c59ea1868bd1c35165438d592cd420b", [:mix], [{:plug, "~> 1.0", [hex: :plug, optional: false]}]}, | ||
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.0.5", "829218c4152ba1e9848e2bf8e161fcde6b4ec679a516259442561d21fde68d0b", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2-rc", [hex: :phoenix, optional: false]}]}, | ||
"phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.1", "c10ddf6237007c804bf2b8f3c4d5b99009b42eca3a0dfac04ea2d8001186056a", [:mix], []}, | ||
"phoenix_slime": {:hex, :phoenix_slime, "0.6.0", "d8f4beb11cffcae3bd44be289b79ab224e1e41e0264856b0f3b37d4d3eda7047", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: false]}, {:phoenix, "~> 1.1 or ~> 1.2-rc", [hex: :phoenix, optional: false]}, {:phoenix_html, "~> 2.3", [hex: :phoenix_html, optional: false]}, {:slime, "~> 0.13.0", [hex: :slime, optional: false]}]}, | ||
"plug": {:hex, :plug, "1.2.2", "cfbda521b54c92ab8ddffb173fbaabed8d8fc94bec07cd9bb58a84c1c501b0bd", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]}, | ||
"poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []}, | ||
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []}, | ||
"postgrex": {:hex, :postgrex, "0.12.1", "2f8b46cb3a44dcd42f42938abedbfffe7e103ba4ce810ccbeee8dcf27ca0fb06", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.0-rc.4", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}, | ||
"ranch": {:hex, :ranch, "1.2.1", "a6fb992c10f2187b46ffd17ce398ddf8a54f691b81768f9ef5f461ea7e28c762", [:make], []}, | ||
"scrivener": {:hex, :scrivener, "2.1.1", "eb52c8b7d283e8999edd6fd50d872ab870669d1f4504134841d0845af11b5ef3", [:mix], []}, | ||
"scrivener_ecto": {:hex, :scrivener_ecto, "1.0.2", "4b10a2e6c23ed8aae59731d7ae71bfd55afea6559aae61b124e6e521055b4a9c", [:mix], [{:ecto, "~> 2.0", [hex: :ecto, optional: false]}, {:postgrex, "~> 0.11.0 or ~> 0.12.0", [hex: :postgrex, optional: true]}, {:scrivener, "~> 2.0", [hex: :scrivener, optional: false]}]}, | ||
"slime": {:hex, :slime, "0.13.0", "fb9b1296b5ef3fe6aed09deec2794a146c94f5270b3bcd9f956c01d3660fc196", [:mix], []}, | ||
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []}, | ||
"timex": {:hex, :timex, "2.1.6", "2c59cd03074bccea47acd668c4dd6aad269879bcc9d6d4dd98fe0ffbaf48fcaa", [:mix], [{:combine, "~> 0.7", [hex: :combine, optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, optional: false]}]}, | ||
"tzdata": {:hex, :tzdata, "0.5.9", "575be217b039057a47e133b72838cbe104fb5329b19906ea4e66857001c37edb", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}]}} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.