1.5.2 • Published 8 years ago

capejs v1.5.2

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Cape.JS

Cape.JS logo

Circle CI Npm Version Bower Version

Cape.JS is a lightweight JavaScript UI framework with following features:

  • Full stack: You can build single-page applications (SPAs) with Cape.JS.
  • Modular: You can place web widgets built by Cape.JS to your static web sites.
  • Virtual DOM: Cape.JS takes advantage of virtual-dom of Matt-Esch for high performance rendering.
  • Markup builder: The markup builder helps you to construct HTML DOM trees with its simple, easy to learn syntax.
  • Form manipulation: You can get or set the value of form fields without jQuery.
  • Data stores: Using data stores, you can build web applications with unidirectional data flow.
  • Resource agents and collection agents: Using resource agents and/or collection agents, you can perform REST requests to the web resources using Fetch API.
  • Router: You can define routes with a DSL (domain specific language) similar to that of Ruby on Rails.

The architecture and terminology of Cape.JS are strongly influenced by React, Riot and Ruby on Rails.

If you want to learn about Cape.JS, check out the Cape.JS Documentation.

A simple example

The following example will insert <div>Hello, World!</div> into the div#hello-message element.

index.html

<h1>Greeting from Cape.JS</h1>
<div id="hello-message" data-name="World"></div>

<script src="./hello_message.js"></script>
<script>
  var component = new HelloMesage()
  component.mount('hello-message')
</script>

hello_message.js

var HelloMesage = Cape.createComponentClass({
  render: function(m) {
    m.div('Hello, ' + this.root.data.name + '!')
  }
})

In this example, the div method corresponds to the div tag of HTML. If you replace it with p, it inserts <p>Hello, World!</p>. In this way, you can generate any HTML5 element, such as blockquote, h1, strong, video, etc.

This example is explained in detail in the Hello World section of Cape.JS Documentation.

Integration with Rails Asset Pipeline

If you combile Cape.JS with Ruby on Rails, you are recommended to use capejs-rails gem.

See capejs/capejs-rails for details.

Router

Cape.JS has a built-in routing library. Using this you can define routes with a DSL (domain specific language) similar to that of Ruby on Rails. Here is an example of routes.js:

var $router = new Cape.Router()

$router.draw(function(m) {
  m.root('welcome')
  m.page('login')
  m.page('help')
  m.many('articles')
})

You can navigate the user to another page by the navigateTo() method:

$router.navigateTo('help')

The following is a full example of Component definition:

var WelcomePage = Cape.createComponentClass({
  render: function(m) {
    m.div(function(m) {
      m.span('Help', {
        class: 'link',
        onclick: function(e) { $router.navigateTo('help') }
      })
    })
  }
})

When the user clicks on the "Help" link, the hash fragment of the URL changes to #help and the Help component will be mounted.

Note that you can construct a single-page application (SPA) in this manner. In the above example, when the user is navigated to the Help component, the HTML document itself does not get reloaded. The Help component is rendered by Cape.JS with the assistance of virtual-dom. An apparent page transition happens within a single page in fact.

ECMAScript 2015 (a.k.a. ES6)

If you are familiar with Babel, you can write the code above more concisely using the ECMAScript 2015 syntax like this:

class WelcomePage extends Cape.Component {
  render(m) {
    m.div(m => {
      m.span('Help', {
        class: 'link',
        onclick: e => $router.navigateTo('doc/help')
      })
    })
  }
}

Tutorials

Demo Applications

Greeter

You can get the source code of demo app from https://github.com/capejs/greeter-demo.

By reading its source code, you can learn how to construct Single Page Applications (SPAs) combining the Cape.JS as front-end framework with the Rails as back-end framework.

Todo List

You can download and try a demo app from https://github.com/oiax/capejs-demo-on-rails.

This is built upon the Ruby on Rails. When you start it and open http://localhost:3000 with your browser, you will see a page like this:

Screen shot of demo app

Click the "Start" button to navigate to Login form. Then, enter your credentials (alice and hotyoga) to login to the sytem.

Screen shot of demo app

You can list, add, update and delete tasks here.

Screen shot of demo app

Click the "Logout" button to show the modal for confirmation.

Screen shot of demo app

Browser Support

  • Microsoft Edge
  • Internet Explorer 11
  • Google Chrome (Current)
  • Mozilla Firefox (Current)
  • Safari (7.1+)
  • Vivaldi (Current)

Any problem with Cape.JS in the above browsers should be reported as a bug in Cape.JS.

Contributing

The Cape.JS is an open source project.

We encourage you to contribute to the Cape.JS! Please see CONTRIBUTING.md for details.

Acknowledgements

The logo of Cape.JS is created by Junya Suzuki.

Trademarks

"Cape.JS" and its logo are trademarks of Oiax Inc. All rights reserved.

License

Cape.JS is released under the MIT License.

1.5.2

8 years ago

2.0.0-alpha

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.5.0-beta.2

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.0

9 years ago

1.1.4

9 years ago

1.2.1

9 years ago

1.3.0-alpha.2

9 years ago

1.2.0

9 years ago

1.2.0-rc.17

9 years ago

1.2.0-rc.16

9 years ago

1.1.3

9 years ago

1.2.0-rc.15

9 years ago

1.2.0-rc.14

9 years ago

1.2.0-rc.13

9 years ago

1.2.0-rc.12

9 years ago

1.2.0-rc.11

9 years ago

1.2.0-rc.10

9 years ago

1.2.0-rc.9

9 years ago

1.2.0-rc.8

9 years ago

1.2.0-rc.7

9 years ago

1.2.0-rc.6

9 years ago

1.2.0-rc.5

9 years ago

1.2.0-rc.4

9 years ago

1.2.0-rc.3

9 years ago

1.1.2

9 years ago

1.0.3

9 years ago

1.2.0-beta.3

9 years ago

1.2.0-beta.2

9 years ago

1.2.0-beta.1

9 years ago

1.2.0-alpha.3

9 years ago

1.2.0-alpha.2

9 years ago

1.2.0-alpha.1

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

1.0.0-rc.2

10 years ago

1.0.0-rc.1

10 years ago

1.0.0-beta.11

10 years ago

1.0.0-beta.10

10 years ago

1.0.0-beta.9

10 years ago

1.0.0-beta.8

10 years ago

1.0.0-beta.7

10 years ago

1.0.0-beta.6

10 years ago

1.0.0-beta.5

10 years ago

1.0.0-beta.4

10 years ago

1.0.0-beta.3

10 years ago

1.0.0-beta.2

10 years ago

1.0.0-beta.1

10 years ago

0.12.1

10 years ago

0.12.0

10 years ago

0.11.5

10 years ago

0.11.2

10 years ago

0.11.0

10 years ago