Sha256: 75fdefacbfcea42ff8dd6cd7dff9a94c8d9f7b76808de93cbcb72612cb7fa165

Contents?: true

Size: 1.44 KB

Versions: 19

Compression:

Stored size: 1.44 KB

Contents

require "json"
require "kconv"

class Search < Sinatra::Base
  helpers Sinatra::Streaming
  get "" do
    q_hash = {}
    puts request.query_string
    request.query_string.split("&").each do |q|
      work = q.split("=")
      if work[1] != nil
        q_hash[work[0]] = CGI.unescape work[1].toutf8
      else
        q_hash[work[0]] = ""
      end
    end
    str = q_hash["path"].gsub(/\\/, "/")
    puts "str=#{str}"
    kind = q_hash["kind"].gsub(/\\/, "/")
    puts "kind=#{kind}"
    res = []
    str = str.gsub(/\\/, "/")
    dir = File.dirname(str)
    file = File.basename(str)
    puts "dir=#{dir}"
    puts "file=#{file}"

    kernel = Facter.value(:kernel)
    if kernel == "windows"
      dir = "c:/" if dir == nil
      dir = "c:/" if dir == "/"
    elsif kernel == "Linux"
      dir = "/" if dir == nil
    else
      dir = "c:/" if dir == nil
      dir = "c:/" if dir == "/"
    end

    path = "#{dir}/#{file}"
    if File.directory?(path)
      path = path + "/*"
    else
      path = path + "*"
    end
    path.gsub!(/[\/]+/, "/")
    puts path
    Dir.glob(path, File::FNM_DOTMATCH).each do |file|
      data = {}
      next if File.basename(file) == "."
      next if kind == "dir" and !File.directory?(file)
      data["label"] = File.basename(file)
      data["label"] += "/" if (File.directory?(file))
      data["value"] = File.expand_path(file)
      res.push data
    end
    JSON.generate res.sort { |a, b| a["value"] <=> b["value"] }
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
python_uml_class-0.1.0 lib/server.rb
ruby_uml_class-0.5.0 lib/server.rb
ruby_uml_class-0.4.0 lib/server.rb
ruby_uml_class-0.3.0 lib/server.rb
ruby_uml_class-0.2.0 lib/server.rb
ruby_uml_class-0.1.0 lib/server.rb
browser_app_base-0.1.7 lib/template/server.rb
browser_app_base-0.1.6 lib/template/server.rb
browser_app_base-0.1.5 lib/template/server.rb
browser_app_base-0.1.4 lib/template/server.rb
browser_app_base-0.1.3 lib/template/server.rb
browser_app_base-0.1.2 lib/template/server.rb
browser_app_base-0.1.1 lib/template/server.rb
browser_app_base-0.1.0 lib/template/server.rb
browser_app_base-0.0.9 lib/template/server.rb
browser_app_base-0.0.8 lib/template/server.rb
browser_app_base-0.0.7 lib/template/server.rb
browser_app_base-0.0.6 lib/template/server.rb
browser_app_base-0.0.5 lib/template/server.rb