diff options
-rw-r--r-- | doc/users-guide.html | 77 | ||||
-rw-r--r-- | doc/users-guide.txt | 73 |
2 files changed, 150 insertions, 0 deletions
diff --git a/doc/users-guide.html b/doc/users-guide.html index 9e9c501..53d4b62 100644 --- a/doc/users-guide.html +++ b/doc/users-guide.html @@ -128,6 +128,8 @@ Erubis now supports Ruby 1.9. </li> <li><a href="#lang-c">C</a> </li> + <li><a href="#lang-cpp">C++</a> + </li> <li><a href="#lang-java">Java</a> </li> <li><a href="#lang-scheme">Scheme</a> @@ -2033,6 +2035,81 @@ fputs(" </tbody>\n" <br> +<a name="lang-cpp"></a> +<h3 class="section2">C++</h3> +<a name="example.ecpp"></a> +<div class="program_caption"> +example.ecpp</div> +<pre class="program"><strong><% +#include <string> +#include <iostream> +#include <sstream> + +int main(int argc, char *argv[]) +{ + std::stringstream _buf; +%></strong> +<html> + <body> + <p>Hello <strong><%= argv[0] %></strong>!</p> + <table> + <tbody> + <strong><% for (int i = 1; i < argc; i++) { %></strong> + <tr bgcolor="<strong><%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %></strong>"> + <td><strong><%= i %></strong></td> + <td><strong><%= argv[i] %></strong></td> + </tr> + <strong><% } %></strong> + </tbody> + </table> + </body> +</html> +<strong><% + std::string output = _buf.str(); + std::cout << output; + return 0; +} +%></strong> +</pre> +<a name="example_c.result"></a> +<div class="terminal_caption"> +compiled source code</div> +<pre class="terminal">$ erubis -l cpp example.ecpp +#line 1 "example.ecpp" + +#include <string> +#include <iostream> +#include <sstream> + +int main(int argc, char *argv[]) +{ + std::stringstream _buf; + +_buf << "<html>\n" + " <body>\n" + " <p>Hello "; _buf << (argv[0]); _buf << "!</p>\n" + " <table>\n" + " <tbody>\n"; + for (int i = 1; i < argc; i++) { +_buf << " <tr bgcolor=\""; _buf << (i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"); _buf << "\">\n" + " <td>"; _buf << (i); _buf << "</td>\n" + " <td>"; _buf << (argv[i]); _buf << "</td>\n" + " </tr>\n"; + } +_buf << " </tbody>\n" + " </table>\n" + " </body>\n" + "</html>\n"; + + std::string output = _buf.str(); + std::cout << output; + return 0; +} + +</pre> +<br> + + <a name="lang-java"></a> <h3 class="section2">Java</h3> <a name="Example.ejava"></a> diff --git a/doc/users-guide.txt b/doc/users-guide.txt index 85431af..f1d61bb 100644 --- a/doc/users-guide.txt +++ b/doc/users-guide.txt @@ -2112,6 +2112,79 @@ fputs(" </tbody>\n" .==================== +.$$ C++ | lang-cpp + +.? example.ecpp +.-------------------- example.ecpp +{{*<% +#include <string> +#include <iostream> +#include <sstream> + +int main(int argc, char *argv[]) +{ + std::stringstream _buf; +%>*}} +<html> + <body> + <p>Hello {{*<%= argv[0] %>*}}!</p> + <table> + <tbody> + {{*<% for (int i = 1; i < argc; i++) { %>*}} + <tr bgcolor="{{*<%= i % 2 == 0 ? "#FFCCCC" : "#CCCCFF" %>*}}"> + <td>{{*<%= i %>*}}</td> + <td>{{*<%= argv[i] %>*}}</td> + </tr> + {{*<% } %>*}} + </tbody> + </table> + </body> +</html> +{{*<% + std::string output = _buf.str(); + std::cout << output; + return 0; +} +%>*}} +.-------------------- + +.? compiled source code +.==================== example_c.result +$ erubis -l cpp example.ecpp +.#.<<<:! (cd guide.d; erubis -l cpp example.ecpp) +#line 1 "example.ecpp" + +#include <string> +#include <iostream> +#include <sstream> + +int main(int argc, char *argv[]) +{ + std::stringstream _buf; + +_buf << "<html>\n" + " <body>\n" + " <p>Hello "; _buf << (argv[0]); _buf << "!</p>\n" + " <table>\n" + " <tbody>\n"; + for (int i = 1; i < argc; i++) { +_buf << " <tr bgcolor=\""; _buf << (i % 2 == 0 ? "#FFCCCC" : "#CCCCFF"); _buf << "\">\n" + " <td>"; _buf << (i); _buf << "</td>\n" + " <td>"; _buf << (argv[i]); _buf << "</td>\n" + " </tr>\n"; + } +_buf << " </tbody>\n" + " </table>\n" + " </body>\n" + "</html>\n"; + + std::string output = _buf.str(); + std::cout << output; + return 0; +} + +.==================== + .$$ Java | lang-java |