apotomo 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/Gemfile +10 -0
  2. data/Gemfile.lock +47 -0
  3. data/README +141 -0
  4. data/README.rdoc +141 -0
  5. data/Rakefile +78 -0
  6. data/TODO +36 -0
  7. data/app/cells/apotomo/child_switch_widget/switch.html.erb +1 -0
  8. data/app/cells/apotomo/child_switch_widget/switch.rhtml +1 -0
  9. data/app/cells/apotomo/deep_link_widget.rb +27 -0
  10. data/app/cells/apotomo/deep_link_widget/setup.html.erb +20 -0
  11. data/app/cells/apotomo/java_script_widget.rb +12 -0
  12. data/app/cells/apotomo/tab_panel_widget.rb +87 -0
  13. data/app/cells/apotomo/tab_panel_widget/display.html.erb +57 -0
  14. data/app/cells/apotomo/tab_widget.rb +18 -0
  15. data/app/cells/apotomo/tab_widget/display.html.erb +1 -0
  16. data/config/routes.rb +3 -0
  17. data/generators/widget/USAGE +15 -0
  18. data/generators/widget/templates/functional_test.rb +8 -0
  19. data/generators/widget/templates/view.html.erb +2 -0
  20. data/generators/widget/templates/view.html.haml +3 -0
  21. data/generators/widget/templates/widget.rb +8 -0
  22. data/generators/widget/widget_generator.rb +34 -0
  23. data/lib/apotomo.rb +59 -0
  24. data/lib/apotomo/caching.rb +37 -0
  25. data/lib/apotomo/container_widget.rb +10 -0
  26. data/lib/apotomo/deep_link_methods.rb +90 -0
  27. data/lib/apotomo/event.rb +9 -0
  28. data/lib/apotomo/event_handler.rb +23 -0
  29. data/lib/apotomo/event_methods.rb +102 -0
  30. data/lib/apotomo/invoke_event_handler.rb +24 -0
  31. data/lib/apotomo/javascript_generator.rb +57 -0
  32. data/lib/apotomo/persistence.rb +139 -0
  33. data/lib/apotomo/proc_event_handler.rb +18 -0
  34. data/lib/apotomo/rails/controller_methods.rb +161 -0
  35. data/lib/apotomo/rails/view_helper.rb +95 -0
  36. data/lib/apotomo/rails/view_methods.rb +7 -0
  37. data/lib/apotomo/request_processor.rb +92 -0
  38. data/lib/apotomo/stateful_widget.rb +8 -0
  39. data/lib/apotomo/transition.rb +46 -0
  40. data/lib/apotomo/tree_node.rb +186 -0
  41. data/lib/apotomo/version.rb +5 -0
  42. data/lib/apotomo/widget.rb +289 -0
  43. data/lib/apotomo/widget_shortcuts.rb +36 -0
  44. data/rails/init.rb +0 -0
  45. data/test/fixtures/application_widget_tree.rb +2 -0
  46. data/test/rails/controller_methods_test.rb +206 -0
  47. data/test/rails/rails_integration_test.rb +99 -0
  48. data/test/rails/view_helper_test.rb +77 -0
  49. data/test/rails/view_methods_test.rb +40 -0
  50. data/test/rails/widget_generator_test.rb +47 -0
  51. data/test/support/assertions_helper.rb +13 -0
  52. data/test/support/test_case_methods.rb +68 -0
  53. data/test/test_helper.rb +77 -0
  54. data/test/unit/apotomo_test.rb +20 -0
  55. data/test/unit/container_test.rb +20 -0
  56. data/test/unit/event_handler_test.rb +67 -0
  57. data/test/unit/event_methods_test.rb +83 -0
  58. data/test/unit/event_test.rb +30 -0
  59. data/test/unit/invoke_test.rb +123 -0
  60. data/test/unit/javascript_generator_test.rb +90 -0
  61. data/test/unit/onfire_integration_test.rb +19 -0
  62. data/test/unit/persistence_test.rb +240 -0
  63. data/test/unit/render_test.rb +203 -0
  64. data/test/unit/request_processor_test.rb +178 -0
  65. data/test/unit/stateful_widget_test.rb +135 -0
  66. data/test/unit/test_addressing.rb +111 -0
  67. data/test/unit/test_caching.rb +54 -0
  68. data/test/unit/test_jump_to_state.rb +89 -0
  69. data/test/unit/test_tab_panel.rb +72 -0
  70. data/test/unit/test_widget_shortcuts.rb +45 -0
  71. data/test/unit/transition_test.rb +33 -0
  72. data/test/unit/widget_shortcuts_test.rb +68 -0
  73. data/test/unit/widget_test.rb +24 -0
  74. metadata +215 -0
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 2.3.8"
4
+ gem "cells", "3.3.4"
5
+ gem "onfire"
6
+ gem "jeweler"
7
+
8
+ # for test env:
9
+ gem "shoulda"
10
+ gem "mocha"
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (2.3.8)
5
+ actionpack (= 2.3.8)
6
+ actionpack (2.3.8)
7
+ activesupport (= 2.3.8)
8
+ rack (~> 1.1.0)
9
+ activerecord (2.3.8)
10
+ activesupport (= 2.3.8)
11
+ activeresource (2.3.8)
12
+ activesupport (= 2.3.8)
13
+ activesupport (2.3.8)
14
+ cells (3.3.4)
15
+ gemcutter (0.6.1)
16
+ git (1.2.5)
17
+ jeweler (1.4.0)
18
+ gemcutter (>= 0.1.0)
19
+ git (>= 1.2.5)
20
+ rubyforge (>= 2.0.0)
21
+ json_pure (1.4.6)
22
+ mocha (0.9.8)
23
+ rake
24
+ onfire (0.1.0)
25
+ rack (1.1.0)
26
+ rails (2.3.8)
27
+ actionmailer (= 2.3.8)
28
+ actionpack (= 2.3.8)
29
+ activerecord (= 2.3.8)
30
+ activeresource (= 2.3.8)
31
+ activesupport (= 2.3.8)
32
+ rake (>= 0.8.3)
33
+ rake (0.8.7)
34
+ rubyforge (2.0.4)
35
+ json_pure (>= 1.1.7)
36
+ shoulda (2.11.3)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ cells (= 3.3.4)
43
+ jeweler
44
+ mocha
45
+ onfire
46
+ rails (~> 2.3.8)
47
+ shoulda
data/README ADDED
@@ -0,0 +1,141 @@
1
+ how does Apotomo handle Ajax and JavaScript?
2
+ framework abstraction with JavascriptGenerator
3
+
4
+ no manual AJAX-routes for dozens of controllers, one generic route to rule them all
5
+
6
+ = Apotomo
7
+
8
+ Apotomo is a stateful widget component framework for Rails.
9
+
10
+ It is good for you if you
11
+ It is perfect for building AJAXed Rich Client Applications.
12
+ It is suitable for iGoogle-like widgets, dashboards, portals, or even full-blown interactive web apps.
13
+ * Development Teams, where separate teams can work on separate components
14
+
15
+ == Widgets
16
+
17
+ === Widget Trees
18
+
19
+
20
+ == Events
21
+
22
+ === Event Handlers
23
+
24
+ == AJAX
25
+
26
+ == Statefulness vs. Stateless
27
+
28
+
29
+
30
+ A stateful WHAT?
31
+
32
+ Well, you know that. In Rails, people tend to have fat controllers. One controller action renders the complete page. While many programmers try to separate their code into helpers, controller actions, RJS logic and partials, it is still the controller that has to care about when to update what, and how!
33
+
34
+
35
+ In Apotomo, it is the opposite. Widgets are small, autonomous components that look and feel like controllers. These tiny monsters listen to events and thus keep updating themselves on the page via AJAX. However, there's no JavaScript for you - they're pure Ruby.
36
+
37
+
38
+ == Man, gimme code!
39
+
40
+ Let's use the famous and tiresome counter example.
41
+
42
+ class CounterCell < Apotomo::StatefulWidget
43
+ transition :from => :display, :to => :increment
44
+
45
+ def display
46
+ respond_to_event :counterClick, :with => :increment
47
+
48
+ @count = 0
49
+ render # renders display.html.erb
50
+ end
51
+
52
+ def increment
53
+ @count += 1 # @count is simply there - that's stateful.
54
+ render :view => :display
55
+ end
56
+ end
57
+
58
+ Since this widget calls <tt>render</tt> it surely needs a view.
59
+
60
+ <!-- I'm display.html.erb -->
61
+
62
+ <h1><%= @count %></h1>
63
+
64
+ <%= link_to_event "Increment me!", :counterClick %>
65
+
66
+
67
+ We now plug the widget in a page.
68
+
69
+ class ExistingController < ApplicationController
70
+ include Apotomo::ControllerHelper
71
+
72
+ def some_action
73
+ # do what you want...
74
+
75
+ use_widgets do |root|
76
+ root << cell(:counter, :display, 'my_first_counter')
77
+ end
78
+ end
79
+ end
80
+
81
+ As soon as the widget is rendered it will jump to its <tt>:display</tt> state which initializes the counter and renders itself.
82
+
83
+ Speaking of rendering: how do we place the widget in our controller?
84
+
85
+ <!-- I'm some_action.html.erb -->
86
+ <p>
87
+ <%= render_widget 'my_first_counter' %>
88
+
89
+ Ok, so this renders the widget in our controller page.
90
+
91
+ When clicking the link it updates automatically on the screen showing the incremented value. Wow.
92
+
93
+
94
+ == That's cool!
95
+ Yes, it is.
96
+
97
+ == Is there more?
98
+ Apotomo got a load of features.
99
+
100
+ [Composability] Widgets can range from small standalone components to nested widget trees like dashboards or forms. Remember that each widget can have any number of children.
101
+
102
+ [Bubbling events] Widgets can trigger events and watch out for them. While events bubble up from their triggering source to root they can be observed, providing a way to implement loosely coupled, distributable components.
103
+
104
+ [Deep Linking] Apotomo deals with deep links (or url fragments) out-of-the-box while using SWFAddress. Components that register for deep linking will update as soon as the deep link changes. That makes your application back-button-safe!
105
+
106
+ [Testing] Needless to say that it is simply easier to test small components instead of fat do-it-all controllers.
107
+
108
+
109
+ Give it a try- you will love the power and simplicity of real stateful components!
110
+
111
+
112
+ == Bugs, Community
113
+ Please visit http://apotomo.de, the official project page with <em>lots</em> of examples.
114
+ Join the mailing list and visit us in the IRC channel. More information is
115
+ here[http://apotomo.de/download].
116
+
117
+
118
+ == License
119
+ Copyright (c) 2007-2010 Nick Sutterer <apotonick@gmail.com>
120
+
121
+ The MIT License
122
+
123
+ Permission is hereby granted, free of charge, to any person obtaining a copy
124
+ of this software and associated documentation files (the "Software"), to deal
125
+ in the Software without restriction, including without limitation the rights
126
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
127
+ copies of the Software, and to permit persons to whom the Software is
128
+ furnished to do so, subject to the following conditions:
129
+
130
+ The above copyright notice and this permission notice shall be included in
131
+ all copies or substantial portions of the Software.
132
+
133
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
134
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
135
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
136
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
137
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
138
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
139
+ THE SOFTWARE.
140
+
141
+
data/README.rdoc ADDED
@@ -0,0 +1,141 @@
1
+ how does Apotomo handle Ajax and JavaScript?
2
+ framework abstraction with JavascriptGenerator
3
+
4
+ no manual AJAX-routes for dozens of controllers, one generic route to rule them all
5
+
6
+ = Apotomo
7
+
8
+ Apotomo is a stateful widget component framework for Rails.
9
+
10
+ It is good for you if you
11
+ It is perfect for building AJAXed Rich Client Applications.
12
+ It is suitable for iGoogle-like widgets, dashboards, portals, or even full-blown interactive web apps.
13
+ * Development Teams, where separate teams can work on separate components
14
+
15
+ == Widgets
16
+
17
+ === Widget Trees
18
+
19
+
20
+ == Events
21
+
22
+ === Event Handlers
23
+
24
+ == AJAX
25
+
26
+ == Statefulness vs. Stateless
27
+
28
+
29
+
30
+ A stateful WHAT?
31
+
32
+ Well, you know that. In Rails, people tend to have fat controllers. One controller action renders the complete page. While many programmers try to separate their code into helpers, controller actions, RJS logic and partials, it is still the controller that has to care about when to update what, and how!
33
+
34
+
35
+ In Apotomo, it is the opposite. Widgets are small, autonomous components that look and feel like controllers. These tiny monsters listen to events and thus keep updating themselves on the page via AJAX. However, there's no JavaScript for you - they're pure Ruby.
36
+
37
+
38
+ == Man, gimme code!
39
+
40
+ Let's use the famous and tiresome counter example.
41
+
42
+ class CounterCell < Apotomo::StatefulWidget
43
+ transition :from => :display, :to => :increment
44
+
45
+ def display
46
+ respond_to_event :counterClick, :with => :increment
47
+
48
+ @count = 0
49
+ render # renders display.html.erb
50
+ end
51
+
52
+ def increment
53
+ @count += 1 # @count is simply there - that's stateful.
54
+ render :view => :display
55
+ end
56
+ end
57
+
58
+ Since this widget calls <tt>render</tt> it surely needs a view.
59
+
60
+ <!-- I'm display.html.erb -->
61
+
62
+ <h1><%= @count %></h1>
63
+
64
+ <%= link_to_event "Increment me!", :counterClick %>
65
+
66
+
67
+ We now plug the widget in a page.
68
+
69
+ class ExistingController < ApplicationController
70
+ include Apotomo::ControllerHelper
71
+
72
+ def some_action
73
+ # do what you want...
74
+
75
+ use_widgets do |root|
76
+ root << cell(:counter, :display, 'my_first_counter')
77
+ end
78
+ end
79
+ end
80
+
81
+ As soon as the widget is rendered it will jump to its <tt>:display</tt> state which initializes the counter and renders itself.
82
+
83
+ Speaking of rendering: how do we place the widget in our controller?
84
+
85
+ <!-- I'm some_action.html.erb -->
86
+ <p>
87
+ <%= render_widget 'my_first_counter' %>
88
+
89
+ Ok, so this renders the widget in our controller page.
90
+
91
+ When clicking the link it updates automatically on the screen showing the incremented value. Wow.
92
+
93
+
94
+ == That's cool!
95
+ Yes, it is.
96
+
97
+ == Is there more?
98
+ Apotomo got a load of features.
99
+
100
+ [Composability] Widgets can range from small standalone components to nested widget trees like dashboards or forms. Remember that each widget can have any number of children.
101
+
102
+ [Bubbling events] Widgets can trigger events and watch out for them. While events bubble up from their triggering source to root they can be observed, providing a way to implement loosely coupled, distributable components.
103
+
104
+ [Deep Linking] Apotomo deals with deep links (or url fragments) out-of-the-box while using SWFAddress. Components that register for deep linking will update as soon as the deep link changes. That makes your application back-button-safe!
105
+
106
+ [Testing] Needless to say that it is simply easier to test small components instead of fat do-it-all controllers.
107
+
108
+
109
+ Give it a try- you will love the power and simplicity of real stateful components!
110
+
111
+
112
+ == Bugs, Community
113
+ Please visit http://apotomo.de, the official project page with <em>lots</em> of examples.
114
+ Join the mailing list and visit us in the IRC channel. More information is
115
+ here[http://apotomo.de/download].
116
+
117
+
118
+ == License
119
+ Copyright (c) 2007-2010 Nick Sutterer <apotonick@gmail.com>
120
+
121
+ The MIT License
122
+
123
+ Permission is hereby granted, free of charge, to any person obtaining a copy
124
+ of this software and associated documentation files (the "Software"), to deal
125
+ in the Software without restriction, including without limitation the rights
126
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
127
+ copies of the Software, and to permit persons to whom the Software is
128
+ furnished to do so, subject to the following conditions:
129
+
130
+ The above copyright notice and this permission notice shall be included in
131
+ all copies or substantial portions of the Software.
132
+
133
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
134
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
135
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
136
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
137
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
138
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
139
+ THE SOFTWARE.
140
+
141
+
data/Rakefile ADDED
@@ -0,0 +1,78 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+ require 'rake/rdoctask'
7
+
8
+ desc 'Default: run unit tests.'
9
+ task :default => :test
10
+
11
+ desc 'Test the Apotomo plugin.'
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << 'lib'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = true
16
+ end
17
+
18
+ namespace 'rdoc' do
19
+ desc 'Generate documentation for Apotomo.'
20
+ Rake::RDocTask.new(:build) do |rdoc|
21
+ rdoc.rdoc_dir = 'rdoc'
22
+ rdoc.title = 'Apotomo API'
23
+ rdoc.options << '--line-numbers' << '--inline-source' << '-m README'
24
+
25
+ rdoc.rdoc_files.include('lib/**/*.rb')
26
+ rdoc.rdoc_files.include('app/**/*.rb')
27
+ rdoc.rdoc_files.include('test/*.rb')
28
+ rdoc.rdoc_files.include('README')
29
+ end
30
+
31
+ desc 'Upload the rdocs to apotomo.rubyforge.org.'
32
+ task :upload do
33
+ sh %{ scp -r rdoc nix@rubyforge.org:/var/www/gforge-projects/apotomo/ }
34
+ end
35
+ end
36
+
37
+ # Gem managment tasks.
38
+ #
39
+ # == Bump gem version (any):
40
+ #
41
+ # rake version:bump:major
42
+ # rake version:bump:minor
43
+ # rake version:bump:patch
44
+ #
45
+ # == Generate gemspec, build & install locally:
46
+ #
47
+ # rake gemspec
48
+ # rake build
49
+ # sudo rake install
50
+ #
51
+ # == Git tag & push to origin/master
52
+ #
53
+ # rake release
54
+ #
55
+ # == Release to Gemcutter.org:
56
+ #
57
+ # rake gemcutter:release
58
+ #
59
+ require 'jeweler'
60
+ require 'lib/apotomo/version'
61
+
62
+ Jeweler::Tasks.new do |spec|
63
+ spec.name = "apotomo"
64
+ spec.version = ::Apotomo::VERSION
65
+ spec.summary = %{Event-driven Widgets for Rails with optional Statefulness.}
66
+ spec.description = "A generic widget framework for Rails. Event-driven. Clean. Fast. Free optional statefulness included."
67
+ spec.homepage = "http://apotomo.de"
68
+ spec.authors = ["Nick Sutterer"]
69
+ spec.email = "apotonick@gmail.com"
70
+
71
+ spec.files = FileList["[A-Z]*", File.join(*%w[{generators,lib,rails,app,config} ** *]).to_s]
72
+
73
+ spec.add_dependency 'cells', '~> 3.3'
74
+ spec.add_dependency 'activesupport', '>= 2.3.0'
75
+ spec.add_dependency 'onfire', '>= 0.1.0'
76
+ end
77
+
78
+ Jeweler::GemcutterTasks.new
data/TODO ADDED
@@ -0,0 +1,36 @@
1
+ Testing
2
+ -------
3
+ - provide something like #assert_transition to test if FSM goes where we want
4
+ - assert_update/assert_execute, to assert which components are updated (e.g. after
5
+ event chain)
6
+
7
+ State Machine
8
+ -------------
9
+ - better debug-output for transitions
10
+ - make #transition_map friendly, maybe some more sophisticated DSL
11
+
12
+ Parameter
13
+ ---------
14
+ - introduce #my_param or something similar so widgets can only access parameters really
15
+ addressed to them. or let #param do this per default.
16
+
17
+ Persistence
18
+ -----------
19
+ - only save id of ActiveRecords, to avoid big sessions (discuss whether this is necessary)
20
+ - provide session storage alternatives, like encoding in url or hidden field
21
+ - introduce a rake task to clear the frozen tree
22
+
23
+ Events
24
+ ------
25
+ - only send back the newer EventHandler content when more than one event was triggered
26
+ and the content of an earlier EventHandler is overridden.
27
+ - provide scrambling of the event url, so users can not trigger events out of scope
28
+ - check if an EventHandler is executed in scope, meaning the triggering event was valid.
29
+
30
+ Apotobug
31
+ --------
32
+ - return exception reports as text, not HTML, for better reading in Firebug.
33
+
34
+ StatefulWidget
35
+ --------------
36
+ - provide an ordered list of rendered child views.