Git Product home page Git Product logo

scene's Introduction

Scene

Scene is a CoffeeScript user interface framework inspired by space-pen.

Builder

Scene uses a simple markup DSL for building views. The $$ function constructs a document fragment:

document.body.appendChild $$ ->
  @h1 "Scene"
  @ol =>
    @li "Simple"
    @li "Concise"
    @li "Reusable"

You can add attributes and event handlers by passing a map to a tag constructor:

document.body.appendChild $$ ->
  @p class: "example", =>
    @button "Click me", click: -> alert "Hello, world!"

Views

Views are a simple wrapper around a DOM node.

class Login extends View
  @content: ->
    @section =>
      @h1 "Sign in"
      @input placeholder: "Username"
      @input type: "password", placeholder: "Password"
      @button "Sign in"

You can add them to the DOM with the embed method:

new Login().embed document.body

Event handlers can be names of methods on the view. You can refer to nodes using the outlet attribute:

class Login extends View
  @content: ->
    @section =>
      @h1 "Sign in"
      @input outlet: "user", placeholder: "Username"
      @input type: "password", placeholder: "Password"
      @button "Sign in", click: "submit"
  
  submit: ->
    alert "Hello, #{@user.value}!"

Views can include subviews in their content with the @subview builder method, which takes an optional outlet name:

class Header extends View
  @content: ->
    @header =>
      @h1 "Scene"
      @subview "login", new Login

Subviews are stored in a view's subviews property. Each view stores a reference to its parent view in the parent property. You can use the add, remove, and replaceWith methods to manipulate subviews:

class Header extends View
  @content: ->
    @header =>
      @h1 "Scene"
      @subview "login", new Login

  addNotice: (n) ->
    if @notice?
      @notice.replaceWith n
    else
      @add @notice = n
    setTimeout @removeNotice, 5000

  removeNotice: =>
    @notice.remove() if @notice?

By default, add inserts the subview as a child of @base, the view's root node. You can pass a different mounting point as the second parameter, and a child node to insert the subview before as the third.

The @content class method and the initialize instance method are passed any constructor arguments:

class Warning extends View
  @content: ({message}) ->
    @p class: "warning", "Warning: #{message}"

header = new Header().embed document.body
header.addNotice new Warning message: "this is a warning"

scene's People

Contributors

nathan avatar

Stargazers

Michael Anthony avatar

Watchers

Michael Anthony avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.