netzke-core 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +12 -3
- data/Rakefile +1 -1
- data/app/controllers/netzke_controller.rb +1 -1
- data/javascripts/core.js +7 -0
- data/lib/netzke/actions.rb +17 -8
- data/lib/netzke/base.rb +2 -2
- data/lib/netzke/composition.rb +26 -14
- data/lib/netzke/configuration.rb +1 -1
- data/lib/netzke/core/session.rb +0 -9
- data/lib/netzke/core/version.rb +1 -1
- data/lib/netzke/core.rb +12 -1
- data/lib/netzke/core_ext/symbol.rb +2 -2
- data/lib/netzke/javascript.rb +1 -1
- data/lib/netzke/services.rb +19 -19
- data/lib/netzke/state.rb +64 -0
- data/lib/netzke-core.rb +1 -0
- data/netzke-core.gemspec +4 -10
- data/test/rails_app/app/components/extended_server_caller.rb +1 -1
- metadata +5 -11
- data/generators/netzke_core/USAGE +0 -8
- data/generators/netzke_core/netzke_core_generator.rb +0 -18
- data/lib/generators/migration_helper.rb +0 -32
- data/lib/generators/netzke/USAGE +0 -8
- data/lib/generators/netzke/core_generator.rb +0 -24
- data/lib/netzke/persistence.rb +0 -118
- data/templates/core/create_netzke_preferences.rb +0 -18
data/CHANGELOG.rdoc
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
= v0.6.
|
1
|
+
= v0.6.4 - 2010-11-05
|
2
|
+
* enhancements
|
3
|
+
* Implemented Netzke.isLoading(), useful for testing
|
4
|
+
* Persistence support
|
5
|
+
|
6
|
+
* API change
|
7
|
+
* +endpoint+ DSL call now results in a method called <endpoint_name>_endpoint, _not_ just <endpoint_name> (beware when overriding endpoint definitions, or calling endpoint methods on child components)
|
8
|
+
* Using +api+ for endpoint declaration is gone
|
9
|
+
|
10
|
+
= v0.6.3 - 2010-11-02
|
2
11
|
* The +ext_config+ option is back, deprecated.
|
3
12
|
|
4
13
|
= v0.6.2 - 2010-10-27
|
@@ -122,7 +131,7 @@
|
|
122
131
|
* New: String#to_b converts a string to true/false
|
123
132
|
* New: Netzke::Base.session introduced for session data
|
124
133
|
* New: weak_children_config and strong_children_config can now be declared by a widget, which specifies weak and strong configuration that every child of this widget will receive (e.g. display/hide configuration tool)
|
125
|
-
* Fix: (degradation) flash message is now shown again in case of erroneous attempt to load a
|
134
|
+
* Fix: (degradation) flash message is now shown again in case of erroneous attempt to load a widge
|
126
135
|
* New: widgets now can check session[:netzke_just_logged_in] and session[:netzke_just_logged_out] automatically set by Netzke after login/logout
|
127
136
|
|
128
137
|
= v0.2.11
|
@@ -213,4 +222,4 @@
|
|
213
222
|
* Meta work: replacing underscore with dash in the name
|
214
223
|
|
215
224
|
= v0.1.0 - 2008-12-11
|
216
|
-
* Initial release
|
225
|
+
* Initial release
|
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ begin
|
|
14
14
|
|
15
15
|
========================================================================
|
16
16
|
|
17
|
-
Thanks for installing
|
17
|
+
Thanks for installing netzke-core!
|
18
18
|
|
19
19
|
Netzke home page: http://netzke.org
|
20
20
|
Netzke Google Groups: http://groups.google.com/group/netzke
|
@@ -49,7 +49,7 @@ class NetzkeController < ApplicationController
|
|
49
49
|
if action
|
50
50
|
w_instance = Netzke::Base.instance_by_config(Netzke::Core.session[:netzke_components][component_name])
|
51
51
|
# only component's actions starting with "endpoint_" are accessible from outside (security)
|
52
|
-
endpoint_action = action.to_s.index('__') ? action : "
|
52
|
+
endpoint_action = action.to_s.index('__') ? action : "_#{action}_ep_wrapper"
|
53
53
|
render :text => w_instance.send(endpoint_action, params), :layout => false
|
54
54
|
else
|
55
55
|
super
|
data/javascripts/core.js
CHANGED
@@ -10,6 +10,11 @@ At this time the following constants have been set by Rails:
|
|
10
10
|
Ext.BLANK_IMAGE_URL = Netzke.RelativeExtUrl + "/resources/images/default/s.gif";
|
11
11
|
Ext.ns('Ext.netzke'); // namespace for extensions that depend on Ext
|
12
12
|
|
13
|
+
Netzke.isLoading=function () {
|
14
|
+
return Netzke.runningRequests!=0;
|
15
|
+
}
|
16
|
+
Netzke.runningRequests=0
|
17
|
+
|
13
18
|
Netzke.deprecationWarning = function(msg){
|
14
19
|
if (typeof console == 'undefined') {
|
15
20
|
// no console defined
|
@@ -479,6 +484,7 @@ Netzke.componentMixin = function(receiver){
|
|
479
484
|
|
480
485
|
// Does the call to the server and processes the response
|
481
486
|
callServer : function(intp, params, callback, scope){
|
487
|
+
Netzke.runningRequests++;
|
482
488
|
if (!params) params = {};
|
483
489
|
Ext.Ajax.request({
|
484
490
|
params: params,
|
@@ -497,6 +503,7 @@ Netzke.componentMixin = function(receiver){
|
|
497
503
|
},
|
498
504
|
scope : this
|
499
505
|
});
|
506
|
+
Netzke.runningRequests--;
|
500
507
|
},
|
501
508
|
|
502
509
|
setResult: function(result) {
|
data/lib/netzke/actions.rb
CHANGED
@@ -22,7 +22,6 @@ module Netzke
|
|
22
22
|
extend ActiveSupport::Concern
|
23
23
|
|
24
24
|
ACTION_METHOD_NAME = "%s_action"
|
25
|
-
ACTION_METHOD_REGEXP = /^(.+)_action$/
|
26
25
|
|
27
26
|
included do
|
28
27
|
alias_method_chain :js_config, :actions
|
@@ -30,6 +29,7 @@ module Netzke
|
|
30
29
|
|
31
30
|
module ClassMethods
|
32
31
|
def action(name, config = {}, &block)
|
32
|
+
register_action(name)
|
33
33
|
config[:name] = name.to_s
|
34
34
|
method_name = ACTION_METHOD_NAME % name
|
35
35
|
|
@@ -47,15 +47,24 @@ module Netzke
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
# Register an action
|
52
|
+
def register_action(name)
|
53
|
+
current_actions = read_inheritable_attribute(:actions) || []
|
54
|
+
current_actions << name
|
55
|
+
write_inheritable_attribute(:actions, current_actions.uniq)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns registered actions
|
59
|
+
def registered_actions
|
60
|
+
read_inheritable_attribute(:actions) || []
|
61
|
+
end
|
62
|
+
|
50
63
|
end
|
51
64
|
|
52
|
-
#
|
65
|
+
# All actions for this instance
|
53
66
|
def actions
|
54
|
-
|
55
|
-
self.class.instance_methods.grep(ACTION_METHOD_REGEXP).inject({}) do |r, m|
|
56
|
-
m.match(ACTION_METHOD_REGEXP)
|
57
|
-
r.merge($1.to_sym => normalize_action_config(send(m)))
|
58
|
-
end
|
67
|
+
@actions ||= self.class.registered_actions.inject({}){ |res, name| res.merge(name.to_sym => normalize_action_config(send(ACTION_METHOD_NAME % name))) }
|
59
68
|
end
|
60
69
|
|
61
70
|
def js_config_with_actions #:nodoc
|
@@ -99,4 +108,4 @@ module Netzke
|
|
99
108
|
# end
|
100
109
|
|
101
110
|
end
|
102
|
-
end
|
111
|
+
end
|
data/lib/netzke/base.rb
CHANGED
@@ -5,7 +5,7 @@ require 'netzke/stylesheets'
|
|
5
5
|
require 'netzke/services'
|
6
6
|
require 'netzke/composition'
|
7
7
|
require 'netzke/configuration'
|
8
|
-
require 'netzke/
|
8
|
+
require 'netzke/state'
|
9
9
|
require 'netzke/embedding'
|
10
10
|
require 'netzke/actions'
|
11
11
|
require 'netzke/session'
|
@@ -28,7 +28,7 @@ module Netzke
|
|
28
28
|
self.default_instance_config = {}
|
29
29
|
|
30
30
|
include Session
|
31
|
-
include
|
31
|
+
include State
|
32
32
|
include Configuration
|
33
33
|
include Javascript
|
34
34
|
include Services
|
data/lib/netzke/composition.rb
CHANGED
@@ -4,6 +4,8 @@ module Netzke
|
|
4
4
|
module Composition
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
+
COMPONENT_METHOD_NAME = "%s_component"
|
8
|
+
|
7
9
|
included do
|
8
10
|
|
9
11
|
# Loads a component on browser's request. Every Nettzke component gets this endpoint.
|
@@ -46,16 +48,23 @@ module Netzke
|
|
46
48
|
# {:data_class => "Book", :title => orig[:title] + ", extended"}
|
47
49
|
# end
|
48
50
|
def component(name, config = {}, &block)
|
51
|
+
register_component(name)
|
49
52
|
config = config.dup
|
50
53
|
config[:class_name] ||= name.to_s.camelize
|
51
54
|
config[:name] = name.to_s
|
52
|
-
method_name =
|
55
|
+
method_name = COMPONENT_METHOD_NAME % name
|
53
56
|
|
54
57
|
if block_given?
|
55
58
|
define_method(method_name, &block)
|
56
59
|
else
|
57
|
-
|
58
|
-
|
60
|
+
if superclass.instance_methods.map(&:to_s).include?(method_name)
|
61
|
+
define_method(method_name) do
|
62
|
+
super().merge(config)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
define_method(method_name) do
|
66
|
+
config
|
67
|
+
end
|
59
68
|
end
|
60
69
|
end
|
61
70
|
end
|
@@ -67,6 +76,18 @@ module Netzke
|
|
67
76
|
config.merge(:component => name)
|
68
77
|
end
|
69
78
|
|
79
|
+
# Register a component
|
80
|
+
def register_component(name)
|
81
|
+
current_components = read_inheritable_attribute(:components) || []
|
82
|
+
current_components << name
|
83
|
+
write_inheritable_attribute(:components, current_components.uniq)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns registered components
|
87
|
+
def registered_components
|
88
|
+
read_inheritable_attribute(:components) || []
|
89
|
+
end
|
90
|
+
|
70
91
|
end
|
71
92
|
|
72
93
|
module InstanceMethods
|
@@ -81,16 +102,7 @@ module Netzke
|
|
81
102
|
|
82
103
|
# All components for this instance, which includes components defined on class level, and components detected in :items
|
83
104
|
def components
|
84
|
-
|
85
|
-
# self.class.components.merge(@components || {})
|
86
|
-
|
87
|
-
@components ||= begin
|
88
|
-
method_regexp = /^_(.+)_component$/
|
89
|
-
self.class.instance_methods.grep(method_regexp).inject({}) do |r, m|
|
90
|
-
m.match(method_regexp)
|
91
|
-
r.merge($1.to_sym => send(m))
|
92
|
-
end
|
93
|
-
end
|
105
|
+
@components ||= self.class.registered_components.inject({}){ |res, name| res.merge(name.to_sym => send(COMPONENT_METHOD_NAME % name)) }
|
94
106
|
end
|
95
107
|
|
96
108
|
def non_late_components
|
@@ -211,7 +223,7 @@ module Netzke
|
|
211
223
|
if action
|
212
224
|
if components[component]
|
213
225
|
# only actions starting with "endpoint_" are accessible
|
214
|
-
endpoint_action = action.to_s.index('__') ? action : "
|
226
|
+
endpoint_action = action.to_s.index('__') ? action : "_#{action}_ep_wrapper"
|
215
227
|
component_instance(component).send(endpoint_action, params)
|
216
228
|
else
|
217
229
|
component_missing(component)
|
data/lib/netzke/configuration.rb
CHANGED
@@ -48,7 +48,7 @@ module Netzke
|
|
48
48
|
|
49
49
|
# Config that is not overridden by parents and sessions
|
50
50
|
def independent_config
|
51
|
-
@independent_config ||= initial_config.merge(weak_independent_options).merge(persistent_options)
|
51
|
+
@independent_config ||= initial_config.merge(weak_independent_options).merge(initial_config[:persistence] ? persistent_options : {})
|
52
52
|
end
|
53
53
|
|
54
54
|
def session_config
|
data/lib/netzke/core/session.rb
CHANGED
@@ -1,15 +1,6 @@
|
|
1
1
|
module Netzke
|
2
2
|
module Core
|
3
3
|
module Session
|
4
|
-
# Access to controller sessions
|
5
|
-
def session
|
6
|
-
@@session ||= {}
|
7
|
-
end
|
8
|
-
|
9
|
-
def session=(s)
|
10
|
-
@@session = s
|
11
|
-
end
|
12
|
-
|
13
4
|
# Should be called by session controller at the moment of successfull login
|
14
5
|
def login
|
15
6
|
session[:_netzke_next_request_is_first_after_login] = true
|
data/lib/netzke/core/version.rb
CHANGED
data/lib/netzke/core.rb
CHANGED
@@ -21,7 +21,12 @@ module Netzke
|
|
21
21
|
extend Session
|
22
22
|
extend Masquerading
|
23
23
|
|
24
|
+
# set in Netzke::ControllerExtensions
|
24
25
|
mattr_accessor :controller
|
26
|
+
|
27
|
+
# set in Netzke::ControllerExtensions
|
28
|
+
mattr_accessor :session
|
29
|
+
@@session = {}
|
25
30
|
|
26
31
|
mattr_accessor :javascripts
|
27
32
|
@@javascripts = ["#{File.dirname(__FILE__)}/../../javascripts/core.js"]
|
@@ -32,8 +37,8 @@ module Netzke
|
|
32
37
|
mattr_accessor :external_css
|
33
38
|
@@external_css = []
|
34
39
|
|
40
|
+
# Set in the Engine after_initialize callback
|
35
41
|
mattr_accessor :ext_location
|
36
|
-
|
37
42
|
mattr_accessor :with_icons
|
38
43
|
|
39
44
|
mattr_accessor :icons_uri
|
@@ -42,6 +47,12 @@ module Netzke
|
|
42
47
|
mattr_accessor :javascript_on_main_page
|
43
48
|
@@javascript_on_main_page = true
|
44
49
|
|
50
|
+
mattr_accessor :persistence_manager
|
51
|
+
@@persistence_manager = "NetzkeComponentState"
|
52
|
+
|
53
|
+
# Set in the Engine after_initialize callback
|
54
|
+
mattr_accessor :persistence_manager_class
|
55
|
+
|
45
56
|
def self.setup
|
46
57
|
yield self
|
47
58
|
end
|
data/lib/netzke/javascript.rb
CHANGED
@@ -217,7 +217,7 @@ module Netzke
|
|
217
217
|
res[:components] = comp_hash unless comp_hash.empty?
|
218
218
|
|
219
219
|
# Api (besides the default "deliver_component" - JavaScript side already knows about it)
|
220
|
-
endpoints = self.class.
|
220
|
+
endpoints = self.class.registered_endpoints - [:deliver_component]
|
221
221
|
res.merge!(:endpoints => endpoints) unless endpoints.empty?
|
222
222
|
|
223
223
|
# Inform the JavaScript side if persistent_config is enabled
|
data/lib/netzke/services.rb
CHANGED
@@ -15,45 +15,45 @@ module Netzke
|
|
15
15
|
# See netzke-basepack's GridPanel for an example.
|
16
16
|
#
|
17
17
|
def api(*api_points)
|
18
|
-
::ActiveSupport::Deprecation.warn("Using the 'api' call
|
18
|
+
::ActiveSupport::Deprecation.warn("Using the 'api' call has no longer effect. Define endpoints instead.", caller)
|
19
19
|
|
20
|
-
api_points.each do |apip|
|
21
|
-
|
22
|
-
end
|
20
|
+
# api_points.each do |apip|
|
21
|
+
# register_endpoint(apip)
|
22
|
+
# end
|
23
23
|
|
24
24
|
# It may be needed later for security
|
25
|
-
api_points.each do |apip|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
25
|
+
# api_points.each do |apip|
|
26
|
+
# module_eval <<-END, __FILE__, __LINE__
|
27
|
+
# def endpoint_#{apip}(*args)
|
28
|
+
# before_api_call_result = defined?(before_api_call) && before_api_call('#{apip}', *args) || {}
|
29
|
+
# (before_api_call_result.empty? ? #{apip}(*args) : before_api_call_result).to_nifty_json
|
30
|
+
# end
|
31
|
+
# END
|
32
|
+
# end
|
33
33
|
end
|
34
34
|
|
35
35
|
# Defines an endpoint
|
36
36
|
def endpoint(name, options = {}, &block)
|
37
|
-
|
38
|
-
define_method
|
37
|
+
register_endpoint(name)
|
38
|
+
define_method("#{name}_endpoint", &block) if block # if no block is given, the method is supposed to be defined elsewhere
|
39
39
|
|
40
40
|
# define_method name, &block if block # if no block is given, the method is supposed to be defined elsewhere
|
41
|
-
define_method :"
|
42
|
-
res = send(name, *args)
|
41
|
+
define_method :"_#{name}_ep_wrapper" do |*args|
|
42
|
+
res = send("#{name}_endpoint", *args)
|
43
43
|
res.respond_to?(:to_nifty_json) && res.to_nifty_json || ""
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
# Register an endpoint
|
48
|
-
def
|
48
|
+
def register_endpoint(ep)
|
49
49
|
current_endpoints = read_inheritable_attribute(:endpoints) || []
|
50
50
|
current_endpoints << ep
|
51
51
|
write_inheritable_attribute(:endpoints, current_endpoints.uniq)
|
52
52
|
end
|
53
53
|
|
54
54
|
# Returns registered endpoints
|
55
|
-
def
|
56
|
-
read_inheritable_attribute(:endpoints)
|
55
|
+
def registered_endpoints
|
56
|
+
read_inheritable_attribute(:endpoints) || []
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
data/lib/netzke/state.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
2
|
+
module Netzke
|
3
|
+
# When a persistence subsystem (such as {netzke-persistence}[https://github.com/skozlov/netzke-persistence]) is used, a widget can store its state using the +update_state+ method that accepts a hash, e.g.:
|
4
|
+
# update_state(:position => {:x => 100, :y => 200})
|
5
|
+
#
|
6
|
+
# Later the state can be retrieved by calling the +state+ method:
|
7
|
+
#
|
8
|
+
# state[:position] #=> {:x => 100, :y => 200}
|
9
|
+
#
|
10
|
+
# To enable persistence for a specific component, configure it with +persistence+ option set to +true+.
|
11
|
+
#
|
12
|
+
# == Sharing state
|
13
|
+
#
|
14
|
+
# Different components can share the state by sharing the persistence key, which can be provided as configuration option, e.g.:
|
15
|
+
#
|
16
|
+
# netzke :books, :class_name => "Basepack::GridPanel", :persistence_key => "books_state_identifier"
|
17
|
+
# netzke :deleted_books, :class_name => "Basepack::GridPanel", :persistence_key => "books_state_identifier"
|
18
|
+
#
|
19
|
+
# Make sure that the provided persistence_key has effect on _application_ level, _not_ only within the view.
|
20
|
+
# By default persistence_key is set to component's global id. Thus, <i>two components named equally will share the state even being used in different views</i>.
|
21
|
+
#
|
22
|
+
module State
|
23
|
+
# A string which will identify the component in persistence subsystem.
|
24
|
+
# If +persistence_key+ is passed, use it. Otherwise use global_id.
|
25
|
+
def persistence_key
|
26
|
+
initial_config[:persistence_key] ? initial_config[:persistence_key] : global_id
|
27
|
+
end
|
28
|
+
|
29
|
+
# Component's persistent state.
|
30
|
+
def state
|
31
|
+
@state ||= (state_manager.state || {}).symbolize_keys
|
32
|
+
end
|
33
|
+
|
34
|
+
# Merges passed hash into component's state.
|
35
|
+
def update_state(hsh)
|
36
|
+
state_manager.update_state!(hsh)
|
37
|
+
@state = nil # reset cache
|
38
|
+
end
|
39
|
+
|
40
|
+
# Options merged into component's configuration right after default and user-passed config, thus being reflected in +Netzke::Base#independent_config+ (see Netzke::Configuration).
|
41
|
+
def persistent_options
|
42
|
+
(state[:persistent_options] || {}).symbolize_keys
|
43
|
+
end
|
44
|
+
|
45
|
+
# Updates +persistent_options+
|
46
|
+
def update_persistent_options(hsh)
|
47
|
+
new_persistent_options = persistent_options.merge(hsh)
|
48
|
+
new_persistent_options.delete_if{ |k,v| v.nil? } # setting values to nil means deleting them
|
49
|
+
update_state(:persistent_options => new_persistent_options)
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
# Initialized state manager class. At this moment this class has current_user, component, and session set.
|
55
|
+
def state_manager
|
56
|
+
@state_manager ||= Netzke::Core.persistence_manager_class.init({
|
57
|
+
:component => persistence_key,
|
58
|
+
:current_user => Netzke::Core.controller.respond_to?(:current_user) && Netzke::Core.controller.current_user,
|
59
|
+
:session => Netzke::Core.session
|
60
|
+
})
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
data/lib/netzke-core.rb
CHANGED
@@ -14,6 +14,7 @@ module Netzke
|
|
14
14
|
# Do some initialization which is only possible after Rails is initialized
|
15
15
|
Netzke::Core.ext_location ||= ::Rails.root.join("public", "extjs")
|
16
16
|
Netzke::Core.with_icons = File.exists?("#{Rails.root}/public#{Netzke::Core.icons_uri}") if Netzke::Core.with_icons.nil?
|
17
|
+
Netzke::Core.persistence_manager_class = Netzke::Core.persistence_manager.constantize rescue nil
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
data/netzke-core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{netzke-core}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sergei Kozlov"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-05}
|
13
13
|
s.description = %q{Allows building ExtJS/Rails reusable code in a DRY way}
|
14
14
|
s.email = %q{sergei@playcode.nl}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -45,14 +45,9 @@ Gem::Specification.new do |s|
|
|
45
45
|
"features/step_definitions/web_steps.rb",
|
46
46
|
"features/support/env.rb",
|
47
47
|
"features/support/paths.rb",
|
48
|
-
"generators/netzke_core/USAGE",
|
49
|
-
"generators/netzke_core/netzke_core_generator.rb",
|
50
48
|
"init.rb",
|
51
49
|
"install.rb",
|
52
50
|
"javascripts/core.js",
|
53
|
-
"lib/generators/migration_helper.rb",
|
54
|
-
"lib/generators/netzke/USAGE",
|
55
|
-
"lib/generators/netzke/core_generator.rb",
|
56
51
|
"lib/netzke-core.rb",
|
57
52
|
"lib/netzke/actions.rb",
|
58
53
|
"lib/netzke/base.rb",
|
@@ -71,12 +66,12 @@ Gem::Specification.new do |s|
|
|
71
66
|
"lib/netzke/embedding.rb",
|
72
67
|
"lib/netzke/ext_component.rb",
|
73
68
|
"lib/netzke/javascript.rb",
|
74
|
-
"lib/netzke/persistence.rb",
|
75
69
|
"lib/netzke/rails/action_view_ext.rb",
|
76
70
|
"lib/netzke/rails/controller_extensions.rb",
|
77
71
|
"lib/netzke/rails/routes.rb",
|
78
72
|
"lib/netzke/services.rb",
|
79
73
|
"lib/netzke/session.rb",
|
74
|
+
"lib/netzke/state.rb",
|
80
75
|
"lib/netzke/stylesheets.rb",
|
81
76
|
"lib/tasks/netzke_core_tasks.rake",
|
82
77
|
"netzke-core.gemspec",
|
@@ -88,7 +83,6 @@ Gem::Specification.new do |s|
|
|
88
83
|
"spec/spec.opt",
|
89
84
|
"spec/spec_helper.rb",
|
90
85
|
"stylesheets/core.css",
|
91
|
-
"templates/core/create_netzke_preferences.rb",
|
92
86
|
"test/fixtures/roles.yml",
|
93
87
|
"test/fixtures/users.yml",
|
94
88
|
"test/rails_app/.gitignore",
|
@@ -166,7 +160,7 @@ Gem::Specification.new do |s|
|
|
166
160
|
s.post_install_message = %q{
|
167
161
|
========================================================================
|
168
162
|
|
169
|
-
Thanks for installing
|
163
|
+
Thanks for installing netzke-core!
|
170
164
|
|
171
165
|
Netzke home page: http://netzke.org
|
172
166
|
Netzke Google Groups: http://groups.google.com/group/netzke
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 0.6.
|
8
|
+
- 4
|
9
|
+
version: 0.6.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sergei Kozlov
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-05 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -70,14 +70,9 @@ files:
|
|
70
70
|
- features/step_definitions/web_steps.rb
|
71
71
|
- features/support/env.rb
|
72
72
|
- features/support/paths.rb
|
73
|
-
- generators/netzke_core/USAGE
|
74
|
-
- generators/netzke_core/netzke_core_generator.rb
|
75
73
|
- init.rb
|
76
74
|
- install.rb
|
77
75
|
- javascripts/core.js
|
78
|
-
- lib/generators/migration_helper.rb
|
79
|
-
- lib/generators/netzke/USAGE
|
80
|
-
- lib/generators/netzke/core_generator.rb
|
81
76
|
- lib/netzke-core.rb
|
82
77
|
- lib/netzke/actions.rb
|
83
78
|
- lib/netzke/base.rb
|
@@ -96,12 +91,12 @@ files:
|
|
96
91
|
- lib/netzke/embedding.rb
|
97
92
|
- lib/netzke/ext_component.rb
|
98
93
|
- lib/netzke/javascript.rb
|
99
|
-
- lib/netzke/persistence.rb
|
100
94
|
- lib/netzke/rails/action_view_ext.rb
|
101
95
|
- lib/netzke/rails/controller_extensions.rb
|
102
96
|
- lib/netzke/rails/routes.rb
|
103
97
|
- lib/netzke/services.rb
|
104
98
|
- lib/netzke/session.rb
|
99
|
+
- lib/netzke/state.rb
|
105
100
|
- lib/netzke/stylesheets.rb
|
106
101
|
- lib/tasks/netzke_core_tasks.rake
|
107
102
|
- netzke-core.gemspec
|
@@ -113,7 +108,6 @@ files:
|
|
113
108
|
- spec/spec.opt
|
114
109
|
- spec/spec_helper.rb
|
115
110
|
- stylesheets/core.css
|
116
|
-
- templates/core/create_netzke_preferences.rb
|
117
111
|
- test/fixtures/roles.yml
|
118
112
|
- test/fixtures/users.yml
|
119
113
|
- test/rails_app/.gitignore
|
@@ -191,7 +185,7 @@ homepage: http://netzke.org
|
|
191
185
|
licenses: []
|
192
186
|
|
193
187
|
post_install_message: "\n\
|
194
|
-
========================================================================\n\n Thanks for installing
|
188
|
+
========================================================================\n\n Thanks for installing netzke-core!\n\n Netzke home page: http://netzke.org\n Netzke Google Groups: http://groups.google.com/group/netzke\n Netzke tutorials: http://blog.writelesscode.com\n\n\
|
195
189
|
========================================================================\n\n"
|
196
190
|
rdoc_options: []
|
197
191
|
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# class NetzkeCoreGenerator < Rails::Generator::NamedBase
|
2
|
-
class NetzkeCoreGenerator < Rails::Generator::Base
|
3
|
-
def manifest
|
4
|
-
record do |m|
|
5
|
-
m.migration_template 'create_netzke_preferences.rb', 'db/migrate', :assigns => {
|
6
|
-
:migration_name => "CreateNetzkePreferences"
|
7
|
-
}, :migration_file_name => "create_netzke_preferences"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.gem_root
|
12
|
-
File.expand_path('../../../', __FILE__)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.source_root
|
16
|
-
File.join(gem_root, 'templates', 'core')
|
17
|
-
end
|
18
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module MigrationHelper
|
2
|
-
include Rails::Generators::Migration
|
3
|
-
|
4
|
-
module ClassMethods
|
5
|
-
def migration_lookup_at(dirname) #:nodoc:
|
6
|
-
Dir.glob("#{dirname}/[0-9]*_*.rb")
|
7
|
-
end
|
8
|
-
|
9
|
-
def migration_exists?(dirname, file_name) #:nodoc:
|
10
|
-
migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first
|
11
|
-
end
|
12
|
-
|
13
|
-
def current_migration_number(dirname) #:nodoc:
|
14
|
-
migration_lookup_at(dirname).collect do |file|
|
15
|
-
File.basename(file).split("_").first.to_i
|
16
|
-
end.max.to_i
|
17
|
-
end
|
18
|
-
|
19
|
-
def next_migration_number(dirname) #:nodoc:
|
20
|
-
orm = Rails.configuration.generators.options[:rails][:orm]
|
21
|
-
require "rails/generators/#{orm}"
|
22
|
-
"#{orm.to_s.camelize}::Generators::Base".constantize.next_migration_number(dirname)
|
23
|
-
rescue
|
24
|
-
raise NotImplementedError
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.included(base) #:nodoc:
|
29
|
-
puts "MigrationHelper included by #{base}"
|
30
|
-
base.extend ClassMethods
|
31
|
-
end
|
32
|
-
end
|
data/lib/generators/netzke/USAGE
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/migration'
|
3
|
-
require 'generators/migration_helper'
|
4
|
-
|
5
|
-
module Netzke
|
6
|
-
module Generators
|
7
|
-
class CoreGenerator < Rails::Generators::Base
|
8
|
-
include ::MigrationHelper
|
9
|
-
|
10
|
-
def execute
|
11
|
-
migration_template 'create_netzke_preferences.rb', 'db/migrate/create_netzke_preferences.rb'
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.source_root
|
15
|
-
File.join(gem_root, 'templates', 'core')
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.gem_root
|
19
|
-
File.expand_path("../../../../", __FILE__)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/netzke/persistence.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
# TODO:
|
3
|
-
# rename persistence_ to persistence_
|
4
|
-
module Persistence
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
# Persistent config manager class
|
8
|
-
def persistence_manager_class
|
9
|
-
Netzke::Base.persistence_manager.try(:constantize)
|
10
|
-
rescue NameError
|
11
|
-
nil
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
module InstanceMethods
|
17
|
-
|
18
|
-
# If the component has persistent config in its disposal
|
19
|
-
def persistence_enabled?
|
20
|
-
!persistence_manager_class.nil? && initial_config[:persistent_config]
|
21
|
-
end
|
22
|
-
|
23
|
-
# Access to own persistent config, e.g.:
|
24
|
-
# persistent_config["window.size"] = 100
|
25
|
-
# persistent_config["window.size"] => 100
|
26
|
-
# This method is user/role-aware
|
27
|
-
# def persistent_config
|
28
|
-
# if persistence_enabled?
|
29
|
-
# config_class = self.class.persistence_manager_class
|
30
|
-
# config_class.component_name = persistence_key.to_s # pass to the config class our unique name
|
31
|
-
# config_class
|
32
|
-
# else
|
33
|
-
# # if we can't use presistent config, all the calls to it will always return nil,
|
34
|
-
# # and the "="-operation will be ignored
|
35
|
-
# logger.debug "==> NETZKE: no persistent config is set up for component '#{global_id}'"
|
36
|
-
# {}
|
37
|
-
# end
|
38
|
-
# end
|
39
|
-
|
40
|
-
# Access to the global persistent config (e.g. of another component)
|
41
|
-
def global_persistent_config(owner = nil)
|
42
|
-
config_class = self.class.persistence_manager_class
|
43
|
-
config_class.component_name = owner
|
44
|
-
config_class
|
45
|
-
end
|
46
|
-
|
47
|
-
# A string which will identify NetzkePreference records for this component.
|
48
|
-
# If <tt>persistence_key</tt> is passed, use it. Otherwise use global component's id.
|
49
|
-
def persistence_key #:nodoc:
|
50
|
-
# initial_config[:persistence_key] ? parent.try(:persistence_key) ? "#{parent.persistence_key}__#{initial_config[:persistence_key]}".to_sym : initial_config[:persistence_key] : global_id.to_sym
|
51
|
-
initial_config[:persistence_key] ? initial_config[:persistence_key] : global_id.to_sym
|
52
|
-
end
|
53
|
-
|
54
|
-
# def update_persistent_ext_config(hsh)
|
55
|
-
# current_config = persistent_config[:ext_config] || {}
|
56
|
-
# current_config.deep_merge!(hsh.deep_convert_keys{ |k| k.to_s }) # first, recursively stringify the keys
|
57
|
-
# persistent_config[:ext_config] = current_config
|
58
|
-
# end
|
59
|
-
|
60
|
-
# Returns a hash built from all persistent config values for the current component, following the double underscore
|
61
|
-
# naming convention. E.g., if we have the following persistent config pairs:
|
62
|
-
# enabled => true
|
63
|
-
# layout__width => 100
|
64
|
-
# layout__header__height => 20
|
65
|
-
#
|
66
|
-
# this method will return the following hash:
|
67
|
-
# {:enabled => true, :layout => {:width => 100, :header => {:height => 20}}}
|
68
|
-
# def persistence_hash_OLD
|
69
|
-
# return {} if !persistence_enabled?
|
70
|
-
#
|
71
|
-
# @persistence_hash ||= begin
|
72
|
-
# prefs = NetzkePreference.find_all_for_component(persistence_key.to_s)
|
73
|
-
# res = {}
|
74
|
-
# prefs.each do |p|
|
75
|
-
# hsh_levels = p.name.split("__").map(&:to_sym)
|
76
|
-
# tmp_res = {} # it decends into itself, building itself
|
77
|
-
# anchor = {} # it will keep the tail of tmp_res
|
78
|
-
# hsh_levels.each do |level_prefix|
|
79
|
-
# tmp_res[level_prefix] ||= level_prefix == hsh_levels.last ? p.normalized_value : {}
|
80
|
-
# anchor = tmp_res[level_prefix] if level_prefix == hsh_levels.first
|
81
|
-
# tmp_res = tmp_res[level_prefix]
|
82
|
-
# end
|
83
|
-
# # Now 'anchor' is a hash that represents the path to the single value,
|
84
|
-
# # for example: {:ext_config => {:title => 100}} (which corresponds to ext_config__title)
|
85
|
-
# # So we need to recursively merge it into the final result
|
86
|
-
# res.deep_merge!(hsh_levels.first => anchor)
|
87
|
-
# end
|
88
|
-
# res.deep_convert_keys{ |k| k.to_sym } # recursively symbolize the keys
|
89
|
-
# end
|
90
|
-
# end
|
91
|
-
|
92
|
-
def update_persistent_options(hash)
|
93
|
-
if persistence_enabled?
|
94
|
-
options = persistent_options
|
95
|
-
persistence_manager_class.pref_to_write(global_id).update_attribute(:value, options.deep_merge(hash))
|
96
|
-
else
|
97
|
-
logger && logger.debug("Netzke warning: No persistence enabled for component '#{global_id}'")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def persistent_options
|
102
|
-
return {} if !persistence_enabled?
|
103
|
-
persistence_manager_class.pref_to_read(global_id).try(:value) || {}
|
104
|
-
end
|
105
|
-
|
106
|
-
# A convenience method for instances
|
107
|
-
def persistence_manager_class
|
108
|
-
self.class.persistence_manager_class
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.included(receiver)
|
114
|
-
receiver.extend ClassMethods
|
115
|
-
receiver.send :include, InstanceMethods
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class CreateNetzkePreferences < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
drop_table(:netzke_preferences) if table_exists?(:netzke_preferences)
|
4
|
-
|
5
|
-
create_table :netzke_preferences do |t|
|
6
|
-
t.string :key
|
7
|
-
t.text :value
|
8
|
-
t.integer :user_id
|
9
|
-
t.integer :role_id
|
10
|
-
|
11
|
-
t.timestamps
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.down
|
16
|
-
drop_table :netzke_preferences
|
17
|
-
end
|
18
|
-
end
|