Class: Maglove::Widgets::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/maglove/widgets/image.rb

Instance Attribute Summary

Attributes inherited from Base

#options, #scope

Instance Method Summary collapse

Methods inherited from Base

#initialize, #widget_options

Constructor Details

This class inherits a constructor from Maglove::Widgets::Base

Instance Method Details

#defaultsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/maglove/widgets/image.rb', line 8

def defaults
  {
    style: "img-responsive",
    align: "center",
    source: false,
    magnify: false,
    tooltip_icon: "bullhorn",
    tooltip_text_alignment: "justify",
    tooltip_text_size: "medium",
    tooltip_position: "top-right",
    tooltip_text: ""
  }
end

#identifierObject



4
5
6
# File 'lib/maglove/widgets/image.rb', line 4

def identifier
  "image"
end

#image_classesObject



22
23
24
25
26
27
# File 'lib/maglove/widgets/image.rb', line 22

def image_classes
  classes = ["image-widget"]
  classes.push("align-#{@options[:align]}")
  classes.push("popup-position-#{@options[:tooltip_position]}") if popup?
  classes.join(" ")
end

#popup?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/maglove/widgets/image.rb', line 29

def popup?
  !@options[:tooltip_text].blank?
end

#template(&block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/maglove/widgets/image.rb', line 33

def template(&block)
  haml_tag :div, class: image_classes do
    if popup?
      haml_tag :i, class: "popup fa fa-lg fa-#{options[:tooltip_icon]}"
      haml_tag :div, class: "popup-box", style: "font-size: #{options[:tooltip_text_size]}, text-align: #{options[:tooltip_text_alignment]};" do
        haml_concat(options[:tooltip_text])
      end
    end
    haml_tag :img, class: "image #{options[:style]} #{options[:magnify] ? 'magnific-image' : ''}", src: options[:source]
    haml_tag :div, class: "image-drop-target"
  end
end