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_block_stack(&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: "", heading_actions: nil, &block) ⇒ Object
- #polaris_choice_list(form:, attribute:, title:, selected:, choices:, data: nil) ⇒ Object
- #polaris_css(version = '13.9.5') ⇒ 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_element_errors(form, attribute) ⇒ 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_inline_error(form, attribute, error) ⇒ Object
- #polaris_layout(&block) ⇒ Object
- #polaris_layout_section(secondary: false, one_half: false, &block) ⇒ Object
- #polaris_legacy_card(heading = nil, footer: nil, extra_class: "", &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 = {}, &block) ⇒ 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
278 279 280 281 282 283 284 285 286 287 |
# File 'lib/polaris_view_helpers/helper.rb', line 278 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
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/polaris_view_helpers/helper.rb', line 372 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
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/polaris_view_helpers/helper.rb', line 355 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
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/polaris_view_helpers/helper.rb', line 338 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
403 404 405 406 407 408 409 |
# File 'lib/polaris_view_helpers/helper.rb', line 403 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
179 180 181 182 183 184 |
# File 'lib/polaris_view_helpers/helper.rb', line 179 def (, &block) render( partial: 'polaris/banner', locals: { options: , block: block } ) end |
#polaris_banner_actions(&block) ⇒ Object
186 187 188 189 190 191 |
# File 'lib/polaris_view_helpers/helper.rb', line 186 def (&block) render( partial: 'polaris/banner_actions', locals: { block: block } ) end |
#polaris_block_stack(&block) ⇒ Object
193 194 195 196 197 198 |
# File 'lib/polaris_view_helpers/helper.rb', line 193 def polaris_block_stack(&block) render( partial: 'polaris/block_stack', locals: { block: block } ) end |
#polaris_button_link_to(name = nil, link_destination = nil, button_options = nil, &block) ⇒ Object
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/polaris_view_helpers/helper.rb', line 200 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
264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/polaris_view_helpers/helper.rb', line 264 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: "", heading_actions: nil, &block) ⇒ Object
432 433 434 435 436 437 |
# File 'lib/polaris_view_helpers/helper.rb', line 432 def polaris_card(heading = nil, footer: nil, extra_class: "", heading_actions: nil, &block) render( partial: 'polaris/card', locals: { block: block, heading: heading, footer: , extra_class: extra_class, heading_actions: heading_actions } ) end |
#polaris_choice_list(form:, attribute:, title:, selected:, choices:, data: nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/polaris_view_helpers/helper.rb', line 39 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 = '13.9.5') ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/polaris_view_helpers/helper.rb', line 10 def polaris_css version = '13.9.5' 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
453 454 455 456 457 458 |
# File 'lib/polaris_view_helpers/helper.rb', line 453 def polaris_css_variable_hack_div(&block) render( partial: 'polaris/polaris_css_variable_hack_div', locals: { block: block } ) end |
#polaris_description_list(&block) ⇒ Object
418 419 420 421 422 423 |
# File 'lib/polaris_view_helpers/helper.rb', line 418 def polaris_description_list(&block) render( partial: 'polaris/description_list', locals: { block: block } ) end |
#polaris_description_list_item(term, &block) ⇒ Object
425 426 427 428 429 430 |
# File 'lib/polaris_view_helpers/helper.rb', line 425 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
446 447 448 449 450 451 |
# File 'lib/polaris_view_helpers/helper.rb', line 446 def (icon: 'next-help-circle', &block) render( partial: 'polaris/footer_help', locals: { block: block, icon: icon } ) end |
#polaris_form_element_errors(form, attribute) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/polaris_view_helpers/helper.rb', line 92 def polaris_form_element_errors(form, attribute) render( partial: 'polaris/form_element_errors', locals: { form: form, attribute: attribute } ) end |
#polaris_form_layout(&block) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/polaris_view_helpers/helper.rb', line 151 def polaris_form_layout(&block) render( partial: 'polaris/form_layout', locals: { block: block } ) end |
#polaris_form_layout_item(form, att, text = nil, &block) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/polaris_view_helpers/helper.rb', line 289 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
301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/polaris_view_helpers/helper.rb', line 301 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
113 114 115 116 117 118 |
# File 'lib/polaris_view_helpers/helper.rb', line 113 def polaris_heading(title) render( partial: 'polaris/heading', locals: { title: title } ) end |
#polaris_icon(name = 'CircleTickMajor') ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/polaris_view_helpers/helper.rb', line 23 def polaris_icon(name = 'CircleTickMajor') render( partial: 'polaris/icon', locals: { name: name, } ) end |
#polaris_inline_error(form, attribute, error) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/polaris_view_helpers/helper.rb', line 85 def polaris_inline_error(form, attribute, error) render( partial: 'polaris/inline_error', locals: { form: form, attribute: attribute, error: error } ) end |
#polaris_layout(&block) ⇒ Object
134 135 136 137 138 139 |
# File 'lib/polaris_view_helpers/helper.rb', line 134 def polaris_layout(&block) render( partial: 'polaris/layout', locals: { block: block } ) end |
#polaris_layout_section(secondary: false, one_half: false, &block) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/polaris_view_helpers/helper.rb', line 141 def polaris_layout_section(secondary: false, one_half: false, &block) extra_class = secondary ? " Polaris-Layout__Section--oneThird " : "" extra_class += " " extra_class += one_half ? " Polaris-Layout__Section--oneHalf " : "" render( partial: 'polaris/layout_section', locals: { block: block, extra_class: extra_class } ) end |
#polaris_legacy_card(heading = nil, footer: nil, extra_class: "", &block) ⇒ Object
439 440 441 442 443 444 |
# File 'lib/polaris_view_helpers/helper.rb', line 439 def polaris_legacy_card(heading = nil, footer: nil, extra_class: "", &block) render( partial: 'polaris/legacy_card', locals: { block: block, heading: heading, footer: , extra_class: extra_class } ) end |
#polaris_link_to(name = nil, link_destination = nil, button_options = nil, &block) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/polaris_view_helpers/helper.rb', line 225 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-Link--#{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
250 251 252 253 254 255 |
# File 'lib/polaris_view_helpers/helper.rb', line 250 def polaris_model_errors model, &block render( partial: 'polaris/model_errors', locals: { model: model, block: block } ) end |
#polaris_page(&block) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/polaris_view_helpers/helper.rb', line 99 def polaris_page(&block) render( partial: 'polaris/page', locals: { block: block } ) end |
#polaris_page_actions(options) ⇒ Object
257 258 259 260 261 262 |
# File 'lib/polaris_view_helpers/helper.rb', line 257 def polaris_page_actions() render( partial: 'polaris/page_actions', locals: ) end |
#polaris_page_content(&block) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/polaris_view_helpers/helper.rb', line 127 def polaris_page_content(&block) render( partial: 'polaris/page_content', locals: { block: block } ) end |
#polaris_page_header(title, &block) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/polaris_view_helpers/helper.rb', line 106 def polaris_page_header(title, &block) render( partial: 'polaris/page_header', locals: { title: title, block: block } ) end |
#polaris_random_input_name ⇒ Object
19 20 21 |
# File 'lib/polaris_view_helpers/helper.rb', line 19 def polaris_random_input_name "pri-#{SecureRandom.hex(8)}" end |
#polaris_resource_list(&block) ⇒ Object
388 389 390 391 392 393 |
# File 'lib/polaris_view_helpers/helper.rb', line 388 def polaris_resource_list(&block) render( partial: 'polaris/resource_list', locals: { block: block } ) end |
#polaris_resource_list_item(attributes = {}, &block) ⇒ Object
395 396 397 398 399 400 401 |
# File 'lib/polaris_view_helpers/helper.rb', line 395 def polaris_resource_list_item(attributes = {}, &block) 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, block: block } ) end |
#polaris_select(form:, attribute:, title: nil, selected: nil, options:, data: nil, select_options: {}) ⇒ Object
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 |
# File 'lib/polaris_view_helpers/helper.rb', line 53 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
120 121 122 123 124 125 |
# File 'lib/polaris_view_helpers/helper.rb', line 120 def polaris_sub_heading(title) render( partial: 'polaris/sub_heading', locals: { title: title } ) end |
#polaris_tab(text, link_path, active = nil) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/polaris_view_helpers/helper.rb', line 165 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
158 159 160 161 162 163 |
# File 'lib/polaris_view_helpers/helper.rb', line 158 def polaris_tabs(&block) render( partial: 'polaris/tabs', locals: { block: block } ) end |
#polaris_text_area(form, attribute, options = {}, element_type = :text_area, &block) ⇒ Object
334 335 336 |
# File 'lib/polaris_view_helpers/helper.rb', line 334 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
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/polaris_view_helpers/helper.rb', line 313 def polaris_text_field(form, attribute, = {}, element_type = :text_field, &block) additional_classes = [:additional_classes] || "" unless attribute.is_a? Array attribute = [attribute] end render( partial: 'polaris/text_field', locals: { form: form, attribute: attribute, additional_classes: additional_classes, element_type: element_type, options: , block: block } ) end |
#polaris_thumbnail(attributes) ⇒ Object
411 412 413 414 415 416 |
# File 'lib/polaris_view_helpers/helper.rb', line 411 def polaris_thumbnail(attributes) render( partial: 'polaris/thumbnail', locals: { attributes: attributes } ) end |
#pvh_svg(name) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/polaris_view_helpers/helper.rb', line 32 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 |