Module: Card::Format::ContextNames

Included in:
Card::Format
Defined in:
lib/card/format/context_names.rb

Instance Method Summary collapse

Instance Method Details

#add_name_context(name = nil) ⇒ Object



31
32
33
34
# File 'lib/card/format/context_names.rb', line 31

def add_name_context name=nil
  name ||= card.name
  @context_names = (context_names + name.to_name.part_names).uniq
end

#context_namesObject



4
5
6
# File 'lib/card/format/context_names.rb', line 4

def context_names
  @context_names ||= initial_context_names
end

#context_names_from_paramsObject

"slot[name_context]" param is a string;



21
22
23
24
# File 'lib/card/format/context_names.rb', line 21

def context_names_from_params
  return [] unless (name_list = Card::Env.slot_opts.delete(:name_context))
  name_list.to_s.split(",").map(&:to_name)
end

#context_names_to_paramsObject



26
27
28
29
# File 'lib/card/format/context_names.rb', line 26

def context_names_to_params
  return if context_names.empty?
  context_names.join(",")
end

#initial_context_namesObject



8
9
10
11
12
# File 'lib/card/format/context_names.rb', line 8

def initial_context_names
  @initial_context_names ||= relevant_context_names do
    parent ? parent.context_names : context_names_from_params
  end
end

#relevant_context_namesObject



14
15
16
17
# File 'lib/card/format/context_names.rb', line 14

def relevant_context_names
  part_keys = @card.name.part_names.map(&:key)
  yield.reject { |n| !part_keys.include? n.key }
end

#title_in_context(title = nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/card/format/context_names.rb', line 36

def title_in_context title=nil
  keep_safe = title&.html_safe?
  title = title ? title.to_name.absolute_name(card.name) : card.name
  newtitle = title.from *context_names
  keep_safe ? newtitle.html_safe : newtitle
end