mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
add support for structured types as input parameters to scaffolding,
fixes scaffolding for APIs like metaWeblog that require an input struct (by dropping structs in nested <ul> lists). git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1265 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
b921b5da15
commit
a080b1a231
6 changed files with 61 additions and 35 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Add support for structured types as input parameters to scaffolding, this should let one test the blogging APIs using scaffolding as well
|
||||||
|
|
||||||
* Fix that generated WSDL was not using relative_url_root for base URI #1210 [Shugo Maeda]
|
* Fix that generated WSDL was not using relative_url_root for base URI #1210 [Shugo Maeda]
|
||||||
|
|
||||||
* Use UTF-8 encoding by default for SOAP responses, but if an encoding is supplied by caller, use that for the response #1211 [Shugo Maeda, NAKAMURA Hiroshi]
|
* Use UTF-8 encoding by default for SOAP responses, but if an encoding is supplied by caller, use that for the response #1211 [Shugo Maeda, NAKAMURA Hiroshi]
|
||||||
|
|
|
@ -217,9 +217,9 @@ module ActionWebService # :nodoc:
|
||||||
# String representation of this method
|
# String representation of this method
|
||||||
def to_s
|
def to_s
|
||||||
fqn = ""
|
fqn = ""
|
||||||
fqn << (@returns ? (friendly_param(@returns[0], false) + " ") : "void ")
|
fqn << (@returns ? (@returns[0].human_name(false) + " ") : "void ")
|
||||||
fqn << "#{@public_name}("
|
fqn << "#{@public_name}("
|
||||||
fqn << @expects.map{ |p| friendly_param(p) }.join(", ") if @expects
|
fqn << @expects.map{ |p| p.human_name }.join(", ") if @expects
|
||||||
fqn << ")"
|
fqn << ")"
|
||||||
fqn
|
fqn
|
||||||
end
|
end
|
||||||
|
@ -236,13 +236,6 @@ module ActionWebService # :nodoc:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def friendly_param(type, show_name=true)
|
|
||||||
name = type.name.to_s
|
|
||||||
type_type = type.array?? type.element_type.type.to_s : type.type.to_s
|
|
||||||
str = type.array?? (type_type + '[]') : type_type
|
|
||||||
show_name ? (str + " " + name) : str
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
require 'ostruct'
|
|
||||||
require 'uri'
|
|
||||||
require 'benchmark'
|
require 'benchmark'
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
|
|
||||||
|
@ -70,7 +68,13 @@ module ActionWebService
|
||||||
@invocation_cgi = @request.respond_to?(:cgi) ? @request.cgi : nil
|
@invocation_cgi = @request.respond_to?(:cgi) ? @request.cgi : nil
|
||||||
bm = Benchmark.measure do
|
bm = Benchmark.measure do
|
||||||
@protocol.register_api(@scaffold_service.api)
|
@protocol.register_api(@scaffold_service.api)
|
||||||
params = @params['method_params'] ? @params['method_params'].dup : nil
|
post_params = @params['method_params'] ? @params['method_params'].dup : nil
|
||||||
|
params = []
|
||||||
|
if @scaffold_method.expects
|
||||||
|
@scaffold_method.expects.length.times do |i|
|
||||||
|
params << post_params[i.to_s]
|
||||||
|
end
|
||||||
|
end
|
||||||
params = @scaffold_method.cast_expects(params)
|
params = @scaffold_method.cast_expects(params)
|
||||||
method_name = public_method_name(@scaffold_service.name, @scaffold_method.public_name)
|
method_name = public_method_name(@scaffold_service.name, @scaffold_method.public_name)
|
||||||
@method_request_xml = @protocol.encode_request(method_name, params, @scaffold_method.expects)
|
@method_request_xml = @protocol.encode_request(method_name, params, @scaffold_method.expects)
|
||||||
|
@ -156,30 +160,49 @@ module ActionWebService
|
||||||
end
|
end
|
||||||
|
|
||||||
module Helpers # :nodoc:
|
module Helpers # :nodoc:
|
||||||
def method_parameter_input_fields(method, type)
|
def method_parameter_input_fields(method, type, field_name_base)
|
||||||
name = type.name.to_s
|
if type.array?
|
||||||
type_name = type.type
|
return content_tag('em', "Typed array input fields not supported yet (#{type.name})")
|
||||||
unless type_name.is_a?(Symbol)
|
|
||||||
raise "Parameter #{name}: Structured/array types not supported in scaffolding input fields yet"
|
|
||||||
end
|
end
|
||||||
field_name = "method_params[]"
|
if type.structured?
|
||||||
case type_name
|
parameters = ""
|
||||||
when :int
|
type.each_member do |member_name, member_type|
|
||||||
text_field_tag field_name
|
label = method_parameter_label(member_name, member_type)
|
||||||
when :string
|
nested_content = method_parameter_input_fields(
|
||||||
text_field_tag field_name
|
method,
|
||||||
when :bool
|
member_type,
|
||||||
radio_button_tag field_name, "True"
|
field_name_base + '[' + member_name.to_s + ']')
|
||||||
radio_button_tag field_name, "False"
|
if member_type.custom?
|
||||||
when :float
|
parameters << content_tag('li', label)
|
||||||
text_field_tag field_name
|
parameters << content_tag('ul', nested_content)
|
||||||
when :time
|
else
|
||||||
select_datetime Time.now, 'name' => field_name
|
parameters << content_tag('li', label + ' ' + nested_content)
|
||||||
when :date
|
end
|
||||||
select_date Date.today, 'name' => field_name
|
end
|
||||||
|
content_tag('ul', parameters)
|
||||||
|
else
|
||||||
|
case type.type
|
||||||
|
when :int
|
||||||
|
text_field_tag field_name_base
|
||||||
|
when :string
|
||||||
|
text_field_tag field_name_base
|
||||||
|
when :bool
|
||||||
|
radio_button_tag field_name_base, "True"
|
||||||
|
radio_button_tag field_name_base, "False"
|
||||||
|
when :float
|
||||||
|
text_field_tag field_name_base
|
||||||
|
when :time
|
||||||
|
select_datetime Time.now, 'name' => field_name_base
|
||||||
|
when :date
|
||||||
|
select_date Date.today, 'name' => field_name_base
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def method_parameter_label(name, type)
|
||||||
|
name.to_s.capitalize + ' (' + type.human_name(false) + ')'
|
||||||
|
end
|
||||||
|
|
||||||
def service_method_list(service)
|
def service_method_list(service)
|
||||||
action = @scaffold_action_name + '_method_params'
|
action = @scaffold_action_name + '_method_params'
|
||||||
methods = service.api_methods_full.map do |desc, name|
|
methods = service.api_methods_full.map do |desc, name|
|
||||||
|
|
|
@ -150,6 +150,12 @@ module ActionWebService # :nodoc:
|
||||||
def structured?
|
def structured?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def human_name(show_name=true)
|
||||||
|
type_type = array? ? element_type.type.to_s : self.type.to_s
|
||||||
|
str = array? ? (type_type + '[]') : type_type
|
||||||
|
show_name ? (str + " " + name.to_s) : str
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ArrayType < BaseType # :nodoc:
|
class ArrayType < BaseType # :nodoc:
|
||||||
|
|
|
@ -10,13 +10,15 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<% if @scaffold_method.expects %>
|
<% if @scaffold_method.expects %>
|
||||||
|
<% i = 0 %>
|
||||||
|
|
||||||
<strong>Method Parameters:</strong><br />
|
<strong>Method Parameters:</strong><br />
|
||||||
<% @scaffold_method.expects.each do |type| %>
|
<% @scaffold_method.expects.each do |type| %>
|
||||||
<p>
|
<p>
|
||||||
<label for="method_params[]"><%= type.name.to_s.camelize %></label><br />
|
<label for="method_params[<%= i %>]"><%= method_parameter_label(type.name, type) %> </label><br />
|
||||||
<%= method_parameter_input_fields(@scaffold_method, type) %>
|
<%= method_parameter_input_fields(@scaffold_method, type, "method_params[#{i}]") %>
|
||||||
</p>
|
</p>
|
||||||
|
<% i += 1 %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -53,7 +53,7 @@ class ScaffoldedControllerTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_scaffold_invoke_submit_hello
|
def test_scaffold_invoke_submit_hello
|
||||||
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Hello', :method_params => ['5', 'hello world']
|
post :scaffold_invoke_submit, :service => 'scaffolded', :method => 'Hello', :method_params => {'0' => '5', '1' => 'hello world'}
|
||||||
assert_rendered_file 'result.rhtml'
|
assert_rendered_file 'result.rhtml'
|
||||||
assert_equal false, @controller.instance_eval{ @method_return_value }
|
assert_equal false, @controller.instance_eval{ @method_return_value }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue