Skip to content
This repository
Browse code

Extended the lib tag with a 'use_absolute_url' option.

  • Loading branch information...
commit 24116b0ac28c32bfe622caf617534b70a3449fea 1 parent 869b478
Maas-Maarten Zeeman authored
10 src/erlydtl/erlydtl_compiler.erl
@@ -455,8 +455,8 @@ body_ast(DjangoParseTree, Context, TreeWalker) ->
455 455 url_ast(Name, Args, Context, TreeWalkerAcc);
456 456 ({'print', Value}, TreeWalkerAcc) ->
457 457 print_ast(Value, Context, TreeWalkerAcc);
458   - ({'lib', LibList}, TreeWalkerAcc) ->
459   - lib_ast(LibList, Context, TreeWalkerAcc);
  458 + ({'lib', LibList, Args}, TreeWalkerAcc) ->
  459 + lib_ast(LibList, Args, Context, TreeWalkerAcc);
460 460 ({'cache', [MaxAge, Args], CacheContents}, TreeWalkerAcc) ->
461 461 cache_ast(MaxAge, Args, CacheContents, Context, TreeWalkerAcc);
462 462 (ValueToken, TreeWalkerAcc) ->
@@ -1428,16 +1428,18 @@ print_ast(Value, Context, TreeWalker) ->
1428 1428 {{PreAst, #ast_info{}}, TreeWalker}.
1429 1429
1430 1430
1431   -lib_ast(LibList, Context, TreeWalker) ->
  1431 +lib_ast(LibList, Args, Context, TreeWalker) ->
1432 1432 Libs = [ unescape_string_literal(V) || {string_literal, _, V} <- LibList ],
1433 1433 LibsAst = erl_syntax:list([ erl_syntax:string(L) || L <- Libs ]),
  1434 + {ArgList, TreeWalker1} = scomp_ast_list_args(Args, Context, TreeWalker),
1434 1435 Ast = erl_syntax:application(
1435 1436 erl_syntax:atom(z_lib_include),
1436 1437 erl_syntax:atom(tag),
1437 1438 [ LibsAst,
  1439 + ArgList,
1438 1440 z_context_ast(Context)
1439 1441 ]),
1440   - {{Ast, #ast_info{}}, TreeWalker}.
  1442 + {{Ast, #ast_info{}}, TreeWalker1}.
1441 1443
1442 1444
1443 1445 cache_ast(MaxAge, Args, Body, Context, TreeWalker) ->
2  src/erlydtl/erlydtl_parser.yrl
@@ -268,7 +268,7 @@ NowTag -> open_tag now_keyword string_literal close_tag : {date, now, '$3'}.
268 268 OptionalAll -> all_keyword : true.
269 269 OptionalAll -> '$empty' : false.
270 270
271   -LibTag -> open_tag lib_keyword LibList close_tag : {lib, '$3'}.
  271 +LibTag -> open_tag lib_keyword LibList Args close_tag : {lib, '$3', '$4'}.
272 272 LibList -> string_literal : ['$1'].
273 273 LibList -> LibList string_literal : '$1' ++ ['$2'].
274 274
19 src/support/z_lib_include.erl
@@ -28,6 +28,7 @@
28 28
29 29 -export([
30 30 tag/2,
  31 + tag/3,
31 32 uncollapse/1
32 33 ]).
33 34
@@ -35,12 +36,16 @@
35 36
36 37 %% @doc Generate the link and/or script tags for the given files.
37 38 tag(Files, Context) ->
  39 + tag(Files, [], Context).
  40 +
  41 +%% @doc Generate the link and/or script tags for the given files.
  42 +tag(Files, Args, Context) ->
38 43 case m_config:get_value(mod_development, libsep, Context) of
39 44 Empty when Empty == []; Empty == <<>>; Empty == undefined ->
40   - tag1(Files, Context);
  45 + tag1(Files, Args, Context);
41 46 _Other ->
42 47 lists:foldr(fun(F, [Css,Js]) ->
43   - [C,J] = tag1([F], Context),
  48 + [C,J] = tag1([F], Args, Context),
44 49 [[C|Css], [J|Js]]
45 50 end,
46 51 [[],[]],
@@ -48,21 +53,25 @@ tag(Files, Context) ->
48 53 end.
49 54
50 55
51   -tag1(Files, Context) ->
  56 +tag1(Files, Args, Context) ->
52 57 {Css, CssPath, Js, JsPath} = collapsed_paths(Files),
  58 + UrlPrefix = case proplists:get_bool(use_absolute_url, Args) of
  59 + true -> [<<"http://">>, z_context:hostname_port(Context), <<"/lib">>];
  60 + false -> <<"/lib">>
  61 + end,
53 62 LinkElement = case CssPath of
54 63 [] ->
55 64 [];
56 65 _ ->
57 66 ModCss = newest(Css, {{1970,1,1},{12,0,0}}, Context),
58   - iolist_to_binary([ <<"<link href=\"/lib">>, CssPath, ?SEP, integer_to_list(ModCss), <<".css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\" />">>])
  67 + iolist_to_binary([ <<"<link href=\"">>, UrlPrefix, CssPath, ?SEP, integer_to_list(ModCss), <<".css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\" />">>])
59 68 end,
60 69 ScriptElement = case JsPath of
61 70 [] ->
62 71 [];
63 72 _ ->
64 73 ModJs = newest(Js, {{1970,1,1},{12,0,0}}, Context),
65   - iolist_to_binary([ <<"<script src=\"/lib">>, JsPath, ?SEP, integer_to_list(ModJs), <<".js\" type=\"text/javascript\"></script>">>])
  74 + iolist_to_binary([ <<"<script src=\"">>, UrlPrefix, JsPath, ?SEP, integer_to_list(ModJs), <<".js\" type=\"text/javascript\"></script>">>])
66 75 end,
67 76 [LinkElement, ScriptElement].
68 77

0 comments on commit 24116b0

Please sign in to comment.
Something went wrong with that request. Please try again.