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 Also known as: append_class



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

def add_class options, klass
  options[:class] = css_classes options[:class], klass
end

#css_classes(*array) ⇒ Object



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

def css_classes *array
  array.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



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

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

#output(*content) ⇒ Object



59
60
61
62
# File 'lib/card/format/content.rb', line 59

def output *content
  content ||= yield
  Array.wrap(content).flatten.compact.join "\n"
end

#prepend_class(options, klass) ⇒ Object



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

def prepend_class options, klass
  options[:class] = css_classes klass, options[:class]
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|
    content_nest chunk_opts.merge(opts)
  end
  content_object.to_s
end

#unique_idObject



55
56
57
# File 'lib/card/format/content.rb', line 55

def unique_id
  "#{card.cardname.safe_key}-#{id_counter}"
end