Class: BootstrapBuilders::Panel

Inherits:
Object
  • Object
show all
Defined in:
lib/bootstrap_builders/panel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Panel

Returns a new instance of Panel.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bootstrap_builders/panel.rb', line 24

def initialize(args)
  @collapsable = args[:collapsable]
  @collapsed = args[:collapsed]
  @title = args.fetch(:title)
  @table = args[:table]
  @context = args[:context]
  @class = args[:class]
  @data = args[:data]

  @controls = args[:controls]
  @controls = [@controls] unless @controls.is_a?(Array)

  @css = {}
  @css[:width] = args.fetch(:width) if args[:width]

  @block = proc do
    args.fetch(:block).call(self)
  end
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



2
3
4
# File 'lib/bootstrap_builders/panel.rb', line 2

def context
  @context
end

#controlsObject

Returns the value of attribute controls.



2
3
4
# File 'lib/bootstrap_builders/panel.rb', line 2

def controls
  @controls
end

Class Method Details

.with_parsed_args(*args_given, &blk) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bootstrap_builders/panel.rb', line 4

def self.with_parsed_args(*args_given, &blk)
  args_parser = BootstrapBuilders::ArgumentsParser.new(
    arguments: args_given,
    short_true_arguments: [
      :collapsable, :collapsed, :table
    ]
  )
  args = args_parser.arguments
  args_hash = args_parser.arguments_hash

  title = args.shift if args.first.is_a?(String)
  width = args.shift unless args.first.is_a?(Hash)

  title = args_hash.fetch(:title) if args_hash.key?(:title)
  width = args_hash[:width] if args_hash.key?(:width)
  right = args_hash[:right] if args_hash.key?(:right)

  BootstrapBuilders::Panel.new(args_hash.merge(title: title, width: width, right: right, block: blk))
end

Instance Method Details

#htmlObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bootstrap_builders/panel.rb', line 44

def html
  @panel = HtmlGen::Element.new(:div, inden: "  ", classes: container_classes, css: @css, data: @data)

  generate_body
  add_heading if heading?
  add_body
  add_heading_controls
  html = @panel.html

  if html.respond_to?(:html_safe)
    html.html_safe # rubocop:disable Rails/OutputSafety
  else
    html
  end
end