Sha256: 5a6b8bb62956a490ab9c21cec974e626f56adeafafa4cde965bb99d8e0d21cbb

Contents?: true

Size: 1.87 KB

Versions: 49

Compression:

Stored size: 1.87 KB

Contents

# -*- encoding : utf-8 -*-
class Card; module Set; class Self; module Search; extend Card::Set
# ~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/standard/set/self/search.rb ~~

format :html do
  view :title do |args|
    vars = root.search_params[:vars]
    if vars && vars[:keyword]
      args[:title] = %(Search results for: <span class="search-keyword">)\
                         "#{vars[:keyword]}</span>"
    end
    super args
  end
end

format :json do
  view :complete do
    term = complete_term
    exact = Card.fetch term, new: {}

    {
      search: true,
      add: add_item(exact),
      new: new_item_of_type(exact),
      goto: goto_items(term, exact)
    }
  end

  def add_item exact
    return unless exact.new_card? &&
                  exact.cardname.valid? &&
                  !exact.virtual? &&
                  exact.ok?(:create)
    exact.name
  end

  def new_item_of_type exact
    return unless (exact.type_id == Card::CardtypeID) &&
                  Card.new(type_id: exact.id).ok?(:create)
    [exact.name, exact.cardname.url_key]
  end

  def goto_items term, exact
    goto_names = Card.search goto_wql(term), "goto items for term: #{term}"
    goto_names.unshift exact.name if add_exact_to_goto_names? exact, goto_names
    goto_names.map do |name|
      [name, highlight(name, term), name.to_name.url_key]
    end
  end

  def add_exact_to_goto_names? exact, goto_names
    exact.known? && !goto_names.find { |n| n.to_name.key == exact.key }
  end

  def complete_term
    term = params["_keyword"]
    if (term =~ /^\+/) && (main = params["main"])
      term = main + term
    end
    term
  end

  # hacky.  here for override
  def goto_wql term
    { complete: term, limit: 8, sort: "name", return: "name" }
  end
end


# ~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/standard/set/self/search.rb ~~
end;end;end;end;

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
card-1.99.6 tmpsets/set/mod016-standard/self/search.rb
card-1.99.5 tmpsets/set/mod016-standard/self/search.rb
card-1.97.0.1 tmpsets/set/mod016-standard/self/search.rb
card-1.97.0 tmpsets/set/mod016-standard/self/search.rb
card-1.96.8 tmpsets/set/mod016-standard/self/search.rb
card-1.96.7 tmpsets/set/mod016-standard/self/search.rb
card-1.96.6 tmpsets/set/mod016-standard/self/search.rb
card-1.96.5 tmpsets/set/mod016-standard/self/search.rb
card-1.96.4 tmpsets/set/mod016-standard/self/search.rb
card-1.96.3 tmpsets/set/mod016-standard/self/search.rb
card-1.96.2 tmpsets/set/mod016-standard/self/search.rb
card-1.96.1 tmpsets/set/mod016-standard/self/search.rb
card-1.96.0 tmpsets/set/mod016-standard/self/search.rb
card-1.95.3 tmpsets/set/mod016-standard/self/search.rb
card-1.95.2 tmpsets/set/mod016-standard/self/search.rb
card-1.95.1 tmpsets/set/mod016-standard/self/search.rb
card-1.95.0 tmpsets/set/mod016-standard/self/search.rb
card-1.94.1 tmpsets/set/mod016-standard/self/search.rb
card-1.94.0 tmpsets/set/mod016-standard/self/search.rb
card-1.93.13 tmpsets/set/mod016-standard/self/search.rb