Module: PolarisViewHelpers::Helper

Defined in:
lib/polaris_view_helpers/helper.rb

Instance Method Summary collapse

Instance Method Details

#polaris_annotated_section(heading: '', description: '', &block) ⇒ Object



199
200
201
202
203
204
205
206
207
208
# File 'lib/polaris_view_helpers/helper.rb', line 199

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



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/polaris_view_helpers/helper.rb', line 289

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



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/polaris_view_helpers/helper.rb', line 272

def polaris_annotated_section_select(form, attribute, select_options = [], 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: select_options,
      block: block
    }
  )
end

#polaris_annotated_section_text_field(form, attribute, options = {}, element_type = :text_field, &block) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/polaris_view_helpers/helper.rb', line 255

def polaris_annotated_section_text_field(form, attribute, options = {}, 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: options,
      block: block
    }
  )
end

#polaris_badge(content, status = nil) ⇒ Object



320
321
322
323
324
325
326
# File 'lib/polaris_view_helpers/helper.rb', line 320

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



109
110
111
112
113
114
# File 'lib/polaris_view_helpers/helper.rb', line 109

def polaris_banner(options, &block)
  render(
    partial: 'polaris/banner',
    locals: { options: options, block: block }
  )
end

#polaris_banner_actions(&block) ⇒ Object



116
117
118
119
120
121
# File 'lib/polaris_view_helpers/helper.rb', line 116

def polaris_banner_actions(&block)
  render(
    partial: 'polaris/banner_actions',
    locals: { block: block }
  )
end


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/polaris_view_helpers/helper.rb', line 123

def polaris_button_link_to(name = nil, link_destination = nil, button_options = nil, &block)
  if block_given?
    button_options, link_destination, name = link_destination, name, nil
  end
  button_options ||= {}

  additional_classes = button_options[:additional_classes] || ""
  (button_options[: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: button_options[:method],
      remote: button_options[:remote],
      target: button_options[:target],
      confirm: button_options[:confirm]
    }
  )
end

#polaris_button_tag(name, button_options) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/polaris_view_helpers/helper.rb', line 185

def polaris_button_tag(name, button_options)
  additional_classes = ""
  (button_options[:modifiers] || []).each do |modifier|
    additional_classes += "Polaris-Button--#{modifier} "
  end

  button_options[:additional_classes] = additional_classes
  button_options[:name] = name
  render(
    partial: 'polaris/button_tag',
    locals: button_options
  )
end

#polaris_card(heading = nil, footer: nil, &block) ⇒ Object



349
350
351
352
353
354
# File 'lib/polaris_view_helpers/helper.rb', line 349

def polaris_card(heading = nil, footer: nil, &block)
  render(
    partial: 'polaris/card',
    locals: { block: block, heading: heading, footer: footer }
  )
end

#polaris_choice_list(form:, attribute:, title:, selected:, choices:, data: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/polaris_view_helpers/helper.rb', line 17

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



363
364
365
366
367
368
# File 'lib/polaris_view_helpers/helper.rb', line 363

def polaris_css_variable_hack_div(&block)
  render(
    partial: 'polaris/polaris_css_variable_hack_div',
    locals: { block: block }
  )
end

#polaris_description_list(&block) ⇒ Object



335
336
337
338
339
340
# File 'lib/polaris_view_helpers/helper.rb', line 335

def polaris_description_list(&block)
  render(
    partial: 'polaris/description_list',
    locals: { block: block }
  )
end

#polaris_description_list_item(term, &block) ⇒ Object



342
343
344
345
346
347
# File 'lib/polaris_view_helpers/helper.rb', line 342

def polaris_description_list_item(term, &block)
  render(
    partial: 'polaris/description_list_item',
    locals: { block: block, term: term }
  )
end


356
357
358
359
360
361
# File 'lib/polaris_view_helpers/helper.rb', line 356

def polaris_footer_help(icon: 'next-help-circle', &block)
  render(
    partial: 'polaris/footer_help',
    locals: { block: block, icon: icon }
  )
end

#polaris_form_layout(&block) ⇒ Object



81
82
83
84
85
86
# File 'lib/polaris_view_helpers/helper.rb', line 81

def polaris_form_layout(&block)
  render(
    partial: 'polaris/form_layout',
    locals: { block: block }
  )
end

#polaris_form_layout_item(form, att, text = nil, &block) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
# File 'lib/polaris_view_helpers/helper.rb', line 210

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



222
223
224
225
226
227
228
229
230
231
232
# File 'lib/polaris_view_helpers/helper.rb', line 222

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



45
46
47
48
49
50
# File 'lib/polaris_view_helpers/helper.rb', line 45

def polaris_heading(title)
  render(
    partial: 'polaris/heading',
    locals: { title: title }
  )
end

#polaris_layout(&block) ⇒ Object



66
67
68
69
70
71
# File 'lib/polaris_view_helpers/helper.rb', line 66

def polaris_layout(&block)
  render(
    partial: 'polaris/layout',
    locals: { block: block }
  )
end

#polaris_layout_section(secondary: false, &block) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/polaris_view_helpers/helper.rb', line 73

def polaris_layout_section(secondary: false, &block)
  extra_class = secondary ? "Polaris-Layout__Section--secondary" : ""
  render(
    partial: 'polaris/layout_section',
    locals: { block: block, extra_class: extra_class }
  )
end


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/polaris_view_helpers/helper.rb', line 148

def polaris_link_to(name = nil, link_destination = nil, button_options = nil, &block)
  if block_given?
    button_options, link_destination, name = link_destination, name, nil
  end
  button_options ||= {}

  additional_classes = ""
  (button_options[: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: button_options[:method],
      confirm: button_options[:confirm]
    }
  )
end

#polaris_model_errors(model) ⇒ Object



171
172
173
174
175
176
# File 'lib/polaris_view_helpers/helper.rb', line 171

def polaris_model_errors model
  render(
    partial: 'polaris/model_errors',
    locals: { model: model }
  )
end

#polaris_page(&block) ⇒ Object



31
32
33
34
35
36
# File 'lib/polaris_view_helpers/helper.rb', line 31

def polaris_page(&block)
  render(
    partial: 'polaris/page',
    locals: { block: block }
  )
end

#polaris_page_actions(options) ⇒ Object



178
179
180
181
182
183
# File 'lib/polaris_view_helpers/helper.rb', line 178

def polaris_page_actions(options)
  render(
    partial: 'polaris/page_actions',
    locals: options
  )
end

#polaris_page_content(&block) ⇒ Object



59
60
61
62
63
64
# File 'lib/polaris_view_helpers/helper.rb', line 59

def polaris_page_content(&block)
  render(
    partial: 'polaris/page_content',
    locals: { block: block }
  )
end

#polaris_page_header(title, &block) ⇒ Object



38
39
40
41
42
43
# File 'lib/polaris_view_helpers/helper.rb', line 38

def polaris_page_header(title, &block)
  render(
    partial: 'polaris/page_header',
    locals: { title: title, block: block }
  )
end

#polaris_random_input_nameObject



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



305
306
307
308
309
310
# File 'lib/polaris_view_helpers/helper.rb', line 305

def polaris_resource_list(&block)
  render(
    partial: 'polaris/resource_list',
    locals: { block: block }
  )
end

#polaris_resource_list_item(attributes) ⇒ Object



312
313
314
315
316
317
318
# File 'lib/polaris_view_helpers/helper.rb', line 312

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_sub_heading(title) ⇒ Object



52
53
54
55
56
57
# File 'lib/polaris_view_helpers/helper.rb', line 52

def polaris_sub_heading(title)
  render(
    partial: 'polaris/sub_heading',
    locals: { title: title }
  )
end

#polaris_tab(text, link_path, active = nil) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/polaris_view_helpers/helper.rb', line 95

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



88
89
90
91
92
93
# File 'lib/polaris_view_helpers/helper.rb', line 88

def polaris_tabs(&block)
  render(
    partial: 'polaris/tabs',
    locals: { block: block }
  )
end

#polaris_text_area(form, attribute, options = {}, element_type = :text_area, &block) ⇒ Object



251
252
253
# File 'lib/polaris_view_helpers/helper.rb', line 251

def polaris_text_area(form, attribute, options = {}, element_type = :text_area, &block)
  polaris_text_field(form, attribute, options, element_type, &block)
end

#polaris_text_field(form, attribute, options = {}, element_type = :text_field, &block) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/polaris_view_helpers/helper.rb', line 234

def polaris_text_field(form, attribute, options = {}, 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: options,
      block: block
    }
  )
end

#polaris_thumbnail(attributes) ⇒ Object



328
329
330
331
332
333
# File 'lib/polaris_view_helpers/helper.rb', line 328

def polaris_thumbnail(attributes)
  render(
    partial: 'polaris/thumbnail',
    locals: { attributes: attributes }
  )
end