Skip to content

Add a view

Scott Erickson edited this page Jan 15, 2016 · 5 revisions

Problem

You want to create a new page on the CodeCombat website.

Solution

Create view, template, and style files and then tie the url to the view in the Router.

Details

First, create the three core files:

  1. View file. In /app/views or one of the subfolders, create the view file. The name should be CamelCase, end with 'View', and be a CoffeeScript file. The contents should be something like this:
RootView = require 'views/core/RootView'
template = require 'templates/foo-view'

module.exports = class FooView extends RootView
  id: 'foo-view'
  template: template

  initialize: (options) ->
    # get things started here
  1. Template file. In /app/templates, or one of the subfolders, create the template file. The name should be hyphenated, end with '-view', and be a jade file, and the subfolder-path should match the View's. The contents should look something like this:
extends /templates/base

block content
  p Hello World
  1. Stylesheet (optional). In /app/styles, or one of the subfolders, create the stylesheet file. The name should be hyphenated, end with '-view', be a sass file, and the subfolder-path should match the View's. The contents should look something like this:
#foo-view
  color: black

Once the files are created, add the route to /app/core/Router.coffee. Use the go function to wrap around the path to the view file.

You should now be able to navigate to your new route and view your new view.

Resources

Clone this wiki locally
You can’t perform that action at this time.