Skip to content

Commit

Permalink
fix tpl basic
Browse files Browse the repository at this point in the history
  • Loading branch information
mihawk committed Nov 7, 2016
1 parent 32d8273 commit cf0458d
Show file tree
Hide file tree
Showing 26 changed files with 178 additions and 214 deletions.
40 changes: 17 additions & 23 deletions priv/basic.skel
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,27 @@
{dir, "{{appid}}/apps/{{appid}}/src/view"}.
{dir, "{{appid}}/apps/{{appid}}/src/view/layout"}.
{dir, "{{appid}}/apps/{{appid}}/src/view/lib"}.
{dir, "{{appid}}/apps/{{appid}}/src/view/{{appid}}_index"}.
{dir, "{{appid}}/apps/{{appid}}/src/view/{{appid}}_error"}.
{dir, "{{appid}}/apps/{{appid}}/src/view/index"}.
{dir, "{{appid}}/apps/{{appid}}/src/view/error"}.

{dir, "{{appid}}/apps/{{appid}}/src/view/lib/tag_html"}.
{dir, "{{appid}}/apps/{{appid}}/src/view/lib/tag_modules"}.
{dir, "{{appid}}/apps/{{appid}}/src/view/lib/filter_modules"}.
{dir, "{{appid}}/apps/{{appid}}/src/view/lib/custom_tags"}.
{dir, "{{appid}}/apps/{{appid}}/priv"}.
{dir, "{{appid}}/apps/{{appid}}/priv/spa"}.
{dir, "{{appid}}/apps/{{appid}}/priv/templates"}.

{template, "basic/rebar2.config", "{{appid}}/apps/{{appid}}/rebar.config"}.
{template, "basic/rebar1.config", "{{appid}}/apps/rebar.config"}.
{template, "basic/rebar.config", "{{appid}}/rebar.config"}.
{template, "basic/vm.args", "{{appid}}/vm.args"}.
{template, "basic/sys.config", "{{appid}}/sys.config"}.
{template, "basic/project.app.src", "{{appid}}/apps/{{appid}}/src/{{appid}}.app.src"}.
{template, "basic/project.erl", "{{appid}}/apps/{{appid}}/src/{{appid}}.erl"}.
{template, "basic/project_controller_index.erl", "{{appid}}/apps/{{appid}}/src/controller/index.erl"}.
{template, "basic/project_controller_error.erl", "{{appid}}/apps/{{appid}}/src/controller/error.erl"}.
{template, "basic/project_routes.erl", "{{appid}}/apps/{{appid}}/src/{{appid}}_routes.erl"}.
{template, "basic/project.routes", "{{appid}}/apps/{{appid}}/priv/{{appid}}.routes"}.

{file, "basic/project_view_layout_n2o.html", "{{appid}}/apps/{{appid}}/src/view/layout/n2o.html"}.
{file, "basic/project_view_layout_page.html", "{{appid}}/apps/{{appid}}/src/view/layout/page.html"}.
{file, "basic/project_view_index_hello.html", "{{appid}}/apps/{{appid}}/src/view/index/hello.html"}.
{file, "basic/project_view_error_404.html", "{{appid}}/apps/{{appid}}/src/view/error/404.html"}.
{file, "basic/project_priv_templates_index.html", "{{appid}}/apps/{{appid}}/priv/templates/index.html"}.
{file, "basic/project_priv_static_synrc.css", "{{appid}}/apps/{{appid}}/priv/static/synrc.css"}.
{file, "basic/project_priv_static_spa_index.htm", "{{appid}}/apps/{{appid}}/priv/static/spa/index.htm"}.
{template,"basic/apps/project/priv/project.routes","{{appid}}/apps/{{appid}}/priv/{{appid}}.routes"}.
{template,"basic/apps/project/rebar.config","{{appid}}/apps/{{appid}}/rebar.config"}.
{template,"basic/apps/project/src/project.app.src","{{appid}}/apps/{{appid}}/src/{{appid}}.app.src"}.
{template,"basic/apps/project/src/project.erl","{{appid}}/apps/{{appid}}/src/{{appid}}.erl"}.
{template,"basic/apps/rebar.config","{{appid}}/apps/rebar.config"}.
{template,"basic/rebar.config","{{appid}}/rebar.config"}.
{template,"basic/sys.config", "{{appid}}/sys.config"}.
{template,"basic/vm.args", "{{appid}}/vm.args"}.

{file,"basic/apps/project/src/controller/error.erl", "{{appid}}/apps/{{appid}}/src/controller/error.erl"}.
{file,"basic/apps/project/src/controller/index.erl", "{{appid}}/apps/{{appid}}/src/controller/index.erl"}.
{file,"basic/apps/project/src/view/error/404.html", "{{appid}}/apps/{{appid}}/src/view/error/404.html"}.
{file,"basic/apps/project/src/view/index/index.html","{{appid}}/apps/{{appid}}/src/view/index/index.html"}.
{file,"basic/apps/project/src/view/layout/n2o.html", "{{appid}}/apps/{{appid}}/src/view/layout/n2o.html"}.
{file,"basic/apps/project/src/view/layout/page.html","{{appid}}/apps/{{appid}}/src/view/layout/page.html"}.
34 changes: 34 additions & 0 deletions priv/basic/apps/project/priv/project.routes
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
%% DISPATCH RULE: {"URL MATCH" , handler, opts()}

%% cowboy static handler, here single file access.
{ "/favicon.ico", cowboy_static, {priv_file, {{appid}}, "static/favicon.ico"}}

%% naga static handler, support gz compression, just gzip your static file
%% you need to keep uncompressed version and a compression version in your static folder, according to client capabiliti
%% the according version will be serve either from disk or memory
,{ "/n2o/[...]", naga_static, { dir, "deps/n2o/priv", [ { mimetypes, cow_mimetypes, all } ] }}
,{ "/{{appid}}/static/[...]", naga_static, { dir, "deps/{{appid}}/priv", [ { mimetypes, cow_mimetypes, all } ] }}

%% naga convenient handler.
,{"/$v/[...]", naga_indexof, { {{appid}},view,"/$v"}}
%,{"/$c/[...]", naga_indexof, { {{appid}},controller,"/$c"}}
,{"/$s/[...]", naga_indexof, { {{appid}},static,"/$s"}}


%% YOUR RULES: dispatch {url/path}|code => application/controller/action
%% no support for regex in url/path
%% app is default alias for application
%% ctrl is default alias for controller
%% act is default alias for action
%% you can redefine alias add in naga config section using
%% {def_application, a},
%% {def_controller, c}
%% {def_action, ac} where a,c,ac are atom

,{ "/index", [{app, {{appid}} },{ctrl, index},{action,index}], []}
,{ "/", [{app, {{appid}} },{ctrl, index},{action,index},{id, 42}], []}

,{ 404, [{application, {{appid}} },{controller, error}, {action, '404'}], []}
,{ 500, [{application, {{appid}} },{controller, error}, {action, '500'}], []}
].
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions priv/basic/apps/project/src/controller/index.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-module(index).
-export([index/3, event/1]).
-default_action(index).
-actions([index]).

-include_lib("n2o/include/wf.hrl").
-include_lib("nitro/include/nitro.hrl").
-include_lib("naga/include/naga.hrl").

index(<<"GET">>, _, _) ->
{ok, [{msg, "Hello World!!!!! "}]}.

event(Event) ->
wf:info(?MODULE,"Unknown Event: ~p~n",[Event]).
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, {{appid}},
[{description, "my awesome {{appid}} "},
{vsn, "0.2"},
[{description, "{{desc}}"},
{vsn, "{{vsn}}"},
{registered, []},
{applications, [kernel, stdlib, naga]},
{mod, { {{appid}}, []}},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 0 additions & 27 deletions priv/basic/project.routes

This file was deleted.

8 changes: 8 additions & 0 deletions priv/basic/project/src/controller/error.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-module(error).
-compile(export_all).
-include_lib("n2o/include/wf.hrl").
-include_lib("nitro/include/nitro.hrl").

'404'(_, _, _) -> {ok, [{msg, "404 Not Found"}]}.

event(Event) -> wf:info(?MODULE,"Unknown Event: ~p~n",[Event]).
14 changes: 14 additions & 0 deletions priv/basic/project/src/controller/index.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-module(index).
-export([index/3, event/1]).
-default_action(index).
-actions([index]).

-include_lib("n2o/include/wf.hrl").
-include_lib("nitro/include/nitro.hrl").
-include_lib("naga/include/naga.hrl").

index(<<"GET">>, _, _) ->
{ok, [{msg, "Hello World!!!!! "}]}.

event(Event) ->
wf:info(?MODULE,"Unknown Event: ~p~n",[Event]).
4 changes: 4 additions & 0 deletions priv/basic/project/src/view/error/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extend "layout/page.html" %}
{% block body %}
{{msg}}
{% endblock %}
14 changes: 14 additions & 0 deletions priv/basic/project/src/view/index/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "layout/page.html" %}

{% block body %}
{{msg}}
<br/>
{{_session_id}}
<br>
{{_app}}
<br>
{{_action}}
<br>
{{_controller}}
{% endblock %}

Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<html>
<head>
<link href="/static/synrc.css" type="text/css" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{{title}}</title>
</head>
<body>
{{body}}
<script>{{script}}</script>
hello layout n2o <br>
{% block body %} {% endblock %}
<script>{{script}}</script>
<script src='/n2o/protocols/bert.js'></script>
<script src='/n2o/protocols/client.js'></script>
<script src='/n2o/protocols/nitrogen.js'></script>
<script src='/n2o/validation.js'></script>
<script src='/n2o/bullet.js'></script>
<script src='/n2o/xhr.js'></script>
<script src='/n2o/utf8.js'></script>
<script src='/n2o/template.js'></script>
<script src='/n2o/n2o.js'></script>
<script>protos = [ $bert, $client ]; N2O_start();</script>
<script src='/n2o/validation.js'></script>
<script>protos = [$client,$bert]; N2O_start();</script>
</body>
</html>
10 changes: 10 additions & 0 deletions priv/basic/project/src/view/layout/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{{title}}</title>
</head>
<body>
hello layout page <br>
{% block body %} {% endblock %}
</body>
</html>
50 changes: 0 additions & 50 deletions priv/basic/project_controller_index.erl

This file was deleted.

21 changes: 0 additions & 21 deletions priv/basic/project_priv_static_spa_index.htm

This file was deleted.

3 changes: 0 additions & 3 deletions priv/basic/project_priv_static_synrc.css

This file was deleted.

34 changes: 0 additions & 34 deletions priv/basic/project_routes.erl

This file was deleted.

3 changes: 1 addition & 2 deletions priv/basic/rebar.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{sub_dirs,["apps"]}.
{deps_dir,"deps"}.
{deps, [
{lager, ".*", {git, "https://github.com/basho/lager", {tag, "3.0.1"} }},
{deps, [
{naga, ".*", {git, "git://github.com/naga-framework/naga", {tag, "master"} }}
]}.

Loading

0 comments on commit cf0458d

Please sign in to comment.