Class: Bridgetown::Tags::ClassMap

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
bridgetown-core/lib/bridgetown-core/tags/class_map.rb

Overview

A ClassMap class is meant to take a hash and append styles based on if the value is truthy or falsy

Examples:

center-var = true
small-var = nil

# input
<div class="{% class_map has-centered-text: center-var, is-small: small-var %}">
  Text
</div>

# output
<div class="has-centered-text">
  Text
</div>

Constant Summary collapse

FALSE_VALUES =
[
  nil, "nil", "NIL", false, 0, "0", :"0", "f", :f, "F", :F, "false",
  false, "FALSE", :FALSE,
].to_set.freeze

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, input, tokens) ⇒ ClassMap

Returns a ClassMap object

Parameters:

  • tag_name (String)

    The name to use for the tag

  • input (String)

    The input to the tag

  • tokens (Hash)

    A hash of config tokens for Liquid.



36
37
38
39
# File 'bridgetown-core/lib/bridgetown-core/tags/class_map.rb', line 36

def initialize(tag_name, input, tokens)
  super
  @input = input
end

Instance Method Details

#render(context) ⇒ Object



41
42
43
# File 'bridgetown-core/lib/bridgetown-core/tags/class_map.rb', line 41

def render(context)
  class_map(@input, context)
end