Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extended the lib tag with a 'use_absolute_url' option.

  • Loading branch information...
commit 24116b0ac28c32bfe622caf617534b70a3449fea 1 parent 869b478
Maas-Maarten Zeeman authored
View
10 src/erlydtl/erlydtl_compiler.erl
@@ -455,8 +455,8 @@ body_ast(DjangoParseTree, Context, TreeWalker) ->
url_ast(Name, Args, Context, TreeWalkerAcc);
({'print', Value}, TreeWalkerAcc) ->
print_ast(Value, Context, TreeWalkerAcc);
- ({'lib', LibList}, TreeWalkerAcc) ->
- lib_ast(LibList, Context, TreeWalkerAcc);
+ ({'lib', LibList, Args}, TreeWalkerAcc) ->
+ lib_ast(LibList, Args, Context, TreeWalkerAcc);
({'cache', [MaxAge, Args], CacheContents}, TreeWalkerAcc) ->
cache_ast(MaxAge, Args, CacheContents, Context, TreeWalkerAcc);
(ValueToken, TreeWalkerAcc) ->
@@ -1428,16 +1428,18 @@ print_ast(Value, Context, TreeWalker) ->
{{PreAst, #ast_info{}}, TreeWalker}.
-lib_ast(LibList, Context, TreeWalker) ->
+lib_ast(LibList, Args, Context, TreeWalker) ->
Libs = [ unescape_string_literal(V) || {string_literal, _, V} <- LibList ],
LibsAst = erl_syntax:list([ erl_syntax:string(L) || L <- Libs ]),
+ {ArgList, TreeWalker1} = scomp_ast_list_args(Args, Context, TreeWalker),
Ast = erl_syntax:application(
erl_syntax:atom(z_lib_include),
erl_syntax:atom(tag),
[ LibsAst,
+ ArgList,
z_context_ast(Context)
]),
- {{Ast, #ast_info{}}, TreeWalker}.
+ {{Ast, #ast_info{}}, TreeWalker1}.
cache_ast(MaxAge, Args, Body, Context, TreeWalker) ->
View
2  src/erlydtl/erlydtl_parser.yrl
@@ -268,7 +268,7 @@ NowTag -> open_tag now_keyword string_literal close_tag : {date, now, '$3'}.
OptionalAll -> all_keyword : true.
OptionalAll -> '$empty' : false.
-LibTag -> open_tag lib_keyword LibList close_tag : {lib, '$3'}.
+LibTag -> open_tag lib_keyword LibList Args close_tag : {lib, '$3', '$4'}.
LibList -> string_literal : ['$1'].
LibList -> LibList string_literal : '$1' ++ ['$2'].
View
19 src/support/z_lib_include.erl
@@ -28,6 +28,7 @@
-export([
tag/2,
+ tag/3,
uncollapse/1
]).
@@ -35,12 +36,16 @@
%% @doc Generate the link and/or script tags for the given files.
tag(Files, Context) ->
+ tag(Files, [], Context).
+
+%% @doc Generate the link and/or script tags for the given files.
+tag(Files, Args, Context) ->
case m_config:get_value(mod_development, libsep, Context) of
Empty when Empty == []; Empty == <<>>; Empty == undefined ->
- tag1(Files, Context);
+ tag1(Files, Args, Context);
_Other ->
lists:foldr(fun(F, [Css,Js]) ->
- [C,J] = tag1([F], Context),
+ [C,J] = tag1([F], Args, Context),
[[C|Css], [J|Js]]
end,
[[],[]],
@@ -48,21 +53,25 @@ tag(Files, Context) ->
end.
-tag1(Files, Context) ->
+tag1(Files, Args, Context) ->
{Css, CssPath, Js, JsPath} = collapsed_paths(Files),
+ UrlPrefix = case proplists:get_bool(use_absolute_url, Args) of
+ true -> [<<"http://">>, z_context:hostname_port(Context), <<"/lib">>];
+ false -> <<"/lib">>
+ end,
LinkElement = case CssPath of
[] ->
[];
_ ->
ModCss = newest(Css, {{1970,1,1},{12,0,0}}, Context),
- iolist_to_binary([ <<"<link href=\"/lib">>, CssPath, ?SEP, integer_to_list(ModCss), <<".css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\" />">>])
+ iolist_to_binary([ <<"<link href=\"">>, UrlPrefix, CssPath, ?SEP, integer_to_list(ModCss), <<".css\" type=\"text/css\" media=\"all\" rel=\"stylesheet\" />">>])
end,
ScriptElement = case JsPath of
[] ->
[];
_ ->
ModJs = newest(Js, {{1970,1,1},{12,0,0}}, Context),
- iolist_to_binary([ <<"<script src=\"/lib">>, JsPath, ?SEP, integer_to_list(ModJs), <<".js\" type=\"text/javascript\"></script>">>])
+ iolist_to_binary([ <<"<script src=\"">>, UrlPrefix, JsPath, ?SEP, integer_to_list(ModJs), <<".js\" type=\"text/javascript\"></script>">>])
end,
[LinkElement, ScriptElement].
Please sign in to comment.
Something went wrong with that request. Please try again.