apotomo 0.1.4 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/Gemfile +5 -2
  2. data/Gemfile.lock +70 -21
  3. data/Rakefile +7 -7
  4. data/config/routes.rb +3 -3
  5. data/lib/apotomo/persistence.rb +21 -48
  6. data/lib/apotomo/rails/view_helper.rb +3 -11
  7. data/lib/apotomo/request_processor.rb +7 -10
  8. data/lib/apotomo/transition.rb +2 -2
  9. data/lib/apotomo/version.rb +1 -1
  10. data/lib/apotomo/widget.rb +12 -25
  11. data/lib/apotomo/widget_shortcuts.rb +1 -1
  12. data/lib/apotomo.rb +6 -0
  13. data/{generators/widget → lib/generators/apotomo}/USAGE +0 -0
  14. data/lib/generators/apotomo/templates/view.erb +7 -0
  15. data/lib/generators/apotomo/templates/view.haml +4 -0
  16. data/{generators/widget → lib/generators/apotomo}/templates/widget.rb +2 -1
  17. data/lib/generators/apotomo/templates/widget_test.rb +11 -0
  18. data/lib/generators/apotomo/widget_generator.rb +19 -0
  19. data/test/dummy/app/controllers/application_controller.rb +3 -0
  20. data/test/dummy/app/helpers/application_helper.rb +2 -0
  21. data/test/dummy/config/application.rb +45 -0
  22. data/test/dummy/config/boot.rb +10 -0
  23. data/test/dummy/config/environment.rb +5 -0
  24. data/test/dummy/config/environments/development.rb +26 -0
  25. data/test/dummy/config/environments/production.rb +49 -0
  26. data/test/dummy/config/environments/test.rb +35 -0
  27. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/test/dummy/config/initializers/inflections.rb +10 -0
  29. data/test/dummy/config/initializers/mime_types.rb +5 -0
  30. data/test/dummy/config/initializers/secret_token.rb +7 -0
  31. data/test/dummy/config/initializers/session_store.rb +8 -0
  32. data/test/dummy/config/routes.rb +59 -0
  33. data/test/dummy/tmp/app/cells/mouse_widget.rb +11 -0
  34. data/test/dummy/tmp/test/widgets/mouse_widget_test.rb +15 -0
  35. data/test/rails/controller_methods_test.rb +11 -14
  36. data/test/rails/rails_integration_test.rb +12 -11
  37. data/test/rails/view_helper_test.rb +4 -27
  38. data/test/rails/view_methods_test.rb +4 -6
  39. data/test/rails/widget_generator_test.rb +40 -37
  40. data/test/support/test_case_methods.rb +34 -7
  41. data/test/test_helper.rb +12 -24
  42. data/test/unit/container_test.rb +2 -1
  43. data/test/unit/event_handler_test.rb +2 -0
  44. data/test/unit/event_methods_test.rb +4 -3
  45. data/test/unit/invoke_test.rb +27 -22
  46. data/test/unit/onfire_integration_test.rb +2 -0
  47. data/test/unit/persistence_test.rb +51 -90
  48. data/test/unit/render_test.rb +6 -4
  49. data/test/unit/request_processor_test.rb +70 -48
  50. data/test/unit/stateful_widget_test.rb +3 -1
  51. data/test/unit/transition_test.rb +1 -0
  52. data/test/unit/widget_shortcuts_test.rb +3 -2
  53. data/test/unit/widget_test.rb +69 -56
  54. metadata +57 -34
  55. data/app/.jeweler_doesnt_like_empty_directories +0 -0
  56. data/generators/widget/templates/functional_test.rb +0 -8
  57. data/generators/widget/templates/view.html.erb +0 -2
  58. data/generators/widget/templates/view.html.haml +0 -3
  59. data/generators/widget/widget_generator.rb +0 -34
  60. data/lib/apotomo/test_methods.rb +0 -8
  61. data/test/support/assertions_helper.rb +0 -13
  62. data/test/unit/test_methods_test.rb +0 -11
data/Gemfile CHANGED
@@ -1,11 +1,14 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "rails", "~> 2.3.8"
4
- gem "cells", "3.3.4"
3
+ gem "rails", "~> 3.0.0"
4
+ gem "cells", :path => "/home/nick/projects/cells"#"3.4.1"
5
5
  gem "onfire"
6
6
  gem "hooks", "~> 0.1.2"
7
+
8
+
7
9
  gem "jeweler"
8
10
 
9
11
  # for test env:
10
12
  gem "shoulda"
11
13
  gem "mocha"
14
+ gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3' # needed in router_test, whatever.
data/Gemfile.lock CHANGED
@@ -1,49 +1,98 @@
1
+ PATH
2
+ remote: /home/nick/projects/cells
3
+ specs:
4
+ cells (3.4.2)
5
+
1
6
  GEM
2
7
  remote: http://rubygems.org/
3
8
  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)
9
+ abstract (1.0.0)
10
+ actionmailer (3.0.0)
11
+ actionpack (= 3.0.0)
12
+ mail (~> 2.2.5)
13
+ actionpack (3.0.0)
14
+ activemodel (= 3.0.0)
15
+ activesupport (= 3.0.0)
16
+ builder (~> 2.1.2)
17
+ erubis (~> 2.6.6)
18
+ i18n (~> 0.4.1)
19
+ rack (~> 1.2.1)
20
+ rack-mount (~> 0.6.12)
21
+ rack-test (~> 0.5.4)
22
+ tzinfo (~> 0.3.23)
23
+ activemodel (3.0.0)
24
+ activesupport (= 3.0.0)
25
+ builder (~> 2.1.2)
26
+ i18n (~> 0.4.1)
27
+ activerecord (3.0.0)
28
+ activemodel (= 3.0.0)
29
+ activesupport (= 3.0.0)
30
+ arel (~> 1.0.0)
31
+ tzinfo (~> 0.3.23)
32
+ activeresource (3.0.0)
33
+ activemodel (= 3.0.0)
34
+ activesupport (= 3.0.0)
35
+ activesupport (3.0.0)
36
+ arel (1.0.1)
37
+ activesupport (~> 3.0.0)
38
+ builder (2.1.2)
39
+ erubis (2.6.6)
40
+ abstract (>= 1.0.0)
15
41
  gemcutter (0.6.1)
16
42
  git (1.2.5)
17
43
  hooks (0.1.2)
44
+ i18n (0.4.1)
18
45
  jeweler (1.4.0)
19
46
  gemcutter (>= 0.1.0)
20
47
  git (>= 1.2.5)
21
48
  rubyforge (>= 2.0.0)
22
49
  json_pure (1.4.6)
50
+ mail (2.2.6.1)
51
+ activesupport (>= 2.3.6)
52
+ mime-types
53
+ treetop (>= 1.4.5)
54
+ mime-types (1.16)
23
55
  mocha (0.9.8)
24
56
  rake
25
57
  onfire (0.1.0)
26
- rack (1.1.0)
27
- rails (2.3.8)
28
- actionmailer (= 2.3.8)
29
- actionpack (= 2.3.8)
30
- activerecord (= 2.3.8)
31
- activeresource (= 2.3.8)
32
- activesupport (= 2.3.8)
33
- rake (>= 0.8.3)
58
+ polyglot (0.3.1)
59
+ rack (1.2.1)
60
+ rack-mount (0.6.13)
61
+ rack (>= 1.0.0)
62
+ rack-test (0.5.6)
63
+ rack (>= 1.0)
64
+ rails (3.0.0)
65
+ actionmailer (= 3.0.0)
66
+ actionpack (= 3.0.0)
67
+ activerecord (= 3.0.0)
68
+ activeresource (= 3.0.0)
69
+ activesupport (= 3.0.0)
70
+ bundler (~> 1.0.0)
71
+ railties (= 3.0.0)
72
+ railties (3.0.0)
73
+ actionpack (= 3.0.0)
74
+ activesupport (= 3.0.0)
75
+ rake (>= 0.8.4)
76
+ thor (~> 0.14.0)
34
77
  rake (0.8.7)
35
78
  rubyforge (2.0.4)
36
79
  json_pure (>= 1.1.7)
37
80
  shoulda (2.11.3)
81
+ sqlite3-ruby (1.2.5)
82
+ thor (0.14.3)
83
+ treetop (1.4.8)
84
+ polyglot (>= 0.3.1)
85
+ tzinfo (0.3.23)
38
86
 
39
87
  PLATFORMS
40
88
  ruby
41
89
 
42
90
  DEPENDENCIES
43
- cells (= 3.3.4)
91
+ cells!
44
92
  hooks (~> 0.1.2)
45
93
  jeweler
46
94
  mocha
47
95
  onfire
48
- rails (~> 2.3.8)
96
+ rails (~> 3.0.0)
49
97
  shoulda
98
+ sqlite3-ruby (= 1.2.5)
data/Rakefile CHANGED
@@ -11,9 +11,9 @@ desc 'Default: run unit tests.'
11
11
  task :default => :test
12
12
 
13
13
  desc 'Test the Apotomo plugin.'
14
- Rake::TestTask.new(:test) do |t|
14
+ Rake::TestTask.new(:test) do |t|
15
15
  t.libs << 'test'
16
- t.pattern = 'test/**/*_test.rb'
16
+ t.test_files = FileList['test/unit/*_test.rb', 'test/rails/*_test.rb']# - ['test/rails/capture_test.rb']
17
17
  t.verbose = true
18
18
  end
19
19
 
@@ -24,16 +24,16 @@ require 'apotomo/version'
24
24
  Jeweler::Tasks.new do |spec|
25
25
  spec.name = "apotomo"
26
26
  spec.version = ::Apotomo::VERSION
27
- spec.summary = %{Event-driven Widgets for Rails with optional Statefulness.}
28
- spec.description = "A generic widget framework for Rails. Event-driven. Clean. Fast. Free optional statefulness included."
27
+ spec.summary = %{Web components for Rails.}
28
+ spec.description = "Web components for Rails. Event-driven. Clean. Fast. Free optional statefulness included."
29
29
  spec.homepage = "http://apotomo.de"
30
30
  spec.authors = ["Nick Sutterer"]
31
31
  spec.email = "apotonick@gmail.com"
32
32
 
33
- spec.files = FileList["app/.jeweler_doesnt_like_empty_directories", "[A-Z]*", File.join(*%w[{generators,lib,rails,app,config} ** *]).to_s]
33
+ spec.files = FileList["[A-Z]*", File.join(*%w[{generators,lib,rails,app,config} ** *]).to_s]
34
34
 
35
- spec.add_dependency 'cells', '~> 3.3'
36
- spec.add_dependency 'activesupport', '>= 2.3.0'
35
+ spec.add_dependency 'cells', '~> 3.4.2'
36
+ spec.add_dependency 'rails', '>= 3.0.0'
37
37
  spec.add_dependency 'onfire', '>= 0.1.0'
38
38
  spec.add_dependency 'hooks', '~> 0.1.2'
39
39
  end
data/config/routes.rb CHANGED
@@ -1,3 +1,3 @@
1
- ActionController::Routing::Routes.draw do |map|
2
- map.apotomo_event ':controller/render_event_response', :action => 'render_event_response'
3
- end
1
+ Rails.application.routes.draw do |map|
2
+ match ":controller/render_event_response", :to => "#render_event_response", :as => "apotomo_event"
3
+ end
@@ -42,59 +42,29 @@ module Apotomo
42
42
  end
43
43
 
44
44
 
45
- # Serializes the widget node structure (not children, not content).
46
- def dump_node
47
- field_sep = self.class.field_sep
48
- "#{@name}#{field_sep}#{self.class}#{field_sep}#{root? ? @name : parent.name}"
45
+ def dump_tree
46
+ collect { |n| [n.class, n.name, n.root? ? nil : n.parent.name] }
49
47
  end
50
48
 
51
- # Serializes the tree structure.
52
- def _dump(depth)
53
- inject("") { |str, node| str << node.dump_node << self.class.node_sep }
54
- end
55
49
 
56
50
  module ClassMethods
57
- def field_sep; '|'; end
58
- def node_sep; "\n"; end
59
-
60
- # Creates an empty widget instance from <tt>line</tt>.
61
- def load_node(line)
62
- name, klass, parent = line.split(field_sep)
63
- [klass.constantize.new(name, nil), parent]
64
- end
65
-
66
- def _load(str)
67
- nodes = {}
68
- root = nil
69
- str.split(node_sep).each do |line|
70
- node, parent = load_node(line)
71
- nodes[node.name] = node
72
-
73
- if node.name == parent # we're at the root node.
74
- root = node and next
75
- end
76
-
77
- nodes[parent].add(node)
78
- end
79
- root
80
- end
81
-
51
+ # Dump the shit to storage.
82
52
  def freeze_for(storage, root)
83
53
  storage[:apotomo_stateful_branches] = []
84
54
  storage[:apotomo_widget_ivars] = {}
85
55
 
86
56
  stateful_branches_for(root).each do |branch|
87
57
  branch.freeze_data_to(storage[:apotomo_widget_ivars]) # save ivars.
88
- storage[:apotomo_stateful_branches] << [branch, branch.parent.name]
89
- branch.root! # disconnect from tree.
58
+ storage[:apotomo_stateful_branches] << branch.dump_tree
90
59
  end
91
60
  end
92
61
 
93
- def thaw_for(storage, root)
62
+ # Create tree from storage and add branches to root/stateless parents.
63
+ def thaw_for(controller, storage, root)
94
64
  branches = storage.delete(:apotomo_stateful_branches) || []
95
- branches.each do |config|
96
- branch = config.first
97
- parent = root.find_widget(config.last) or raise "Couldn't find parent `#{config.last}` for `#{branch.name}`"
65
+ branches.each do |data|
66
+ branch = load_tree(controller, data)
67
+ parent = root.find_widget(data.first.last) or raise "Couldn't find parent `#{data.first.last}` for `#{branch.name}`"
98
68
 
99
69
  parent << branch
100
70
  branch.thaw_data_from(storage.delete(:apotomo_widget_ivars) || {})
@@ -102,16 +72,9 @@ module Apotomo
102
72
 
103
73
  root
104
74
  end
105
-
106
- def thaw_from(storage)
107
- root = storage[:apotomo_root]
108
- root.thaw_data_from(storage.fetch(:apotomo_widget_ivars, {}))
109
- root
110
- end
111
75
 
112
76
  def frozen_widget_in?(storage)
113
- branches = storage[:apotomo_stateful_branches]
114
- branches.present? and branches.first.first.kind_of? Apotomo::StatefulWidget
77
+ storage[:apotomo_stateful_branches].kind_of? Array
115
78
  end
116
79
 
117
80
  def flush_storage(storage)
@@ -134,6 +97,16 @@ module Apotomo
134
97
  stateful_roots
135
98
  end
136
99
 
100
+ private
101
+ def load_tree(parent_controller, cold_widgets)
102
+ root = nil
103
+ cold_widgets.each do |data|
104
+ node = data[0].new(parent_controller, data[1], "")
105
+ root = node and next unless root
106
+ root.find_widget(data[2]) << node
107
+ end
108
+ root
109
+ end
137
110
  end
138
111
  end
139
- end
112
+ end
@@ -22,14 +22,6 @@ module Apotomo
22
22
  js_generator.xhr(url_for_event(type, options))
23
23
  end
24
24
 
25
- # Creates a link that triggers an event via AJAX.
26
- # This link will <em>only</em> work in JavaScript-able browsers.
27
- #
28
- # Note that the link is created using #link_to_remote.
29
- def link_to_event(title, type, options={}, html_options={})
30
- link_to_remote(title, {:url => url_for_event(type, options)}, html_options)
31
- end
32
-
33
25
  # Creates a form tag that triggers an event via AJAX when submitted.
34
26
  # See StatefulWidget::address_for_event for options.
35
27
  #
@@ -49,7 +41,7 @@ module Apotomo
49
41
  html_options.reverse_merge! :target => :apotomo_iframe, :multipart => true
50
42
 
51
43
  # i hate rails:
52
- concat('<iframe id="apotomo_iframe" name="apotomo_iframe" style="display: none;"></iframe>') << form_tag(url_for_event(type, options), html_options, &block)
44
+ concat('<iframe id="apotomo_iframe" name="apotomo_iframe" style="display: none;"></iframe>'.html_safe) << form_tag(url_for_event(type, options), html_options, &block)
53
45
  end
54
46
 
55
47
  # Returns the url to trigger a +type+ event from the currently rendered widget.
@@ -62,7 +54,7 @@ module Apotomo
62
54
  # #=> http://apotomo.de/mouse/process_event_request?type=paginate&source=mouse&page=2
63
55
  def url_for_event(type, options={})
64
56
  options.reverse_merge! :source => widget_id
65
- controller.url_for_event(type, options)
57
+ @cell.url_for_event(type, options) # FIXME: don't access @parent_controller but @cell.
66
58
  end
67
59
 
68
60
  ### TODO: test me.
@@ -73,7 +65,7 @@ module Apotomo
73
65
  ### TODO: test me.
74
66
  ### DISCUSS: rename to rendered_children ?
75
67
  def content
76
- @rendered_children.collect{|e| e.last}.join("\n")
68
+ @rendered_children.collect{|e| e.last}.join("\n").html_safe
77
69
  end
78
70
 
79
71
  # needs: suppress_javascript
@@ -1,20 +1,17 @@
1
1
  module Apotomo
2
2
  class RequestProcessor
3
- include WidgetShortcuts
4
-
5
3
  attr_reader :session, :root
6
4
 
7
5
  def initialize(controller, session, options={}, has_widgets_blocks=[])
8
6
  @session = session
9
7
  @widgets_flushed = false
10
8
 
11
- @root = widget('apotomo/widget', 'root')
12
- @root.controller = controller
9
+ @root = Widget.new(controller, 'root', :display)
13
10
 
14
11
  attach_stateless_blocks_for(has_widgets_blocks, @root, controller)
15
12
 
16
13
  if options[:flush_widgets].blank? and ::Apotomo::StatefulWidget.frozen_widget_in?(session)
17
- @root = ::Apotomo::StatefulWidget.thaw_for(session, @root)
14
+ @root = ::Apotomo::StatefulWidget.thaw_for(controller, session, @root)
18
15
  else
19
16
  #@root = flushed_root
20
17
 
@@ -27,14 +24,14 @@ module Apotomo
27
24
  def attach_stateless_blocks_for(blocks, root, controller)
28
25
  blocks.each do |blk|
29
26
  if blk.arity == 1
30
- blk.call(root) and next # fixes misbehaviour in ruby 1.8.
27
+ #blk.call(root) and next # fixes misbehaviour in ruby 1.8.
28
+ root.instance_exec(root, &blk) and next
31
29
  end
32
-
33
- blk.call(root, controller)
30
+ ### FIXME: use Widget.has_widgets func.
31
+ root.instance_exec(root, controller, &blk)
34
32
  end
35
33
  end
36
34
 
37
-
38
35
  def flushed_root
39
36
  StatefulWidget.flush_storage(session)
40
37
  @widgets_flushed = true
@@ -95,4 +92,4 @@ module Apotomo
95
92
  options
96
93
  end
97
94
  end
98
- end
95
+ end
@@ -26,7 +26,7 @@ module Apotomo::Transition
26
26
  # to the start state.
27
27
  def transition(options)
28
28
  if from = options[:from]
29
- class_transitions[from] = options[:to]
29
+ class_transitions[from.to_s] = options[:to]
30
30
  elsif loop = options[:in]
31
31
  transition :from => loop, :to => loop
32
32
  end
@@ -41,6 +41,6 @@ module Apotomo::Transition
41
41
  # Returns the next state for <tt>state</tt> or nil. A next state must have been defined
42
42
  # with #transition.
43
43
  def next_state_for(state)
44
- self.class.class_transitions[state]
44
+ self.class.class_transitions[state.to_s]
45
45
  end
46
46
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Apotomo
4
- VERSION = '0.1.4'
4
+ VERSION = '1.0.0.beta1'
5
5
  end
@@ -35,10 +35,6 @@ module Apotomo
35
35
  attr_writer :controller
36
36
  attr_accessor :version
37
37
 
38
- #class << self
39
- # include WidgetShortcuts
40
- #end
41
-
42
38
  include TreeNode
43
39
 
44
40
  include Onfire
@@ -56,30 +52,29 @@ module Apotomo
56
52
  self.class.callbacks_for_hook(name).each { |blk| instance_exec(*args, &blk) }
57
53
  end
58
54
 
59
-
60
55
  def add_has_widgets_blocks(*)
61
56
  run_widget_hook(:has_widgets, self)
62
57
  end
63
58
  after_initialize :add_has_widgets_blocks
64
59
 
65
60
 
66
- # Constructor which needs a unique id for the widget and one or multiple start states.
67
- # <tt>start_state</tt> may be a symbol or an array of symbols.
68
- def initialize(id, start_state, opts={})
69
- @opts = opts
61
+ # Constructor which needs a unique id for the widget and one or multiple start states.
62
+ def initialize(parent_controller, id, start_state, opts={})
63
+ super(parent_controller, opts) # do that as long as cells do need a parent_controller.
64
+
70
65
  @name = id
71
66
  @start_state = start_state
72
67
 
73
68
  @visible = true
74
- @version = 0
69
+ @version = 0 ### DISCUSS: neeed in stateLESS?
75
70
 
76
- @cell = self
71
+ @cell = self ### DISCUSS: needed?
77
72
 
78
73
  run_hook(:after_initialize, id, start_state, opts)
79
74
  end
80
75
 
81
76
  def last_state
82
- @state_name
77
+ action_name
83
78
  end
84
79
 
85
80
  def visible?
@@ -93,7 +88,7 @@ module Apotomo
93
88
  end
94
89
 
95
90
  def unfreezable_ivars
96
- [:@childrenHash, :@children, :@parent, :@controller, :@cell, :@invoke_block, :@rendered_children, :@page_updates, :@opts,
91
+ [:@childrenHash, :@children, :@parent, :@parent_controller, :@_request, :@_config, :@cell, :@invoke_block, :@rendered_children, :@page_updates, :@opts,
97
92
  :@suppress_javascript ### FIXME: implement with ActiveHelper and :locals.
98
93
 
99
94
  ]
@@ -126,13 +121,6 @@ module Apotomo
126
121
  end
127
122
 
128
123
 
129
-
130
- # called in Cell::Base#render_state
131
- def dispatch_state(state)
132
- send(state, &@invoke_block)
133
- end
134
-
135
-
136
124
  # Render the view for the current state. Usually called at the end of a state method.
137
125
  #
138
126
  # ==== Options
@@ -184,11 +172,10 @@ module Apotomo
184
172
 
185
173
  options[:locals].reverse_merge!(:rendered_children => rendered_children)
186
174
 
187
- @controller = controller # that dependency SUCKS.
188
175
  @suppress_js = options[:suppress_js] ### FIXME: implement with ActiveHelper and :locals.
189
176
 
190
177
 
191
- render_view_for(options, @state_name) # defined in Cell::Base.
178
+ render_view_for(options, action_name) # defined in Cell::Base.
192
179
  end
193
180
 
194
181
  alias_method :emit, :render
@@ -242,7 +229,7 @@ module Apotomo
242
229
  end
243
230
 
244
231
  def render_children(invoke_options={})
245
- returning rendered_children = ActiveSupport::OrderedHash.new do
232
+ ActiveSupport::OrderedHash.new.tap do |rendered_children|
246
233
  visible_children.each do |kid|
247
234
  child_state = decide_state_for(kid, invoke_options)
248
235
  logger.debug " #{kid.name} -> #{child_state}"
@@ -295,8 +282,8 @@ module Apotomo
295
282
  find {|node| node.name.to_s == widget_id.to_s}
296
283
  end
297
284
 
298
- def controller
299
- root? ? @controller : root.controller
285
+ def url_for_event(*args)
286
+ parent_controller.url_for_event(*args)
300
287
  end
301
288
 
302
289
  alias_method :widget_id, :name
@@ -12,7 +12,7 @@ module Apotomo
12
12
  #
13
13
  # widget('jquery/tabs', 'panel')
14
14
  def widget(class_name, id, state=:display, *args)
15
- object = constant_for(class_name).new(id, state, *args)
15
+ object = constant_for(class_name).new(parent_controller, id, state, *args)
16
16
  yield object if block_given?
17
17
  object
18
18
  end
data/lib/apotomo.rb CHANGED
@@ -40,6 +40,9 @@ module Apotomo
40
40
  yield self
41
41
  end
42
42
  end
43
+
44
+ class Engine < Rails::Engine
45
+ end
43
46
  end
44
47
 
45
48
  require 'apotomo/javascript_generator'
@@ -49,3 +52,6 @@ require 'apotomo/widget'
49
52
  require 'apotomo/stateful_widget'
50
53
  require 'apotomo/container_widget'
51
54
  require 'apotomo/widget_shortcuts'
55
+ require 'apotomo/rails/controller_methods'
56
+
57
+ #require 'apotomo/engine' if defined?(Rails)
File without changes
@@ -0,0 +1,7 @@
1
+ <h1>
2
+ <%= class_name %>#<%= @state %>
3
+ </h1>
4
+
5
+ <p>
6
+ Find me in <%= @path %>
7
+ </p>
@@ -0,0 +1,4 @@
1
+ %h1
2
+ <%= class_name %>#<%= @state %>
3
+ %p
4
+ Find me in <%= @path %>
@@ -1,8 +1,9 @@
1
1
  class <%= class_name %> < Apotomo::Widget
2
+
2
3
  <% for action in actions -%>
3
4
  def <%= action %>
4
5
  render
5
6
  end
6
-
7
+
7
8
  <% end -%>
8
9
  end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < Apotomo::TestCase
4
+ <% for state in @states -%>
5
+ test "<%= state %>" do
6
+ invoke :<%= state %>
7
+ assert_select "p"
8
+ end
9
+
10
+ <% end %>
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'generators/cells/cell_generator'
2
+
3
+ module Apotomo
4
+ module Generators
5
+ class WidgetGenerator < Cells::Generators::CellGenerator
6
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
7
+
8
+ def create_cell_file
9
+ puts "creating #{file_name}.rb"
10
+ template 'widget.rb', File.join('app/cells', class_path, "#{file_name}.rb")
11
+ end
12
+
13
+ def create_test
14
+ @states = actions
15
+ template 'widget_test.rb', File.join('test/widgets/', "#{file_name}_test.rb")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ #require "dummy"
11
+
12
+ module Dummy
13
+ class Application < Rails::Application
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+
18
+ # Custom directories with classes and modules you want to be autoloadable.
19
+ # config.autoload_paths += %W(#{config.root}/extras)
20
+
21
+ # Only load the plugins named here, in the order given (default is alphabetical).
22
+ # :all can be used as a placeholder for all plugins not explicitly named.
23
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
+
25
+ # Activate observers that should always be running.
26
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
+
28
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
+ # config.time_zone = 'Central Time (US & Canada)'
31
+
32
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
+ # config.i18n.default_locale = :de
35
+
36
+ # JavaScript files you want as :defaults (application.js is always included).
37
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
38
+
39
+ # Configure the default encoding used in templates for Ruby 1.9.
40
+ config.encoding = "utf-8"
41
+
42
+ # Configure sensitive parameters which will be filtered from the log file.
43
+ config.filter_parameters += [:password]
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!