Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added <verbatim> tag for .yaws files, It works as the pre (or the cod…

…e) tag really should work, i.e. verbatim

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@794 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit f875c2b44058a5b83e0291b696e7583f11d4dcb1 1 parent cc115dc
@klacke authored
View
38 src/yaws_compile.erl
@@ -65,6 +65,7 @@ compile_file(File) ->
erase(yfile),
erase(yfile_data),
erase(yfile_data_orig),
+ ?Debug("Spec: ~p~n", [Spec]),
Spec;
_Err ->
yaws:elog("can't open ~s~n", [File]),
@@ -74,10 +75,17 @@ compile_file(File) ->
[node()], infinity).
+clump_data([{data, I}, {data, J} | Tail]) ->
+ clump_data([{data, I+J}|Tail]);
+clump_data([H|T]) ->
+ [H|clump_data(T)];
+clump_data([]) ->
+ [].
+
compile_file(C, _LineNo, eof, _Mode, NumChars, Ack, Errors) ->
file_close(C#comp.infd),
- {ok, [{errors, Errors} |lists:reverse([{data, NumChars} |Ack])]};
+ {ok, [{errors, Errors} | clump_data(lists:reverse([{data, NumChars} |Ack]))]};
%% skip initial space if first thing is <erl> otherwise not
@@ -109,6 +117,30 @@ compile_file(C, LineNo, Chars = "<erl>" ++ _Tail, html, NumChars, Ack,Es) ->
Ack, Es) %hack
end;
+compile_file(C, LineNo, Chars = "<verbatim>" ++ _Tail, html, NumChars, Ack,Es) ->
+ ?Debug("start verbatim:~p",[LineNo]),
+ Len = length(Chars),
+ C2 = C#comp{outfile = ["<pre>\n"]}, %% use as accumulator
+ compile_file(C2, LineNo+1, line() , verbatim , Len, [{data, NumChars} | Ack], Es);
+
+compile_file(C, LineNo, Chars = "</verbatim>" ++ Tail, verbatim, NumChars, Ack, Es) ->
+ Data = list_to_binary(lists:reverse(["</pre>\n" | C#comp.outfile])),
+ Len = length(Chars),
+ io:format("Data = ~p~n", [Data]),
+ compile_file(C#comp{outfile = undefined}, LineNo, line(), html, 0,
+ [{verbatim, NumChars+Len, Data} |Ack], Es);
+
+compile_file(C, LineNo, Chars, verbatim, NumChars, Ack,Es) ->
+ case has_str(Chars, ["</verbatim>"]) of
+ {ok, Skipped, Chars2} ->
+ compile_file(C, LineNo, Chars2, verbatim, NumChars + Skipped, Ack,Es);
+ false ->
+ io:format("Ack ~p~n",[Chars]),
+ C2 = C#comp{outfile = [yaws_api:htmlize(Chars) | C#comp.outfile]},
+ compile_file(C2, LineNo+1, line(), verbatim, NumChars +
+ length(Chars), Ack,Es)
+ end;
+
compile_file(C, LineNo, Chars = "</erl>" ++ Tail, erl, NumChars, Ack, Es) ->
?Debug("stop erl:~p",[LineNo]),
file:close(C#comp.outfd),
@@ -158,9 +190,11 @@ compile_file(C, LineNo, [], html, NumChars, Ack, Es) ->
compile_file(C, LineNo+1, line(), html, NumChars, Ack, Es);
compile_file(C, LineNo, Chars, html, NumChars, Ack,Es) ->
- case has_str(Chars, ["<erl>", "%%"]) of
+ case has_str(Chars, ["<erl>", "%%", "<verbatim>"]) of
{ok, Skipped, "<erl>"++_ = Chars2} ->
compile_file(C, LineNo, Chars2, html, NumChars+Skipped, Ack, Es);
+ {ok, Skipped, "<verbatim>"++_ = Chars2} ->
+ compile_file(C, LineNo, Chars2, html, NumChars+Skipped, Ack, Es);
{ok, Skipped, "%%"++Chars2} ->
compile_file(C, LineNo, Chars2, binding, 2,
[{data, NumChars+Skipped}|Ack], Es);
View
4 src/yaws_server.erl
@@ -1567,6 +1567,10 @@ deliver_dyn_file(CliSock, Bin, Fd, [H|T],Arg, UT, N) ->
{_, Bin2} = skip_data(Bin, Fd, NumChars),
accumulate_content(Str),
deliver_dyn_file(CliSock, Bin2, Fd, T,Arg,UT, N);
+ {verbatim, NumChars, Data} ->
+ {_Send, Bin2} = skip_data(Bin, Fd, NumChars),
+ accumulate_content(Data),
+ deliver_dyn_file(CliSock, Bin2, Fd, T,Arg,UT,N);
yssi ->
ok
end;
View
61 www/bindings.yaws
@@ -40,59 +40,60 @@ out(A) ->
An example:
</p>
- <div class="box">
- <pre>
-&lt;erl&gt;
-out(A) -&gt; {bindings, [{"A", "foo"}, {"B", "baz"}]}.
-&lt;/erl&gt;
+ <div class="box">
+ <verbatim>
+<erl>
+out(A) -> {bindings, [{"A", "foo"}, {"B", "baz"}]}.
+</erl>
-&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;
+<html>
+ <body>
+ <p>%%A%%</p>
+ <p><font size="4">%%A%% != %%B%%</font></p>
+ <p>An enormous amount of plain html source here.</p>
-&lt;erl&gt;
-out(A) -&gt;
+<erl>
+out(A) ->
Value = yaws_api:binding("A"),
{ehtml, {ul, [],
[{li, [],
Value},
{li, [],
"gazonk"}]}}.
-&lt;/erl&gt;
+</erl>
%%A%% = %%A%% (hit me)
-&lt;/body&gt;
-&lt;/html&gt;
- </pre>
- </div>
+</body>
+</html>
+
+</verbatim>
+</div>
+
<p>
Which expands to:</p>
<div class="box">
- <pre>
-
+ <verbatim>
+<html>
+ <body>
+ <p>foo</p>
+ <p><font size="4">foo != baz</font></p>
+ <p>An enormous amount of plain html source here.</p>
-&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;
+ <ul>
+ <li>foo</li>
+ <li>gazonk</li></ul>
foo = foo (hit me)
+ </body>
+</html>
-
- </pre>
+ </verbatim>
</div>
View
39 www/embed.yaws
@@ -43,7 +43,9 @@ out(A) ->
<ol>
<li><p>GC is a #gconf{} record. The definition of the
record is:</p>
- <pre>
+
+<div class="box">
+ <verbatim>
%% global conf
-record(gconf,{file,
yaws_dir,
@@ -66,7 +68,8 @@ out(A) ->
username, %% maybe run as a different user than root
uid %% unix uid of user that started yaws
}).
- </pre>
+ </verbatim>
+</div>
<p>The easiest way to figure out what the individual record
fields mean is to have a look in the source file yaws_config.erl</p>
@@ -83,7 +86,8 @@ out(A) ->
</p>
<p>
The sconf record is defined as:</p>
- <pre>
+<div class="box">
+ <verbatim>
-record(ssl,
{
@@ -128,7 +132,8 @@ out(A) ->
allowed_scripts = [yaws]
}).
- </pre>
+ </verbatim>
+ </div>
</li>
</ol>
@@ -139,10 +144,11 @@ out(A) ->
</p>
<p>We start Erlang as:
</p>
-
+<div class="box">
<pre>
# erl -pa /usr/local/lib/yaws/ebin -yaws embedded true -s ybed
</pre>
+</div>
<p>The ybed module is very small and is named
<a href="code.yaws?file=/ybed.erl">ybed.erl</a>
@@ -151,18 +157,20 @@ out(A) ->
<p>The above "erl" command line gives:
</p>
- <pre>
+<div class="box">
+ <verbatim>
# erl -pa /usr/local/lib/yaws/ebin -yaws embedded true -s ybed
Erlang (BEAM) emulator version 5.3.b1 [source] [hipe]
Eshell V5.3.b1 (abort with ^G)
-1&gt;
+1>
=INFO REPORT==== 25-Nov-2003::00:27:18 ===
Yaws: Listening to 0.0.0.0:8888 for servers
- foobar under /tmp
1>
-</pre>
+</verbatim>
+</div>
<p>The actual web server then runs inside the larger application
@@ -188,18 +196,25 @@ make up the web GUI application, is easily available there.
<p>In essence, if we construct the #sconf as</p>
-<pre>
+
+<div class="box">
+<verbatim>
SC#sconf{opaque = {mystruct, foobar},
.....
-</pre>
+</verbatim>
+</div>
+
<p>A .yaws web page, can do:</p>
-<pre>
+
+<div class="box">
+<verbatim>
out(Arg) ->
MyStruct = Arg#arg.opaque
.....
-</pre>
+</verbatim>
+</div>
<p>Thus passing data from the surrounding applications configuration routines
down to each .yaws web page.</p>
View
7 www/index.yaws
@@ -6,6 +6,9 @@ out(A) ->
{ehtml,
[{'div', [{id, "entry"}],
[{h1,[],"Yaws"},
+
+ {pre_html, "<pre> < > < > & </pre>"},
+
{p,[],"Yaws is a HTTP high perfomance 1.1 webserver."
"Two separate modes of operations are supported."},
{ul,[],
@@ -25,9 +28,7 @@ out(A) ->
" underlying Erlang system and its ability to handle concurrent "
" processes in an efficent way. Its elegance comes from Erlang as "
"well. Web applications dont have to be written in ugly adhoc "
- "languages. A Yaws web server can handle high load in a way that an apache/php server"
- " isn't even close to match."
- },
+ "languages."},
{h2,[], "yaws.hyber.org"},
View
4 www/redirect.yaws
@@ -61,7 +61,7 @@ out(_A) ->
For example:</p>
<div class="box">
-<pre>
+<verbatim>
# curl -I http://rubin.hyber.org:8000/redirect3.yaws
HTTP/1.1 302 Found
Server: Yaws/1.49 Yet Another Web Server
@@ -69,7 +69,7 @@ Location: http://rubin.hyber.org:8000/redirect2.yaws
Date: Tue, 16 Nov 2004 20:16:01 GMT
Content-Type: text/html
-<pre>
+<verbatim>
</div>
<p>Where <tt> http://rubin.hyber.org:8000</tt> is where I am currently
Please sign in to comment.
Something went wrong with that request. Please try again.