Module: Card::Format::Content

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

Instance Method Summary collapse

Instance Method Details

#add_class(options, klass) ⇒ Object



35
36
37
# File 'lib/card/format/content.rb', line 35

def add_class options, klass
  options[:class] = [options[:class], klass].flatten.uniq.compact * " "
end

#format_date(date, include_time = true) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/card/format/content.rb', line 21

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

#get_content_object(content, opts) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/card/format/content.rb', line 13

def get_content_object content, opts
  if content.is_a? Card::Content
    content
  else
    Card::Content.new content, self, opts.delete(:content_opts)
  end
end

#id_counterObject



39
40
41
42
43
# File 'lib/card/format/content.rb', line 39

def id_counter
  return @parent.id_counter if @parent
  @id_counter ||= 0
  @id_counter += 1
end

#output(content) ⇒ Object



49
50
51
52
53
54
# File 'lib/card/format/content.rb', line 49

def output content
  case content
  when String then content
  when Array then content.compact.join "\n"
  end
end

#process_content(override_content = nil, opts = {}) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/card/format/content.rb', line 4

def process_content override_content=nil, opts={}
  content = override_content || render_raw || ""
  content_object = get_content_object content, opts
  content_object.process_each_chunk do |chunk_opts|
    prepare_nest chunk_opts.merge(opts)
  end
  content_object.to_s
end

#unique_idObject



45
46
47
# File 'lib/card/format/content.rb', line 45

def unique_id
  "#{card.key}-#{id_counter}"
end