Sha256: dbb02a1ca7e047a9d023f26f7d3a5b341b5e938a60f004be88a6951d44ce81ec
Contents?: true
Size: 928 Bytes
Versions: 6
Compression:
Stored size: 928 Bytes
Contents
module DismissibleBlocksHelper def render_dismissible_block(name, &block) unless dismissed?(name) if block_given? contents = capture(name, &block) add_block_name_to_attributes(contents, name) else raise DismissibleBlocks::ContentMissing end end end private def dismissed?(name) if respond_to?(:current_user) if !current_user.respond_to?(:dismissed_blocks) raise DismissibleBlocks::AttributeUnavailable elsif !current_user.dismissed_blocks.is_a?(Array) raise DismissibleBlocks::AttributeNotArray else current_user.dismissed_blocks.include?(name) end else raise DismissibleBlocks::ModelUnavailable end end def add_block_name_to_attributes(contents, name) contents.gsub!(/(data-dismissible)(-hide)?(?![-=])/, "\\1\\2='#{name}'") contents.html_safe end end
Version data entries
6 entries across 6 versions & 1 rubygems