lib/knj/web.rb in knjrbfw-0.0.21 vs lib/knj/web.rb in knjrbfw-0.0.22
- old
+ new
@@ -464,11 +464,11 @@
def self.input(args)
Knj::ArrayExt.hash_sym(args)
if args.key?(:value)
- if args[:value].is_a?(Array) and args[:value].first.is_a?(NilClass)
+ if args[:value].is_a?(Array) and (args[:value].first.is_a?(NilClass) or args[:value].first == false)
value = nil
elsif args[:value].is_a?(Array)
if !args[:value][2] or args[:value][2] == :key
value = args[:value].first[args[:value][1]]
elsif args[:value][2] == :callb
@@ -528,10 +528,11 @@
"type" => args[:type],
"class" => "input_#{args[:type]}"
}
attr.merge!(args[:attr]) if args[:attr]
attr["disabled"] = "disabled" if args[:disabled]
+ attr["maxlength"] = args[:maxlength] if args.key?(:maxlength)
raise "No name given to the Web::input()-method." if !args[:name] and args[:type] != :info and args[:type] != :textshow and args[:type] != :plain and args[:type] != :spacer and args[:type] != :headline
css = {}
css["text-align"] = args[:align] if args.key?(:align)
@@ -551,10 +552,16 @@
classes_tr_html = " class=\"#{classes_tr.join(" ")}\""
else
classes_tr_html = ""
end
+ if args.key?(:title)
+ title_html = args[:title].to_s.html
+ elsif args.key?(:title_html)
+ title_html = args[:title_html]
+ end
+
html = ""
classes = ["input_#{args[:type]}"]
classes = classes | args[:classes] if args.key?(:classes)
attr["class"] = classes.join(" ")
@@ -565,21 +572,21 @@
attr["checked"] = "checked" if value.is_a?(TrueClass)
html << "<tr#{classes_tr_html}>"
html << "<td colspan=\"2\" class=\"tdcheck\">"
html << "<input#{self.attr_html(attr)} />"
- html << "<label for=\"#{args[:id].html}\">#{args[:title].html}</label>"
+ html << "<label for=\"#{args[:id].html}\">#{title_html}</label>"
html << "</td>"
html << "</tr>"
elsif args[:type] == :headline
- html << "<tr#{classes_tr_html}><td colspan=\"2\"><h2 class=\"input_headline\">#{args[:title].html}</h2></td></tr>"
+ html << "<tr#{classes_tr_html}><td colspan=\"2\"><h2 class=\"input_headline\">#{title_html}</h2></td></tr>"
elsif args[:type] == :spacer
html << "<tr#{classes_tr_html}><td colspan=\"2\"> </td></tr>"
else
html << "<tr#{classes_tr_html}>"
html << "<td class=\"tdt\">"
- html << args[:title].to_s.html
+ html << title_html
html << "</td>"
html << "<td#{self.style_html(css)} class=\"tdc\">"
if args[:type] == :textarea
if args.key?(:height)
@@ -669,16 +676,11 @@
return html
end
def self.opts(opthash, curvalue = nil, opts_args = {})
opts_args = {} if !opts_args
- opts_args.each do |key, value|
- if !key.is_a?(Symbol)
- opts_args[key.to_sym] = value
- opts_args.delete(key)
- end
- end
+ Knj::ArrayExt.hash_sym(opts_args)
return "" if !opthash
cname = curvalue.class.name
curvalue = curvalue.id if (cname == "Knj::Db_row" or cname == "Knj::Datarow")
@@ -737,11 +739,11 @@
return "webkit"
elsif agent.index("gecko") != nil
return "gecko"
elsif agent.index("msie") != nil
return "msie"
- elsif agent.index("w3c") != nil or agent.index("baiduspider") != nil or agent.index("googlebot") != nil
+ elsif agent.index("w3c") != nil or agent.index("baiduspider") != nil or agent.index("googlebot") != nil or agent.index("bot") != nil
return "bot"
else
#print "Unknown agent: #{agent}"
return false
end
@@ -885,19 +887,39 @@
version = match[1]
elsif match = agent.match(/ahrefsbot\/([\d\.]+)/)
browser = "bot"
title = "AhrefsBot"
version = match[1]
+ elsif agent.index("sosospider") != nil
+ browser = "bot"
+ title = "Bot"
+ version = "Sosospider"
else
browser = "unknown"
title = "(unknown browser)"
version = "(unknown version)"
end
+ os = nil
+ os_version = nil
+ if agent.index("linux") != nil
+ os = "linux"
+ elsif match = agent.match(/mac\s+os\s+x\s+([\d_+])/)
+ os = "mac"
+ elsif match = agent.match(/windows\s+nt\s+([\d\.]+)/)
+ os = "windows"
+
+ if match[1] == "5.1"
+ os_version = "xp"
+ end
+ end
+
return {
"browser" => browser,
"title" => title,
- "version" => version
+ "version" => version,
+ "os" => os,
+ "os_version" => os_version
}
end
def self.locale(args = {})
begin
\ No newline at end of file