# HTMLPage use fluent interface so you can chain calls as:
# add("div").attr("id", "mydiv").text("My Div")
class HTMLPage
+ super Streamable
# Define head content
fun head do end
private var current: HTMLTag = root
private var stack = new List[HTMLTag]
- # Render the page as a html string
- fun render: String do
+ redef fun write_to(stream) do
root.children.clear
open("head")
head
open("body")
body
close("body")
- return "<!DOCTYPE html>{root.html}"
+ stream.write "<!DOCTYPE html>"
+ root.write_to(stream)
end
# Add a html tag to the current element
end
current = stack.pop
end
-
- # Save html page in the specified file
- fun save(file: String) do
- var out = new OFStream.open(file)
- out.write(self.render)
- out.close
- end
end
class HTMLTag
+ super Streamable
+
# HTML tagname: 'div' for <div></div>
var tag: String
init(tag: String) do
# Clear all child and set the text of element
# var p = new HTMLTag("p")
# p.text("Hello World!")
- # assert p.html == "<p>Hello World!</p>"
+ # assert p.write_to_string == "<p>Hello World!</p>"
# Text is escaped see: `standard::String::html_escape`
fun text(txt: String): HTMLTag do
# p.append("Hello")
# p.add(new HTMLTag("br"))
# p.append("World!")
- # assert p.html == "<p>Hello<br/>World!</p>"
+ # assert p.write_to_string == "<p>Hello<br/>World!</p>"
# Text is escaped see: standard::String::html_escape
fun append(txt: String): HTMLTag do
add(new HTMLRaw(txt.html_escape))
return self
end
- # Render the element as HTML string
- fun html: String do
- var res = new Array[String]
- render_in(res)
- return res.to_s
- end
-
- # Save html page in the specified file
- fun save(file: String) do
- var out = new OFStream.open(file)
+ redef fun write_to(stream) do
var res = new Array[String]
render_in(res)
for r in res do
- out.write(r)
+ stream.write(r)
end
- out.close
end
# In order to avoid recursive concatenation,
private var content: String
init(content: String) do self.content = content
- redef fun html do return content
redef fun render_in(res) do res.add content
end
private fun full_markdown: String do
if n_moduledecl != null and n_moduledecl.n_doc != null then
- return n_moduledecl.n_doc.full_markdown.html
+ return n_moduledecl.n_doc.full_markdown.write_to_string
end
return ""
end
end
private fun full_markdown: String do
- if n_doc != null then return n_doc.full_markdown.html
+ if n_doc != null then return n_doc.full_markdown.write_to_string
return ""
end
end
private fun full_markdown: String do
- if n_doc != null then return n_doc.full_markdown.html
+ if n_doc != null then return n_doc.full_markdown.write_to_string
return ""
end
end
if dir != null then
- page.save("{dir}/{mm.name}.html")
+ page.write_to_file("{dir}/{mm.name}.html")
else
- print page.html
+ page.write_to(stdout)
end
end
n2.text(mm.name)
end
page.add_raw_html "</li></body>"
- page.save("{dir}/index.html")
+ page.write_to_file("{dir}/index.html")
var v = new HighlightVisitor
toolcontext.info("write {dir}/style.css", 1)
<!DOCTYPE html><html><head><meta charset="utf-8"/><title>Nit</title><link rel="icon" href="http://nitlanguage.org/favicon.ico" type="image/x-icon"/><link rel="stylesheet" href="http://nitlanguage.org/style.css" type="text/css"/><link rel="stylesheet" href="http://nitlanguage.org/local.css" type="text/css"/></head><body><article class="page"><section class="pageheader"><a id='toptitle_first' class='toptitle'>the</a><a id='toptitle_second' class='toptitle' href=''>Nit</a><a id='toptitle_third' class='toptitle' href=''>Programming Language</a><header class="header"><div class="topsubtitle"><p>A Fun Language for Serious Programming</p></div></header></section><div id="pagebody"><section id="content"><h1># What is Nit?</h1><p>Nit is an object-oriented programming language. The goal of Nit is to propose a robust statically typed programming language where structure is not a pain.</p><p>So, what does the famous hello world program look like, in Nit?</p><pre><tt><span class='normal'>print </span><span class='string'>'Hello, World!'</span></tt></pre><h1># Feature Highlights</h1><h2>Usability</h2><p>Nit's goal is to be usable by real programmers for real projects</p><ul><li><a href="http://en.wikipedia.org/wiki/KISS_principle">KISS principle</a></li><li>Script-like language without verbosity nor cryptic statements</li><li>Painless static types: static typing should help programmers</li><li>Efficient development, efficient execution, efficient evolution.</li></ul><h2>Robustness</h2><p>Nit will help you to write bug-free programs</p><ul><li>Strong static typing</li><li>No more NullPointerException</li></ul><h2>Object-Oriented</h2><p>Nit's guideline is to follow the most powerful OO principles</p><ul><li><a href="./everything_is_an_object/">Everything is an object</a></li><li><a href="./multiple_inheritance/">Multiple inheritance</a></li><li><a href="./refinement/">Open classes</a></li><li><a href="./virtual_types/">Virtual types</a></li></ul><h1># Getting Started</h1><p>Get Nit from its Git repository:</p><pre><code>$ git clone http://nitlanguage.org/nit.git</code></pre><p>Build the compiler (may be long):</p><pre><code>$ cd nit
-$ make</code></pre><p>Compile a program:</p><pre><code>$ bin/nitc examples/hello_world.nit</code></pre><p>Execute the program:</p><pre><code>$ ./hello_world</code></pre></section></div></article></body></html>
+$ make</code></pre><p>Compile a program:</p><pre><code>$ bin/nitc examples/hello_world.nit</code></pre><p>Execute the program:</p><pre><code>$ ./hello_world</code></pre></section></div></article></body></html>
\ No newline at end of file
<span class="nc_k">var</span> <span class="nc_v nc_i" title="c: C">c</span> = <span class="nc_k">new</span> <a href="base_simple3.html#base_simple3#C"><span class="nc_t" title="base_simple3::C">C</span></a>(<span class="nc_l">9</span>)
<span class="nc_v nc_i" title="c: C">c</span><span class="nc_o">.</span><a href="base_simple3.html#base_simple3#C#val1"><span class="nc_i" title="base_simple3#C#val1: Int">val1</span></a><span class="nc_o">.</span><a href="base_simple3.html#base_simple3#Int#output"><span class="nc_i" title="base_simple3#Int#output">output</span></a>
<span class="nc_v nc_i" title="c: C">c</span><span class="nc_o">.</span><a href="base_simple3.html#base_simple3#C#val2"><span class="nc_i" title="base_simple3#C#val2: Int">val2</span></a><span class="nc_o">.</span><a href="base_simple3.html#base_simple3#Int#output"><span class="nc_i" title="base_simple3#Int#output">output</span></a></span>
-</span>
+</span>
\ No newline at end of file