right-rails 1.0.3 → 1.0.5

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 (36) hide show
  1. data/CHANGELOG +8 -2
  2. data/Rakefile +28 -28
  3. data/lib/right_rails/java_script_generator.rb +59 -51
  4. data/public/images/{colorpicker.png → rightjs-ui/colorpicker.png} +0 -0
  5. data/public/images/{resizable.png → rightjs-ui/resizable.png} +0 -0
  6. data/public/javascripts/right-olds-src.js +47 -46
  7. data/public/javascripts/right-safe-src.js +103 -102
  8. data/public/javascripts/right-safe.js +1 -1
  9. data/public/javascripts/right-src.js +611 -541
  10. data/public/javascripts/right.js +86 -85
  11. data/public/javascripts/right/autocompleter-src.js +81 -77
  12. data/public/javascripts/right/autocompleter.js +1 -1
  13. data/public/javascripts/right/calendar-src.js +209 -197
  14. data/public/javascripts/right/calendar.js +6 -6
  15. data/public/javascripts/right/colorpicker-src.js +127 -117
  16. data/public/javascripts/right/colorpicker.js +6 -6
  17. data/public/javascripts/right/dnd-src.js +63 -63
  18. data/public/javascripts/right/dnd.js +2 -2
  19. data/public/javascripts/right/in-edit-src.js +53 -48
  20. data/public/javascripts/right/in-edit.js +2 -2
  21. data/public/javascripts/right/lightbox-src.js +107 -99
  22. data/public/javascripts/right/lightbox.js +2 -2
  23. data/public/javascripts/right/rater-src.js +48 -46
  24. data/public/javascripts/right/rater.js +3 -3
  25. data/public/javascripts/right/resizable-src.js +53 -61
  26. data/public/javascripts/right/resizable.js +4 -4
  27. data/public/javascripts/right/selectable-src.js +97 -95
  28. data/public/javascripts/right/selectable.js +2 -2
  29. data/public/javascripts/right/slider-src.js +47 -45
  30. data/public/javascripts/right/slider.js +8 -8
  31. data/public/javascripts/right/sortable-src.js +54 -52
  32. data/public/javascripts/right/tabs-src.js +181 -171
  33. data/public/javascripts/right/tooltip-src.js +39 -37
  34. data/public/javascripts/right/uploader-src.js +21 -19
  35. data/spec/lib/right_rails/java_script_generator_spec.rb +61 -56
  36. metadata +9 -7
data/CHANGELOG CHANGED
@@ -1,10 +1,16 @@
1
+ 2010-09-20 Nikolay Nemshilov
2
+ o Version 1.0.4
3
+ * RightJS 2.0.0 release updates
4
+ * page.document now returns '$(document)'
5
+ * page.window now returns '$(window)'
6
+
1
7
  2010-09-06 Nikolay Nemshilov
2
8
  o Version 1.0.0
3
9
  * RightJS v2.0.0-rc2
4
10
  * All new RightJS UI 2.0 widgets
5
11
  * RightRails configuration interface
6
12
  * Full Rails 3 support
7
-
13
+
8
14
 
9
15
  2010-01-16 Nikolay V. Nemshilov aka St.
10
16
  o Version 0.4.4
@@ -13,7 +19,7 @@
13
19
  * Updated JSON and Events
14
20
  * New in-place edit plugin
15
21
  * Dutch i18n module
16
-
22
+
17
23
 
18
24
  2009-12-26 Nikolay V. Nemshilov aka St.
19
25
  o Version 0.4.3
data/Rakefile CHANGED
@@ -48,15 +48,15 @@ end
48
48
  #
49
49
  namespace :rjs do
50
50
  CURRENT_DIR = File.dirname(__FILE__)
51
-
51
+
52
52
  OUTPUT_DIR = CURRENT_DIR + '/public'
53
53
  OUTPUT_JSS_DIR = OUTPUT_DIR + "/javascripts"
54
- OUTPUT_IMG_DIR = OUTPUT_DIR + "/images"
55
-
54
+ OUTPUT_IMG_DIR = OUTPUT_DIR + "/images/rightjs-ui"
55
+
56
56
  RIGHTJS_CORE_DIR = CURRENT_DIR + '/../RightJS'
57
57
  RIGHTJS_PLUGINS_DIR = CURRENT_DIR + '/../RightJSPlugins'
58
58
  RIGHTJS_UI_DIR = CURRENT_DIR + '/../RightJSUI'
59
-
59
+
60
60
  desc 'Builds all the RightJS files and tosses them into the directories'
61
61
  task :build do
62
62
  Rake::Task['rjs:nuke'].invoke
@@ -67,26 +67,26 @@ namespace :rjs do
67
67
  Rake::Task['rjs:i18n'].invoke
68
68
  Rake::Task['rjs:toss'].invoke
69
69
  end
70
-
70
+
71
71
  desc 'Nukes the RightJS sources directory'
72
72
  task :nuke do
73
73
  require 'fileutils'
74
-
74
+
75
75
  puts "\e[31m<<<<<<<<<<<<< TERMAL CLEANING >>>>>>>>>>>>>>>>>\e[0m"
76
-
76
+
77
77
  FileUtils.rm_rf OUTPUT_DIR if File.exists? OUTPUT_DIR
78
78
  FileUtils.mkdir_p OUTPUT_DIR
79
79
  FileUtils.mkdir_p OUTPUT_IMG_DIR
80
80
  FileUtils.mkdir_p OUTPUT_JSS_DIR
81
81
  FileUtils.mkdir_p OUTPUT_JSS_DIR + "/right"
82
-
82
+
83
83
  puts "\e[32mDONE \e[0m"
84
84
  end
85
-
85
+
86
86
  desc 'Builds RightJS core and copies them in place'
87
87
  task :'build:core' do
88
88
  puts "\e[31m<<<<<<<<<<<< BUILDING THE CORE >>>>>>>>>>>>>>>>\e[0m"
89
-
89
+
90
90
  system(%Q{
91
91
  cd #{RIGHTJS_CORE_DIR};
92
92
  rake build OPTIONS=no-olds;
@@ -94,49 +94,49 @@ namespace :rjs do
94
94
  rake build OPTIONS=safe;
95
95
  cp build/right-safe*.js #{OUTPUT_JSS_DIR};
96
96
  })
97
-
97
+
98
98
  puts "\e[32mDONE \e[0m"
99
99
  end
100
-
100
+
101
101
  desc 'Builds RightJS plugins and copies them in place'
102
102
  task :'build:plugins' do
103
103
  puts "\e[31m<<<<<<<<<<<<< BUILDING PLUGINS >>>>>>>>>>>>>>>>>\e[0m"
104
-
104
+
105
105
  system(%Q{
106
106
  cd #{RIGHTJS_PLUGINS_DIR};
107
107
  rake build;
108
108
  cp build/*.js #{OUTPUT_JSS_DIR}/right;
109
109
  })
110
-
110
+
111
111
  puts "\e[32mDONE \e[0m"
112
112
  end
113
-
113
+
114
114
  desc 'Builds RightJS UI modules and copies them in place'
115
115
  task :'build:ui' do
116
116
  puts "\e[31m<<<<<<<<<<< BUILDING UI MODULES >>>>>>>>>>>>>>>\e[0m"
117
-
117
+
118
118
  system(%Q{
119
119
  cd #{RIGHTJS_UI_DIR};
120
120
  rake build;
121
121
  cp build/*.js #{OUTPUT_JSS_DIR}/right;
122
122
  })
123
-
123
+
124
124
  system(%Q{
125
125
  cd #{RIGHTJS_UI_DIR};
126
126
  cp img/* #{OUTPUT_IMG_DIR};
127
127
  })
128
-
128
+
129
129
  puts "\e[32mDONE \e[0m"
130
130
  end
131
-
131
+
132
132
  desc 'Patches the RightJS UI modules for the Rails directories structure'
133
133
  task :'patch' do
134
134
  puts "\e[31m<<<<<<< PATCHING UI MODULES FOR RAILS >>>>>>>>>\e[0m"
135
-
135
+
136
136
  FileList["#{OUTPUT_JSS_DIR}/right/*.js"].each do |filename|
137
137
  old_content = File.read(filename)
138
138
  new_content = old_content.gsub('url(../../img/', "url(/images/rightjs-ui/")
139
-
139
+
140
140
  if old_content != new_content
141
141
  puts "Patching: #{File.basename(filename)}"
142
142
  File.open(filename, "w") do |f|
@@ -144,29 +144,29 @@ namespace :rjs do
144
144
  end
145
145
  end
146
146
  end
147
-
147
+
148
148
  puts "\e[32mDONE \e[0m"
149
149
  end
150
-
150
+
151
151
  desc 'Copies the RightJS UI i18n modules in place'
152
152
  task :i18n do
153
153
  puts "\e[31m<<<<<<<<<<< COPYING I18N MODULES >>>>>>>>>>>>>>\e[0m"
154
-
154
+
155
155
  system(%Q{
156
156
  cp -r #{RIGHTJS_UI_DIR}/i18n #{OUTPUT_JSS_DIR}/right;
157
157
  })
158
-
158
+
159
159
  puts "\e[32mDONE \e[0m"
160
160
  end
161
-
161
+
162
162
  desc 'Prepares the files as they will be placed in Rails'
163
163
  task :toss do
164
164
  puts "\e[31m<<<<<<<<< PREPARING FILES FOR RAILS >>>>>>>>>>>\e[0m"
165
-
165
+
166
166
  FileList["#{OUTPUT_JSS_DIR}/right/right-*.js"].each do |filename|
167
167
  system "mv #{filename.gsub('/right/right-', '/right/{right-,}')}"
168
168
  end
169
-
169
+
170
170
  puts "\e[32mDONE \e[0m"
171
171
  end
172
172
  end
@@ -2,14 +2,14 @@
2
2
  # The right-rails scripts generator
3
3
  #
4
4
  class RightRails::JavaScriptGenerator
5
-
5
+
6
6
  def initialize(template, thread=nil)
7
7
  @util = Util.new(template, thread)
8
8
  end
9
-
9
+
10
10
  # the top-level constants that the generator should respond to transparently
11
- JS_CONSTANTS = [:document, :window, :top, :RR]
12
-
11
+ JS_CONSTANTS = [:top, :RR]
12
+
13
13
  # method calls catchup
14
14
  def method_missing(name, *args)
15
15
  cmd = if JS_CONSTANTS.include?(name)
@@ -19,15 +19,15 @@ class RightRails::JavaScriptGenerator
19
19
  else
20
20
  "#{name}(#{@util.to_js_args(args)})"
21
21
  end
22
-
22
+
23
23
  @util.record(cmd)
24
24
  end
25
-
25
+
26
26
  # returns the result script
27
27
  def to_s
28
28
  @util.build_script
29
29
  end
30
-
30
+
31
31
  #
32
32
  # This module contains the predefined methods collection
33
33
  #
@@ -58,15 +58,23 @@ class RightRails::JavaScriptGenerator
58
58
  @util.record("var #{name}=#{@util.to_js_type(value)}")
59
59
  end
60
60
 
61
+ def document
62
+ @util.record('$(document)')
63
+ end
64
+
65
+ def window
66
+ @util.record('$(window)')
67
+ end
68
+
61
69
  # generates the redirection script
62
70
  def redirect_to(location)
63
- self.document[:location].href = (location.is_a?(String) ? location : @util.template.url_for(location))
71
+ self.get(:document)[:location].href = (location.is_a?(String) ? location : @util.template.url_for(location))
64
72
  self
65
73
  end
66
74
 
67
75
  # generates the page reload script
68
76
  def reload
69
- self.document[:location].reload
77
+ self.get(:document)[:location].reload
70
78
  self
71
79
  end
72
80
 
@@ -74,7 +82,7 @@ class RightRails::JavaScriptGenerator
74
82
  def insert(record, position=nil)
75
83
  self.RR.insert(*[record.class.table_name, @util.render(record), position].compact)
76
84
  end
77
-
85
+
78
86
  # generates a script that inserts the record partial, then updates the form and the flashes block
79
87
  def insert_and_care(record, position=nil)
80
88
  insert(record, position)
@@ -108,93 +116,93 @@ class RightRails::JavaScriptGenerator
108
116
  def replace_form_for(record)
109
117
  self.RR.replace_form(@util.form_id_for(record), @util.render('form'))
110
118
  end
111
-
119
+
112
120
  # updates the flashes block
113
121
  def update_flash(content=nil)
114
122
  self.RR.update_flash(content || @util.template.flashes)
115
123
  @util.template.flash.clear
116
124
  end
117
125
  end
118
-
126
+
119
127
  include Methods
120
-
128
+
121
129
  protected
122
130
 
123
131
  #
124
132
  # Keeps the javascript method calls sequence and then represents iteslf like a string of javascript
125
133
  #
126
134
  class MethodCall
127
-
135
+
128
136
  def initialize(this, util, parent)
129
137
  @this = this
130
138
  @util = util
131
139
  @parent = parent
132
140
  end
133
-
141
+
134
142
  # catches the properties request
135
143
  def [](name)
136
144
  @child = @util.make_call(".#{name}", self)
137
145
  end
138
-
146
+
139
147
  # attribute assignment hook
140
148
  def []=(name, value)
141
149
  send "#{name}=", value
142
150
  end
143
-
151
+
144
152
  OPERATIONS = %w{+ - * / % <<}
145
-
153
+
146
154
  # catches all the method calls
147
155
  def method_missing(name, *args, &block)
148
156
  name = name.to_s
149
157
  args << block if block_given?
150
-
151
-
158
+
159
+
152
160
  cmd = if name[name.size-1, name.size] == '='
153
161
  # assignments
154
162
  ".#{name[0,name.size-1]}=#{@util.to_js_type(args.first)}"
155
-
163
+
156
164
  # operation calls
157
165
  elsif OPERATIONS.include?(name)
158
166
  name = "+=" if name == '<<'
159
167
  "#{name}#{@util.to_js_type(args.first)}"
160
-
168
+
161
169
  # usual method calls
162
170
  else
163
171
  ".#{name}(#{@util.to_js_args(args)})"
164
172
  end
165
-
173
+
166
174
  @child = @util.make_call(cmd, self)
167
175
  end
168
-
176
+
169
177
  # exports the whole thing into a javascript string
170
178
  def to_s
171
179
  nodes = []
172
180
  node = self
173
-
181
+
174
182
  while node
175
183
  nodes << node
176
184
  node = node.instance_variable_get(@parent.nil? ? "@child" : "@parent")
177
185
  end
178
-
186
+
179
187
  # reversing the calls list if building from the right end
180
188
  nodes.reverse! unless @parent.nil?
181
-
189
+
182
190
  nodes.collect{|n| n.instance_variable_get("@this").to_s }.join('')
183
191
  end
184
192
  end
185
-
193
+
186
194
  #
187
195
  # We use this class to cleanup the main namespace of the JavaScriptGenerator instances
188
196
  # So that the mesod_missing didn't interferate with the util methods
189
197
  #
190
198
  class Util
191
199
  attr_reader :template
192
-
200
+
193
201
  def initialize(template, thread=nil)
194
202
  @template = template
195
203
  @thread = thread || []
196
204
  end
197
-
205
+
198
206
  # returns a conventional dom id for the record
199
207
  def dom_id(record)
200
208
  if [String, Symbol].include?(record.class)
@@ -203,7 +211,7 @@ protected
203
211
  @template.dom_id(record)
204
212
  end
205
213
  end
206
-
214
+
207
215
  # generates the form-id for the given record
208
216
  def form_id_for(record)
209
217
  record.new_record? ? "new_#{record.class.table_name.singularize}" : "edit_#{dom_id(record)}"
@@ -213,29 +221,29 @@ protected
213
221
  def render(what)
214
222
  @template.render(what)
215
223
  end
216
-
224
+
217
225
  # builds a new method call object
218
226
  def make_call(string, parent=nil)
219
227
  MethodCall.new(string, self, parent)
220
228
  end
221
-
229
+
222
230
  # Records a new call
223
231
  def record(command)
224
232
  @thread << (line = make_call(command))
225
233
  line
226
234
  end
227
-
235
+
228
236
  # writes a pline script code into the thread
229
237
  def write(script)
230
238
  @thread << script
231
239
  end
232
-
240
+
233
241
  # builds the end script
234
242
  def build_script
235
243
  list = @thread.collect do |line|
236
244
  line.is_a?(String) ? line : (line.to_s + ';')
237
245
  end
238
-
246
+
239
247
  list.join('')
240
248
  end
241
249
 
@@ -244,10 +252,10 @@ protected
244
252
  list = args.collect do |value|
245
253
  to_js_type(value)
246
254
  end
247
-
255
+
248
256
  list.join(',')
249
257
  end
250
-
258
+
251
259
  # converts any ruby type into an javascript type
252
260
  def to_js_type(value)
253
261
  case value.class.name.to_sym
@@ -256,7 +264,7 @@ protected
256
264
  when :Array then "[#{to_js_args(value)}]"
257
265
  when :Proc then proc_to_function(&value)
258
266
  else
259
-
267
+
260
268
  # the other method-calls processing
261
269
  if value.is_a?(MethodCall)
262
270
  # removing the call out of the calls thread
@@ -267,13 +275,13 @@ protected
267
275
  parent = parent.instance_variable_get('@parent')
268
276
  end
269
277
  @thread.reject!{ |item| item == top }
270
-
278
+
271
279
  value.to_s
272
-
280
+
273
281
  # converting all sorts of strings
274
282
  elsif value.is_a?(String)
275
283
  "\"#{@template.escape_javascript(value)}\""
276
-
284
+
277
285
  # simple hashes processing
278
286
  elsif value.is_a?(Hash)
279
287
  pairs = []
@@ -281,18 +289,18 @@ protected
281
289
  pairs << "#{to_js_type(key)}:#{to_js_type(value)}"
282
290
  end
283
291
  "{#{pairs.sort.join(',')}}"
284
-
292
+
285
293
  # JSON exportable values processing
286
294
  elsif value.respond_to?(:to_json)
287
295
  to_js_type(value.to_json)
288
-
296
+
289
297
  # throwing an ansupported class name
290
298
  else
291
299
  throw "RightRails::JavaScriptGenerator doesn't support instances of #{value.class.name} yet"
292
300
  end
293
301
  end
294
302
  end
295
-
303
+
296
304
  # converts a proc into a javascript function
297
305
  def proc_to_function(&block)
298
306
  thread = []
@@ -300,24 +308,24 @@ protected
300
308
  names = []
301
309
  name = 'a'
302
310
  page = RightRails::JavaScriptGenerator.new(@template, thread)
303
-
311
+
304
312
  block.arity.times do |i|
305
313
  args << page.get(name)
306
314
  names << name
307
315
  name = name.succ
308
316
  end
309
-
317
+
310
318
  # swapping the current thread with the block's one
311
319
  old_thread = @thread
312
320
  @thread = thread
313
-
321
+
314
322
  yield(*args)
315
-
323
+
316
324
  # swapping the current therad back
317
325
  @thread = old_thread
318
-
326
+
319
327
  "function(#{names.join(',')}){#{page.to_s}}"
320
328
  end
321
329
  end
322
-
330
+
323
331
  end