-
-
Save brayhoward/ae0f271d2a90238827a5ef32c12c5d31 to your computer and use it in GitHub Desktop.
Phoenix content_for prototype
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<meta name="description" content=""> | |
<meta name="author" content=""> | |
<title>Hello Phoenix!</title> | |
<link rel="stylesheet" href="/css/phoenix.css"> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="header"> | |
<ul class="nav nav-pills pull-right"> | |
<li><a href="http://www.phoenixframework.org/docs">Get Started</a></li> | |
</ul> | |
<span class="logo"></span> | |
<%= yield(:introducting) %> | |
</div> | |
<%= @inner %> | |
<div class="footer"> | |
<p><a href="http://phoenixframework.org">phoenixframework.org</a></p> | |
</div> | |
</div> <!-- /container --> | |
</body> | |
</html> |
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
defmodule ContentFor do | |
use Application | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
spawn fn -> | |
:ets.new :phoenix, [:public, :named_table] | |
receive do | |
:exit -> | |
:ok | |
end | |
end | |
# ... | |
end | |
end |
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
<%= content_for :introducting do %> | |
<div class="jumbotron"> | |
<h2> Introducing: <%= @name %> </h2> | |
</div> | |
end %> | |
<div class="jumbotron"> | |
<h2>Welcome to Phoenix!</h2> | |
<p class="lead">Phoenix is an Elixir Web Framework targeting full-featured, fault tolerant applications with realtime functionality.</p> | |
</div> | |
<div class="row marketing"> | |
<div class="col-lg-6"> | |
<h4>Resources</h4> | |
<ul> | |
<li> | |
<a href="http://hexdocs.pm/phoenix">Docs</a> | |
</li> | |
<li> | |
<a href="https://github.com/phoenixframework/phoenix">Source</a> | |
</li> | |
</ul> | |
</div> | |
<div class="col-lg-6"> | |
<h4>Help</h4> | |
<ul> | |
<li> | |
<a href="https://github.com/phoenixframework/phoenix/issues?state=open">Issues</a> | |
</li> | |
<li> | |
<a href="irc://irc.freenode.net/elixir-lang">#elixir-lang on freenode IRC</a> | |
</li> | |
<li> | |
<a href="https://twitter.com/chris_mccord">@chris_mccord</a> | |
</li> | |
</ul> | |
</div> | |
</div> | |
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
defmodule ContentFor.View do | |
use Phoenix.View, root: "web/templates" | |
require Logger | |
using do | |
quote do | |
import ContentFor.Router.Helpers | |
use Phoenix.HTML | |
end | |
end | |
def content_for name , do: block do | |
:ets.insert :phoenix, {name, block} | |
nil | |
end | |
def yield(name) do | |
fun = :ets.lookup(:phoenix, name) | |
|> Keyword.get(name) | |
|> Phoenix.HTML.safe | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment