rlayout 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/CHANGELOG +3 -0
  2. data/Rakefile +1 -1
  3. data/lib/rlayout/model.rb +52 -22
  4. metadata +7 -11
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ Changes in version 0.5.2 (2009-4-20)
2
+ improve error handling
3
+
1
4
  Changes in version 0.5.1 (2009-3-9)
2
5
  support rails 2.3
3
6
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
3
  PKG_NAME = "rlayout"
4
- PKG_VERSION = "0.5.1"
4
+ PKG_VERSION = "0.5.2"
5
5
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
6
6
  PKG_FILES = FileList[
7
7
  '[A-Z]*',
data/lib/rlayout/model.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  =begin Rlayout
2
- author: Leon Li(scorpio_leon@hotmail.com)
2
+ # author: Leon Li(scorpio_leon@hotmail.com)
3
3
  =end
4
- #TODO support multi-model
4
+ # #TODO support multi-model
5
5
  require 'rlayout/common'
6
6
  module Rlayout
7
7
  module Model
@@ -16,12 +16,20 @@ module Rlayout
16
16
  execute_create
17
17
  create_success_callback if respond_to?(:create_success_callback)
18
18
  result = result[:success].dup
19
- result_type = result.delete(:type)
20
19
  rescue => e
21
- create_error_callback(e) if respond_to?(:create_error_callback)
22
- result = result[:error].dup
20
+ if respond_to?(:create_error_callback)
21
+ create_error_callback(e)
22
+ else
23
+ add_error e
24
+ end
25
+ if result[:error].present?
26
+ result = result[:error].dup
27
+ else
28
+ raise e
29
+ end
23
30
  end
24
31
  before_create_result if respond_to?(:before_create_result)
32
+ result_type = result.delete(:type)
25
33
  case result_type.to_s
26
34
  when 'redirect'
27
35
  redirect_to(self.class.parse_result(result, binding))
@@ -37,12 +45,20 @@ module Rlayout
37
45
  execute_update
38
46
  update_success_callback if respond_to?(:update_success_callback)
39
47
  result = result[:success].dup
40
- result_type = result.delete(:type)
41
48
  rescue => e
42
- update_error_callback(e) if respond_to?(:update_error_callback)
43
- result = result[:error].dup
49
+ if respond_to?(:update_error_callback)
50
+ update_error_callback(e)
51
+ else
52
+ add_error e
53
+ end
54
+ if result[:error].present?
55
+ result = result[:error].dup
56
+ else
57
+ raise e
58
+ end
44
59
  end
45
60
  before_update_result if respond_to?(:before_update_result)
61
+ result_type = result.delete(:type)
46
62
  case result_type.to_s
47
63
  when 'redirect'
48
64
  redirect_to(self.class.parse_result(result, binding))
@@ -58,12 +74,20 @@ module Rlayout
58
74
  execute_destroy
59
75
  destroy_success_callback if respond_to?(:destroy_success_callback)
60
76
  result = result[:success].dup
61
- result_type = result.delete(:type)
62
77
  rescue => e
63
- destroy_error_callback(e) if respond_to?(:destroy_error_callback)
64
- result = result[:error].dup
78
+ if respond_to?(:destroy_error_callback)
79
+ destroy_error_callback(e)
80
+ else
81
+ add_error e
82
+ end
83
+ if result[:error].present?
84
+ result = result[:error].dup
85
+ else
86
+ raise e
87
+ end
65
88
  end
66
89
  before_destroy_result if respond_to?(:before_destroy_result)
90
+ result_type = result.delete(:type)
67
91
  case result_type.to_s
68
92
  when 'redirect'
69
93
  redirect_to(self.class.parse_result(result, binding))
@@ -73,8 +97,15 @@ module Rlayout
73
97
  end
74
98
 
75
99
  protected
100
+
101
+ def add_error(error=nil)
102
+ flash[:error] ||= []
103
+ flash[:error] = [flash[:error]] unless flash[:error].is_a?(Array)
104
+ flash[:error] << (error || $!.to_s)
105
+ end
106
+
76
107
  def find_model_by_id
77
- self.class.get_model_class.find(params[:id])
108
+ self.class.get_model_class.find(params[:id])
78
109
  end
79
110
 
80
111
  def need_model?
@@ -88,7 +119,7 @@ module Rlayout
88
119
  false
89
120
  else
90
121
  model_require_options = self.class.get_model_require_options
91
- #TODO use regex
122
+ # #TODO use regex
92
123
  if model_require_options && model_require_options[:except] && model_require_options[:except].include?(@action_name_sym)
93
124
  false
94
125
  else
@@ -115,7 +146,7 @@ module Rlayout
115
146
  params_key = self.class.get_full_model_name.gsub(/\//, "_").to_sym
116
147
  @model.attributes=params[params_key] unless @model.nil? || params[params_key].nil?
117
148
  end
118
- #bind @model to @#{self.class.get_model_name}
149
+ # #bind @model to @#{self.class.get_model_name}
119
150
  instance_variable_set("@#{self.class.get_model_name}", @model)
120
151
  else
121
152
  @model = instance_variable_get("@#{self.class.get_model_name}")
@@ -124,7 +155,7 @@ module Rlayout
124
155
  end
125
156
 
126
157
  def model?
127
- @model_exists = (@model && @model.id) if @model_exists.nil?
158
+ @model_exists = (@model && @model.id) if @model_exists.nil?
128
159
  end
129
160
 
130
161
  def execute_create
@@ -165,7 +196,7 @@ module Rlayout
165
196
  end
166
197
 
167
198
  def get_model_require
168
- @model_require
199
+ @model_require
169
200
  end
170
201
  def get_model_require_options
171
202
  @model_require_options
@@ -179,8 +210,7 @@ module Rlayout
179
210
  @need_model = need
180
211
  end
181
212
 
182
- # get the model_name
183
- # override this if the model's name is special
213
+ # get the model_name override this if the model's name is special
184
214
  def get_model_name
185
215
  @model_name ||= self.class_simple_name.underscore[0..-12].singularize
186
216
  end
@@ -199,17 +229,17 @@ module Rlayout
199
229
  @model_full_name = model_class.class_full_name.underscore
200
230
  end
201
231
 
202
- #inheritable
232
+ # #inheritable
203
233
  def get_default_results
204
234
  read_inheritable_attribute("default_results") || {}
205
235
  end
206
236
 
207
- #inheritable
237
+ # #inheritable
208
238
  def set_default_result(hash)
209
239
  write_inheritable_hash("default_results", hash)
210
240
  end
211
241
 
212
- #inheritable
242
+ # #inheritable
213
243
  def default_create_result(hash)
214
244
  set_default_result(:create => hash)
215
245
  end
@@ -218,7 +248,7 @@ module Rlayout
218
248
  end
219
249
  def default_destroy_result(hash)
220
250
  set_default_result(:destroy => hash)
221
- end
251
+ end
222
252
 
223
253
  def set_action_result(hash)
224
254
  @action_results ||= {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rlayout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Li
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-09 00:00:00 +08:00
12
+ date: 2009-05-12 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: improve rails layout such as simplifying content_for usage and let erb file can determine layout
16
+ description: " improve rails layout such as simplifying content_for usage and let erb file can determine layout\n"
17
17
  email: scorpio_leon@hotmail.com
18
18
  executables: []
19
19
 
@@ -26,7 +26,6 @@ files:
26
26
  - Rakefile
27
27
  - CHANGELOG
28
28
  - README
29
- - lib/rlayout
30
29
  - lib/rlayout/model.rb
31
30
  - lib/rlayout/template.rb
32
31
  - lib/rlayout/layout.rb
@@ -36,19 +35,16 @@ files:
36
35
  - lib/rlayout.rb
37
36
  - lib/rlayout_controller.rb
38
37
  - lib/rlayout_layout.rb
39
- - example/templates
40
- - example/templates/simple
41
38
  - example/templates/simple/common.html.erb
42
- - example/templates/xhtml
43
39
  - example/templates/xhtml/controlfooter.html.erb
44
40
  - example/templates/xhtml/common.html.erb
45
41
  - example/templates/xhtml/controlheader.html.erb
46
- - example/templates/simple_mce
47
42
  - example/templates/simple_mce/text_area.html.erb
48
- - example/templates/xhtml_mce
49
43
  - example/templates/xhtml_mce/text_area.html.erb
50
44
  has_rdoc: false
51
45
  homepage: http://rlayout.rubyforge.org/
46
+ licenses: []
47
+
52
48
  post_install_message:
53
49
  rdoc_options: []
54
50
 
@@ -69,9 +65,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
65
  requirements: []
70
66
 
71
67
  rubyforge_project: Rails Layout Extension
72
- rubygems_version: 1.3.1
68
+ rubygems_version: 1.3.2
73
69
  signing_key:
74
- specification_version: 2
70
+ specification_version: 3
75
71
  summary: improve rails layout such as simplifying content_for usage and let erb file can determine layout
76
72
  test_files: []
77
73