Skip to content

add #any? and #empty? to Lucky::FlashStore#977

Merged
paulcsmith merged 1 commit intoluckyframework:masterfrom
bdtomlin:flash-store-any
Nov 23, 2019
Merged

add #any? and #empty? to Lucky::FlashStore#977
paulcsmith merged 1 commit intoluckyframework:masterfrom
bdtomlin:flash-store-any

Conversation

@bdtomlin
Copy link
Contributor

Purpose

Add a couple of missing but useful methods to the Lucky::FlashStore (any?, and empty?) #975

Description

Some common ways of using the flash store were missing (any?, and empty?), for example...

# src/components/shared/flash_messages.cr
class Shared::FlashMessages < BaseComponent
  needs flash : Lucky::FlashStore

  FLASH_CSS_CLASSES = {
    "primary": "is-primary",
    "info":    "is-info",
    "link":    "is-link",
    "success": "is-success",
    "warning": "is-warning",
    "failure": "is-danger",
  }

  def render
    if @flash.any?
      div class: "flash-messages" do
        @flash.each do |flash_type, flash_message|
          div class: "notification #{class_for_flash(flash_type)}", flow_id: "flash" do
            button class: "delete"
            text flash_message
          end
        end
      end
    end
  end

  private def class_for_flash(flash_type)
    FLASH_CSS_CLASSES[flash_type]
  end
end

Checklist

  • - An issue already exists detailing the issue/or feature request that this PR fixes
  • - All specs are formatted with crystal tool format spec src
  • - Inline documentation has been added and/or updated
  • - Lucky builds on docker with ./script/setup
  • - All builds and specs pass on docker with ./script/test

Copy link
Member

@paulcsmith paulcsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you

@paulcsmith paulcsmith merged commit 33606a6 into luckyframework:master Nov 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants