maiha-mjs 0.0.3 → 0.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.
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ AUTHOR = "maiha"
9
9
  EMAIL = "maiha@wota.jp"
10
10
  HOMEPAGE = "http://github.com/maiha/mjs"
11
11
  SUMMARY = "A slice for the Merb framework that offers Ajax actions like RJS with jQuery"
12
- GEM_VERSION = "0.0.3"
12
+ GEM_VERSION = "0.0.4"
13
13
 
14
14
  spec = Gem::Specification.new do |s|
15
15
  s.rubyforge_project = 'merb'
data/lib/mjs/helper.rb CHANGED
@@ -15,6 +15,19 @@ module Mjs
15
15
  end
16
16
  end
17
17
 
18
+ # experimental: not tested yet
19
+ def button_to(name, url='', opts={})
20
+ ajax = remote_function(opts)
21
+ opts[:type] = 'button'
22
+ opts[:value] = name
23
+ opts[:remote] ||= true if opts[:submit]
24
+ if opts.delete(:remote)
25
+ ajax = remote_function(opts)
26
+ opts[:onclick] = "#{opts.delete(:onclick)}; #{ajax}; return false;"
27
+ end
28
+ %{<input #{ opts.to_xml_attributes }>}
29
+ end
30
+
18
31
  # override! :link_to # for Ajax
19
32
  def link_to(name, url='', opts={})
20
33
  opts[:href] ||= url
@@ -72,7 +85,7 @@ module Mjs
72
85
  }
73
86
 
74
87
  def options_for_ajax(options)
75
- js_options = build_callbacks(options)
88
+ js_options = build_callbacks!(options)
76
89
 
77
90
  submit = options.delete(:submit)
78
91
  target =
@@ -111,7 +124,8 @@ module Mjs
111
124
  end
112
125
  end
113
126
 
114
- def build_callbacks(options)
127
+ # this method affects "options"
128
+ def build_callbacks!(options)
115
129
  callbacks = {}
116
130
 
117
131
  # special callback
@@ -124,6 +138,7 @@ module Mjs
124
138
  options.each do |callback, code|
125
139
  if (name = AJAX_FUNCTIONS[callback])
126
140
  callbacks[name.to_s] = "function(request){#{code}}"
141
+ options.delete(callback)
127
142
  end
128
143
  end
129
144
 
@@ -362,6 +362,14 @@ module Mjs
362
362
 
363
363
  def javascript_object_for(object)
364
364
  object.respond_to?(:to_json) ? object.to_json : object.inspect
365
+
366
+ # TODO: to_json is too buggy!
367
+ rescue JSON::GeneratorError
368
+ if object.is_a?(String)
369
+ object.inspect
370
+ else
371
+ raise
372
+ end
365
373
  end
366
374
 
367
375
  def arguments_for_call(arguments, block = nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maiha-mjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - maiha
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-28 00:00:00 -07:00
12
+ date: 2009-08-28 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -68,8 +68,9 @@ files:
68
68
  - stubs/app/controllers
69
69
  - stubs/app/controllers/main.rb
70
70
  - stubs/app/controllers/application.rb
71
- has_rdoc: true
71
+ has_rdoc: false
72
72
  homepage: http://github.com/maiha/mjs
73
+ licenses:
73
74
  post_install_message:
74
75
  rdoc_options: []
75
76
 
@@ -90,9 +91,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  requirements: []
91
92
 
92
93
  rubyforge_project: merb
93
- rubygems_version: 1.2.0
94
+ rubygems_version: 1.3.5
94
95
  signing_key:
95
- specification_version: 2
96
+ specification_version: 3
96
97
  summary: A slice for the Merb framework that offers Ajax actions like RJS with jQuery
97
98
  test_files: []
98
99