Sha256: 2279b81e7f490ea1da34b2a71539277b9cad3ce62ed153628974f23bdf7319b0

Contents?: true

Size: 991 Bytes

Versions: 5

Compression:

Stored size: 991 Bytes

Contents

-module (views).
-compile(export_all).

wrap_page(Name) ->
	AssetMatch = "(.*)([css|js])+",
	case regexp:first_match(Name, AssetMatch) of
		{match,_,_} ->			
			erlang:binary_to_list(read_asset(Name));
		nomatch ->
			wrap(read_page(Name));
		{_, _} ->
			io:format("Error: ~p~n", [Name]),
			"error"
	end.

json(Content) ->
	mochijson2:encode(Content).

wrap(Content) ->
	Header = read_partial("header"),
	Menu = read_partial("menu"),
	Footer = read_partial("footer"),
	Out = erlang:list_to_binary([Header, Menu, protect(Content), Footer]),
	erlang:binary_to_list(Out).

read_page(Name) ->
	{_, Cont} = file:read_file("priv/www/pages/"++Name++".html"),
	protect(Cont).
read_partial(Name) ->
	{_, Cont} = file:read_file("priv/www/partials/"++Name++".html"),
	protect(Cont).
read_asset(Name) ->
	{_, Cont} = file:read_file("priv/www/"++Name),
	protect(Cont).

protect(Content) ->
	case Content of
		enoent ->
			read_partial("error");
		[] ->
			read_partial("error");
		_ ->
			Content
	end.

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
auser-poolparty-0.2.40 lib/erlang/cloudpanel/src/views.erl
auser-poolparty-0.2.41 lib/erlang/cloudpanel/src/views.erl
auser-poolparty-0.2.42 lib/erlang/cloudpanel/src/views.erl
auser-poolparty-0.2.44 lib/erlang/cloudpanel/src/views.erl
auser-poolparty-0.2.45 lib/erlang/cloudpanel/src/views.erl