diff --git a/app/helpers/washout_builder_helper.rb b/app/helpers/washout_builder_helper.rb index b613c46..224a75f 100644 --- a/app/helpers/washout_builder_helper.rb +++ b/app/helpers/washout_builder_helper.rb @@ -4,39 +4,49 @@ def create_html_complex_types(xml, types) types.each { |hash| create_complex_type_html(xml, hash[:obj], hash[:class], hash[:ancestors]) } end + + + def create_element_type_html(pre, complex_class, element) + unless complex_class.nil? + if element.multiplied == false + pre << "#{complex_class} #{element.name}" + else + pre << "Array of #{complex_class} #{element.name}" + end + end + end + + + def create_class_type_html(xml, class_name, ancestors) + xml.h3 { |pre| pre << "#{class_name} #{ancestors.blank? ? "" : "(extends #{ancestors[0].to_s.classify})" } " } + end + + + def create_complex_type_element_html(xml, element) + element.type = "string" if element.type == "text" + element.type = "integer" if element.type == "int" + xml.li { |pre| + if WashoutBuilder::Type::BASIC_TYPES.include?(element.type) + pre << "#{element.type} #{element.name}" + else + complex_class = element.get_complex_class_name + create_element_type_html(pre, complex_class, element) + end + } + end def create_complex_type_html(xml, param, class_name, ancestors) unless param.blank? xml.a( "name" => "#{class_name}") { } - xml.h3 { |pre| pre << "#{class_name} #{ancestors.blank? ? "" : "(extends #{ancestors[0].to_s.classify})" } " } - + + create_class_type_html(xml, class_name, ancestors) if param.is_a?(WashOut::Param) xml.ul("class" => "pre") { - param.map.each do |element| - element.type = "string" if element.type == "text" - # raise YAML::dump(element) if class_name.include?("ype") and element.name == "members" - xml.li { |pre| - if WashoutBuilder::Type::BASIC_TYPES.include?(element.type) - element.type = "integer" if element.type == "int" - pre << "#{element.type} #{element.name}" - else - complex_class = element.get_complex_class_name - unless complex_class.nil? - if element.multiplied == false - pre << "#{complex_class} #{element.name}" - else - pre << "Array of #{complex_class} #{element.name}" - end - end - end - } - + create_complex_type_element_html(xml, element) end - } - end end end @@ -50,31 +60,37 @@ def create_html_fault_types_details(xml, fault_types) end end + def create_virtus_model_complex_element_type(pre, attr_primitive, attribute, array) + attribute_primitive = array == true ? "Array of #{attr_primitive}" : "#{attr_primitive}" + pre << " #{attribute_primitive} #{attribute}" + end + + + def create_html_virtus_model_element_type(xml, attribute, attr_details) + xml.li { |pre| + if WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:primitive].to_s.downcase) || attr_details[:primitive] == "nilclass" + pre << "#{attr_details[:primitive].to_s.downcase == "nilclass" ? "string" : attr_details[:primitive].to_s.downcase } #{attribute}" + + else + if attr_details[:primitive].to_s.downcase == "array" + + attr_primitive = WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:member_type].to_s.downcase) ? attr_details[:member_type].to_s.downcase : attr_details[:member_type] + create_virtus_model_complex_element_type(pre,attr_primitive, attribute, true ) + else + create_virtus_model_complex_element_type(pre,attr_details[:primitive], attribute, false ) + end + end + } + end - def create_html_virtus_model_type(xml, param, fault_structure, ancestors) if param.is_a?(Class) - xml.h3 { |pre| pre << "#{param} #{ancestors.blank? ? "" : "(extends #{ancestors[0].to_s.classify})" } " } + create_class_type_html(xml, param, ancestors) xml.a("name" => "#{param}") {} xml.ul("class" => "pre") { - - fault_structure.each do |attribute, attr_details| - xml.li { |pre| - if WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:primitive].to_s.downcase) || attr_details[:primitive] == "nilclass" - pre << "#{attr_details[:primitive].to_s.downcase == "nilclass" ? "string" : attr_details[:primitive].to_s.downcase } #{attribute}" - - else - if attr_details[:primitive].to_s.downcase == "array" - - attr_primitive = WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:member_type].to_s.downcase) ? attr_details[:member_type].to_s.downcase : attr_details[:member_type] - pre << "Array of #{attr_primitive} #{attribute}" - else - pre << "#{attr_details[:primitive]} #{attribute}" - end - end - } + create_html_virtus_model_element_type(xml, attribute, attr_details) end } end @@ -87,73 +103,35 @@ def create_html_public_methods(xml, map) end end + + def create_return_complex_type_html(xml, complex_class, builder_out) + return_content = builder_out[0].multiplied == false ? "#{complex_class}" : "Array of #{complex_class}" + xml.span("class" => "pre") { xml.a("href" => "##{complex_class}") { |xml| xml.span("class" => "lightBlue") { |y| y<<"#{return_content}" } } } + end - - def create_html_public_method(xml, operation, formats) - # raise YAML::dump(formats[:builder_in]) - xml.h3 "#{operation}" - xml.a("name" => "#{operation}") {} - - - xml.p("class" => "pre"){ |pre| - unless formats[:builder_out].nil? - complex_class = formats[:builder_out][0].get_complex_class_name - if WashoutBuilder::Type::BASIC_TYPES.include?(formats[:builder_out][0].type) - xml.span("class" => "blue") { |y| y<< "#{formats[:builder_out][0].type}" } - else - unless complex_class.nil? - if formats[:builder_out][0].multiplied == false - pre << "#{complex_class}" - else - pre << "Array of #{complex_class}" - end - end - end - else - pre << "void" - end - - xml.span("class" => "bold") {|y| y << "#{operation} (" } - mlen = formats[:builder_in].size - xml.br if mlen > 1 - spacer = "    " - if mlen > 0 - j=0 - while j 1 ? true : false - if WashoutBuilder::Type::BASIC_TYPES.include?(param.type) - pre << "#{use_spacer ? spacer: ''}#{param.type} #{param.name}" + + def create_return_type_html(xml, formats) + xml.p "Return value:" + xml.ul { + xml.li { + unless formats[:builder_out].nil? + complex_class = formats[:builder_out][0].get_complex_class_name + if WashoutBuilder::Type::BASIC_TYPES.include?(formats[:builder_out][0].type) + xml.span("class" => "pre") { |xml| xml.span("class" => "blue") { |sp| sp << "#{formats[:builder_out][0].type}" } } else - unless complex_class.nil? - if param.multiplied == false - pre << "#{use_spacer ? spacer: ''}#{complex_class} #{param.name}" - else - pre << "#{use_spacer ? spacer: ''}Array of #{complex_class} #{param.name}" - end - end + create_return_complex_type_html(xml, complex_class, formats[:builder_out]) unless complex_class.nil? end - if j< (mlen-1) - xml.span ", " - end - if mlen > 1 - xml.br - end - if (j+1) == mlen - xml.span("class" => "bold") {|y| y << ")" } - end - j+=1 + else + xml.span("class" => "pre") { |sp| sp << "void" } end - - end - - - + + } } - xml.p "#{formats[:description]}" if !formats[:description].blank? + end + + + def create_parameters_html(xml, formats) xml.p "Parameters:" - xml.ul { j=0 mlen = formats[:builder_in].size @@ -164,47 +142,21 @@ def create_html_public_method(xml, operation, formats) if WashoutBuilder::Type::BASIC_TYPES.include?(param.type) pre << "#{param.type} #{param.name}" else - unless complex_class.nil? - if param.multiplied == false - pre << "#{complex_class} #{param.name}" - else - pre << "Array of #{complex_class} #{param.name}" - end - end + create_element_type_html(pre, complex_class, param) end } j+=1 end - - } - - xml.p "Return value:" - xml.ul { - xml.li { - unless formats[:builder_out].nil? - complex_class = formats[:builder_out][0].get_complex_class_name - if WashoutBuilder::Type::BASIC_TYPES.include?(formats[:builder_out][0].type) - xml.span("class" => "pre") { |xml| xml.span("class" => "blue") { |sp| sp << "#{formats[:builder_out][0].type}" } } - else - unless complex_class.nil? - if formats[:builder_out][0].multiplied == false - xml.span("class" => "pre") { xml.a("href" => "##{complex_class}") { |xml| xml.span("class" => "lightBlue") { |y| y<<"#{complex_class}" } } } - else - xml.span("class" => "pre") { xml.a("href" => "##{complex_class}") { |xml| xml.span("class" => "lightBlue") { |y| y<<"Array of #{complex_class}" } } } - end - end - end - else - xml.span("class" => "pre") { |sp| sp << "void" } - end - - } + } + end + + def create_exceptions_list_html(xml, formats) unless formats[:raises].blank? faults = formats[:raises] faults = [formats[:raises]] if !faults.is_a?(Array) - faults = faults.select { |x| x.is_a?(Class) && (x.ancestors.detect{ |fault| WashoutBuilder::Type.get_fault_classes.include?(fault) }.present? || WashoutBuilder::Type.get_fault_classes.include?(x) ) } + faults = faults.select { |x| WashoutBuilder::Type.valid_fault_class?(x) } unless faults.blank? xml.p "Exceptions:" xml.ul { @@ -215,5 +167,79 @@ def create_html_public_method(xml, operation, formats) end end end + + + def create_html_public_method_return_type(xml,pre, formats) + unless formats[:builder_out].nil? + complex_class = formats[:builder_out][0].get_complex_class_name + if WashoutBuilder::Type::BASIC_TYPES.include?(formats[:builder_out][0].type) + xml.span("class" => "blue") { |y| y<< "#{formats[:builder_out][0].type}" } + else + unless complex_class.nil? + if formats[:builder_out][0].multiplied == false + pre << "#{complex_class}" + else + pre << "Array of #{complex_class}" + end + end + end + else + pre << "void" + end + end + + def create_html_public_method_arguments_complex_type(pre, spacer, use_spacer, complex_class, param) + argument_content = param.multiplied == false ? "#{complex_class}" : "Array of #{complex_class}" + pre << "#{use_spacer ? spacer: ''}#{argument_content} #{param.name}" + end + + def create_html_public_method_arguments(xml, pre, operation, formats) + xml.span("class" => "bold") {|y| y << "#{operation} (" } + mlen = formats[:builder_in].size + xml.br if mlen > 1 + spacer = "    " + if mlen > 0 + j=0 + while j 1 ? true : false + if WashoutBuilder::Type::BASIC_TYPES.include?(param.type) + pre << "#{use_spacer ? spacer: ''}#{param.type} #{param.name}" + else + unless complex_class.nil? + create_html_public_method_arguments_complex_type(pre, spacer, use_spacer, complex_class, param) + end + end + if j< (mlen-1) + xml.span ", " + end + if mlen > 1 + xml.br + end + if (j+1) == mlen + xml.span("class" => "bold") {|y| y << ")" } + end + j+=1 + end + + end + end + + + def create_html_public_method(xml, operation, formats) + # raise YAML::dump(formats[:builder_in]) + xml.h3 "#{operation}" + xml.a("name" => "#{operation}") {} + + xml.p("class" => "pre"){ |pre| + create_html_public_method_return_type(xml,pre, formats) + create_html_public_method_arguments(xml, pre, operation, formats) + } + xml.p "#{formats[:description]}" if !formats[:description].blank? + create_parameters_html(xml, formats) + create_return_type_html(xml, formats) + create_exceptions_list_html(xml, formats) + end end diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index d2f354c..27a4b0a 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -1,3 +1,3 @@ module WashoutBuilder - VERSION = "0.12.3" + VERSION = "0.12.4" end