Files
Fortran-docker-mvc/static/controller.html
Tommy Parnell a7037b9e92 init
2017-02-20 16:06:45 -05:00

90 lines
2.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>fortran - Controller</title>
<link rel="stylesheet" type="text/css" href="/static/bootstrap.min.css"/>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="page-header">
<h1>
<a href="/">fortran</a>
<small>finally, a Fortran Web Framework</small>
</h1>
</div>
</div>
</div>
<div class="row">
<div class="navbar navbar-default">
<ul class="nav navbar-nav">
<li>
<a href="/">Home</a>
</li>
<li>
<a href="/static/model.html">Model</a>
</li>
<li>
<a href="/static/view.html">View</a>
</li>
<li class="active">
<a href="/static/controller.html">Controller</a>
</li>
</ul>
</div>
</div>
<div class="row">
<p>The controller is written in Fortran itself:</p>
<p>Here is an example where you write HTML using multiline strings:</p>
<pre>
case ('/html')
! HTML
write(unitNo,AFORMAT) '&lt;div class="container"&gt;' // &
'&lt;h1&gt;Hello World&lt;/h1&gt;' // &
'&lt;/div&gt;'
</pre>
<p>Here is an example where you load a Jade template:</p>
<pre>
case ('/')
! most pages look like this
templatefile = 'template/index.jade'
call jadefile(templatefile, unitNo)
</pre>
<p>You have access to URL variables:</p>
<pre>
case ('/search')
call cgi_get(dict, 'q', query)
call calculate(query)
</pre>
<p>Jade files can also have template strings with each variable in a #{template}. Pass variables using the pagevars 2D array.<p>
<pre>
case ('/profile')
pagevars(1,1) = 'name'
pagevars(1,2) = 'Nick'
templatefile = 'template/profile.jade'
call jadetemplate(templatefile, unitNo, pagevars)
</pre>
<p>In searches fortran controller gets input from the model and URL variables, and displays it in the view.</p>
<pre>
case ('/search')
pagevars(1,1) = 'name'
pagevars(2,1) = 'latinName'
call cgi_get( dict, 'q', query)
call getOneMarsupial(query, pagevars(1,2), pagevars(2,2))
if (len(trim(name)) == 0) then
write(unitNo,AFORMAT) '<p>No results in this database :-(</p>'
else
! template with string
templatefile = 'template/result.jade'
call jadetemplate(templatefile, unitNo, pagevars)
endif
</pre>
</div>
</div>
</body>
</html>