Class: BulmaPhlex::Rails::BlockDisplayOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/bulma_phlex/rails/models/block_display_options.rb

Overview

# Block Display Options

This model enables options to be collected in a nested fashion. It translates column and grid options into a flags for the form fields and stores the full options for the column and grid containers.

One small difference between the two is that the column options are specified with a plural (‘columms`) in `with_options` but the flag that gets passed to the form fields is singular (`column: true`). For grid options, both are singular (`grid`).

Instance Method Summary collapse

Constructor Details

#initializeBlockDisplayOptions

Returns a new instance of BlockDisplayOptions.



16
17
18
19
20
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 16

def initialize
  @stack = [{}]
  @grid_options = []
  @column_options = []
end

Instance Method Details

#column?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 45

def column?
  current[:column]
end

#column_optionsObject



53
54
55
56
57
58
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 53

def column_options
  return {} unless column?

  opts = @column_options.last
  opts == true ? {} : opts
end

#currentObject



41
42
43
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 41

def current
  @stack.last
end

#grid?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 49

def grid?
  current[:grid]
end

#grid_optionsObject



60
61
62
63
64
65
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 60

def grid_options
  return {} unless grid?

  opts = @grid_options.last
  opts == true ? {} : opts
end

#popObject



36
37
38
39
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 36

def pop
  @grid_options.pop
  @stack.pop
end

#push(options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 22

def push(options)
  options = options.dup

  # store the columns option, then add a boolean flag
  @column_options.push(options.delete(:columns))
  options[:column] = !!@column_options.last # rubocop:disable Style/DoubleNegation

  # store the grid option, then convert it to a boolean flag
  @grid_options.push(options[:grid])
  options[:grid] = !!options[:grid] # rubocop:disable Style/DoubleNegation

  @stack.push(current.merge(options))
end