netzke-core 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +19 -0
- data/README.markdown +43 -0
- data/TODO +1 -5
- data/app/controllers/netzke_controller.rb +47 -15
- data/config/database.yml +2 -0
- data/features/component_loader.feature +6 -1
- data/features/composition.feature +2 -0
- data/features/js_include.feature +18 -0
- data/features/nested_views.feature +9 -0
- data/features/persistence.feature +6 -4
- data/features/support/paths.rb +3 -0
- data/javascripts/core.js +166 -519
- data/javascripts/ext.js +355 -0
- data/javascripts/touch.js +47 -0
- data/lib/netzke/actions.rb +31 -38
- data/lib/netzke/base.rb +48 -6
- data/lib/netzke/composition.rb +52 -63
- data/lib/netzke/configuration.rb +6 -2
- data/lib/netzke/core/version.rb +2 -2
- data/lib/netzke/core.rb +22 -15
- data/lib/netzke/javascript/scopes.rb +39 -0
- data/lib/netzke/javascript.rb +145 -114
- data/lib/netzke/railz/action_view_ext/ext.rb +59 -0
- data/lib/netzke/railz/action_view_ext/touch.rb +50 -0
- data/lib/netzke/railz/action_view_ext.rb +86 -0
- data/lib/netzke/railz/controller_extensions.rb +33 -0
- data/lib/netzke/{rails → railz}/routes.rb +0 -0
- data/lib/netzke/railz.rb +3 -0
- data/lib/netzke/session.rb +18 -3
- data/lib/netzke/state.rb +42 -15
- data/lib/netzke/stylesheets.rb +23 -8
- data/lib/netzke-core.rb +23 -16
- data/netzke-core.gemspec +52 -10
- data/spec/component/base_spec.rb +11 -0
- data/spec/component/javascript_spec.rb +3 -2
- data/spec/component/state_spec.rb +18 -0
- data/spec/spec_helper.rb +1 -1
- data/test/rails_app/Gemfile +3 -2
- data/test/rails_app/Gemfile.lock +73 -71
- data/test/rails_app/app/components/component_loader.rb +39 -4
- data/test/rails_app/app/components/{custom.css → component_with_custom_css/stylesheets/custom.css} +0 -0
- data/test/rails_app/app/components/component_with_custom_css.rb +2 -2
- data/test/rails_app/app/components/component_with_js_mixin/javascripts/extra_one.js +2 -0
- data/test/rails_app/app/components/component_with_js_mixin/javascripts/extra_two.js +2 -0
- data/test/rails_app/app/components/component_with_js_mixin/javascripts/method_set_one.js +6 -0
- data/test/rails_app/app/components/component_with_js_mixin/javascripts/method_set_two.js +5 -0
- data/test/rails_app/app/components/component_with_js_mixin.rb +8 -0
- data/test/rails_app/app/components/component_with_session_persistence.rb +10 -3
- data/test/rails_app/app/components/extended_component_with_js_mixin/javascripts/some_method_set.js +5 -0
- data/test/rails_app/app/components/extended_component_with_js_mixin.rb +7 -0
- data/test/rails_app/app/components/hello_world_component.rb +31 -0
- data/test/rails_app/app/components/server_caller.rb +1 -1
- data/test/rails_app/app/components/simple_panel.rb +2 -0
- data/test/rails_app/app/components/touch/hello_world_component.rb +25 -0
- data/test/rails_app/app/components/touch/server_caller.rb +28 -0
- data/test/rails_app/app/components/touch/simple_carousel.rb +17 -0
- data/test/rails_app/app/controllers/components_controller.rb +6 -1
- data/test/rails_app/app/controllers/touch_controller.rb +6 -0
- data/test/rails_app/app/helpers/touch_helper.rb +2 -0
- data/test/rails_app/app/views/components/panel_with_autoload.html.erb +2 -0
- data/test/rails_app/app/views/components/some_tab_panel.html.erb +11 -0
- data/test/rails_app/app/views/layouts/nested.html.erb +5 -0
- data/test/rails_app/app/views/layouts/touch.html.erb +13 -0
- data/test/rails_app/config/initializers/netzke.rb +1 -1
- data/test/rails_app/config/locales/en.yml +7 -1
- data/test/rails_app/config/routes.rb +10 -1
- data/test/rails_app/db/migrate/20110110132720_create_netzke_component_states.rb +20 -0
- data/test/rails_app/db/schema.rb +14 -1
- data/test/rails_app/spec/controllers/touch_controller_spec.rb +5 -0
- data/test/rails_app/spec/helpers/touch_helper_spec.rb +15 -0
- data/test/unit/netzke_core_test.rb +2 -6
- metadata +53 -11
- data/README.rdoc +0 -136
- data/lib/netzke/rails/action_view_ext.rb +0 -103
- data/lib/netzke/rails/controller_extensions.rb +0 -31
- data/test/rails_app/db/migrate/20100905214933_create_netzke_preferences.rb +0 -16
data/README.rdoc
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
= netzke-core
|
2
|
-
|
3
|
-
Create Ext JS + Rails components with minimum effort.
|
4
|
-
|
5
|
-
This is the bare bones of the Netzke framework. Use it to build your own components from scratch. For pre-built components (like panels, grids, forms, trees, applications), see the http://github.com/skozlov/netzke-basepack.
|
6
|
-
|
7
|
-
The idea behind the Netzke framework is that it allows you write reusable client/server code. Create a component, and then embed it straight to your Rails' view, load it dynamically into your Ext-based applications, or use it as a building block for other (composite) components. For more info, see the links below.
|
8
|
-
|
9
|
-
== Requirements
|
10
|
-
|
11
|
-
* Ruby >= 1.9.2 (1.8.7 may work, too)
|
12
|
-
* Rails >= 3.0.0
|
13
|
-
* Ext >= 3.3.0
|
14
|
-
|
15
|
-
== Installation
|
16
|
-
|
17
|
-
For the latest ("edge") stuff, tell bundler to get the gem straight from github:
|
18
|
-
|
19
|
-
gem 'netzke-core', :git => "git://github.com/skozlov/netzke-core.git"
|
20
|
-
|
21
|
-
Netzke assumes that your ExtJS library is in public/extjs (which may be a symbolic link):
|
22
|
-
|
23
|
-
ln -s ~/code/sencha/ext-3.3.0 public/extjs
|
24
|
-
|
25
|
-
== Usage
|
26
|
-
|
27
|
-
=== Creating a simple component
|
28
|
-
|
29
|
-
Let's create a simple "Hello world!" component and embed it into a Rails' view. It'll be an Ext.Panel-based component with a button that triggers a client-server communication.
|
30
|
-
|
31
|
-
Create YOUR_APP/app/components/hello_world_component.rb, and put in the following content:
|
32
|
-
|
33
|
-
class HelloWorldComponent < Netzke::Base
|
34
|
-
# Ext.Panel's config option "title"
|
35
|
-
js_property :title, "My Hello World Component"
|
36
|
-
|
37
|
-
# Bottom bar with an automatically created action
|
38
|
-
js_property :bbar, [:bug_server.action]
|
39
|
-
|
40
|
-
# Action to be placed on the bottom bar
|
41
|
-
action :bug_server, :text => 'Ask server', :icon => :accept
|
42
|
-
|
43
|
-
# Method in the JS class that (by default) processes the action's "click" event
|
44
|
-
js_method :on_bug_server, <<-JS
|
45
|
-
function(){
|
46
|
-
// Remotely calling the server's method greet_the_world (defined below)
|
47
|
-
this.greetTheWorld();
|
48
|
-
}
|
49
|
-
JS
|
50
|
-
|
51
|
-
# Server's method that gets called from the JS
|
52
|
-
endpoint :greet_the_world do |params|
|
53
|
-
# Tell the client side to call its method showGreeting with "Hello World!" as parameter
|
54
|
-
{:show_greeting => "Hello World!"}
|
55
|
-
end
|
56
|
-
|
57
|
-
# Another method in the JS class that gets remotely called by the server side
|
58
|
-
js_method :show_greeting, <<-JS
|
59
|
-
function(greeting){
|
60
|
-
this.body.update("Server says: " + greeting);
|
61
|
-
}
|
62
|
-
JS
|
63
|
-
end
|
64
|
-
|
65
|
-
=== Embedding components into Rails views
|
66
|
-
|
67
|
-
To embed a Netzke component into your Rails view do the following:
|
68
|
-
|
69
|
-
* Add <tt>netzke</tt> routes:
|
70
|
-
|
71
|
-
# in routes.rb
|
72
|
-
RailsApp::Application.routes.draw do
|
73
|
-
netzke
|
74
|
-
...
|
75
|
-
end
|
76
|
-
|
77
|
-
* In your layout, within the "head" tag, use the <tt>netzke_init</tt> helper to include all the necessary JavaScript and styles.
|
78
|
-
|
79
|
-
<%= netzke_init %>
|
80
|
-
|
81
|
-
# You can optionally specify an Ext theme:
|
82
|
-
|
83
|
-
<%= netzke_init :ext_theme => 'grey' %>
|
84
|
-
|
85
|
-
* In your view use the <tt>netzke</tt> helper to embed the component:
|
86
|
-
|
87
|
-
<%= netzke :hello_world_component %>
|
88
|
-
|
89
|
-
That's it. While playing with the component, use Firebug or similar tool to check the AJAX requests to understand better what's going on behind the scenes. Also check the source code of the page embedding the component.
|
90
|
-
|
91
|
-
== Running tests
|
92
|
-
|
93
|
-
netzke-core is bundled with cucumber and RSpec tests. Before you can run them, you must link your Ext JS library to test/rails_app/public, e.g. (from plugin's root):
|
94
|
-
|
95
|
-
ln -s ~/code/sencha/ext-3.3.0 test/rails_app/public/extjs
|
96
|
-
|
97
|
-
For cucumber tests:
|
98
|
-
|
99
|
-
cucumber features
|
100
|
-
|
101
|
-
RSpec tests:
|
102
|
-
|
103
|
-
rspec spec
|
104
|
-
|
105
|
-
== Testing playground
|
106
|
-
|
107
|
-
The bundled test/rails_app application is also a convenient playground to learn more about the framework, as it may be run as a stand-alone Rails app. It's also a pretty good source of examples. After starting it, access any of the app/components/netzke test components by using the following url:
|
108
|
-
|
109
|
-
http://localhost:3000/components/<name of the component's class>
|
110
|
-
|
111
|
-
e.g.:
|
112
|
-
|
113
|
-
http://localhost:3000/components/ServerCaller
|
114
|
-
|
115
|
-
or, for scoped components:
|
116
|
-
|
117
|
-
http://localhost:3000/components/ScopedComponents::SomeScopedComponent
|
118
|
-
|
119
|
-
== Migrating from 0.5.x
|
120
|
-
|
121
|
-
There have been a significant amount of changes that made 0.6 version backward-incompatible. Please, refer to CHANGELOG.rdoc for the (hopefully) full list of changes that most certainly would make your current application break. Additionally, this wiki page may be of some help, too: http://github.com/skozlov/netzke-core/wiki/Upgrading-from-0.5.x-to-0.6.0
|
122
|
-
|
123
|
-
== More info
|
124
|
-
Netzke website: http://netzke.org
|
125
|
-
|
126
|
-
Live-demo with sample code: http://demo.netzke.org
|
127
|
-
|
128
|
-
Tutorials: http://blog.writelesscode.com
|
129
|
-
|
130
|
-
Twitter: http://twitter.com/skozlov
|
131
|
-
|
132
|
-
The netzke-basepack project (pre-built full-featured components): http://github.com/skozlov/netzke-basepack
|
133
|
-
|
134
|
-
---
|
135
|
-
|
136
|
-
Copyright (c) 2008-2010 Sergei Kozlov, released under the MIT license
|
@@ -1,103 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
module ActionViewExt
|
3
|
-
# Include JavaScript
|
4
|
-
def netzke_js_include
|
5
|
-
res = []
|
6
|
-
|
7
|
-
# ExtJS
|
8
|
-
res << (ENV['RAILS_ENV'] == 'development' ? javascript_include_tag("/extjs/adapter/ext/ext-base-debug", "/extjs/ext-all-debug") : javascript_include_tag("/extjs/adapter/ext/ext-base", "/extjs/ext-all"))
|
9
|
-
|
10
|
-
# Netzke (dynamically generated)
|
11
|
-
res << javascript_include_tag("/netzke/netzke")
|
12
|
-
res.join("\n")
|
13
|
-
end
|
14
|
-
|
15
|
-
# Include CSS
|
16
|
-
def netzke_css_include(theme_name = "default")
|
17
|
-
# ExtJS base
|
18
|
-
res = stylesheet_link_tag("/extjs/resources/css/ext-all")
|
19
|
-
# ExtJS theming
|
20
|
-
res << "\n" << stylesheet_link_tag("/extjs/resources/css/xtheme-#{theme_name}") unless theme_name.to_s == "default"
|
21
|
-
# Netzke (dynamically generated)
|
22
|
-
res << "\n" << stylesheet_link_tag("/netzke/netzke")
|
23
|
-
|
24
|
-
# External stylesheets (which cannot be loaded dynamically along with the rest of the component, e.g. due to that
|
25
|
-
# relative paths are used in them)
|
26
|
-
res << "\n" << stylesheet_link_tag(Netzke::Core.external_css)
|
27
|
-
|
28
|
-
res
|
29
|
-
end
|
30
|
-
|
31
|
-
# JavaScript for all Netzke classes in this view, and Ext.onReady which renders all Netzke components in this view
|
32
|
-
def netzke_js
|
33
|
-
res = []
|
34
|
-
if Netzke::Core.javascript_on_main_page
|
35
|
-
res << content_for(:netzke_js_classes)
|
36
|
-
res << "\n"
|
37
|
-
end
|
38
|
-
res << "Ext.onReady(function(){"
|
39
|
-
res << content_for(:netzke_on_ready)
|
40
|
-
res << "});"
|
41
|
-
|
42
|
-
javascript_tag res.join("\n")
|
43
|
-
end
|
44
|
-
|
45
|
-
def netzke_css
|
46
|
-
%{
|
47
|
-
<style type="text/css" media="screen">
|
48
|
-
#{content_for(:netzke_css)}
|
49
|
-
</style>}
|
50
|
-
end
|
51
|
-
|
52
|
-
# Wrapper for all the above. Use it in your layout.
|
53
|
-
# Params: <tt>:ext_theme</tt> - the name of ExtJS theme to apply (optional)
|
54
|
-
# E.g.:
|
55
|
-
# <%= netzke_init :ext_theme => "grey" %>
|
56
|
-
def netzke_init(params = {})
|
57
|
-
theme = params[:ext_theme] || :default
|
58
|
-
raw([netzke_css_include(theme), netzke_css, netzke_js_include, netzke_js].join("\n"))
|
59
|
-
end
|
60
|
-
|
61
|
-
# Use this helper in your views to embed Netzke components. E.g.:
|
62
|
-
# netzke :my_grid, :class_name => "Basepack::GridPanel", :columns => [:id, :name, :created_at]
|
63
|
-
# On how to configure a component, see documentation for Netzke::Base or/and specific component
|
64
|
-
def netzke(name, config = {})
|
65
|
-
@rendered_classes ||= []
|
66
|
-
|
67
|
-
# if we are the first netzke call on the page, reset components hash in the session
|
68
|
-
if @rendered_classes.empty?
|
69
|
-
Netzke::Core.reset_components_in_session
|
70
|
-
end
|
71
|
-
|
72
|
-
class_name = config[:class_name] ||= name.to_s.camelcase
|
73
|
-
|
74
|
-
config[:name] = name
|
75
|
-
|
76
|
-
Netzke::Core.reg_component(config)
|
77
|
-
|
78
|
-
w = Netzke::Base.instance_by_config(config)
|
79
|
-
w.before_load # inform the component about initial load
|
80
|
-
|
81
|
-
if Netzke::Core.javascript_on_main_page
|
82
|
-
content_for :netzke_js_classes, raw(w.js_missing_code(@rendered_classes))
|
83
|
-
end
|
84
|
-
|
85
|
-
content_for :netzke_css, raw(w.css_missing_code(@rendered_classes))
|
86
|
-
|
87
|
-
content_for :netzke_on_ready, raw("#{w.js_component_instance}\n\n#{w.js_component_render}")
|
88
|
-
|
89
|
-
# Now mark this component's class as rendered, so that we only generate it once per view
|
90
|
-
@rendered_classes << class_name unless @rendered_classes.include?(class_name)
|
91
|
-
|
92
|
-
# Return the html for this component
|
93
|
-
raw(w.js_component_html)
|
94
|
-
end
|
95
|
-
|
96
|
-
def ext(name, config = {})
|
97
|
-
comp = Netzke::ExtComponent.new(name, config)
|
98
|
-
content_for :netzke_on_ready, raw("#{comp.js_component_render}")
|
99
|
-
raw(comp.js_component_html)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
module ControllerExtensions
|
3
|
-
def self.included(base)
|
4
|
-
base.send(:before_filter, :set_session_data)
|
5
|
-
base.send(:before_filter, :set_controller)
|
6
|
-
end
|
7
|
-
|
8
|
-
def set_session_data
|
9
|
-
::Netzke::Core.session = session
|
10
|
-
session[:netzke_user_id] = defined?(current_user) ? current_user.try(:id) : nil
|
11
|
-
# set netzke_just_logged_in and netzke_just_logged_out states (may be used by Netzke components)
|
12
|
-
if session[:_netzke_next_request_is_first_after_login]
|
13
|
-
session[:netzke_just_logged_in] = true
|
14
|
-
session[:_netzke_next_request_is_first_after_login] = false
|
15
|
-
else
|
16
|
-
session[:netzke_just_logged_in] = false
|
17
|
-
end
|
18
|
-
|
19
|
-
if session[:_netzke_next_request_is_first_after_logout]
|
20
|
-
session[:netzke_just_logged_out] = true
|
21
|
-
session[:_netzke_next_request_is_first_after_logout] = false
|
22
|
-
else
|
23
|
-
session[:netzke_just_logged_out] = false
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def set_controller
|
28
|
-
::Netzke::Core.controller = self
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class CreateNetzkePreferences < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :netzke_preferences do |t|
|
4
|
-
t.string :key
|
5
|
-
t.text :value
|
6
|
-
t.integer :user_id
|
7
|
-
t.integer :role_id
|
8
|
-
|
9
|
-
t.timestamps
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.down
|
14
|
-
drop_table :netzke_preferences
|
15
|
-
end
|
16
|
-
end
|