Skip to content

Commit 7f5c0bc

Browse files
author
Raoul Hess
committed
Stub on how things should possibly map up.
1 parent 8a9e098 commit 7f5c0bc

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/components_js_minifier.erl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-module(components_js_minifier).
2+
3+
-behaviour(cowboy_http_handler).
4+
5+
-export([init/3]).
6+
-export([handle/2]).
7+
-export([terminate/3]).
8+
9+
%% Cowboy callbacks
10+
11+
init(_, Req, _Opts) ->
12+
{ok, Req, []}.
13+
14+
handle(Req, State) ->
15+
%% Proplist with one or more components to minfify
16+
{Components, Req1} = cowboy:qs_vals(Req),
17+
18+
%% Build a map with all components like
19+
ComponentsWithFiles = get_files_components(Components),
20+
21+
%% maps:map through the entire map and minify each file an put'em together
22+
minify_components_js(),
23+
{ok, Req, State}.
24+
25+
terminate(_Reason, _Req, _State) ->
26+
ok.
27+
28+
%% End %%
29+
30+
%% Return #{components => {tag, [files]}}
31+
get_components_files(Components) ->
32+
33+
34+
35+
%% @doc
36+
%% Go through each component/tag minify and concatenate result to one file.
37+
%% Each file must be in the order specified.
38+
%% Files may be a list of files or just one file.
39+
%% A file may be a relative in the components or a url either starting with // (assume http)
40+
%% Fetch external files and add to right spot
41+
%% If file is named .min.js do not minify just return value.
42+
minify_components_js(_Map) ->
43+
ok.

src/divapi_app.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ start(_Type, _Args) ->
88
inets:start(),
99
Routes = [{"/", diversity_api_handler, []},
1010
{"/components/", component_list_handler, []},
11+
{"/components/minified/", components_js_minifier, []},
1112
{"/components/:component/", component_handler, []},
1213
{"/components/:component/register", component_action, [register]},
1314
{"/components/:component/update", component_action, [update]},

0 commit comments

Comments
 (0)