Module: Card::Set::All::Json::JsonFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
tmpsets/set/mod006-basic_formats/all/json.rb

Instance Method Summary collapse

Instance Method Details

#atomObject



141
142
143
144
145
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 141

def atom
  h = nucleus
  h[:content] = render_content if card.known? && !card.structure
  h
end

#default_item_viewObject



18
19
20
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 18

def default_item_view
  params[:item] || :name
end

#default_nest_viewObject



14
15
16
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 14

def default_nest_view
  :atom
end

#essentialsObject



124
125
126
127
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 124

def essentials
  return {} if card.structure
  { content: card.db_content }
end

#item_cardsObject

because card.item_cards returns "[[#self]]"



10
11
12
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 10

def item_cards
  uniq_nested_cards
end

#marksObject

DEPRECATED



107
108
109
110
111
112
113
114
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 107

view :marks do
  {
    id: card.id,
    name: card.name,
    key: card.key,
    url: path
  }
end

#max_depthObject



22
23
24
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 22

def max_depth
  params[:max_depth].present? ? params[:max_depth].to_i : 1
end

#moleculeObject



147
148
149
150
151
152
153
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 147

def molecule
  atom.merge items: _render_items,
             links: _render_links,
             ancestors: _render_ancestors,
             html_url: path,
             type: nest(card.type_card, view: :nucleus)
end

#nucleusObject

NOTE: moving these to methods prevents potential caching problems, because other views manipulate their hashes.



132
133
134
135
136
137
138
139
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 132

def nucleus
  h = { id: card.id,
        name: card.name,
        type: card.type_name,
        url: path(format: :json) }
  h[:codename] = card.codename if card.codename
  h
end

#request_urlObject



53
54
55
56
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 53

def request_url
  req = controller.request
  req ? req.original_url : path
end

#show(view, args) ⇒ Object

TODO: support layouts in json eg layout=stamp gives you the metadata currently in "page" view and layout=none gives you ONLY the requested view (default atom)



29
30
31
32
33
34
35
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 29

def show view, args
  view ||= :molecule
  raw = render! view, args
  return raw if raw.is_a? String
  method = params[:compress] ? :generate : :pretty_generate
  JSON.send method, raw
end