rtml 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. data/History.txt +3 -0
  2. data/Manifest.txt +51 -13
  3. data/Rakefile +6 -1
  4. data/builtin/controllers/rtml_controller.rb +12 -1
  5. data/builtin/models/rtml/document.rb +24 -18
  6. data/builtin/models/rtml/document_model_object.rb +6 -0
  7. data/builtin/models/rtml/dom/collections/element_set.rb +6 -0
  8. data/builtin/models/rtml/dom/collections/property_set.rb +11 -0
  9. data/builtin/models/rtml/dom/element.rb +79 -27
  10. data/builtin/models/rtml/dom/frontend_element.rb +41 -20
  11. data/builtin/models/rtml/dom/property.rb +43 -26
  12. data/builtin/models/rtml/dom/screen_element.rb +13 -0
  13. data/builtin/widgets/document_variable_processing.rb +42 -18
  14. data/builtin/widgets/element_builder.rb +4 -4
  15. data/builtin/widgets/screen_variable_processing.rb +2 -2
  16. data/builtin/widgets/screen_variants.rb +31 -4
  17. data/builtin/widgets/screens.rb +13 -1
  18. data/builtin/widgets/static_content.rb +20 -6
  19. data/do_profile.rb +15 -0
  20. data/lib/extensions/action_controller/response.rb +0 -18
  21. data/lib/extensions/action_controller/routing/route_set.rb +28 -18
  22. data/lib/extensions/hpricot/doc.rb +3 -3
  23. data/lib/extensions/hpricot/elem.rb +3 -3
  24. data/lib/extensions/string.rb +2 -18
  25. data/lib/rtml.rb +0 -12
  26. data/lib/rtml/assigns.rb +32 -0
  27. data/lib/rtml/controller/document_generator.rb +9 -0
  28. data/lib/rtml/controller/render_helpers.rb +42 -18
  29. data/lib/rtml/controller/state.rb +2 -1
  30. data/lib/rtml/dependencies.rb +20 -15
  31. data/lib/rtml/dsl.rb +10 -10
  32. data/lib/rtml/environment.rb +13 -1
  33. data/lib/rtml/errors/application_error.rb +5 -0
  34. data/lib/rtml/errors/simulation_error.rb +4 -0
  35. data/lib/rtml/errors/variable_error.rb +5 -0
  36. data/lib/rtml/high_level/variable_manager.rb +11 -7
  37. data/lib/rtml/inherited_instance_variables.rb +8 -1
  38. data/lib/rtml/links.rb +17 -0
  39. data/lib/rtml/rules/dom_validation.rb +1 -0
  40. data/lib/rtml/test/builtin_variables.rb +33 -0
  41. data/lib/rtml/test/resemblance_test.rb +97 -0
  42. data/lib/rtml/test/screen.rb +126 -0
  43. data/lib/rtml/test/simulator.rb +240 -0
  44. data/lib/rtml/test/simulator_post_processors/base.rb +7 -0
  45. data/lib/rtml/test/simulator_post_processors/card_parsers.rb +32 -0
  46. data/lib/rtml/test/simulator_post_processors/receipt.rb +15 -0
  47. data/lib/rtml/test/simulator_post_processors/submit.rb +15 -0
  48. data/lib/rtml/test/spec.rb +14 -7
  49. data/lib/rtml/test/spec/matchers.rb +24 -0
  50. data/lib/rtml/test/tml_application.rb +331 -0
  51. data/lib/rtml/test/unit.rb +13 -0
  52. data/lib/rtml/test/variable_scope.rb +146 -0
  53. data/lib/rtml/version.rb +1 -1
  54. data/lib/rtml/widget.rb +26 -14
  55. data/lib/rtml/widget_core/class_methods.rb +8 -4
  56. data/lib/rtml/widget_core/widget_accessor_instance_methods.rb +6 -6
  57. data/lib/rtml/widgets.rb +22 -3
  58. data/lib/rtml_routes.rb +1 -1
  59. data/rails_generators/rtml/rtml_generator.rb +3 -0
  60. data/rails_generators/rtml/templates/db/migrate/20100513165226_add_options_to_rtml_documents.rb +9 -0
  61. data/rails_generators/rtml/templates/db/migrate/20100513165242_remove_dom_elements_mirror.rb +16 -0
  62. data/rails_generators/rtml/templates/db/migrate/20100513165249_remove_dom_properties_mirror.rb +16 -0
  63. data/rails_generators/rtml/templates/lib/tasks/rtml.rake +1 -1
  64. data/rtml.gemspec +65 -0
  65. data/spec/controllers/rtml_controller_spec.rb +1 -1
  66. data/spec/integration/post_tests_spec.rb +8 -0
  67. data/spec/lib/rtml/high_level/variable_manager_spec.rb +8 -0
  68. data/spec/lib/rtml/routes_spec.rb +23 -22
  69. data/spec/lib/rtml/test/simulator/receipt_spec.rb +18 -0
  70. data/spec/lib/rtml/test/simulator_spec.rb +185 -0
  71. data/spec/lib/rtml/test/tml_application_spec.rb +119 -0
  72. data/spec/lib/rtml/test/variable_scope_spec.rb +65 -0
  73. data/spec/lib/rtml/widget_spec.rb +1 -0
  74. data/spec/lib/rtml/widgets_spec.rb +30 -0
  75. data/spec/models/rtml/document_spec.rb +8 -0
  76. data/spec/models/rtml/dom/screen_element_spec.rb +15 -0
  77. data/spec/models/rtml/instruction_spec.rb +2 -2
  78. data/spec/rtml_action_spec.rb +25 -0
  79. data/spec/spec_helper.rb +31 -1
  80. data/spec/support/app/controllers/post_tests_controller.rb +11 -0
  81. data/spec/support/app/views/inherited/instance_variables_test/display.rtml.erb +1 -0
  82. data/spec/support/config/boot.rb +1 -0
  83. data/spec/support/config/routes.rb +3 -2
  84. data/spec/support/db/rtml_test_db.sqlite3 +0 -0
  85. data/spec/support/raw_tml/avs.tml +27 -0
  86. data/spec/support/raw_tml/document_level_events.tml +18 -0
  87. data/spec/support/raw_tml/empty_screen.tml +15 -0
  88. data/spec/support/raw_tml/enter_amount.tml +40 -0
  89. data/spec/support/raw_tml/foreign_receiver.tml +10 -0
  90. data/spec/support/raw_tml/foreign_reference.tml +10 -0
  91. data/spec/support/raw_tml/hello_world.tml +13 -0
  92. data/spec/support/raw_tml/loop_x_times.tml +39 -0
  93. data/spec/support/raw_tml/one_screen_with_setvar.tml +8 -0
  94. data/spec/support/raw_tml/receipt.tml +15 -0
  95. data/spec/support/raw_tml/simulator.tml +122 -0
  96. data/spec/support/raw_tml/tmlvar_reference.tml +34 -0
  97. data/spec/support/raw_tml/user_input.tml +47 -0
  98. data/spec/support/raw_tml/valid_document.tml +6 -0
  99. data/spec/support/rspec/example_groups.rb +1 -1
  100. data/spec/support/rspec/matchers.rb +0 -11
  101. data/spec/widgets/document_variable_processing_spec.rb +25 -39
  102. data/spec/widgets/element_builder_spec.rb +4 -0
  103. data/spec/widgets/event_listener_spec.rb +9 -0
  104. data/spec/widgets/highlevel_variable_processing_spec.rb +27 -2
  105. data/spec/widgets/screen_variable_processing_spec.rb +34 -0
  106. data/spec/widgets/screens_spec.rb +22 -0
  107. data/spec/widgets/simulator_post_processors/card_parsers_spec.rb +70 -0
  108. data/spec/widgets/simulator_post_processors/submit_spec.rb +44 -0
  109. data/tasks/stats.rake +10 -0
  110. data/test/test_rtml_generator.rb +3 -0
  111. metadata +55 -49
  112. data/builtin/widgets/subroutine.rb +0 -54
  113. data/lib/rtml/high_level/subroutine.rb +0 -22
  114. data/lib/rtml/reverse_engineering/crawler.rb +0 -58
  115. data/lib/rtml/reverse_engineering/simulator.rb +0 -269
  116. data/lib/rtml/reverse_engineering/simulator/casting.rb +0 -9
  117. data/lib/rtml/reverse_engineering/simulator/snapshot.rb +0 -18
  118. data/lib/rtml/reverse_engineering/simulator/variable_lookup.rb +0 -32
  119. data/lib/rtml/reverse_engineering/simulator/variable_value.rb +0 -105
  120. data/spec/lib/rtml/reverse_engineering/crawler_spec.rb +0 -24
  121. data/spec/lib/rtml/reverse_engineering/simulator/variable_value_spec.rb +0 -120
  122. data/spec/lib/rtml/reverse_engineering/simulator_spec.rb +0 -96
  123. data/spec/support/config/tml_dom_ruleset.rb +0 -82
  124. data/spec/widgets/subroutine_spec.rb +0 -109
@@ -1,3 +1,6 @@
1
+ === 2.0.3 2010-04-19
2
+ * RTML 2.0 released!
3
+
1
4
  === 0.0.1 2010-04-12
2
5
 
3
6
  * 1 major enhancement:
@@ -9,6 +9,9 @@ app_generators/rtml/templates/rtml_template.rb
9
9
  bin/rtml
10
10
  builtin/controllers/rtml_controller.rb
11
11
  builtin/models/rtml/document.rb
12
+ builtin/models/rtml/document_model_object.rb
13
+ builtin/models/rtml/dom/collections/element_set.rb
14
+ builtin/models/rtml/dom/collections/property_set.rb
12
15
  builtin/models/rtml/dom/element.rb
13
16
  builtin/models/rtml/dom/frontend_element.rb
14
17
  builtin/models/rtml/dom/property.rb
@@ -33,7 +36,7 @@ builtin/widgets/screen_variants.rb
33
36
  builtin/widgets/screens.rb
34
37
  builtin/widgets/shorthand.rb
35
38
  builtin/widgets/static_content.rb
36
- builtin/widgets/subroutine.rb
39
+ do_profile.rb
37
40
  generators/rtml_widget/USAGE
38
41
  generators/rtml_widget/rtml_widget_generator.rb
39
42
  generators/rtml_widget/templates/default_widget.erb
@@ -47,6 +50,7 @@ lib/extensions/hpricot/doc.rb
47
50
  lib/extensions/hpricot/elem.rb
48
51
  lib/extensions/string.rb
49
52
  lib/rtml.rb
53
+ lib/rtml/assigns.rb
50
54
  lib/rtml/configuration.rb
51
55
  lib/rtml/controller/before_filters.rb
52
56
  lib/rtml/controller/cache_helpers.rb
@@ -60,6 +64,7 @@ lib/rtml/controller/url_helpers.rb
60
64
  lib/rtml/dependencies.rb
61
65
  lib/rtml/dsl.rb
62
66
  lib/rtml/environment.rb
67
+ lib/rtml/errors/application_error.rb
63
68
  lib/rtml/errors/invalid_format.rb
64
69
  lib/rtml/errors/invalid_operation.rb
65
70
  lib/rtml/errors/invalid_option_error.rb
@@ -70,25 +75,33 @@ lib/rtml/errors/processing_error.rb
70
75
  lib/rtml/errors/rules_violation_error.rb
71
76
  lib/rtml/errors/screen_not_found.rb
72
77
  lib/rtml/errors/screen_variant_error.rb
78
+ lib/rtml/errors/simulation_error.rb
73
79
  lib/rtml/errors/sti_type_error.rb
74
80
  lib/rtml/errors/subprocessing_not_supported.rb
75
81
  lib/rtml/errors/unknown_rtml_action.rb
82
+ lib/rtml/errors/variable_error.rb
76
83
  lib/rtml/high_level/managed_variable.rb
77
- lib/rtml/high_level/subroutine.rb
78
84
  lib/rtml/high_level/variable_manager.rb
79
85
  lib/rtml/inherited_instance_variables.rb
80
86
  lib/rtml/init.rb
81
- lib/rtml/reverse_engineering/crawler.rb
82
- lib/rtml/reverse_engineering/simulator.rb
83
- lib/rtml/reverse_engineering/simulator/casting.rb
84
- lib/rtml/reverse_engineering/simulator/snapshot.rb
85
- lib/rtml/reverse_engineering/simulator/variable_lookup.rb
86
- lib/rtml/reverse_engineering/simulator/variable_value.rb
87
+ lib/rtml/links.rb
87
88
  lib/rtml/rules/dom_ruleset.rb
88
89
  lib/rtml/rules/dom_tag.rb
89
90
  lib/rtml/rules/dom_validation.rb
90
91
  lib/rtml/rules/tml_param_parser.rb
92
+ lib/rtml/test/builtin_variables.rb
93
+ lib/rtml/test/resemblance_test.rb
94
+ lib/rtml/test/screen.rb
95
+ lib/rtml/test/simulator.rb
96
+ lib/rtml/test/simulator_post_processors/base.rb
97
+ lib/rtml/test/simulator_post_processors/card_parsers.rb
98
+ lib/rtml/test/simulator_post_processors/receipt.rb
99
+ lib/rtml/test/simulator_post_processors/submit.rb
91
100
  lib/rtml/test/spec.rb
101
+ lib/rtml/test/spec/matchers.rb
102
+ lib/rtml/test/tml_application.rb
103
+ lib/rtml/test/unit.rb
104
+ lib/rtml/test/variable_scope.rb
92
105
  lib/rtml/tmlized_conditions.rb
93
106
  lib/rtml/version.rb
94
107
  lib/rtml/widget.rb
@@ -113,6 +126,9 @@ rails_generators/rtml/templates/db/migrate/20100113131401_add_options_to_propert
113
126
  rails_generators/rtml/templates/db/migrate/20100127173146_add_parent_type_to_rtml_dom_elements.rb
114
127
  rails_generators/rtml/templates/db/migrate/20100208114234_create_rtml_states.rb
115
128
  rails_generators/rtml/templates/db/migrate/20100303021609_add_x_and_y_to_rtml_instructions.rb
129
+ rails_generators/rtml/templates/db/migrate/20100513165226_add_options_to_rtml_documents.rb
130
+ rails_generators/rtml/templates/db/migrate/20100513165242_remove_dom_elements_mirror.rb
131
+ rails_generators/rtml/templates/db/migrate/20100513165249_remove_dom_properties_mirror.rb
116
132
  rails_generators/rtml/templates/doc/io_tml-application-development-guidelines.pdf
117
133
  rails_generators/rtml/templates/lib/tasks/rtml.rake
118
134
  rails_generators/rtml_action/USAGE
@@ -125,22 +141,26 @@ rails_generators/widget/templates/default_widget.feature.erb
125
141
  rails_generators/widget/templates/default_widget_spec.erb
126
142
  rails_generators/widget/templates/default_widget_test.erb
127
143
  rails_generators/widget/widget_generator.rb
144
+ rtml.gemspec
128
145
  script/console
129
146
  script/destroy
130
147
  script/generate
131
148
  script/server
132
149
  spec/controllers/inherited_controller_spec.rb
133
150
  spec/controllers/rtml_controller_spec.rb
151
+ spec/integration/post_tests_spec.rb
134
152
  spec/lib/extensions/hpricot/doc_spec.rb
135
153
  spec/lib/extensions/hpricot/elem_spec.rb
136
154
  spec/lib/extensions/string_spec.rb
137
155
  spec/lib/rtml/extensions_spec.rb
138
- spec/lib/rtml/reverse_engineering/crawler_spec.rb
139
- spec/lib/rtml/reverse_engineering/simulator/variable_value_spec.rb
140
- spec/lib/rtml/reverse_engineering/simulator_spec.rb
156
+ spec/lib/rtml/high_level/variable_manager_spec.rb
141
157
  spec/lib/rtml/routes_spec.rb
142
158
  spec/lib/rtml/rules/dom_ruleset_spec.rb
143
159
  spec/lib/rtml/rules/dom_validation_spec.rb
160
+ spec/lib/rtml/test/simulator/receipt_spec.rb
161
+ spec/lib/rtml/test/simulator_spec.rb
162
+ spec/lib/rtml/test/tml_application_spec.rb
163
+ spec/lib/rtml/test/variable_scope_spec.rb
144
164
  spec/lib/rtml/widget_core/generic_widget_consumer_spec.rb
145
165
  spec/lib/rtml/widget_core/gui_configuration_spec.rb
146
166
  spec/lib/rtml/widget_core/widget_proxy_spec.rb
@@ -155,29 +175,45 @@ spec/models/rtml/instruction_spec.rb
155
175
  spec/models/rtml/state/variable_mapping_spec.rb
156
176
  spec/models/rtml/state_spec.rb
157
177
  spec/rcov.opts
178
+ spec/rtml_action_spec.rb
158
179
  spec/spec.opts
159
180
  spec/spec_helper.rb
160
181
  spec/support/app/controllers/application_controller.rb
161
182
  spec/support/app/controllers/inherited_controller.rb
183
+ spec/support/app/controllers/post_tests_controller.rb
162
184
  spec/support/app/rtml_helpers/inherited/index.rb
163
185
  spec/support/app/rtml_helpers/rtml/index.rb
164
186
  spec/support/app/views/README.txt
187
+ spec/support/app/views/inherited/instance_variables_test/display.rtml.erb
165
188
  spec/support/app/views/layouts/layout.rtml.erb
166
189
  spec/support/app/views/magcard/_partial.erb
167
190
  spec/support/app/views/magcard/main.rtml.erb
168
191
  spec/support/app/views/rtml/index.html.erb
169
192
  spec/support/app/views/rtml/index/main.rtml.erb
193
+ spec/support/config/boot.rb
170
194
  spec/support/config/database.yml
171
195
  spec/support/config/environment.rb
172
196
  spec/support/config/environments/development.rb
173
197
  spec/support/config/initializers/rtml.rb
174
198
  spec/support/config/routes.rb
175
- spec/support/config/tml_dom_ruleset.rb
176
199
  spec/support/db/rtml_test_db.sqlite3
177
200
  spec/support/db/schema.rb
178
201
  spec/support/lib/rtml/widgets/test_widget1.rb
179
202
  spec/support/lib/rtml/widgets/test_widget2.rb
180
203
  spec/support/rails.rb
204
+ spec/support/raw_tml/avs.tml
205
+ spec/support/raw_tml/document_level_events.tml
206
+ spec/support/raw_tml/empty_screen.tml
207
+ spec/support/raw_tml/enter_amount.tml
208
+ spec/support/raw_tml/foreign_receiver.tml
209
+ spec/support/raw_tml/foreign_reference.tml
210
+ spec/support/raw_tml/hello_world.tml
211
+ spec/support/raw_tml/loop_x_times.tml
212
+ spec/support/raw_tml/one_screen_with_setvar.tml
213
+ spec/support/raw_tml/receipt.tml
214
+ spec/support/raw_tml/simulator.tml
215
+ spec/support/raw_tml/tmlvar_reference.tml
216
+ spec/support/raw_tml/user_input.tml
181
217
  spec/support/raw_tml/valid_document.tml
182
218
  spec/support/rspec/example_groups.rb
183
219
  spec/support/rspec/matchers.rb
@@ -192,11 +228,13 @@ spec/widgets/highlevel_variable_processing_spec.rb
192
228
  spec/widgets/screen_variable_processing_spec.rb
193
229
  spec/widgets/screen_variants_spec.rb
194
230
  spec/widgets/screens_spec.rb
231
+ spec/widgets/simulator_post_processors/card_parsers_spec.rb
232
+ spec/widgets/simulator_post_processors/submit_spec.rb
195
233
  spec/widgets/static_content_spec.rb
196
- spec/widgets/subroutine_spec.rb
197
234
  tasks/db.rake
198
235
  tasks/rspec.rake
199
236
  tasks/rtml.rake
237
+ tasks/stats.rake
200
238
  test/test_generator_helper.rb
201
239
  test/test_helper.rb
202
240
  test/test_rtml_action_generator.rb
data/Rakefile CHANGED
@@ -1,5 +1,9 @@
1
1
  #RTML_ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
2
2
  #require 'rubygems'
3
+ unless defined?(Rails)
4
+ gem 'rails', '= 2.3.5'
5
+ end
6
+
3
7
  require './spec/support/rails'
4
8
  gem 'hoe', '>= 2.1.0'
5
9
  require 'hoe'
@@ -19,7 +23,8 @@ $hoe = Hoe.spec 'rtml' do
19
23
  self.extra_dev_deps = [['rspec','>= 1.3.0'], ['rspec-rails','>= 1.3.2'], ['webrat', '>= 0.7.0']]
20
24
  self.version = Rtml::VERSION::STRING
21
25
  self.readme_file = "README.rdoc"
22
- self.summary = "RubyTML (or just RTML) is a Ruby framework for communicating with Ingenico's Incendo-based payment devices."
26
+ self.summary = self.description =
27
+ "RubyTML (or just RTML) is a Ruby framework for communicating with Ingenico's Incendo-based payment devices."
23
28
  end
24
29
 
25
30
  require 'newgem/tasks'
@@ -13,8 +13,16 @@ class RtmlController < (defined? Rails) ? ApplicationController : ActionControll
13
13
  hide_action :rtml_document, :rtml_exception
14
14
  hide_action :screen_layout, :embedded_app
15
15
  helper_method :screen_layout, :embedded_app
16
-
17
16
  rescue_from Exception, :with => :rtml_exception
17
+
18
+ # These are instance variables which will not be copied into RTML Actions or Widgets.
19
+ class_inheritable_array :rtml_protected_instance_variables
20
+ read_inheritable_attribute(:rtml_protected_instance_variables) ||
21
+ write_inheritable_attribute(:rtml_protected_instance_variables, %w(
22
+ @during_finalization_blocks @terminal_state @rtml_helpers @exception @rtml_document @_request
23
+ @render_proxy @real_format @update @template
24
+ ))
25
+ delegate :rtml_protected_instance_variables, :to => "self.class"
18
26
 
19
27
  def rtml_exception
20
28
  add_view_path(File.expand_path(File.join(Rtml.root, 'builtin/views')))
@@ -28,6 +36,8 @@ class RtmlController < (defined? Rails) ? ApplicationController : ActionControll
28
36
 
29
37
  if (params[:error_mode] == 'rtml' || rtml) && rtml_helpers.respond_to?(method)
30
38
  @exception = $!
39
+ Rails.logger.error $!.message
40
+ Rails.logger.error $!.backtrace.join("\n ")
31
41
  rtml_document.reset!
32
42
  erase_results
33
43
  render :rtml => method
@@ -50,6 +60,7 @@ class RtmlController < (defined? Rails) ? ApplicationController : ActionControll
50
60
  :controller => self)
51
61
  end
52
62
 
63
+
53
64
  protected
54
65
  def add_view_path(path)
55
66
  view_paths << path
@@ -3,15 +3,18 @@ class Rtml::Document < ActiveRecord::Base
3
3
  @@ruleset_file = File.expand_path(File.join(Rtml.root, "rails_generators/rtml/templates/config/tml_dom_ruleset.rb")) unless File.file?(@@ruleset_file)
4
4
  include Rtml::DSL
5
5
  include Rtml::Widgets
6
+ include Rtml::Assigns
6
7
  include ActionController::Layout
7
8
  layout :layout
8
9
 
9
10
  set_table_name 'rtml_documents'
10
- has_one :root, :class_name => 'Rtml::Dom::Element', :as => :parent, :autosave => true
11
+ attr_accessor :root
12
+ #has_one :root, :class_name => 'Rtml::Dom::Element', :as => :parent, :autosave => true
11
13
  has_many :instructions, :class_name => 'Rtml::Instruction', :as => :source, :autosave => true
12
14
  attr_reader :rules, :controller
13
15
  delegate :render, :view_paths, :view_paths=, :to => :view
14
16
  delegate :request, :response, :params, :flash, :to => :controller
17
+ serialize :options, HashWithIndifferentAccess
15
18
 
16
19
  validates_presence_of :name
17
20
  validates_uniqueness_of :name
@@ -19,30 +22,35 @@ class Rtml::Document < ActiveRecord::Base
19
22
  def initialize_with_default_document(attributes = nil)
20
23
  if attributes
21
24
  @controller = attributes.delete(:controller)
22
- @initialize_to_empty = attributes.delete(:empty)
23
25
  apply_document_options(attributes)
26
+ attributes.merge!(:options => { :initialize_to_empty => attributes.delete(:empty) })
24
27
  end
25
- initialize_without_default_document(attributes)
28
+ initialize_without_default_document(attributes ? attributes.with_indifferent_access : nil)
26
29
  end
27
30
 
28
31
  include Rtml::InheritedInstanceVariables
29
- protected_instance_variables.concat ["@controller", "@changed_attributes", "@view", "@new_record", "@initialize_to_empty", "@widget_instances", "@rules", "@root", "@attributes_cache", "@attributes"]
30
-
32
+ protected_instance_variables.concat %w(
33
+ @controller @changed_attributes @view @new_record @initialize_to_empty @widget_instances
34
+ @rules @root @attributes_cache @attributes @during_finalization_blocks @instructions @layout_file
35
+ )
36
+ alias_method_chain :initialize, :default_document
37
+
31
38
  def after_initialize
32
- @rules = Rtml::Document.rules
33
- if new_record? && !@initialize_to_empty
39
+ self.options ||= HashWithIndifferentAccess.new
40
+ @rules ||= Rtml::Document.rules
41
+ if !options[:initialize_to_empty]
34
42
  setup_default_document
35
43
  end
36
44
  end
37
45
 
38
- # This calls root.target, because root is technically an Association object, and target retrieves the actual object.
39
- # This resolves ambiguities such as root.build(), which exists as both an Association method (build a new root object)
40
- # and as a Widget method (build a new RTML Element).
41
- def root_with_target
42
- root_without_target.nil? ? nil : root_without_target.target
43
- end
44
-
45
- alias_method_chain :root, :target
46
+ # # This calls root.target, because root is technically an Association object, and target retrieves the actual object.
47
+ # # This resolves ambiguities such as root.build(), which exists as both an Association method (build a new root object)
48
+ # # and as a Widget method (build a new RTML Element).
49
+ # def root_with_target
50
+ # root_without_target.nil? ? nil : root_without_target.target
51
+ # end
52
+ #
53
+ # alias_method_chain :root, :target
46
54
 
47
55
  def layout(assignment = :_no_assignment)
48
56
  if assignment != :_no_assignment
@@ -93,12 +101,10 @@ class Rtml::Document < ActiveRecord::Base
93
101
  end
94
102
  end
95
103
 
96
- alias_method_chain :initialize, :default_document
97
-
98
104
  def reset!
99
105
  #elements.destroy_all
100
106
  #self.elements = []
101
- root.destroy if root
107
+ #root.destroy if root
102
108
  self.root = nil
103
109
  setup_default_document
104
110
  self
@@ -0,0 +1,6 @@
1
+ # A placeholder. In RTML, we often check whether an object is an instance of, say, ActiveRecord::Base.
2
+ # Since we may or may not back out ActiveRecord::Base, we need something to stand in as a superclass
3
+ # of all Widget-able models.
4
+ class Rtml::DocumentModelObject
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ class Rtml::Dom::Collections::ElementSet < Array
2
+ def destroy_all
3
+ each { |item| item.before_destroy if item.respond_to?(:before_destroy) }
4
+ clear
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ class Rtml::Dom::Collections::PropertySet < Array
2
+ def build(options)
3
+ self << (ret = Rtml::Dom::Property.new(options))
4
+ ret
5
+ end
6
+
7
+ def destroy_all
8
+ each { |item| item.before_destroy if item.respond_to?(:before_destroy) }
9
+ clear
10
+ end
11
+ end
@@ -1,24 +1,40 @@
1
- class Rtml::Dom::Element < ActiveRecord::Base
1
+ class Rtml::Dom::Element < Rtml::DocumentModelObject
2
2
  @@tml_ids = {}
3
- set_table_name 'rtml_dom_elements'
4
- belongs_to :document, :class_name => 'Rtml::Document'
5
- belongs_to :parent, :polymorphic => true#:class_name => 'Rtml::Dom::Element'
6
- has_many :elements, :class_name => 'Rtml::Dom::Element', :as => :parent, :autosave => true
7
- has_many :properties, :class_name => 'Rtml::Dom::Property', :foreign_key => 'element_id', :autosave => true
8
- #alias_method :children, :elements
3
+ # set_table_name 'rtml_dom_elements'
4
+ # belongs_to :document, :class_name => 'Rtml::Document'
5
+ # belongs_to :parent, :polymorphic => true#:class_name => 'Rtml::Dom::Element'
6
+ # has_many :elements, :class_name => 'Rtml::Dom::Element', :as => :parent, :autosave => true
7
+ # #has_many :properties, :class_name => 'Rtml::Dom::Property', :foreign_key => 'element_id', :autosave => true
9
8
  include Rtml::DSL
10
9
  include Rtml::Widgets
10
+ include Rtml::Assigns
11
11
 
12
12
  delegate :request, :response, :params, :flash, :controller, :to => :document
13
13
  delegate :params, :url_for, :to => :controller
14
14
 
15
+ attr_accessor :document, :parent, :elements
16
+ attr_writer :name
17
+
18
+ class_inheritable_array :rtml_protected_instance_variables
19
+ read_inheritable_attribute(:rtml_protected_instance_variables) || write_inheritable_attribute(:rtml_protected_instance_variables, %w(
20
+ @name @parent @during_finalization_blocks @properties @document @elements
21
+ ))
22
+
23
+ def properties
24
+ @properties ||= Rtml::Dom::Collections::PropertySet.new
25
+ end
26
+
15
27
  def initialize(*args) #:nodoc:
28
+ @elements = Rtml::Dom::Collections::ElementSet.new
16
29
  options = args.extract_options!
17
30
  options[:name] = options[:name].to_s if options.key?(:name)
18
31
  properties = options.delete(:properties)
19
- if options.empty? then super(options)
20
- else super options
21
- end
32
+ @name = options[:name]
33
+ @document = options[:document]
34
+ #if options.empty? then super(options)
35
+ #else super options
36
+ #end
37
+ after_initialize if respond_to?(:after_initialize)
22
38
  update_properties(properties) if properties
23
39
  end
24
40
 
@@ -32,7 +48,7 @@ class Rtml::Dom::Element < ActiveRecord::Base
32
48
  def rules; document ? document.rules : nil; end #:nodoc:
33
49
 
34
50
  def name #:nodoc:
35
- (s = super).kind_of?(String) ? s : s.to_s
51
+ @name.kind_of?(String) ? @name : @name.to_s
36
52
  end
37
53
 
38
54
  def contains?(query)
@@ -90,16 +106,28 @@ class Rtml::Dom::Element < ActiveRecord::Base
90
106
 
91
107
  # Produces the TML for this element and its children.
92
108
  def to_tml
93
- top = "#{name} #{properties_string}".strip
94
109
  # Going to add a comment here to make it easier for the user to find their junk in raw TML
95
110
  r = (property?('id') && !property('id').blank?) ? "<!--#{property('id')}-->".ljust(30) : ""
96
111
  if elements.empty?
97
- "#{r}<#{top} /> "
112
+ r + build_empty_tag
98
113
  else
99
- "#{r}<#{top}> \n#{elements.collect { |i| i.to_tml }.join("\n").indent}\n</#{name}>"
114
+ r + build_content_tag { elements.collect { |i| i.to_tml }.join("\n").indent }
100
115
  end
101
116
  end
102
117
 
118
+ # Produces an empty TML tag in the form of <tag_name [attributes] />
119
+ def build_empty_tag
120
+ top = "#{name} #{properties_string}".strip
121
+ "<#{top} /> "
122
+ end
123
+
124
+ # Produces a TML content tag in the form of <tag_name [attributes]>content</tag_name>
125
+ # Contents are specified as a block, which returns a string.
126
+ def build_content_tag
127
+ top = "#{name} #{properties_string}".strip
128
+ "<#{top}> \n#{yield}\n</#{name}>"
129
+ end
130
+
103
131
  # Produces the TML properties string for this element.
104
132
  # For instance, if this element has a property with name :next and value 'credit', this method will return:
105
133
  # "next=\"credit\""
@@ -133,25 +161,33 @@ class Rtml::Dom::Element < ActiveRecord::Base
133
161
  prop.value
134
162
  end
135
163
 
164
+ # Finds a property using properties#select rather than properties#find. Useful for when properties exist,
165
+ # but have not been added to the database.
166
+ def find_property(name)
167
+ name = name.to_s if !name.kind_of?(String)
168
+ properties.select { |prop| return prop if prop.name == name }
169
+ nil
170
+ end
171
+
136
172
  # Finds or adds a property for this element with the specified name
137
173
  def find_or_add_property(name, options={:drop_if_blank => true})
138
174
  options = {:value => options} unless options.kind_of?(Hash)
139
175
  prop = properties.select { |p| p.name == name.to_s }.first
140
176
  if prop
141
177
  if options.key?(:value)
142
- if prop.new_record? || prop.changed?
178
+ #if prop.new_record? || prop.changed?
143
179
  prop.value = options.delete(:value)
144
- else
145
- prop.update_attribute(:value, options.delete(:value))
146
- end
180
+ #else
181
+ # prop.update_attribute(:value, options.delete(:value))
182
+ #end
147
183
  end
148
184
  else
149
- if new_record? || changed?
185
+ #if new_record? || changed?
150
186
  prop = properties.build(:name => name.to_s, :value => options.delete(:value), :options => options.with_indifferent_access)
151
187
  prop.element = self
152
- else
153
- prop = properties.create!(:name => name.to_s, :value => options.delete(:value), :options => options.with_indifferent_access)
154
- end
188
+ #else
189
+ # prop = properties.create!(:name => name.to_s, :value => options.delete(:value), :options => options.with_indifferent_access)
190
+ #end
155
191
  #prop = Rtml::Dom::Property.new(:name => name.to_s, :element => self)
156
192
  #properties << prop
157
193
  #prop.options.merge!(options)
@@ -159,6 +195,14 @@ class Rtml::Dom::Element < ActiveRecord::Base
159
195
  prop
160
196
  end
161
197
 
198
+ def tml_id
199
+ if (prop = find_property('id')) && !prop.value.blank?
200
+ self.class.find_or_create_tml_id(prop.value)
201
+ else
202
+ nil
203
+ end
204
+ end
205
+
162
206
  class << self #:nodoc:
163
207
  ## STI hack; allows you to pass :type => 'SomeClassName' so that they're not all instances of Element
164
208
  def new_with_cast(*a, &b)
@@ -171,6 +215,15 @@ class Rtml::Dom::Element < ActiveRecord::Base
171
215
  end
172
216
  alias_method_chain :new, :cast
173
217
 
218
+ # Finds a pre-existing TML ID. Returns nil if it's not found.
219
+ def find_tml_id(rtml_name)
220
+ rtml_name = rtml_name.to_s
221
+ if @@tml_ids.key?(rtml_name)
222
+ return @@tml_ids[rtml_name]
223
+ end
224
+ nil
225
+ end
226
+
174
227
  # Some elements must have an "id" property according to the TML specification, and other elements must be able to
175
228
  # reference them by this ID. Unfortunately, according to the spec, the ID must not be greater than 12 characters long.
176
229
  # This is a decided disadvantage, so we're going to allow RTML developers to create elements with longer names and
@@ -178,14 +231,13 @@ class Rtml::Dom::Element < ActiveRecord::Base
178
231
  # need to be truncated. Also, they need a unique identifier attached to them in case the truncation results in
179
232
  # ambiguities with other screens. This method takes the specified name and processes it as mentioned, returning
180
233
  # this element's TML-ID counterpart.
181
- def lookup_tml_id(rtml_name)
182
- rtml_name = rtml_name.to_s
183
- if @@tml_ids.key?(rtml_name)
184
- return @@tml_ids[rtml_name]
234
+ def find_or_create_tml_id(rtml_name)
235
+ if tml_id = find_tml_id(rtml_name)
236
+ return tml_id
185
237
  end
186
238
 
187
239
  next_tml_id = @@tml_ids.keys.length.to_s
188
- tmlid = rtml_name
240
+ tmlid = rtml_name.to_s
189
241
  @@tml_ids[rtml_name] =
190
242
  if tmlid.length > 12
191
243
  tmlid[0...(12-next_tml_id.length)] + next_tml_id