Class: Cloudpress::Renderers::Flash

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudpress/renderers/flash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, type, options = {}) ⇒ Flash

Returns a new instance of Flash.



7
8
9
10
11
# File 'lib/cloudpress/renderers/flash.rb', line 7

def initialize(context, type, options={})
  @context   = context
  @type      = type
  @options   = options.reverse_merge(default_options)
end

Instance Attribute Details

#contentObject



13
14
15
# File 'lib/cloudpress/renderers/flash.rb', line 13

def content
  @content ? @content : @context.(:p, @context.flash[type])
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/cloudpress/renderers/flash.rb', line 5

def options
  @options
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/cloudpress/renderers/flash.rb', line 5

def type
  @type
end

Instance Method Details

#content?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/cloudpress/renderers/flash.rb', line 17

def content?
  !!content
end

#flash_html_attributesObject



32
33
34
35
36
37
# File 'lib/cloudpress/renderers/flash.rb', line 32

def flash_html_attributes
  {
    id: options[:id],
    class: css_classes
  }.reject { |k, v| v.blank? }
end

#iconObject



21
22
23
# File 'lib/cloudpress/renderers/flash.rb', line 21

def icon
  @context.icon(options[:icon]) if icon?
end

#renderObject



25
26
27
28
29
30
# File 'lib/cloudpress/renderers/flash.rb', line 25

def render
  return nil unless content?
  @context.render(layout: 'cloudpress/flashes/flash', locals: {renderer: self}) do
    content
  end
end