module Card::Format::Nest::Fetch

Fetch card for a nest

Private Instance Methods

content_from_shorthand_param() click to toggle source
# File lib/card/format/nest/fetch.rb, line 63
def content_from_shorthand_param
  # FIXME: this is a lame shorthand; could be another card's key
  # should be more robust and managed by Card::Name
  shorthand_param = view_opts[:nest_name].tr "+", "_"
  Env.params[shorthand_param]
end
content_from_subcard_params() click to toggle source
# File lib/card/format/nest/fetch.rb, line 70
def content_from_subcard_params
  Env.params.dig "subcards", view_opts[:nest_name], "content"
end
fetch_card(cardish) click to toggle source
# File lib/card/format/nest/fetch.rb, line 8
def fetch_card cardish
  case cardish
  when Card            then cardish
  when Symbol, Integer then Card.fetch cardish
  when "_", "_self"    then format.context_card
  else                      new_card cardish
  end
rescue Card::Error::CodenameNotFound
  not_found_codename cardish
end
new_card(cardish) click to toggle source
# File lib/card/format/nest/fetch.rb, line 30
def new_card cardish
  view_opts[:nest_name] = Card::Name[cardish].to_s
  Card.fetch cardish, new: new_card_args
end
new_card_args() click to toggle source
# File lib/card/format/nest/fetch.rb, line 35
def new_card_args
  args = { name: view_opts[:nest_name] }
  args[:type] = view_opts[:type] if view_opts[:type]
  args.merge(new_supercard_args)
      .merge(new_main_args)
      .merge(new_content_args)
end
new_content_args() click to toggle source
# File lib/card/format/nest/fetch.rb, line 58
def new_content_args
  content = content_from_shorthand_param || content_from_subcard_params
  content ? { content: content } : {}
end
new_main_args() click to toggle source
# File lib/card/format/nest/fetch.rb, line 50
def new_main_args
  nest_name = view_opts[:nest_name]
  return {} unless nest_name =~ /main/

  { name: nest_name.gsub(/^_main\+/, "+"),
    supercard: format.root.card }
end
new_supercard_args() click to toggle source
# File lib/card/format/nest/fetch.rb, line 43
def new_supercard_args
  # special case.  gets absolutized incorrectly. fix in name?
  return {} if view_opts[:nest_name].strip.blank?

  { supercard: format.context_card }
end
not_found_codename(cardish) click to toggle source
# File lib/card/format/nest/fetch.rb, line 19
def not_found_codename cardish
  @view = :not_found
  c = Card.new name: Array.wrap(cardish).join(Card::Name.joint).to_s
  c.errors.add :codename, not_found_codename_error(cardish)
  c
end
not_found_codename_error(codename) click to toggle source
# File lib/card/format/nest/fetch.rb, line 26
def not_found_codename_error codename
  ::I18n.t :lib_exception_unknown_codename, codename: codename
end