lolita 3.2.0.rc.3 → 3.2.0.rc.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.
@@ -15,6 +15,7 @@
15
15
  * All fields must have name as well as tabs must have type
16
16
 
17
17
  * Bug fixes
18
+ * Each hook call runs as new instance of Hooks::Runner
18
19
  * All classes fixed to work with both mongoid and AR
19
20
 
20
21
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.0.rc.3
1
+ 3.2.0.rc.4
@@ -32,7 +32,7 @@ $(function(){
32
32
  })
33
33
  // All tabs are closable when clicked on tab title.
34
34
  $(".tab .tab-title.grey").live('click',function(){
35
- $(this).parent().toggleClass("minimized")
35
+ $(this).parent().toggleClass("minimized").trigger("tab.toggle")
36
36
  })
37
37
  // Integer field validator
38
38
  $(".integer").live("keydown",function(event){
@@ -10,7 +10,7 @@
10
10
  <meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
11
11
 
12
12
  <title>Lolita</title><meta name="description" content=""><meta name="author" content="">
13
- <link rel="shortcut icon" href="/favicon.ico">
13
+ <link rel="shortcut icon" href="/lolita/favicon.ico">
14
14
 
15
15
  <%= stylesheet_link_tag "lolita/application.css" %>
16
16
  <%= yield :style %>
@@ -70,7 +70,7 @@ module Lolita
70
70
  def output_with_callbacks(partial_name,name,locals)
71
71
  @component_locals ||={}
72
72
  @component_locals[name] = locals
73
-
73
+
74
74
  output = Lolita::Hooks.component(name).run(:before,:run_scope => self).to_s
75
75
  block_output = Lolita::Hooks.component(name).run(:around, :run_scope => self) do
76
76
  render(:partial => partial_name,:locals=>locals)
@@ -59,6 +59,126 @@ module Lolita
59
59
  # ==Named hooks
60
60
  # See Lolita::Hooks::NamedHook for details.
61
61
  module Hooks
62
+ class Runner
63
+
64
+ attr_accessor :hooks_run_scope, :given_callback_content
65
+ attr_writer :hooks_scope
66
+
67
+ def initialize(hook_class,hook_name, options)
68
+ @hook_class = hook_class
69
+ @hook_name = hook_name
70
+ @options = options
71
+ end
72
+
73
+ # Hooks scope is used to execute callbacks. By default it is class itself.
74
+ def hooks_scope
75
+ @hooks_scope || @hook_class
76
+ end
77
+
78
+ def run(&block)
79
+ result = nil
80
+ in_hooks_scope(@options[:scope],@options[:run_scope]) do
81
+ callback = get_callback(@hook_name)
82
+ result = run_callback(callback,&block)
83
+ end
84
+ result
85
+ end
86
+
87
+ # Call callback block inside of run block.
88
+ # ====Example
89
+ # MyClass.run(:before_save) do
90
+ # do_stuff
91
+ # let_content # execute callback block(-s) in same scope as run is executed.
92
+ # end
93
+ def let_content
94
+ if self.given_callback_content.respond_to?(:call)
95
+ run_block(self.given_callback_content)
96
+ elsif self.given_callback_content
97
+ self.given_callback_content
98
+ end
99
+ end
100
+
101
+ protected
102
+
103
+ # Switch between self and given <em>scope</em>. Block will be executed with <em>scope</em>.
104
+ # And after that it will switch back to self.
105
+ def in_hooks_scope(scope,run_scope=nil)
106
+ begin
107
+ this = self
108
+ self.hooks_scope=scope || @hook_class
109
+ self.hooks_scope.define_singleton_method(:let_content) do
110
+ this.let_content
111
+ end
112
+ if run_scope
113
+ run_scope.define_singleton_method(:let_content) do
114
+ this.let_content
115
+ end
116
+ end
117
+ self.hooks_run_scope = run_scope || self.hooks_scope
118
+ yield
119
+ ensure
120
+ self.hooks_scope = @hook_class
121
+ self.hooks_run_scope = self.hooks_scope
122
+ end
123
+ end
124
+
125
+ # Return all callbacks
126
+ # If scope is not class then it merge class callbacks with scope callbacks. That means that
127
+ # class callbacks always will be called before scope callbacks.
128
+ def get_callback(name)
129
+ scope_callbacks = hooks_scope.callbacks[name.to_sym] || {}
130
+
131
+ @hook_class.superclasses.each do |const_name|
132
+ scope_callbacks = @hook_class.collect_callbacks_from(name,const_name,scope_callbacks)
133
+ end
134
+ scope_callbacks
135
+ end
136
+
137
+ # Run callback. Each callback is Hash with <i>:methods</i> Array and </i>:blocks</i> Array
138
+ def run_callback(callback,&block)
139
+ method_results=run_methods(callback[:methods],&block)
140
+ block_results=run_blocks(callback[:blocks],&block)
141
+ method_results+block_results
142
+ end
143
+
144
+ # Run methods from <em>methods</em> Array
145
+ def run_methods methods, &block
146
+ result = ""
147
+ (methods||[]).each do |method_name|
148
+ result << (hooks_run_scope.__send__(method_name,&block)).to_s
149
+ end
150
+ result
151
+ end
152
+
153
+ # Run blocks from <em>blocks</em> Array. Also it set #given_callback_content if block is given, this
154
+ # will allow to call #let_content. Each block is runned with #run_block.
155
+ # After first run result of first block become #given_callback_content, and when next block
156
+ # call #let_content, this string will be returned for that block
157
+ def run_blocks blocks,&given_block
158
+ result=""
159
+
160
+ self.given_callback_content=block_given? ? given_block : nil
161
+
162
+ if blocks && !blocks.empty?
163
+ blocks.each do |block|
164
+ result << (run_block(block,&given_block)).to_s
165
+ self.given_callback_content=result
166
+ end
167
+ elsif block_given?
168
+ self.given_callback_content=nil
169
+ result << run_block(given_block).to_s
170
+ end
171
+ result
172
+ end
173
+
174
+ # Run block in scope.
175
+ def run_block block, &given_block
176
+ hooks_run_scope.instance_eval(&block)
177
+ end
178
+
179
+
180
+ end # end of Runner
181
+
62
182
  def self.included(base)
63
183
  base.extend(ClassMethods)
64
184
  base.extend(CommonMethods)
@@ -92,28 +212,14 @@ module Lolita
92
212
  end
93
213
 
94
214
  module ClassMethods
95
- attr_accessor :hooks_run_scope
96
-
97
- # Setter for #hook_scope.
98
- def hooks_scope=(object)
99
- @hooks_scope=object
100
- end
101
215
 
102
- # Hooks scope is used to execute callbacks. By default it is class itself.
103
- def hooks_scope
104
- @hooks_scope||self
216
+ def hooks_scope=(value)
217
+ @hooks_scope = value
105
218
  end
106
219
 
107
- # Setter for #callback_content
108
- def given_callback_content=(content)
109
- @given_callback_content=content
220
+ def hooks_scope
221
+ @hooks_scope || self
110
222
  end
111
-
112
- # Callback content is used to let callback content executed insede of run block.
113
- def given_callback_content
114
- @given_callback_content
115
- end
116
-
117
223
  # All hooks for class. This is Array of hook names.
118
224
  def hooks
119
225
  @hooks||=[]
@@ -163,6 +269,15 @@ module Lolita
163
269
  }
164
270
  end
165
271
 
272
+ def in_hooks_scope(scope)
273
+ begin
274
+ self.hooks_scope = scope
275
+ yield
276
+ ensure
277
+ self.hooks_scope = self
278
+ end
279
+ end
280
+
166
281
  # run is used to execute callback. Method accept one or more <i>hook_names</i> and optional block.
167
282
  # It will raise error if hook don't exist for this class. Also it accept <em>:scope</em> options, that
168
283
  # is used to #get_callbacks and #run_callbacks.
@@ -171,16 +286,10 @@ module Lolita
171
286
  # # this will call callbacks in MyClass instance scope, that means that self will be MyClass instance.
172
287
  def run(hook_name,*args,&block)
173
288
 
174
- result=nil
175
289
  options=args ? args.extract_options! : {}
176
-
177
290
  raise Lolita::HookNotFound, "Hook #{hook_name} is not defined for #{self}." unless self.has_hook?(hook_name)
178
- in_hooks_scope(options[:scope],options[:run_scope]) do
179
- callback=get_callback(hook_name)
180
- result=run_callback(callback,&block)
181
- end
182
-
183
- result
291
+ runner = Lolita::Hooks::Runner.new(self,hook_name,options)
292
+ runner.run(&block)
184
293
  end
185
294
 
186
295
  # Is hook with <em>name</em> is defined for class.
@@ -196,20 +305,6 @@ module Lolita
196
305
  end
197
306
  end
198
307
 
199
- # Call callback block inside of run block.
200
- # ====Example
201
- # MyClass.run(:before_save) do
202
- # do_stuff
203
- # let_content # execute callback block(-s) in same scope as run is executed.
204
- # end
205
- def let_content
206
- if self.given_callback_content.respond_to?(:call)
207
- run_block(self.given_callback_content)
208
- elsif self.given_callback_content
209
- self.given_callback_content
210
- end
211
- end
212
-
213
308
  # Set #method_missing
214
309
  def recognize_hook_methods method_name, *args, &block
215
310
  if method_name.to_s.match(/^run_(\w+)/)
@@ -218,81 +313,6 @@ module Lolita
218
313
  end
219
314
  end
220
315
 
221
- protected
222
-
223
- # Switch between self and given <em>scope</em>. Block will be executed with <em>scope</em>.
224
- # And after that it will switch back to self.
225
- def in_hooks_scope(scope,run_scope=nil)
226
- begin
227
- self.hooks_scope=scope||self
228
- if run_scope
229
- run_scope.define_singleton_method(:let_content) do
230
- scope.let_content
231
- end
232
- end
233
- self.hooks_run_scope=run_scope || self.hooks_scope
234
- yield
235
- ensure
236
- self.hooks_scope=self
237
- self.hooks_run_scope=self.hooks_scope
238
- end
239
- end
240
-
241
- # Run callback. Each callback is Hash with <i>:methods</i> Array and </i>:blocks</i> Array
242
- def run_callback(callback,&block)
243
- method_results=run_methods(callback[:methods],&block)
244
- block_results=run_blocks(callback[:blocks],&block)
245
- method_results+block_results
246
- end
247
-
248
- # Run methods from <em>methods</em> Array
249
- def run_methods methods, &block
250
- result=""
251
- (methods||[]).each do |method_name|
252
- result << (hooks_run_scope.__send__(method_name,&block)).to_s
253
- end
254
- result
255
- end
256
-
257
- # Run blocks from <em>blocks</em> Array. Also it set #given_callback_content if block is given, this
258
- # will allow to call #let_content. Each block is runned with #run_block.
259
- # After first run result of first block become #given_callback_content, and when next block
260
- # call #let_content, this string will be returned for that block
261
- def run_blocks blocks,&given_block
262
- result=""
263
-
264
- self.given_callback_content=block_given? ? given_block : nil
265
-
266
- if blocks && !blocks.empty?
267
- blocks.each do |block|
268
- result << (run_block(block,&given_block)).to_s
269
- self.given_callback_content=result
270
- end
271
- elsif block_given?
272
- self.given_callback_content=nil
273
- result << run_block(given_block).to_s
274
- end
275
- result
276
- end
277
-
278
- # Run block in scope.
279
- def run_block block, &given_block
280
- hooks_run_scope.instance_eval(&block)
281
- end
282
-
283
- # Return all callbacks
284
- # If scope is not class then it merge class callbacks with scope callbacks. That means that
285
- # class callbacks always will be called before scope callbacks.
286
- def get_callback(name)
287
- scope_callbacks=hooks_scope.callbacks[name.to_sym] || {}
288
-
289
- superclasses.each do |const_name|
290
- scope_callbacks=collect_callbacks_from(name,const_name,scope_callbacks)
291
- end
292
- scope_callbacks
293
- end
294
-
295
-
296
316
  def collect_callbacks_from(name,const_name,scope_callbacks)
297
317
  class_callbacks=const_name.callbacks[name.to_sym] || {}
298
318
  [:methods,:blocks].each do |attr|
@@ -339,11 +359,6 @@ module Lolita
339
359
  self.class.run(*hook_names,options,&block)
340
360
  end
341
361
 
342
- # See Lolita::Hooks::ClassMethods#let_content
343
- def let_content
344
- self.class.let_content
345
- end
346
-
347
362
  # See Lolita::Hooks::ClassMethods#method_missing
348
363
  def method_missing(*args,&block)
349
364
  unless self.class.recognize_hook_methods(*args,:scope=>self,&block)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lolita"
8
- s.version = "3.2.0.rc.3"
8
+ s.version = "3.2.0.rc.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ITHouse (Latvia) and Arturs Meisters"]
12
- s.date = "2011-09-09"
12
+ s.date = "2011-10-04"
13
13
  s.description = "Great Rails CMS, that turns your business logic into good-looking, fully functional workspace. "
14
14
  s.email = "support@ithouse.lv"
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "README.md",
27
27
  "Rakefile",
28
28
  "VERSION",
29
+ "app/assets/images/lolita/favicon.ico",
29
30
  "app/assets/images/lolita/plus.png",
30
31
  "app/assets/javascripts/lolita/application.js",
31
32
  "app/assets/javascripts/lolita/base64.js",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolita
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0.rc.3
4
+ version: 3.2.0.rc.4
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-09 00:00:00.000000000Z
12
+ date: 2011-10-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &85967590 !ruby/object:Gem::Requirement
16
+ requirement: &76601680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *85967590
24
+ version_requirements: *76601680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: kaminari
27
- requirement: &85963300 !ruby/object:Gem::Requirement
27
+ requirement: &76600440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.12.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *85963300
35
+ version_requirements: *76600440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: abstract
38
- requirement: &85962920 !ruby/object:Gem::Requirement
38
+ requirement: &76599760 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *85962920
46
+ version_requirements: *76599760
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: builder
49
- requirement: &85962540 !ruby/object:Gem::Requirement
49
+ requirement: &76599090 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *85962540
57
+ version_requirements: *76599090
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: haml
60
- requirement: &85962140 !ruby/object:Gem::Requirement
60
+ requirement: &76598340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 3.1.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *85962140
68
+ version_requirements: *76598340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jquery-rails
71
- requirement: &85961800 !ruby/object:Gem::Requirement
71
+ requirement: &76597790 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *85961800
79
+ version_requirements: *76597790
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: tinymce-rails
82
- requirement: &85961450 !ruby/object:Gem::Requirement
82
+ requirement: &76597200 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *85961450
90
+ version_requirements: *76597200
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: jeweler
93
- requirement: &85961080 !ruby/object:Gem::Requirement
93
+ requirement: &76596670 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.5.2
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *85961080
101
+ version_requirements: *76596670
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rspec
104
- requirement: &85960610 !ruby/object:Gem::Requirement
104
+ requirement: &76596160 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 2.6.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *85960610
112
+ version_requirements: *76596160
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rspec-rails
115
- requirement: &85959250 !ruby/object:Gem::Requirement
115
+ requirement: &76595590 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 2.6.1
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *85959250
123
+ version_requirements: *76595590
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: factory_girl
126
- requirement: &85958850 !ruby/object:Gem::Requirement
126
+ requirement: &76533130 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *85958850
134
+ version_requirements: *76533130
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: ffaker
137
- requirement: &85957860 !ruby/object:Gem::Requirement
137
+ requirement: &76532330 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *85957860
145
+ version_requirements: *76532330
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: ruby-debug19
148
- requirement: &85956980 !ruby/object:Gem::Requirement
148
+ requirement: &76531520 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *85956980
156
+ version_requirements: *76531520
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: database_cleaner
159
- requirement: &85956420 !ruby/object:Gem::Requirement
159
+ requirement: &76530500 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,7 +164,7 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *85956420
167
+ version_requirements: *76530500
168
168
  description: ! 'Great Rails CMS, that turns your business logic into good-looking,
169
169
  fully functional workspace. '
170
170
  email: support@ithouse.lv
@@ -183,6 +183,7 @@ files:
183
183
  - README.md
184
184
  - Rakefile
185
185
  - VERSION
186
+ - app/assets/images/lolita/favicon.ico
186
187
  - app/assets/images/lolita/plus.png
187
188
  - app/assets/javascripts/lolita/application.js
188
189
  - app/assets/javascripts/lolita/base64.js
@@ -482,7 +483,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
482
483
  version: '0'
483
484
  segments:
484
485
  - 0
485
- hash: 675447699
486
+ hash: -235037699
486
487
  required_rubygems_version: !ruby/object:Gem::Requirement
487
488
  none: false
488
489
  requirements: