Netzke Core Build Status Code Climate


Netzke Core is the bare bones of the Netzke framework. For pre-built full-featured components (like grids, forms, tab/accordion panels, etc), see netzke-basepack and netzke-communitypack.

Some knowledge of Sencha Ext JS will be needed in order to fully understand this overview.


Sencha Ext JS is a powerful front-end framework, which is used for crafting web-apps that give the end user experience similar to that of a desktop application. It has an extensive set of widgets ('components'), and leverages a modular approach to its fullest: a developer can extend components (using Ext JS's own class system), nest components using many powerful layouts, dynamically create and destroy them. The architecture of Ext JS is well-thought and very complete.

However, with Ext JS being server-agnostic, it is not always a trivial task for a developer to bind Ext JS components to the server-side data and application business logic, especially in complex applications. Netzke as the solution that allows you to extend the modular approach to the server side.

Netzke Core takes the burden of implementing the following key aspects of the framework:

...and more.

All this extremely facilitates building fast, low-traffic, robust, and highly maintainable applications. As a result, your code scales much better in the sense of complexity, compared to using conventional MVC, where developers are pretty much limited with programming techniques they can apply.

HelloWorld component

This component is distributed as a part of the test application, see test/core_test_app/components.

In YOUR_APP/components/hello_world.rb:

class HelloWorld < Netzke::Base
  # Configure client class
  js_configure do |c|
    c.title = "Hello World component"
    c.mixin # mix in methods from hello_world/javascripts/hello_world.js

  # Actions are used by Ext JS to share functionality and state b/w buttons and menu items
  # The handler for this action should be called onPingServer by default
  action :ping_server

  # Self-configure with a bottom toolbar
  def configure(c)
    c.bbar = [:ping_server] # embed the action into bottom toolbar as a button

  # Endpoint callable from client class
  endpoint :greet_the_world do |params,this|
    # call client class' method showGreeting
    this.show_greeting("Hello World!")

In YOUR_APP/components/hello_world/javascripts/hello_world.js put the client class (JavaScript) methods:

  // handler for the ping_server action
  onPingServer: function(){
    // calling greet_the_world endpoint

  // called by the server as the result of executing the endpoint
  showGreeting: function(greeting){
    this.update("Server says: " + greeting);

To embed the component in Rails view:

Add netzke routes:

# in routes.rb
RailsApp::Application.routes.draw do

Use load_netzke in the layout to include Ext JS and Netzke scripts and stylesheets:

<!DOCTYPE html>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  <%= csrf_meta_tag %>
  <%= load_netzke %>
  <%= yield %>

Embed the component in the Rails view:

<%= netzke :hello_world %>

What is a Netzke component

A Netzke component is a Ruby class (further referred to as "server class"), which is being represented by an Ext JS Component on the server-side (further referred to as "client class"). The responsibility of the server class is to "assemble" the client class and provide the configuration for its instance (further referred as "client class instance"). Even if it may sound a bit complicated, Netzke provides a simple API for defining and configuring the client class. See Client class for details.

Further, each Netzke component inherits convenient API for enabling the communication between the client and server class. See Client-server interaction for details.

With Netzke components being a Ruby class, and the client class being incapsulated in it, it is possible to use a Netzke component in your application by simply writing Ruby code. However, while creating a component, developers can fully use their Ext JS skills - Netzke puts no obstacles here.

A typical Netzke component's code is structured like this (on example of MyComponent):

      my_component.rb             <-- the Ruby class
        some_module.rb            <-- optional extra Ruby code
          some_dependency.js      <-- optional external JS library
          init_component.js       <-- optional mixins to the client class
          extra_functionality.js  <-- more mixins (mixin-in may depend on component class configuration)
          my_special_button.css    <-- optional custom CSS

Client class

The generated client class is inherited (as defined by the Ext JS class system) from an Ext JS class, which by default is Ext.panel.Panel. For example, a component defined like this:

class HelloWorld < Netzke::Base

will have the following client class generated by Netzke (simplified):

Ext.define('Netzke.classes.HelloWorld', {"extend":"Ext.panel.Panel", "mixins":["Netzke.classes.Core.Mixin"]});

Netzke.classes.Core.Mixin contains a set of client class methods and properties common to every Netzke component.

Extending HelloWorld will be automatically reflected on the client-class level:

class HelloNewWorld < HelloWorld

will have the following client class generated (simplified):

Ext.define('Netzke.classes.HelloNewWorld', {"extend":"Netzke.classes.HelloWorld"});

The configuration of a client-class is done by using the Netzke::Base.js_configure. For example, in order to inherit from a different Ext JS component, and to mix in the methods defined in an external JavaScript class:

class MyTabPanel < Netzke::Base
  js_configure do |c|
    c.extend = ""
    c.mixin :extra_functionality

For more details on defining the client class, refer to Netzke::Core::ClientClass.


Any Netzke component can define child components, which can either be statically nested in the compound layout (e.g. as different regions of the 'border' layout), or dynamically loaded at a request (as in the case of the edit form window in Netzke::Basepack::GridPanel, for example).

Defining child components

You can define a child component by calling the component class method which normally requires a block:

component :users do |c|
  c.klass = GridPanel
  c.model = "User"
  c.title = "Users"

Nesting components

Declared components can be referred to in the component layout:

def configure(c)
  c.items = [
    { xtype: :panel, title: "Simple Ext panel" },

Dynamic loading of components

Next to being statically nested in the layout, a child component can also be dynamically loaded by using client class' netzkeLoadComponent method:


this will load the "users" component and add it to the current container.

For more details on dynamic component loading refer to inline docs of javascript/ext.js.

For more details on composition refer to Netzke::Core::Composition.

Actions, toolbars, and menus

Actions are used by Ext JS to share functionality and state among multiple buttons and menu items. Define actions with the action class method:

action :show_report do |c|
  c.text = "Show report"
  c.icon = :report

The icon for this button will be images/icons/report.png (see Icons support).

Refer to actions in toolbars:

def configure(c)
  c.bbar = [:show_report]

Actions can also be referred to is submenus:

  c.tbar = [{text: 'Menu', menu: {items: [:show_report]}}]

For more details on composition refer to Netzke::Core::Action.

Client-server interaction

Communication between the client class and the corresponding server class is done by means of defining endpoints. By defining an endpoint on the server, the client class automatically gets a method that is used to call the server.

Calling an endpoint from client class

By defining an endpoint like this:

class SimpleComponent < Netzke::Base
  endpoint :whats_up_server do |params, this|
  # ...

...the client class will obtain a method called whatsUpServer:

this.whatsUpServer(params, callback, scope);


Calling client class methods from endpoint

An endpoint can instruct the client class to execute a set of methods after its execution, passing those methods arbitrary parameters. For example:

class SimpleComponent < Netzke::Base
  endpoint :whats_up_server do |params, this|
    this.set_title("All quiet here on the server")

Here the client class will call its setTitle method (defined in Ext.panel.Panel) with parameter passed from the endpoint. Then a custom method myMethod will be called with no parameters.

For more details on client-server communication see Netzke::Core::Services.

Icons support

Netzke can optionally make use of icons for making clickable elements like buttons and menu items more visual. The icons should be (by default) located in public/images/icons.

An example of specifying an icon for an action:

action :logout do |c|
  c.icon = :door

The logout action will be configured with public/images/icons/door.png as icon.

For more details on using icons refer to Netzke::Core::Actions.


Netzke Core will automatically include Ext JS localization files based on current I18n.locale.

Also, Netzke Core uses some conventions for localizing actions. Refer to Netzke::Core::Actions.



$ gem install netzke-core

For the latest ("edge") stuff, instruct the bundler to get the gem straight from github:

gem 'netzke-core', git: "git://"

By default, Netzke assumes that your Ext JS library is located in public/extjs. It can be a symbolic link, e.g.:

$ ln -s ~/code/sencha/ext-4.1.1 public/extjs

(Make sure that the location of the license.txt distributed with Ext JS is exactly public/extjs/license.txt)

Running tests

The bundled test/core_test_app application used for automated testing can be easily run as a stand-alone Rails app. It's a good source of concise, focused examples. After starting the application, access any of the test components (located in app/components) by using the following url:

http://localhost:3000/components/{name of the component's class}

For example http://localhost:3000/components/ServerCaller

Before being able run the test app and the tests themselves, you must link your Ext JS library to test/core_test_app/public, e.g. (from the gems's root):

$ ln -s ~/code/sencha/ext-4.1.1 test/core_test_app/public/extjs

For cucumber tests (from test/core_test_app):

$ cucumber features

For RSpec tests (from test/core_test_app):

$ rspec spec

Useful links

Copyright (c) 2008-2012 netzke, released under the MIT license (see LICENSE).

Note that Ext JS is licensed differently, and you may need to purchase a commercial license in order to use it in your projects!