Class: HotGlue::Layout::Builder
- Inherits:
-
Object
- Object
- HotGlue::Layout::Builder
- Includes:
- DefaultConfigLoader
- Defined in:
- lib/generators/hot_glue/layout/builder.rb
Instance Attribute Summary collapse
-
#bootstrap_column_width ⇒ Object
readonly
Returns the value of attribute bootstrap_column_width.
-
#buttons_width ⇒ Object
readonly
Returns the value of attribute buttons_width.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#downnest_object ⇒ Object
readonly
Returns the value of attribute downnest_object.
-
#include_setting ⇒ Object
readonly
Returns the value of attribute include_setting.
-
#smart_layout ⇒ Object
readonly
Returns the value of attribute smart_layout.
-
#specified_grouping_mode ⇒ Object
readonly
Returns the value of attribute specified_grouping_mode.
-
#stacked_downnesting ⇒ Object
readonly
Returns the value of attribute stacked_downnesting.
Instance Method Summary collapse
- #construct ⇒ Object
-
#initialize(generator:, include_setting:, buttons_width:) ⇒ Builder
constructor
A new instance of Builder.
Methods included from DefaultConfigLoader
#default_configs, #get_default_from_config
Constructor Details
#initialize(generator:, include_setting:, buttons_width:) ⇒ Builder
Returns a new instance of Builder.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/generators/hot_glue/layout/builder.rb', line 13 def initialize(generator: , include_setting:, buttons_width: ) @generator = generator @modify_as = generator.modify_as @display_as = generator.display_as @columns = generator.columns @smart_layout = generator.smart_layout @stacked_downnesting = generator.stacked_downnesting || false @downnest_object = generator.downnest_object @include_setting = include_setting @buttons_width = @no_buttons = @buttons_width == 0 @specified_grouping_mode = include_setting.include?(":") @bootstrap_column_width = generator.bootstrap_column_width.to_i @big_edit = generator.big_edit @default_boolean_display = get_default_from_config(key: :default_boolean_display) end |
Instance Attribute Details
#bootstrap_column_width ⇒ Object (readonly)
Returns the value of attribute bootstrap_column_width.
7 8 9 |
# File 'lib/generators/hot_glue/layout/builder.rb', line 7 def bootstrap_column_width @bootstrap_column_width end |
#buttons_width ⇒ Object (readonly)
Returns the value of attribute buttons_width.
7 8 9 |
# File 'lib/generators/hot_glue/layout/builder.rb', line 7 def @buttons_width end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
7 8 9 |
# File 'lib/generators/hot_glue/layout/builder.rb', line 7 def columns @columns end |
#downnest_object ⇒ Object (readonly)
Returns the value of attribute downnest_object.
7 8 9 |
# File 'lib/generators/hot_glue/layout/builder.rb', line 7 def downnest_object @downnest_object end |
#include_setting ⇒ Object (readonly)
Returns the value of attribute include_setting.
7 8 9 |
# File 'lib/generators/hot_glue/layout/builder.rb', line 7 def include_setting @include_setting end |
#smart_layout ⇒ Object (readonly)
Returns the value of attribute smart_layout.
7 8 9 |
# File 'lib/generators/hot_glue/layout/builder.rb', line 7 def smart_layout @smart_layout end |
#specified_grouping_mode ⇒ Object (readonly)
Returns the value of attribute specified_grouping_mode.
7 8 9 |
# File 'lib/generators/hot_glue/layout/builder.rb', line 7 def specified_grouping_mode @specified_grouping_mode end |
#stacked_downnesting ⇒ Object (readonly)
Returns the value of attribute stacked_downnesting.
7 8 9 |
# File 'lib/generators/hot_glue/layout/builder.rb', line 7 def stacked_downnesting @stacked_downnesting end |
Instance Method Details
#construct ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/generators/hot_glue/layout/builder.rb', line 39 def construct layout_object = { columns: { size_each: smart_layout ? bootstrap_column_width : (specified_grouping_mode ? nil : 1), container: [] , # array of arrays, bootstrap_column_width: [], column_custom_widths: [], fields: { }, # hash of fields }, portals: { }, buttons: { size: @buttons_width}, modify_as: @modify_as, display_as: @display_as } # downnest_object.each do |child, size| # layout_object[:portals][child] = {size: size} # end bootstrap_columns = (12 - @buttons_width ) unless @big_edit # how_many_downnest = downnest_object.size if(!stacked_downnesting) bootstrap_columns = bootstrap_columns - (downnest_object.size * 4) else bootstrap_columns = bootstrap_columns - 4 end # downnest_children_width = [] @downnest_object.each do |child, data| layout_object[:portals][child] = {size: data[:extra_size] + 4} end end available_columns = (bootstrap_columns / bootstrap_column_width).floor # when set to 2, turns the 12-column grid into a 6-column grid if available_columns < 0 raise "Cannot build layout -- too few columns" end # smart layout: bootstrap_column_width columns per field; 4 column for EACH downnested portal, 2 column for buttons if smart_layout # automatic control # if columns.size > available_columns if available_columns == 0 raise "Oopps... No available columns in SMART LAYOUT" end each_col_can_have = (columns.size.to_f / available_columns.to_f).round layout_object[:columns][:container] = (0..available_columns-1).collect { |x| columns.slice(0+(x*each_col_can_have),each_col_can_have) } layout_object[:columns][:container].last.append *columns.slice(0+(available_columns*each_col_can_have),each_col_can_have) else layout_object[:columns][:container] = (0..available_columns-1).collect { |x| [ columns[x] ] } layout_object[:columns][:container] = (0..available_columns-1).collect { |x| [columns[x]] } layout_object[:columns][:container].reject!{|x| x == [nil]} end elsif ! specified_grouping_mode # not smart and no specified grouping layout_object[:columns][:button_columns] = bootstrap_column_width layout_object[:columns][:container] = columns.collect{|col| [col]} if include_setting.split(",").any?{|col| col.include?("(")} raise "Your include list has a ( character; to specify a column width, use specified grouping mode only" end else # specified grouping mode -- the builder is given control unless a column width is explicitly set using (..) layout_object[:columns][:button_columns] = bootstrap_column_width (0..available_columns-1).each do |int| layout_object[:columns][:container][int] = [] end # input control user_layout_columns = @include_setting.split(":") fixed_widths = {} user_layout_columns.each_with_index do |column_data,i | if column_data.include?("(") column_data =~ /(.*)\((.*)\)/ column_fields = $1 fixed_col_width = $2 fixed_widths[i] = fixed_col_width else column_fields = column_data end user_layout_columns[i] = column_fields end extra_columns = available_columns - user_layout_columns.size columns_to_work_with = (12 - @buttons_width) if columns_to_work_with < user_layout_columns.size raise "Your include statement #{@include_setting } has #{user_layout_columns.size} columns, but I can only construct up to #{columns_to_work_with}" end target_col_size = columns_to_work_with / user_layout_columns.size extra_columns = columns_to_work_with % user_layout_columns.size user_layout_columns.each_with_index do |column, i| layout_object[:columns][:container][i] = column.split(",").collect{|x| x.gsub("-","").gsub("=","") if x.include?("(") x =~ /(.*)\((.*)\)/ x = $1 end x }.collect(&:to_sym) layout_object[:columns][:bootstrap_column_width][i] = fixed_widths[i] || target_col_size if i < extra_columns && ! fixed_widths[i] layout_object[:columns][:bootstrap_column_width][i] += 1 end end if user_layout_columns.size < layout_object[:columns][:container].size layout_object[:columns][:container].reject!{|x| x == []} end end # go through the columns and build the split visibility (show / form) columns.each do |col| layout_object[:columns][:fields][col] = {show: true, form: true} end @include_setting.split(":").collect { |column_list| column_list.split(",").collect do |field| if field.include?("(") field =~ /(.*)\((.*)\)/ field_short = $1 else field_short = field end field_short = field_short.gsub("-", "").gsub("=", "") layout_object[:columns][:fields][field_short.to_sym] = { show: true, form: true } if field.starts_with?("**") nil end if field.include?("-") layout_object[:columns][:fields][field_short.to_sym][:show] = false; end if field.include?("=") layout_object[:columns][:fields][field_short.to_sym][:form] = false; end end } puts "*** SPECIFIED GROUPING SETTINGS: #{layout_object.inspect}" layout_object end |