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
- #atom ⇒ Object
- #default_item_view ⇒ Object
- #default_nest_view ⇒ Object
- #essentials ⇒ Object
-
#item_cards ⇒ Object
because card.item_cards returns "[[#self]]".
-
#marks ⇒ Object
DEPRECATED.
- #max_depth ⇒ Object
- #molecule ⇒ Object
-
#nucleus ⇒ Object
NOTE: moving these to methods prevents potential caching problems, because other views manipulate their hashes.
- #request_url ⇒ Object
-
#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).
Instance Method Details
#atom ⇒ Object
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_view ⇒ Object
18 19 20 |
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 18 def default_item_view params[:item] || :name end |
#default_nest_view ⇒ Object
14 15 16 |
# File 'tmpsets/set/mod006-basic_formats/all/json.rb', line 14 def default_nest_view :atom end |
#essentials ⇒ Object
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_cards ⇒ Object
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 |
#marks ⇒ Object
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_depth ⇒ Object
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 |
#molecule ⇒ Object
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 |
#nucleus ⇒ Object
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_url ⇒ Object
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 |