Skip to content

Commit c263fbc

Browse files
committed
Add Guide section
1 parent 45d47f6 commit c263fbc

File tree

7 files changed

+166
-2
lines changed

7 files changed

+166
-2
lines changed

config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ category = "categories"
1212

1313
[params.highlight]
1414
style = "github"
15-
languages = ["elixir", "javascript"]
15+
languages = ["elixir", "javascript", "bash"]
1616

1717
[[params.social]]
1818
url = "https://github.com/elixirscript"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
+++
2+
date = "2017-03-05T14:27:53-06:00"
3+
title = "using with phoenix"
4+
+++
5+
6+
This guide will walk through setting up a Phoenix project with Elixirscript. This guide assumes you have already created a Phoenix project
7+
8+
**NOTE**: This guide covers Phoenix 1.2. It will be updated when Phoenix 1.3 is released
9+
10+
Update your mix.exs file to add the current version of elixirscript to your dependencies:
11+
12+
```elixir
13+
defp deps do
14+
[
15+
#other deps
16+
{:elixir_script, "~> x.x.x"}
17+
]
18+
```
19+
20+
Run `mix deps.get`:
21+
22+
```bash
23+
mix deps.get
24+
```
25+
26+
Next, Add the `elixir_script` compiler to your list of mix compilers. Also add in the `elixir_script` configuration:
27+
28+
```elixir
29+
def project do
30+
[app: :my_app,
31+
version: "0.0.1",
32+
elixir: "~> 1.2",
33+
elixirc_paths: elixirc_paths(Mix.env),
34+
compilers: [:phoenix, :gettext, :elixir_script] ++ Mix.compilers,
35+
build_embedded: Mix.env == :prod,
36+
start_permanent: Mix.env == :prod,
37+
deps: deps(),
38+
elixir_script: [
39+
input: "web/static/elixirscript",
40+
output: "web/static/js/build"
41+
]
42+
]
43+
end
44+
```
45+
46+
Elixirscript by default will looks for input in the `lib/elixirscript` directory. It will also by default output to `priv/elixirscript`. Update the input directory to `web/static/elixirscript`. Update the output directory to `web/static/js/build`. This lets it tie into Brunch's pipeline.
47+
48+
Next, update the watcher configuration to use the Elixirscript watcher:
49+
50+
```elixir
51+
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
52+
cd: Path.expand("../", __DIR__)], mix: ["elixirscript.watch"]]
53+
```
54+
55+
Whenever your Elixirscript code changes, the elixirscript compiler will recompile it.
56+
57+
Create `app.ex` in the `web/static/elixirscript` directory
58+
59+
```bash
60+
touch web/static/elixirscript/app.ex
61+
```
62+
63+
For this example, write a simple module that will write `Hello, world` to the console on start:
64+
65+
```elixir
66+
defmodule App do
67+
68+
def start(_type, _args) do
69+
:console.log("Hello, world")
70+
end
71+
72+
end
73+
```
74+
75+
Finally, update `web/static/js/app.js` to start your Elixirscript app:
76+
77+
```javascript
78+
import Elixir from './build/Elixir.App';
79+
Elixir.start(Elixir.App, [])
80+
```
81+
82+
The empty array is list of initial arguments for your app.
83+
84+
85+
If you run `mix compile`, you should see a JavaScript file, `Elixir.App.js` in your `web/static/js/build` directory.
86+
87+
If you run `mix phoenix.server`, open your browser, and then open your console, you should see `Hello, world`. Any changes should cause a reload
88+

layouts/_default/list.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{ partial "header" . }} {{ partial "nav" . }}
2+
<section class="section">
3+
<div class="container">
4+
{{ range (where .Data.Pages "Section" "post") sort .Paginator.Pages }}
5+
<article>
6+
<h2 class="subtitle is-6">{{ .Date.Format "January 2, 2006" }}</h2>
7+
<h1 class="title"><a href="{{ .Permalink }}">{{ .Title }}</a>{{ if .Draft }} ::Draft{{ end }}</h1>
8+
{{ if .Params.tags }} {{ partial "tags" .Params.tags }} {{ end }}
9+
<div class="content">
10+
{{ .Summary | plainify | safeHTML }} {{ if .Truncated }} ...
11+
<a class="button is-link" href="{{ .Permalink }}" style="height:28px">
12+
Read more
13+
<span class="icon is-small">
14+
<i class="fa fa-angle-double-right"></i>
15+
</span>
16+
</a> {{ end }}
17+
</div>
18+
</article>
19+
{{ end }}
20+
</div>
21+
</section>
22+
{{ partial "pager" . }} {{ partial "footer" . }}

layouts/guide/single.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{ partial "header" . }} {{ partial "nav" . }}
2+
<section class="section">
3+
<div class="container">
4+
<h1 class="title">{{ .Title }}</h1>
5+
{{ if .Params.tags }} {{ partial "tags" .Params.tags }} {{ end }}
6+
<div class="content">
7+
{{ .Content }}
8+
</div>
9+
</div>
10+
</section>
11+
{{ partial "footer" . }}

layouts/partials/nav.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<section class="section">
2+
<div class="container">
3+
<nav class="nav">
4+
<div class="nav-left">
5+
<a class="nav-item" href="{{ .Site.BaseURL }}">
6+
<h1 class="title is-4">{{ .Site.Title }}</h1>
7+
</a>
8+
</div>
9+
<div class="nav-right">
10+
<nav class="nav-item level is-mobile">
11+
<a class="level-item" href="/guide">Guide</a> {{ range .Site.Params.social }}
12+
<a class="level-item" href="{{ .url }}">
13+
<span class="icon">
14+
<i class="fa {{ .fa_icon }}"></i>
15+
</span>
16+
</a>
17+
{{ end }}
18+
</nav>
19+
</div>
20+
</nav>
21+
</div>
22+
</section>

layouts/section/guide.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{ partial "header" . }} {{ partial "nav" . }}
2+
<section class="section">
3+
<div class="container">
4+
{{ range sort .Paginator.Pages }}
5+
<article>
6+
<h1 class="title"><a href="{{ .Permalink }}">{{ .Title }}</a>{{ if .Draft }} ::Draft{{ end }}</h1>
7+
{{ if .Params.tags }} {{ partial "tags" .Params.tags }} {{ end }}
8+
<div class="content">
9+
{{ .Summary | plainify | safeHTML }} {{ if .Truncated }} ...
10+
<a class="button is-link" href="{{ .Permalink }}" style="height:28px">
11+
Read more
12+
<span class="icon is-small">
13+
<i class="fa fa-angle-double-right"></i>
14+
</span>
15+
</a> {{ end }}
16+
</div>
17+
</article>
18+
{{ end }}
19+
</div>
20+
</section>
21+
{{ partial "pager" . }} {{ partial "footer" . }}

0 commit comments

Comments
 (0)