This project builds on top of Phoenix, so you'll need a new phoenix project. These install docs assume you're using phoenix 1.3+.
You can find an example lightweight application here. The commits on the example project are just following the installation below.
Installation
1. Add dependencies
# file: ./mix.exs
defp deps do
[
...
{:texas, "^x.x.x"}, # latest should be denoted by the texas hex badge at the top
...
]
end
# file: ./assets/package.json
...
"dependencies": {
...
"texasjs": "^x.x.x", # latest should be denoted by the texasjs npm badge at the top
...
},install the deps
$ mix deps.get$ cd assets/ && npm install
2. setup your websocket channels and texasjs
# file: ./assets/js/app.js
import socket from "./socket"
import texasjs from "texasjs"
// texas needs access to the phoenix apps websocket
new texasjs(socket)# file: ./lib/<your_app>_web/channels/user_socket.ex
defmodule WorkingOnDocsWeb.UserSocket do
...
use Texas.Socket
end3. let texas know where your endpoint and router modules are via config and setup the templating engine to compile .tex files
# file: config/config.ex
config :texas, pubsub: <YourApp>Web.Endpoint
config :texas, router: <YourApp>Web.Router
config :phoenix, :template_engines,
tex: Texas.TemplateEngine4. insert the texas plug into your http pipeline and import some rendering functions texas gives you into the controllers you want to use with texas
# file: ./lib/<your_app>_web/router.ex
defmodule <YourAppWeb>.Router do
...
pipeline :browser do
...
Texas.Plug
end
...
end
# file: ./lib/<your_app>_web/controllers/page_controller.ex
defmodule <YourApp>Web.PageController do
...
import Texas.Controller
...
end5. Creating a dynamic template and view
note: the template needs to be
.tex(or whatever you put in your config) to get run thru the texas template engine!
# file: ./lib/<your_app>_web/templates/<your_view>/index.html.tex
<div data-texas="example_list">
Some example prototype data that will be overwritten.
</div>
# file: ./lib/<your_app>_web/views/<your_view>.ex
defmodule <YourApp>Web.<YourView> do
use <YourApp>Web, :view
def data(conn) do
%{ example_list: example_list(conn) }
end
def example_list(_conn) do
{"div", [class: "some-class"], []}
end
end6. responding with that rendered view via a controller
# file: ./lib/<your_app>_web/controllers/page_controller.ex
...
def index(conn, _params) do
texas_render conn, "index.html", [texas: <YourApp>Web.<YourView>.data(conn)]
end
...