Module: PolarisViewHelpers::Helper
- Defined in:
- lib/polaris_view_helpers/helper.rb
Instance Method Summary collapse
- #polaris_annotated_section(heading: '', description: '', &block) ⇒ Object
- #polaris_annotated_section_input(form, attribute, input, &block) ⇒ Object
- #polaris_annotated_section_select(form, attribute, select_options = [], element_type = :select, &block) ⇒ Object
- #polaris_annotated_section_text_field(form, attribute, options = {}, element_type = :text_field, &block) ⇒ Object
- #polaris_badge(content, status = nil) ⇒ Object
- #polaris_banner(options, &block) ⇒ Object
- #polaris_banner_actions(&block) ⇒ Object
- #polaris_button_link_to(name = nil, link_destination = nil, button_options = nil, &block) ⇒ Object
- #polaris_button_tag(name, button_options) ⇒ Object
- #polaris_card(heading = nil, footer: nil, extra_class: "", &block) ⇒ Object
- #polaris_choice_list(form:, attribute:, title:, selected:, choices:, data: nil) ⇒ Object
- #polaris_css(version = '7.5.0') ⇒ Object
- #polaris_css_variable_hack_div(&block) ⇒ Object
- #polaris_description_list(&block) ⇒ Object
- #polaris_description_list_item(term, &block) ⇒ Object
- #polaris_footer_help(icon: 'next-help-circle', &block) ⇒ Object
- #polaris_form_layout(&block) ⇒ Object
- #polaris_form_layout_item(form, att, text = nil, &block) ⇒ Object
- #polaris_form_layout_item_select(form, att, text = nil, &block) ⇒ Object
- #polaris_heading(title) ⇒ Object
- #polaris_icon(name = 'CircleTickMajor') ⇒ Object
- #polaris_layout(&block) ⇒ Object
- #polaris_layout_section(secondary: false, one_half: false, &block) ⇒ Object
- #polaris_link_to(name = nil, link_destination = nil, button_options = nil, &block) ⇒ Object
- #polaris_model_errors(model, &block) ⇒ Object
- #polaris_page(&block) ⇒ Object
- #polaris_page_actions(options) ⇒ Object
- #polaris_page_content(&block) ⇒ Object
- #polaris_page_header(title, &block) ⇒ Object
- #polaris_random_input_name ⇒ Object
- #polaris_resource_list(&block) ⇒ Object
- #polaris_resource_list_item(attributes) ⇒ Object
- #polaris_select(form:, attribute:, title: nil, selected: nil, options:, data: nil, select_options: {}) ⇒ Object
- #polaris_sub_heading(title) ⇒ Object
- #polaris_tab(text, link_path, active = nil) ⇒ Object
- #polaris_tabs(&block) ⇒ Object
- #polaris_text_area(form, attribute, options = {}, element_type = :text_area, &block) ⇒ Object
- #polaris_text_field(form, attribute, options = {}, element_type = :text_field, &block) ⇒ Object
- #polaris_thumbnail(attributes) ⇒ Object
- #pvh_svg(name) ⇒ Object
Instance Method Details
#polaris_annotated_section(heading: '', description: '', &block) ⇒ Object
251 252 253 254 255 256 257 258 259 260 |
# File 'lib/polaris_view_helpers/helper.rb', line 251 def polaris_annotated_section(heading:'', description:'', &block) render( partial: 'polaris/annotated_section', locals: { heading: heading, description: description, block: block } ) end |
#polaris_annotated_section_input(form, attribute, input, &block) ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/polaris_view_helpers/helper.rb', line 341 def polaris_annotated_section_input(form, attribute, input, &block) unless attribute.is_a? Array attribute = [attribute] end render( partial: 'polaris/annotated_section_input', locals: { form: form, attribute: attribute, input: input, block: block } ) end |
#polaris_annotated_section_select(form, attribute, select_options = [], element_type = :select, &block) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/polaris_view_helpers/helper.rb', line 324 def polaris_annotated_section_select(form, attribute, = [], element_type = :select, &block) unless attribute.is_a? Array attribute = [attribute] end render( partial: 'polaris/annotated_section_select', locals: { form: form, attribute: attribute, element_type: element_type, select_options: , block: block } ) end |
#polaris_annotated_section_text_field(form, attribute, options = {}, element_type = :text_field, &block) ⇒ Object
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/polaris_view_helpers/helper.rb', line 307 def polaris_annotated_section_text_field(form, attribute, = {}, element_type = :text_field, &block) unless attribute.is_a? Array attribute = [attribute] end render( partial: 'polaris/annotated_section_text_field', locals: { form: form, attribute: attribute, element_type: element_type, options: , block: block } ) end |
#polaris_badge(content, status = nil) ⇒ Object
372 373 374 375 376 377 378 |
# File 'lib/polaris_view_helpers/helper.rb', line 372 def polaris_badge(content, status = nil) extra_class = status.present? ? "Polaris-Badge--status#{status.to_s.capitalize}" : "" render( partial: 'polaris/badge', locals: { content: content, status: status, extra_class: extra_class } ) end |
#polaris_banner(options, &block) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/polaris_view_helpers/helper.rb', line 159 def (, &block) render( partial: 'polaris/banner', locals: { options: , block: block } ) end |
#polaris_banner_actions(&block) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/polaris_view_helpers/helper.rb', line 166 def (&block) render( partial: 'polaris/banner_actions', locals: { block: block } ) end |
#polaris_button_link_to(name = nil, link_destination = nil, button_options = nil, &block) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/polaris_view_helpers/helper.rb', line 173 def (name = nil, link_destination = nil, = nil, &block) if block_given? , link_destination, name = link_destination, name, nil end ||= {} additional_classes = [:additional_classes] || "" ([:modifiers] || []).each do |modifier| additional_classes += "Polaris-Button--#{modifier} " end render( partial: 'polaris/button_link_to', locals: { name: name, block: block, additional_classes: additional_classes, link_destination: link_destination, method: [:method], remote: [:remote], target: [:target], confirm: [:confirm] } ) end |
#polaris_button_tag(name, button_options) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/polaris_view_helpers/helper.rb', line 237 def (name, ) additional_classes = "" ([:modifiers] || []).each do |modifier| additional_classes += "Polaris-Button--#{modifier} " end [:additional_classes] = additional_classes [:name] = name render( partial: 'polaris/button_tag', locals: ) end |
#polaris_card(heading = nil, footer: nil, extra_class: "", &block) ⇒ Object
401 402 403 404 405 406 |
# File 'lib/polaris_view_helpers/helper.rb', line 401 def polaris_card(heading = nil, footer: nil, extra_class: "", &block) render( partial: 'polaris/card', locals: { block: block, heading: heading, footer: , extra_class: extra_class } ) end |
#polaris_choice_list(form:, attribute:, title:, selected:, choices:, data: nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/polaris_view_helpers/helper.rb', line 33 def polaris_choice_list(form:, attribute:, title:, selected:, choices:, data: nil) render( partial: 'polaris/choice_list', locals: { form: form, attribute: attribute, title: title, selected: selected, choices: choices, data: data } ) end |
#polaris_css(version = '7.5.0') ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/polaris_view_helpers/helper.rb', line 4 def polaris_css version = '7.5.0' major_version = version.split('.').first.to_i if major_version <= 6 %[<link rel="stylesheet" href="https://unpkg.com/@shopify/polaris@#{version}/dist/styles.css" />].html_safe else %[<link rel="stylesheet" href="https://unpkg.com/@shopify/polaris@#{version}/build/esm/styles.css" />].html_safe end end |
#polaris_css_variable_hack_div(&block) ⇒ Object
415 416 417 418 419 420 |
# File 'lib/polaris_view_helpers/helper.rb', line 415 def polaris_css_variable_hack_div(&block) render( partial: 'polaris/polaris_css_variable_hack_div', locals: { block: block } ) end |
#polaris_description_list(&block) ⇒ Object
387 388 389 390 391 392 |
# File 'lib/polaris_view_helpers/helper.rb', line 387 def polaris_description_list(&block) render( partial: 'polaris/description_list', locals: { block: block } ) end |
#polaris_description_list_item(term, &block) ⇒ Object
394 395 396 397 398 399 |
# File 'lib/polaris_view_helpers/helper.rb', line 394 def polaris_description_list_item(term, &block) render( partial: 'polaris/description_list_item', locals: { block: block, term: term } ) end |
#polaris_footer_help(icon: 'next-help-circle', &block) ⇒ Object
408 409 410 411 412 413 |
# File 'lib/polaris_view_helpers/helper.rb', line 408 def (icon: 'next-help-circle', &block) render( partial: 'polaris/footer_help', locals: { block: block, icon: icon } ) end |
#polaris_form_layout(&block) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/polaris_view_helpers/helper.rb', line 131 def polaris_form_layout(&block) render( partial: 'polaris/form_layout', locals: { block: block } ) end |
#polaris_form_layout_item(form, att, text = nil, &block) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/polaris_view_helpers/helper.rb', line 262 def polaris_form_layout_item(form, att, text = nil, &block) render( partial: 'polaris/form_layout_item', locals: { form: form, att: att, text: text, block: block } ) end |
#polaris_form_layout_item_select(form, att, text = nil, &block) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/polaris_view_helpers/helper.rb', line 274 def polaris_form_layout_item_select(form, att, text = nil, &block) render( partial: 'polaris/form_layout_item_select', locals: { form: form, att: att, text: text, block: block } ) end |
#polaris_heading(title) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/polaris_view_helpers/helper.rb', line 93 def polaris_heading(title) render( partial: 'polaris/heading', locals: { title: title } ) end |
#polaris_icon(name = 'CircleTickMajor') ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/polaris_view_helpers/helper.rb', line 17 def polaris_icon(name = 'CircleTickMajor') render( partial: 'polaris/icon', locals: { name: name, } ) end |
#polaris_layout(&block) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/polaris_view_helpers/helper.rb', line 114 def polaris_layout(&block) render( partial: 'polaris/layout', locals: { block: block } ) end |
#polaris_layout_section(secondary: false, one_half: false, &block) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/polaris_view_helpers/helper.rb', line 121 def polaris_layout_section(secondary: false, one_half: false, &block) extra_class = secondary ? "Polaris-Layout__Section--secondary" : "" extra_class += " " extra_class += one_half ? "Polaris-Layout__Section--oneHalf" : "" render( partial: 'polaris/layout_section', locals: { block: block, extra_class: extra_class } ) end |
#polaris_link_to(name = nil, link_destination = nil, button_options = nil, &block) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/polaris_view_helpers/helper.rb', line 198 def polaris_link_to(name = nil, link_destination = nil, = nil, &block) if block_given? , link_destination, name = link_destination, name, nil end ||= {} additional_classes = "" ([:modifiers] || []).each do |modifier| additional_classes += "Polaris-Button--#{modifier} " end render( partial: 'polaris/link_to', locals: { name: name, block: block, additional_classes: additional_classes, link_destination: link_destination, method: [:method], remote: [:remote], target: [:target], confirm: [:confirm] } ) end |
#polaris_model_errors(model, &block) ⇒ Object
223 224 225 226 227 228 |
# File 'lib/polaris_view_helpers/helper.rb', line 223 def polaris_model_errors model, &block render( partial: 'polaris/model_errors', locals: { model: model, block: block } ) end |
#polaris_page(&block) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/polaris_view_helpers/helper.rb', line 79 def polaris_page(&block) render( partial: 'polaris/page', locals: { block: block } ) end |
#polaris_page_actions(options) ⇒ Object
230 231 232 233 234 235 |
# File 'lib/polaris_view_helpers/helper.rb', line 230 def polaris_page_actions() render( partial: 'polaris/page_actions', locals: ) end |
#polaris_page_content(&block) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/polaris_view_helpers/helper.rb', line 107 def polaris_page_content(&block) render( partial: 'polaris/page_content', locals: { block: block } ) end |
#polaris_page_header(title, &block) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/polaris_view_helpers/helper.rb', line 86 def polaris_page_header(title, &block) render( partial: 'polaris/page_header', locals: { title: title, block: block } ) end |
#polaris_random_input_name ⇒ Object
13 14 15 |
# File 'lib/polaris_view_helpers/helper.rb', line 13 def polaris_random_input_name "pri-#{SecureRandom.hex(8)}" end |
#polaris_resource_list(&block) ⇒ Object
357 358 359 360 361 362 |
# File 'lib/polaris_view_helpers/helper.rb', line 357 def polaris_resource_list(&block) render( partial: 'polaris/resource_list', locals: { block: block } ) end |
#polaris_resource_list_item(attributes) ⇒ Object
364 365 366 367 368 369 370 |
# File 'lib/polaris_view_helpers/helper.rb', line 364 def polaris_resource_list_item(attributes) extra_classes = attributes[:media].present? ? "Polaris-ResourceList__Item--mediaThumbnail Polaris-ResourceList__Item--sizeMedium" : "" render( partial: 'polaris/resource_list_item', locals: { attributes: attributes, extra_classes: extra_classes } ) end |
#polaris_select(form:, attribute:, title: nil, selected: nil, options:, data: nil, select_options: {}) ⇒ Object
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 |
# File 'lib/polaris_view_helpers/helper.rb', line 47 def polaris_select(form:, attribute:, title: nil, selected: nil, options:, data: nil, select_options: {}) selected ||= form.object&.send(attribute) selected_label = selected = .map do |option| real_option = option if option.is_a? Array real_option = OpenStruct.new(label: option[0], value: option[1]) elsif option.respond_to?(:label) && .respond_to?(:value) #real_option = option else real_option = OpenStruct.new(label: option[:label], value: option[:value]) end if real_option.value.to_s == selected.to_s selected_label = real_option.label end real_option end render( partial: 'polaris/select', locals: { form: form, attribute: attribute, title: title, selected: selected, selected_label: selected_label, options: , select_options: , data: data } ) end |
#polaris_sub_heading(title) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/polaris_view_helpers/helper.rb', line 100 def polaris_sub_heading(title) render( partial: 'polaris/sub_heading', locals: { title: title } ) end |
#polaris_tab(text, link_path, active = nil) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/polaris_view_helpers/helper.rb', line 145 def polaris_tab(text, link_path, active = nil) unless active.present? active = link_path == request.original_fullpath end render( partial: 'polaris/tab', locals: { text: text, link_path: link_path, active: active } ) end |
#polaris_tabs(&block) ⇒ Object
138 139 140 141 142 143 |
# File 'lib/polaris_view_helpers/helper.rb', line 138 def polaris_tabs(&block) render( partial: 'polaris/tabs', locals: { block: block } ) end |
#polaris_text_area(form, attribute, options = {}, element_type = :text_area, &block) ⇒ Object
303 304 305 |
# File 'lib/polaris_view_helpers/helper.rb', line 303 def polaris_text_area(form, attribute, = {}, element_type = :text_area, &block) polaris_text_field(form, attribute, , element_type, &block) end |
#polaris_text_field(form, attribute, options = {}, element_type = :text_field, &block) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/polaris_view_helpers/helper.rb', line 286 def polaris_text_field(form, attribute, = {}, element_type = :text_field, &block) unless attribute.is_a? Array attribute = [attribute] end render( partial: 'polaris/text_field', locals: { form: form, attribute: attribute, element_type: element_type, options: , block: block } ) end |
#polaris_thumbnail(attributes) ⇒ Object
380 381 382 383 384 385 |
# File 'lib/polaris_view_helpers/helper.rb', line 380 def polaris_thumbnail(attributes) render( partial: 'polaris/thumbnail', locals: { attributes: attributes } ) end |
#pvh_svg(name) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/polaris_view_helpers/helper.rb', line 26 def pvh_svg(name) our_path = File.dirname(__FILE__) file_path = File.join(our_path, "..", "..", "app/views/polaris/icons/#{name}.svg") return File.read(file_path).html_safe if File.exists?(file_path) "(#{name} not found)" end |