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



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

def add_class options, klass
  return if klass.blank?
  options[:class] = css_classes options[:class], klass
end

#content_nest(opts = {}) ⇒ Object

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



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

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 nest_name, opts
end

#css_classes(*array) ⇒ Object



47
48
49
# File 'lib/card/format/content.rb', line 47

def css_classes *array
  array.flatten.uniq.compact * " "
end

#format_date(date, include_time = true) ⇒ Object



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

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_counterObject



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

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

#output(*content) ⇒ Object



61
62
63
64
# File 'lib/card/format/content.rb', line 61

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

#prepend_class(options, klass) ⇒ Object



43
44
45
# File 'lib/card/format/content.rb', line 43

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

#process_content(override_content = nil, content_opts = nil) ⇒ Object



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

def process_content override_content=nil, content_opts=nil
  content = override_content || render_raw || ""
  content_object = get_content_object content, content_opts
  content_object.process_each_chunk do |chunk_opts|
    content_nest chunk_opts
  end
  content_object.to_s
end

#unique_idObject



57
58
59
# File 'lib/card/format/content.rb', line 57

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