Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

documented jockes new bindings feature

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@582 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit 379666bf086a8191a074ca888669284fad2127d4 1 parent a9a9971
@klacke authored
View
9 man/yaws_api.5
@@ -489,6 +489,15 @@ occur inside a deep ehtml structure.
.TP
+\fB{bindings, [{Key1, Value2}, {Key2, Value2} .....]}\fR
+Establish variable bindings that can be used in the page.
+
+All bindings can then be used in the rest of yaws code
+(in HTML source and within erl tags).
+In HTML source %%Key%% is expanded to Value and within erl
+tags yaws_api:get_binding(Key) can be used to extract Value.
+
+.TP
\fB[ListOfValues]\fR
It is possible to return a deep list of the above defined
return values. Any occurrence of \fIstream_content\fR, \fIget_more\fR
View
10 src/yaws_compile.erl
@@ -134,8 +134,8 @@ compile_file(C, LineNo, Chars = "</erl>" ++ Tail, erl, NumChars, Ack, Es) ->
%% this is boring but does actually happen
%% in order to get proper user errors here we need to catch i/o
%% or hack compiler/parser
- yaws:elog("Dynamic compile error in file ~s, line ~w~n~s",
- [C#comp.infile, LineNo, Str]),
+ yaws:elog("Dynamic compile error in file ~s (~s), line ~w~n~s",
+ [C#comp.infile, C#comp.outfile,LineNo, Str]),
A2 = {error, NumChars, ?F("<pre> Dynamic compile error in file "
" ~s line ~w~n~s </pre>",
[C#comp.infile, LineNo, Str])},
@@ -262,9 +262,11 @@ comp_err(C, _LineNo, NumChars, Err) ->
[{_FileName, [ {Line0, Mod, E} |_]} |_] when integer(Line0) ->
Line = Line0 + C#comp.startline - 10,
?Debug("XX ~p~n", [{_LineNo, Line0}]),
- Str = io_lib:format("~s:~w:~n ~s\n",
+ Str = io_lib:format("~s:~w:~n ~s\ngenerated file at: ~s~n",
[C#comp.infile, Line,
- apply(Mod, format_error, [E])]),
+ apply(Mod, format_error, [E]),
+ C#comp.outfile
+ ]),
HtmlStr = ?F("~n<pre>~nDynamic compile error: ~s~n</pre>~n",
[Str]),
yaws:elog("Dynamic compiler err ~s", [Str]),
View
9 src/yaws_server.erl
@@ -712,6 +712,15 @@ handle_method_result(Res, CliSock, IP, GS, SC, Req, H, Num) ->
erase(post_parse),
erase(query_parse),
erase(outh),
+ lists:foreach(fun(X) ->
+ case X of
+ {binding, _} ->
+ erase(X);
+ _ ->
+ ok
+ end
+ end, get()),
+
aloop(CliSock, GS, Num+1);
done ->
maybe_access_log(IP, SC, Req, H),
View
2  www/EXHEAD
@@ -10,6 +10,8 @@
<td> <A HREF="/form.yaws">Forms</a> </td>
<td> <A HREF="/redirect.yaws">Redirect</a> </td>
<td> <A HREF="/ssi.yaws">Server side include</a> </td>
+ <td> <A HREF="/bindings.yaws">Bindings</a> </td>
+
</tr>
<tr border="2">
View
115 www/bindings.yaws
@@ -0,0 +1,115 @@
+<erl>
+out(A) ->
+ [{ssi, "HEAD", [],[]},
+ {ssi, "EXHEAD", [],[]}].
+</erl>
+
+
+<p>
+Bindings is the opposite of <a href="ssi.yaws"> SSI, Server Side Includes</a>,
+SSI is primarily used when basicaly the entire pages are written in EHTML and
+snippets of HTML, or more typical, javascript code is inserted into the EHTML
+code.
+
+<p> Bindings are used the other way around, basically the entire
+pages are written in regular HTML but parts of the HTML needs to be
+dynamically generated.
+
+<p>The yaws callback out/1 can return
+
+<div class="box">
+<pre>
+{bindings, [{Key1, Value2}, {Key2, Value2} .....]}.
+</pre>
+</div>
+
+
+<p>All bindings can then be used in the rest of yaws code (in HTML source and
+within erl tags). In HTML source %%Key%% is expanded to Value and
+within erl tags yaws_api:get_binding(Key) can be used to extract Value.
+
+<p>With the binding feature it is easier to write transparant yaws code making
+it easier to to work together with Web people knowing little or
+nothing about Erlang.
+
+An example:
+
+
+<div class="box">
+<pre>
+
+&lt;erl&gt;
+out(A) -&gt; {bindings, [{"A", "foo"}, {"B", "baz"}]}.
+&lt;/erl&gt;
+
+&lt;html&gt;
+ &lt;body&gt;
+ &lt;p&gt;%%A%%&lt;/p&gt;
+ &lt;p&gt;&lt;font size="4"&gt;%%A%% != %%B%%&lt;/font&gt;&lt;/p&gt;
+ &lt;p&gt;An enormous amount of plain html source here.&lt;/p&gt;
+
+&lt;erl&gt;
+out(A) -&gt;
+ Value = yaws_api:binding("A"),
+ {ehtml, {ul, [],
+ [{li, [],
+ Value},
+ {li, [],
+ "gazonk"}]}}.
+&lt;/erl&gt;
+
+%%A%% = %%A%% (hit me)
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+</div>
+
+
+<p>
+Which expands to:
+
+<div class="box">
+<pre>
+
+
+
+&lt;html&gt;
+&lt;body&gt;
+&lt;p&gt;foo&lt;/p&gt;
+&lt;p&gt;&lt;font size="4"&gt;foo != baz&lt;/font&gt;&lt;/p&gt;
+&lt;p&gt;An enormous amount of plain html source here.&lt;/p&gt;
+
+&lt;ul&gt;
+&lt;li&gt;foo&lt;/li&gt;
+&lt;li&gt;gazonk&lt;/li&gt;&lt;/ul&gt;
+
+foo = foo (hit me)
+
+
+
+</pre>
+</div>
+
+
+And is rendered as:
+<div class="box">
+<p>foo</p>
+<p><font size="4">foo != baz</font></p>
+<p>An enormous amount of plain html source here.</p>
+
+<ul>
+<li>foo</li>
+<li>gazonk</li></ul>
+
+foo = foo (hit me)
+</div>
+
+
+
+
+
+</html>
+
+
+
+
View
2  www/man.yaws
@@ -22,7 +22,7 @@ out(A) ->
end
end, Page) of
true ->
- os:cmd("man " ++ Page ++ " | col -b");
+ os:cmd("man " ++ Page ++ " | col -b -p -x");
false ->
"illegal character detected in query arg"
end;
View
7 www/redirect.yaws
@@ -4,7 +4,7 @@
<meta name="keywords" content="post">
-<TITLE>Top EE page</TITLE>
+<TITLE>Redirect example</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@@ -16,12 +16,12 @@
<H1> redirect.yaws </H1>
-<p> This a redirection example, the following <a href="redirect2.yaws">redirection url</a> contains the following code in its first <erl> group.
+<p> This a redirection example, the following <a href="redirect2.yaws">redirection url</a> contains the following code in its first erl group.
<erl>
-out(_) -> yaws_api:pre_ssi_string(
+out(_) -> 1 yaws_api:pre_ssi_string(
"
out(_) ->
yaws_api:redirect(
@@ -37,3 +37,4 @@ as well as a Location header.
</HTML>
+
Please sign in to comment.
Something went wrong with that request. Please try again.