module Card::Format::Content

Public Instance Methods

add_class(options, klass) click to toggle source
# File lib/card/format/content.rb, line 43
def add_class options, klass
  return if klass.blank?

  options[:class] = css_classes options[:class], klass
end
Also aliased as: append_class
append_class(options, klass)
Alias for: add_class
content_nest(opts={}) click to toggle source

nested by another card’s content (as opposed to a direct API nest)

# File lib/card/format/content.rb, line 20
def content_nest opts={}
  return opts[:comment] if opts.key? :comment # commented nest

  nest_name = opts[:nest_name]
  return main_nest(opts) if main_nest?(nest_name) && @nest_mode != :template

  nest nest_name, opts
end
css_classes(*array) click to toggle source
# File lib/card/format/content.rb, line 55
def css_classes *array
  array.flatten.uniq.compact * " "
end
format_date(date, include_time=true) click to toggle source
# File lib/card/format/content.rb, line 29
def format_date date, include_time=true
  # using DateTime because Time doesn't support %e on some platforms
  if include_time
    # .strftime('%B %e, %Y %H:%M:%S')
    I18n.localize(DateTime.new(date.year, date.mon, date.day,
                               date.hour, date.min, date.sec),
                  format: :card_date_seconds)
  else
    # .strftime('%B %e, %Y')
    I18n.localize(DateTime.new(date.year, date.mon, date.day),
                  format: :card_date_only)
  end
end
id_counter() click to toggle source
# File lib/card/format/content.rb, line 59
def id_counter
  return @parent.id_counter if @parent

  @id_counter ||= 0
  @id_counter += 1
end
output(*content) { || ... } click to toggle source
# File lib/card/format/content.rb, line 70
def output *content
  content = yield if block_given?
  Array.wrap(content).flatten.compact.join "\n"
end
prepend_class(options, klass) click to toggle source
# File lib/card/format/content.rb, line 51
def prepend_class options, klass
  options[:class] = css_classes klass, options[:class]
end
process_content(override_content=nil, content_opts=nil, &block) click to toggle source
# File lib/card/format/content.rb, line 4
def process_content override_content=nil, content_opts=nil, &block
  content_obj = content_object override_content, content_opts
  content_obj.process_chunks(&block)
  content_obj.to_s
end
safe_process_content(override_content=nil, content_opts=nil, &block) click to toggle source
  1. Break out references (nests / links) into separate chunks

  2. yields the other (non-ref) content

  3. processes references

# File lib/card/format/content.rb, line 13
def safe_process_content override_content=nil, content_opts=nil, &block
  content_obj = content_object override_content, chunk_list: :references
  process_content content_obj.without_references(&block), content_opts
end
unique_id() click to toggle source
# File lib/card/format/content.rb, line 66
def unique_id
  "#{card.name.safe_key}-#{id_counter}"
end

Private Instance Methods

content_object(content=nil, content_opts=voo&.content_opts) click to toggle source
# File lib/card/format/content.rb, line 77
def content_object content=nil, content_opts=voo&.content_opts
  return content if content.is_a? Card::Content

  content ||= render_raw || ""
  Card::Content.new content, self, content_opts
end