Conquer Your Views. Frustration Free.
All of Gunther is contained in a single javascript file, which you can obtain from its GitHub repo. Since it's no longer 1999, you can also use a package manager to install (and update) Gunther:
Bower.io is a package manager for the web. Bower is the recommended method of installation. Simply run
| bower install gunther
|
to install Gunther to `bower_components/gunther/lib/gunther.min.js'
If you want to install Gunther's dependencies too, use:
| bower install jquery underscore backbone gunther
|
Gunther is also included in NPM.
| npm install gunther
|
Will install Gunther to `node_modules/gunther/lib/gunther.min.js'
The following example contains all you need to get started. See below for an explanation of the parts.
We will be using CoffeeScript in the browser here. Typically you'll want to compile the CoffeeScript separately, but for brevity we are doing it in the HTML document here.
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<!-- dependencies, from CDN's, but you can obviously include these locally -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<!-- your local gunther install -->
<script src="bower_components/gunther/lib/gunther.js"></script>
<!-- Optional, but needed to complete this tutorial -->
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.7.1/coffee-script.min.js"></script>
<div id="gunther-output"></div>
<script type="text/coffeescript">
# Create a view
class ExampleView extends Gunther.View
template: ->
@p "hello world!"
# Render the view
view = new ExampleView el: $ '#gunther-output'
do view.render
</script>
</body>
</html>
|
Gunther is built around jQuery, and Backbone.js. You can replace jQuery with Zepto.js.
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<!-- dependencies, from CDN's, but you can obviously include these locally -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<!-- your local gunther install -->
<script src="bower_components/gunther/lib/gunther.js"></script>
</body>
</html>
|
In your HTML document, include a div with id output
.
| <div id="gunther-output"></div>
|
The template is a simple one, it creates a <p />
with the inspired text
"Hello World!". We will be including this inside of a <script />
tag,
compiling the CoffeeScript in the browser.
| <!-- CoffeeScript for the browser -->
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.7.1/coffee-script.min.js"></script>
<div id="gunther-output"></div>
<script type="text/coffeescript">
# Create a view
class ExampleView extends Gunther.View
template: ->
@p "hello world!"
# Render the view
view = new ExampleView el: $ '#gunther-output'
do view.render
</script>
|