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.
Files changed (76) hide show
  1. data/CHANGELOG.rdoc +19 -0
  2. data/README.markdown +43 -0
  3. data/TODO +1 -5
  4. data/app/controllers/netzke_controller.rb +47 -15
  5. data/config/database.yml +2 -0
  6. data/features/component_loader.feature +6 -1
  7. data/features/composition.feature +2 -0
  8. data/features/js_include.feature +18 -0
  9. data/features/nested_views.feature +9 -0
  10. data/features/persistence.feature +6 -4
  11. data/features/support/paths.rb +3 -0
  12. data/javascripts/core.js +166 -519
  13. data/javascripts/ext.js +355 -0
  14. data/javascripts/touch.js +47 -0
  15. data/lib/netzke/actions.rb +31 -38
  16. data/lib/netzke/base.rb +48 -6
  17. data/lib/netzke/composition.rb +52 -63
  18. data/lib/netzke/configuration.rb +6 -2
  19. data/lib/netzke/core/version.rb +2 -2
  20. data/lib/netzke/core.rb +22 -15
  21. data/lib/netzke/javascript/scopes.rb +39 -0
  22. data/lib/netzke/javascript.rb +145 -114
  23. data/lib/netzke/railz/action_view_ext/ext.rb +59 -0
  24. data/lib/netzke/railz/action_view_ext/touch.rb +50 -0
  25. data/lib/netzke/railz/action_view_ext.rb +86 -0
  26. data/lib/netzke/railz/controller_extensions.rb +33 -0
  27. data/lib/netzke/{rails → railz}/routes.rb +0 -0
  28. data/lib/netzke/railz.rb +3 -0
  29. data/lib/netzke/session.rb +18 -3
  30. data/lib/netzke/state.rb +42 -15
  31. data/lib/netzke/stylesheets.rb +23 -8
  32. data/lib/netzke-core.rb +23 -16
  33. data/netzke-core.gemspec +52 -10
  34. data/spec/component/base_spec.rb +11 -0
  35. data/spec/component/javascript_spec.rb +3 -2
  36. data/spec/component/state_spec.rb +18 -0
  37. data/spec/spec_helper.rb +1 -1
  38. data/test/rails_app/Gemfile +3 -2
  39. data/test/rails_app/Gemfile.lock +73 -71
  40. data/test/rails_app/app/components/component_loader.rb +39 -4
  41. data/test/rails_app/app/components/{custom.css → component_with_custom_css/stylesheets/custom.css} +0 -0
  42. data/test/rails_app/app/components/component_with_custom_css.rb +2 -2
  43. data/test/rails_app/app/components/component_with_js_mixin/javascripts/extra_one.js +2 -0
  44. data/test/rails_app/app/components/component_with_js_mixin/javascripts/extra_two.js +2 -0
  45. data/test/rails_app/app/components/component_with_js_mixin/javascripts/method_set_one.js +6 -0
  46. data/test/rails_app/app/components/component_with_js_mixin/javascripts/method_set_two.js +5 -0
  47. data/test/rails_app/app/components/component_with_js_mixin.rb +8 -0
  48. data/test/rails_app/app/components/component_with_session_persistence.rb +10 -3
  49. data/test/rails_app/app/components/extended_component_with_js_mixin/javascripts/some_method_set.js +5 -0
  50. data/test/rails_app/app/components/extended_component_with_js_mixin.rb +7 -0
  51. data/test/rails_app/app/components/hello_world_component.rb +31 -0
  52. data/test/rails_app/app/components/server_caller.rb +1 -1
  53. data/test/rails_app/app/components/simple_panel.rb +2 -0
  54. data/test/rails_app/app/components/touch/hello_world_component.rb +25 -0
  55. data/test/rails_app/app/components/touch/server_caller.rb +28 -0
  56. data/test/rails_app/app/components/touch/simple_carousel.rb +17 -0
  57. data/test/rails_app/app/controllers/components_controller.rb +6 -1
  58. data/test/rails_app/app/controllers/touch_controller.rb +6 -0
  59. data/test/rails_app/app/helpers/touch_helper.rb +2 -0
  60. data/test/rails_app/app/views/components/panel_with_autoload.html.erb +2 -0
  61. data/test/rails_app/app/views/components/some_tab_panel.html.erb +11 -0
  62. data/test/rails_app/app/views/layouts/nested.html.erb +5 -0
  63. data/test/rails_app/app/views/layouts/touch.html.erb +13 -0
  64. data/test/rails_app/config/initializers/netzke.rb +1 -1
  65. data/test/rails_app/config/locales/en.yml +7 -1
  66. data/test/rails_app/config/routes.rb +10 -1
  67. data/test/rails_app/db/migrate/20110110132720_create_netzke_component_states.rb +20 -0
  68. data/test/rails_app/db/schema.rb +14 -1
  69. data/test/rails_app/spec/controllers/touch_controller_spec.rb +5 -0
  70. data/test/rails_app/spec/helpers/touch_helper_spec.rb +15 -0
  71. data/test/unit/netzke_core_test.rb +2 -6
  72. metadata +53 -11
  73. data/README.rdoc +0 -136
  74. data/lib/netzke/rails/action_view_ext.rb +0 -103
  75. data/lib/netzke/rails/controller_extensions.rb +0 -31
  76. data/test/rails_app/db/migrate/20100905214933_create_netzke_preferences.rb +0 -16
@@ -22,4 +22,15 @@ describe Netzke::Base do
22
22
  Parent.with_feature.should == "maybe"
23
23
  Child.with_feature.should == "no"
24
24
  end
25
+
26
+ it "should return correct i18n_id" do
27
+ module Netzke
28
+ module MyComponents
29
+ class CoolComponent < Netzke::Base
30
+ end
31
+ end
32
+ end
33
+
34
+ Netzke::MyComponents::CoolComponent.new.i18n_id.should == "netzke.my_components.cool_component"
35
+ end
25
36
  end
@@ -8,8 +8,9 @@ module Netzke
8
8
  class InheritedComponent < SomeComponent
9
9
  end
10
10
 
11
- describe "extends_netzke_component?" do
12
- InheritedComponent.extends_netzke_component?.should == true
11
+ it "should be indicated by extends_netzke_component? if we're extending a Netzke component" do
12
+ SomeComponent.send(:"extends_netzke_component?").should == false
13
+ InheritedComponent.send(:"extends_netzke_component?").should == true
13
14
  end
14
15
  end
15
16
  end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'netzke-core'
3
+
4
+ module Netzke
5
+ describe State do
6
+ it "should be possible to save component's state" do
7
+ component = Base.new(:name => 'some_component', :persistence => true)
8
+ component.state.should == {}
9
+
10
+ component.update_state(:value_to_remember, 42)
11
+ component.state.should == {:value_to_remember => 42}
12
+
13
+ component.update_state(:more_to_remember => "a string", :and_yet_more => "another string")
14
+ component.state.should == {:value_to_remember => 42, :more_to_remember => "a string", :and_yet_more => "another string"}
15
+
16
+ end
17
+ end
18
+ end
data/spec/spec_helper.rb CHANGED
@@ -26,7 +26,7 @@ RSpec.configure do |config|
26
26
  config.mock_with :rspec
27
27
 
28
28
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
29
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
29
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
30
30
 
31
31
  # If you're not using ActiveRecord, or you'd prefer not to run each of your
32
32
  # examples within a transaction, remove the following line or assign false
@@ -1,6 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'rails', '3.0.1'
3
+ gem 'rails', '3.0.3'
4
4
 
5
5
  # Bundle edge Rails instead:
6
6
  # gem 'rails', :git => 'git://github.com/rails/rails.git'
@@ -30,7 +30,8 @@ group :development, :test do
30
30
  gem 'database_cleaner'
31
31
  gem 'cucumber-rails'
32
32
  gem 'cucumber'
33
- gem 'rspec-rails', "~>2.0.0"
33
+ gem 'rspec-rails'
34
34
  gem 'spork'
35
35
  gem 'launchy' # So you can do Then show me the page
36
+ gem 'netzke-persistence'
36
37
  end
@@ -2,34 +2,33 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  abstract (1.0.0)
5
- actionmailer (3.0.1)
6
- actionpack (= 3.0.1)
7
- mail (~> 2.2.5)
8
- actionpack (3.0.1)
9
- activemodel (= 3.0.1)
10
- activesupport (= 3.0.1)
5
+ actionmailer (3.0.3)
6
+ actionpack (= 3.0.3)
7
+ mail (~> 2.2.9)
8
+ actionpack (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
11
11
  builder (~> 2.1.2)
12
12
  erubis (~> 2.6.6)
13
- i18n (~> 0.4.1)
13
+ i18n (~> 0.4)
14
14
  rack (~> 1.2.1)
15
- rack-mount (~> 0.6.12)
16
- rack-test (~> 0.5.4)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.6)
17
17
  tzinfo (~> 0.3.23)
18
- activemodel (3.0.1)
19
- activesupport (= 3.0.1)
18
+ activemodel (3.0.3)
19
+ activesupport (= 3.0.3)
20
20
  builder (~> 2.1.2)
21
- i18n (~> 0.4.1)
22
- activerecord (3.0.1)
23
- activemodel (= 3.0.1)
24
- activesupport (= 3.0.1)
25
- arel (~> 1.0.0)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.3)
23
+ activemodel (= 3.0.3)
24
+ activesupport (= 3.0.3)
25
+ arel (~> 2.0.2)
26
26
  tzinfo (~> 0.3.23)
27
- activeresource (3.0.1)
28
- activemodel (= 3.0.1)
29
- activesupport (= 3.0.1)
30
- activesupport (3.0.1)
31
- arel (1.0.1)
32
- activesupport (~> 3.0.0)
27
+ activeresource (3.0.3)
28
+ activemodel (= 3.0.3)
29
+ activesupport (= 3.0.3)
30
+ activesupport (3.0.3)
31
+ arel (2.0.6)
33
32
  builder (2.1.2)
34
33
  capybara (0.4.0)
35
34
  celerity (>= 0.7.9)
@@ -40,86 +39,88 @@ GEM
40
39
  rack-test (>= 0.5.4)
41
40
  selenium-webdriver (>= 0.0.27)
42
41
  xpath (~> 0.1.2)
43
- celerity (0.8.2)
44
- childprocess (0.1.3)
42
+ celerity (0.8.7)
43
+ childprocess (0.1.6)
45
44
  ffi (~> 0.6.3)
46
- configuration (1.1.0)
47
- cucumber (0.9.3)
48
- builder (~> 2.1.2)
45
+ configuration (1.2.0)
46
+ cucumber (0.10.0)
47
+ builder (>= 2.1.2)
49
48
  diff-lcs (~> 1.1.2)
50
- gherkin (~> 2.2.9)
49
+ gherkin (~> 2.3.2)
51
50
  json (~> 1.4.6)
52
51
  term-ansicolor (~> 1.0.5)
53
52
  cucumber-rails (0.3.2)
54
53
  cucumber (>= 0.8.0)
55
- culerity (0.2.12)
56
- database_cleaner (0.5.2)
54
+ culerity (0.2.14)
55
+ database_cleaner (0.6.0)
57
56
  diff-lcs (1.1.2)
58
57
  erubis (2.6.6)
59
58
  abstract (>= 1.0.0)
60
59
  ffi (0.6.3)
61
60
  rake (>= 0.8.7)
62
- gherkin (2.2.9)
61
+ gherkin (2.3.3)
63
62
  json (~> 1.4.6)
64
- term-ansicolor (~> 1.0.5)
65
- i18n (0.4.1)
63
+ i18n (0.5.0)
66
64
  json (1.4.6)
67
65
  json_pure (1.4.6)
68
66
  launchy (0.3.7)
69
67
  configuration (>= 0.0.5)
70
68
  rake (>= 0.8.1)
71
- mail (2.2.7)
69
+ mail (2.2.14)
72
70
  activesupport (>= 2.3.6)
73
- mime-types
74
- treetop (>= 1.4.5)
71
+ i18n (>= 0.4.0)
72
+ mime-types (~> 1.16)
73
+ treetop (~> 1.4.8)
75
74
  mime-types (1.16)
76
- nokogiri (1.4.3.1)
75
+ netzke-persistence (0.1.1)
76
+ nokogiri (1.4.4)
77
77
  polyglot (0.3.1)
78
78
  rack (1.2.1)
79
79
  rack-mount (0.6.13)
80
80
  rack (>= 1.0.0)
81
- rack-test (0.5.6)
81
+ rack-test (0.5.7)
82
82
  rack (>= 1.0)
83
- rails (3.0.1)
84
- actionmailer (= 3.0.1)
85
- actionpack (= 3.0.1)
86
- activerecord (= 3.0.1)
87
- activeresource (= 3.0.1)
88
- activesupport (= 3.0.1)
89
- bundler (~> 1.0.0)
90
- railties (= 3.0.1)
91
- railties (3.0.1)
92
- actionpack (= 3.0.1)
93
- activesupport (= 3.0.1)
94
- rake (>= 0.8.4)
95
- thor (~> 0.14.0)
83
+ rails (3.0.3)
84
+ actionmailer (= 3.0.3)
85
+ actionpack (= 3.0.3)
86
+ activerecord (= 3.0.3)
87
+ activeresource (= 3.0.3)
88
+ activesupport (= 3.0.3)
89
+ bundler (~> 1.0)
90
+ railties (= 3.0.3)
91
+ railties (3.0.3)
92
+ actionpack (= 3.0.3)
93
+ activesupport (= 3.0.3)
94
+ rake (>= 0.8.7)
95
+ thor (~> 0.14.4)
96
96
  rake (0.8.7)
97
- rspec (2.0.1)
98
- rspec-core (~> 2.0.1)
99
- rspec-expectations (~> 2.0.1)
100
- rspec-mocks (~> 2.0.1)
101
- rspec-core (2.0.1)
102
- rspec-expectations (2.0.1)
103
- diff-lcs (>= 1.1.2)
104
- rspec-mocks (2.0.1)
105
- rspec-core (~> 2.0.1)
106
- rspec-expectations (~> 2.0.1)
107
- rspec-rails (2.0.1)
108
- rspec (~> 2.0.0)
97
+ rspec (2.4.0)
98
+ rspec-core (~> 2.4.0)
99
+ rspec-expectations (~> 2.4.0)
100
+ rspec-mocks (~> 2.4.0)
101
+ rspec-core (2.4.0)
102
+ rspec-expectations (2.4.0)
103
+ diff-lcs (~> 1.1.2)
104
+ rspec-mocks (2.4.0)
105
+ rspec-rails (2.4.1)
106
+ actionpack (~> 3.0)
107
+ activesupport (~> 3.0)
108
+ railties (~> 3.0)
109
+ rspec (~> 2.4.0)
109
110
  rubyzip (0.9.4)
110
- selenium-webdriver (0.0.29)
111
- childprocess (>= 0.0.7)
111
+ selenium-webdriver (0.1.2)
112
+ childprocess (~> 0.1.5)
112
113
  ffi (~> 0.6.3)
113
114
  json_pure
114
115
  rubyzip
115
116
  spork (0.8.4)
116
- sqlite3-ruby (1.3.1)
117
+ sqlite3-ruby (1.3.2)
117
118
  term-ansicolor (1.0.5)
118
- thor (0.14.3)
119
- treetop (1.4.8)
119
+ thor (0.14.6)
120
+ treetop (1.4.9)
120
121
  polyglot (>= 0.3.1)
121
122
  tzinfo (0.3.23)
122
- xpath (0.1.2)
123
+ xpath (0.1.3)
123
124
  nokogiri (~> 1.3)
124
125
 
125
126
  PLATFORMS
@@ -131,7 +132,8 @@ DEPENDENCIES
131
132
  cucumber-rails
132
133
  database_cleaner
133
134
  launchy
134
- rails (= 3.0.1)
135
- rspec-rails (~> 2.0.0)
135
+ netzke-persistence
136
+ rails (= 3.0.3)
137
+ rspec-rails
136
138
  spork
137
139
  sqlite3-ruby
@@ -16,6 +16,8 @@ class ComponentLoader < Netzke::Base
16
16
  :lazy_loading => true
17
17
  }
18
18
 
19
+ component :some_composite, :lazy_loading => true
20
+
19
21
  js_method :on_load_with_feedback, <<-JS
20
22
  function(){
21
23
  this.loadComponent({name: 'simple_component', callback: function(){
@@ -28,10 +30,14 @@ class ComponentLoader < Netzke::Base
28
30
 
29
31
  action :load_window_with_simple_component
30
32
 
33
+ action :load_composite
34
+
35
+ action :load_with_params
36
+
31
37
  js_properties(
32
38
  :title => "Component Loader",
33
39
  :layout => "fit",
34
- :bbar => [{:text => "Load component", :ref => "../button"}, {:text => "Load in window", :ref => "../loadInWindowButton"}, :load_with_feedback.action, :load_window_with_simple_component.action]
40
+ :bbar => [{:text => "Load component", :ref => "../button"}, {:text => "Load in window", :ref => "../loadInWindowButton"}, :load_with_feedback.action, :load_window_with_simple_component.action, :load_composite.action, :load_with_params.action]
35
41
  )
36
42
 
37
43
  js_method :on_load_window_with_simple_component, <<-JS
@@ -40,6 +46,18 @@ class ComponentLoader < Netzke::Base
40
46
  }
41
47
  JS
42
48
 
49
+ js_method :on_load_composite, <<-JS
50
+ function(params){
51
+ this.loadComponent({name: "some_composite"});
52
+ }
53
+ JS
54
+
55
+ js_method :on_load_with_params, <<-JS
56
+ function(params){
57
+ this.loadComponent({name: "simple_component", params: {html: "Simple Component with changed HTML"}});
58
+ }
59
+ JS
60
+
43
61
  js_method :init_component, <<-JS
44
62
  function(){
45
63
  #{js_full_class_name}.superclass.initComponent.call(this);
@@ -49,11 +67,28 @@ class ComponentLoader < Netzke::Base
49
67
  }, this);
50
68
 
51
69
  this.loadInWindowButton.on('click', function(){
52
- var w = new Ext.Window({width: 500, height: 400, modal: true, layout:'fit'});
70
+ var w = new Ext.Window({
71
+ width: 500, height: 400, modal: true, layout:'fit',
72
+ items: [{xtype: 'panel'}]
73
+ });
53
74
  w.show(null, function(){
54
- this.loadComponent({name: 'component_loaded_in_window', container: w.getId()});
75
+ this.loadComponent({name: 'component_loaded_in_window', container: w.items.first().getId()});
55
76
  }, this);
56
77
  }, this);
57
78
  }
58
79
  JS
59
- end
80
+
81
+ def deliver_component_endpoint(params)
82
+ if params[:name] == "simple_component" && params[:html]
83
+ components[:simple_component].merge!(:html => params[:html])
84
+ end
85
+ super
86
+ end
87
+
88
+ # For visual testing purposes
89
+ # def deliver_component_endpoint(params)
90
+ # sleep 2
91
+ # super
92
+ # end
93
+
94
+ end
@@ -2,7 +2,7 @@
2
2
  class ComponentWithCustomCss < Netzke::Base
3
3
  js_property :title, "ComponentWithCustomCss"
4
4
 
5
- js_property :html, "A component with the header hidden by means of custom CSS"
5
+ js_property :html, "A component with the body hidden by means of custom CSS"
6
6
 
7
- css_include "#{File.dirname(__FILE__)}/custom.css"
7
+ css_include :custom
8
8
  end
@@ -0,0 +1,2 @@
1
+ // Some included JS code
2
+ actionOneMessage = "Action " + "One triggered!";
@@ -0,0 +1,2 @@
1
+ // Some included JS code
2
+ actionTwoMessage = "Action " + "Two triggered!";
@@ -0,0 +1,6 @@
1
+ // Some comments should be ok here
2
+ {
3
+ onActionTwo: function() {
4
+ this.setTitle(actionTwoMessage);
5
+ }
6
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ onActionOne: function() {
3
+ this.setTitle(actionOneMessage);
4
+ }
5
+ }
@@ -0,0 +1,8 @@
1
+ class ComponentWithJsMixin < Netzke::Base
2
+ js_property :title, "ComponentWithJsMixin"
3
+ js_include :extra_one, :extra_two
4
+ js_mixin :method_set_one, :method_set_two
5
+ action :action_one
6
+ action :action_two
7
+ js_property :bbar, [:action_one.action, :action_two.action]
8
+ end
@@ -1,8 +1,14 @@
1
1
  class ComponentWithSessionPersistence < Netzke::Base
2
- js_property :title, "No Title (yet!)"
2
+ js_property :title, "Default Title"
3
3
  js_property :bbar, [{:text => "Tell server to store new title", :ref => "../button"}]
4
4
 
5
- config :default, :session_persistence => true
5
+ def default_config
6
+ super.merge(:session_persistence => true)
7
+ end
8
+
9
+ def configuration
10
+ super.merge(:html => component_session[:html_content] || "Default HTML")
11
+ end
6
12
 
7
13
  js_method :bug_server, <<-JS
8
14
  function(){
@@ -18,7 +24,8 @@ class ComponentWithSessionPersistence < Netzke::Base
18
24
  JS
19
25
 
20
26
  endpoint :whats_up do |params|
21
- update_session_options(:title => "New Title!")
27
+ update_session_options(:title => "Title From Session") # setting a value in session_options, which will get auto-merged into +config+
28
+ component_session[:html_content] = "HTML from session" # setting some custom session key/value, which we use manually in +configuration+
22
29
  {}
23
30
  end
24
31
 
@@ -0,0 +1,5 @@
1
+ {
2
+ onActionThree: function() {
3
+ this.setTitle("Action " + "Three triggered!");
4
+ }
5
+ }
@@ -0,0 +1,7 @@
1
+ class ExtendedComponentWithJsMixin < ComponentWithJsMixin
2
+ js_mixin :some_method_set
3
+ action :action_three
4
+
5
+ js_property :title, "ExtendedComponentWithJsMixin"
6
+ js_property :bbar, superclass.js_properties[:bbar] + [:action_three.action]
7
+ end