Module: Card::Format::Content
- Included in:
- Card::Format
- Defined in:
- lib/card/format/content.rb
Instance Method Summary collapse
- #add_class(options, klass) ⇒ Object (also: #append_class)
-
#content_nest(opts = {}) ⇒ Object
nested by another card’s content (as opposed to a direct API nest).
- #css_classes(*array) ⇒ Object
- #format_date(date, include_time = true) ⇒ Object
- #id_counter ⇒ Object
- #output(*content) ⇒ Object
- #prepend_class(options, klass) ⇒ Object
- #process_content(override_content = nil, content_opts = nil, &block) ⇒ Object
-
#safe_process_content(override_content = nil, content_opts = nil, &block) ⇒ Object
Preserves the syntax in all nests.
- #unique_id ⇒ Object
Instance Method Details
#add_class(options, klass) ⇒ Object Also known as: append_class
45 46 47 48 49 |
# File 'lib/card/format/content.rb', line 45 def add_class , klass return if klass.blank? [:class] = css_classes [:class], klass end |
#content_nest(opts = {}) ⇒ Object
nested by another card’s content (as opposed to a direct API nest)
22 23 24 25 26 27 28 29 |
# File 'lib/card/format/content.rb', line 22 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) ⇒ Object
57 58 59 |
# File 'lib/card/format/content.rb', line 57 def css_classes *array array.flatten.uniq.compact * " " end |
#format_date(date, include_time = true) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/card/format/content.rb', line 31 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 ⇒ Object
61 62 63 64 65 66 |
# File 'lib/card/format/content.rb', line 61 def id_counter return @parent.id_counter if @parent @id_counter ||= 0 @id_counter += 1 end |
#output(*content) ⇒ Object
72 73 74 75 |
# File 'lib/card/format/content.rb', line 72 def output *content content = yield if block_given? Array.wrap(content).flatten.compact.join "\n" end |
#prepend_class(options, klass) ⇒ Object
53 54 55 |
# File 'lib/card/format/content.rb', line 53 def prepend_class , klass [:class] = css_classes klass, [:class] end |
#process_content(override_content = nil, content_opts = nil, &block) ⇒ Object
4 5 6 7 8 |
# 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) ⇒ Object
Preserves the syntax in all nests. The content is yielded with placeholders for all nests. After executing the given block the original nests are put back in. Placeholders are numbers in double curly brackets like {2}.
13 14 15 16 17 18 |
# 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_keep_escaping result = content_obj.without_references(&block) process_content result, content_opts end |
#unique_id ⇒ Object
68 69 70 |
# File 'lib/card/format/content.rb', line 68 def unique_id "#{card.name.safe_key}-#{id_counter}" end |