Sha256: d5db4354c3099fe816ab8a96c617f6ba2ea8150ebcb28323070cd3a7bd34c8cc
Contents?: true
Size: 1.95 KB
Versions: 4
Compression:
Stored size: 1.95 KB
Contents
module WidgetList class Utils def self.numeric?(object) true if Float(object) rescue false end def self.date?(object) true if Date.parse(object) rescue false end #JsonEncode def self.json_encode(arr,return_string = false) if return_string p JSON.generate(arr) else JSON.generate(arr) end end #BuildQueryString def self.build_query_string(args) q = [] args.each { |k,v| if v.class.name == 'Hash' q << {k => v}.to_params else q << k.to_s + '=' + URI.encode(URI.decode(v.to_s)) end } q.join('&') end #BuildUrl def self.build_url(page='',args = {}, append_get=false) qs = build_query_string(args) getvars = '' if append_get && $_REQUEST getvars = build_query_string($_REQUEST) end unless page =~ /\?/ "#{page}?" + qs + '&' + getvars else "#{page}" + qs + '&' + getvars end end #Fill def self.fill(tags = {}, template = '') tpl = template.dup tags.each { |k,v| tpl = tpl.gsub(k.to_s,v.to_s) } tpl end #test_all def self.test_all output_final = '' output_final += "JsonEncode\n<br/>\n<br/>" a = { } a['asdfasdf'] = 'asfd' a[:test] = 1234 a[2153125] = nil output_final += Utils.json_encode(a) output_final += "\n<br/>\n<br/>BuildQueryString\n<br/>\n<br/>" a = { } a['asdfasdf'] = 'asdf asdfj ajskdfhasdf' a['dave'] = 'a)(J#(*J@T2p2kfasdfa fas %20fj ajskdfhasdf' output_final += Utils.build_query_string(a) output_final += "\n<br/>\n<br/>BuildUrl\n<br/>\n<br/>" output_final += Utils.build_url('page.php?',a) output_final += "\n<br/>\n<br/>Fill\n<br/>\n<br/>" output_final += Utils.fill({'<!--CONTENT-->'=>'dave','<!--TITLE-->'=>'the title'},'<!--TITLE--> --------- <!--CONTENT-->') end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
widget_list-1.3.5 | lib/widget_list/utils.rb |
widget_list-1.2.0 | lib/widget_list/utils.rb |
widget_list-1.1.9 | lib/widget_list/utils.rb |
widget_list-1.1.8 | lib/widget_list/utils.rb |