Module: TimelineRailsHelper::Helpers

Defined in:
lib/timeline_rails_helper/helpers.rb

Overview

This module expands the helper method into ActiveSupport helper.

Instance Method Summary collapse

Instance Method Details

#timeline_molecules_tag(records, condition = nil) ⇒ String

Create a timeline_molecules tag usable with vanilla CSS.

timeline_molecules_tag [{title: (DateTime.now - 3.days).strftime('%Y-%m-%d'),
                          body: 'This is a test'},
                        {title: DateTime.now.strftime('%Y-%m-%d'),
                          body: 'This is a test'}]
=>   "<div class=\"entries\">
        <div class=\"entry\">
          <div class=\"title \">2022-04-13</div>
          <div class=\"body\">This is a test</div>
        </div>
        <div class=\"entry\">
          <div class=\"title \">2022-04-16</div>
          <div class=\"body\">This is a test</div>
        </div>
      </div>"

Available options:

:condition

Add a condition which corresponds to the title, then assign the CSS property. (default: nil)

Parameters:

  • records (Array)
  • condition (String) (defaults to: nil)

Returns:

  • (String)


32
33
34
35
36
37
38
# File 'lib/timeline_rails_helper/helpers.rb', line 32

def timeline_molecules_tag(records, condition = nil)
  return "" if records.empty?

  wrap_container = ->(x) { "<div class=\"entry\">\n#{x}\n</div>" }
  content = records.map(&(wrap_tag(condition) >> wrap_container)).join("\n")
  "<div class=\"entries\">\n#{content}\n</div>"
end