Sha256: 56440da159f86fe1748663cc0d0d1b5e4f5ef1a722571c235f6a0c48f0c78298

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

# -*- encoding : utf-8 -*-
format :json do

  def get_inclusion_defaults
    { :view=>:atom }
  end

  def default_item_view
    params[:item] || :atom
  end
  
  def max_depth
    params[:max_depth] || 1
  end
  
  def default_search_params
    { :default_limit => 0 }
  end
  

  def show args
    view = args[:view] || :content
    raw = render view, args
    case
    when String === raw  ;  raw
    when params[:pretty] ;  JSON.pretty_generate raw
    else                 ;  JSON( raw )
    end
  end

  view :name_complete do |args|
    card.item_cards :complete=>params['term'], :limit=>8, :sort=>'name', :return=>'name', :context=>''
  end
  
  view :status, :tags=>:unknown_ok, :perms=>:none do |args|
    status = case
    when !card.known?       ;  :unknown
# do we want the following to prevent fishing?  of course, they can always post...        
    when !card.ok?(:read)   ;  :unknown
    when card.real?         ;  :real
    when card.virtual?      ;  :virtual
    else                    ;  :wtf
    end
    
    hash = { :key=>card.key, :url_key=>card.cardname.url_key, :status=>status }
    hash[:id] = card.id if status == :real
     
    hash
  end

  view :content do |args|
    {
      :url       => controller.request.original_url,
      :timestamp => Time.now.to_s,
      :card      => _render_atom
    }
  end
  
  view :atom do |args|
    h = {
      :name    => card.name,
      :type    => card.type_name,
      :content => card.raw_content
    }
    h[:codename] = card.codename     if card.codename
    h[:value]    = _render_core args if @depth < max_depth
    h
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wagn-1.12.13 mods/standard/sets/all/json.rb
wagn-1.12.12 mods/standard/sets/all/json.rb
wagn-1.12.11 mods/standard/sets/all/json.rb