Coder Social home page Coder Social logo

torch's Introduction

Torch

Slackin Hex.pm Build Status Deps Status

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

Installation

To install Torch, perform the following steps:

  1. Add torch to your list of dependencies in mix.exs. Then, run mix deps.get:
def deps do
  [{:torch, "~> 1.0.0-rc.5"}]
end
  1. Ensure :torch is started in your applications list in mix.exs:
def application do
  [applications: [:torch]]
end
  1. Add torch to your package.json dependencies. Then, run npm install.
"dependencies": {
  "phoenix": "file:deps/phoenix",
  "phoenix_html": "file:deps/phoenix_html",
+ "torch": "file:deps/torch"
},
  1. Import torch.js in your app.js:
import "torch"
  1. 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.

  2. 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 assets/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:

@import "admin_variables";
@import "../../../node_modules/torch/assets/css/torch";

Then, update your brunch-config.js sass settings to make Brunch watch your node_modules directory:

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.
stylesheets: {
  joinTo: {
    'css/app.css': /^(web|node_modules)/
  }
}
  1. Add torch to the npm configuration:
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:

$ mix torch.gen eex Admin Post posts title:string body:text inserted_at:date

And the output would be:

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

torch's People

Contributors

danielberkompas avatar darinwilson avatar codeithuman avatar zberkom avatar silasjmatson avatar hanskenis avatar jamonholmgren avatar debetux avatar lboekhorst avatar yulolimum avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.