Class: BulmaPhlex::Rails::BlockDisplayOptions
- Inherits:
-
Object
- Object
- BulmaPhlex::Rails::BlockDisplayOptions
- 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
- #column? ⇒ Boolean
- #column_options ⇒ Object
- #current ⇒ Object
- #grid? ⇒ Boolean
- #grid_options ⇒ Object
-
#initialize ⇒ BlockDisplayOptions
constructor
A new instance of BlockDisplayOptions.
- #pop ⇒ Object
- #push(options) ⇒ Object
Constructor Details
#initialize ⇒ BlockDisplayOptions
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
45 46 47 |
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 45 def column? current[:column] end |
#column_options ⇒ Object
53 54 55 56 57 58 |
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 53 def return {} unless column? opts = @column_options.last opts == true ? {} : opts end |
#current ⇒ Object
41 42 43 |
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 41 def current @stack.last end |
#grid? ⇒ Boolean
49 50 51 |
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 49 def grid? current[:grid] end |
#grid_options ⇒ Object
60 61 62 63 64 65 |
# File 'lib/bulma_phlex/rails/models/block_display_options.rb', line 60 def return {} unless grid? opts = @grid_options.last opts == true ? {} : opts end |
#pop ⇒ Object
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() = .dup # store the columns option, then add a boolean flag @column_options.push(.delete(:columns)) [:column] = !!@column_options.last # rubocop:disable Style/DoubleNegation # store the grid option, then convert it to a boolean flag @grid_options.push([:grid]) [:grid] = !![:grid] # rubocop:disable Style/DoubleNegation @stack.push(current.merge()) end |