Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Overview

##### BEGIN LICENSE BLOCK ##### Ekylibre - Simple agricultural ERP Copyright (C) 2009 Brice Texier, Thibaud Merigon

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.

##### END LICENSE BLOCK #####

Defined Under Namespace

Classes: AttributesList

Instance Method Summary collapse

Instance Method Details

#are_you_sure_you_want_to(action_expr, options = {}) ⇒ Object


793
794
795
796
797
798
# File 'app/helpers/application_helper.rb', line 793

def are_you_sure_you_want_to(action_expr, options = {})
  options[:default] ||= []
  options[:default] = [options[:default]] unless options[:default].is_a?(Array)
  options[:default] << "are_you_sure_you_want_to_#{action_expr}".tl(options)
  "are_you_sure_you_want_to.#{action_expr}".tl(options)
end

#attribute_item(object, attribute, options = {}) ⇒ Object


293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'app/helpers/application_helper.rb', line 293

def attribute_item(object, attribute, options = {})
  value_class = 'value'
  if object.is_a? String
    label = object
    value = attribute
    value = value.to_s unless [String, TrueClass, FalseClass].include? value.class
  else
    #     label = object.class.human_attribute_name(attribute.to_s)
    value = object.send(attribute)
    model = object.class
    model_name = model.name.underscore
    default = ["activerecord.attributes.#{model_name}.#{attribute}_id".to_sym]
    default << "activerecord.attributes.#{model_name}.#{attribute.to_s[0..-7]}".to_sym if attribute.to_s =~ /_label$/
    default << "attributes.#{attribute}".to_sym
    default << "attributes.#{attribute}_id".to_sym
    label = "activerecord.attributes.#{model_name}.#{attribute}".t(default: default)
    if value.is_a? ActiveRecord::Base
      record = value
      value = record.send(options[:label] || %i[label name code number inspect].detect { |x| record.respond_to?(x) })
      options[:url] = { action: :show } if options[:url].is_a? TrueClass
      if options[:url].is_a? Hash
        options[:url][:id] ||= record.id
        # raise [model_name.pluralize, record, record.class.name.underscore.pluralize].inspect
        options[:url][:controller] ||= record.class.name.underscore.pluralize
      end
    elsif value.is_a? Nomen::Item
      value = value.human_name
    else
      options[:url] = { action: :show } if options[:url].is_a? TrueClass
      if options[:url].is_a? Hash
        options[:url][:controller] ||= object.class.name.underscore.pluralize
        options[:url][:id] ||= object.id
      end
    end
    value_class << ' code' if attribute.to_s == 'code'
  end
  if [TrueClass, FalseClass].include? value.class
    value = (:div, '', class: "checkbox-#{value}")
  elsif value.respond_to?(:text)
    value = value.send(:text)
  elsif attribute.to_s =~ /(^|_)currency$/
    value = Nomen::Currency[value].human_name
  elsif attribute.to_s =~ /^state$/
    value = I18n.translate("models.#{model_name}.states.#{value}")
  elsif options[:currency] && value.is_a?(Numeric)
    value = ::I18n.localize(value, currency: (options[:currency].is_a?(TrueClass) ? object.send(:currency) : options[:currency].is_a?(Symbol) ? object.send(options[:currency]) : options[:currency]))
    value = link_to(value.to_s, options[:url]) if options[:url]
  elsif value.respond_to?(:strftime) || value.respond_to?(:l) || value.is_a?(Numeric)
    value = value.l
    value = link_to(value.to_s, options[:url]) if options[:url]
  elsif options[:duration]
    duration = value
    duration *= 60 if options[:duration] == :minutes
    duration *= 3600 if options[:duration] == :hours
    hours = (duration / 3600).floor.to_i
    minutes = (duration / 60 - 60 * hours).floor.to_i
    seconds = (duration - 60 * minutes - 3600 * hours).round.to_i
    value = :duration_in_hours_and_minutes.tl(hours: hours, minutes: minutes, seconds: seconds)
    value = link_to(value.to_s, options[:url]) if options[:url]
  elsif value.is_a? String
    classes = []
    classes << 'code' if attribute.to_s == 'code'
    classes << value.class.name.underscore
    value = link_to(value.to_s, options[:url]) if options[:url]
    value = (:div, value.html_safe, class: classes.join(' '))
  end
  [label, value]
end

#attributes_list(*args, &block) ⇒ Object


362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'app/helpers/application_helper.rb', line 362

def attributes_list(*args, &block)
  options = args.extract_options!
  record = args.shift || resource
  options[:columns] ||= []
  attribute_list = AttributesList.new(record)
  if block_given?
    unless block.arity == 1
      raise ArgumentError, 'One parameter needed for attribute_list block'
    end
    yield attribute_list
  end
  if resource.customizable? && !options[:custom_fields].is_a?(FalseClass) &&
    !attribute_list.items.detect { |item| item[0] == :custom_fields }
    attribute_list.custom_fields
  end
  unless options[:stamps].is_a?(FalseClass)
    attribute_list.attribute :creator, label: :full_name
    attribute_list.attribute :created_at
    attribute_list.attribute :updater, label: :full_name
    attribute_list.attribute :updated_at
    # attribute_list.attribute :lock_version
  end
  unless options[:columns].empty?
    options[:columns].each do |c|
      next unless record.respond_to? c
      attribute_list.attribute c
    end
  end
  code = ''
  items = attribute_list.items # .delete_if { |x| x[0] == :custom_fields }
  if items.any?
    items.each do |item|
      label, value = if item[0] == :custom
                       attribute_item(*item[1])
                     elsif item[0] == :attribute
                       attribute_item(record, *item[1])
                     end
      if value.present? || (item[2].is_a?(Hash) && item[2][:show] == :always)
        code << (:dl, (:dt, label) + (:dd, value))
      end
    end
    code = (:div, code.html_safe, class: 'attributes-list')
  end
  code.html_safe
end

#authorized?(url_options = {}) ⇒ Boolean

Helper which check authorization of an action

Returns:

  • (Boolean)

26
27
28
# File 'app/helpers/application_helper.rb', line 26

def authorized?(url_options = {})
  controller.authorized?(url_options)
end

#available_languages(native_language = true) ⇒ Object


257
258
259
260
261
# File 'app/helpers/application_helper.rb', line 257

def available_languages(native_language = true)
  I18n.available_locales.map do |l|
    [native_language ? I18n.t('i18n.name', locale: l) : Nomen::Language.find(l).human_name, l]
  end.sort_by(&:second)
end

#back_urlObject


284
285
286
# File 'app/helpers/application_helper.rb', line 284

def back_url
  :back
end

#backend_fields_for(object, *args, &block) ⇒ Object


912
913
914
915
# File 'app/helpers/application_helper.rb', line 912

def backend_fields_for(object, *args, &block)
  options = args.extract_options!
  simple_fields_for(object, *(args << options.merge(builder: Backend::FormBuilder)), &block)
end

#backend_form_for(object, *args, &block) ⇒ Object


907
908
909
910
# File 'app/helpers/application_helper.rb', line 907

def backend_form_for(object, *args, &block)
  options = args.extract_options!
  simple_form_for([:backend, object], *(args << options.merge(builder: Backend::FormBuilder)), &block)
end

#button_group(options = {}, &block) ⇒ Object


438
439
440
441
# File 'app/helpers/application_helper.rb', line 438

def button_group(options = {}, &block)
  options[:class] = options[:class].to_s + ' btn-group'
  (:div, options, &block)
end

#choices_yes_noObject


60
61
62
# File 'app/helpers/application_helper.rb', line 60

def choices_yes_no
  [[::I18n.translate('general.y'), true], [I18n.t('general.n'), false]]
end

#condition_label(condition) ⇒ Object


983
984
985
986
987
988
989
990
991
# File 'app/helpers/application_helper.rb', line 983

def condition_label(condition)
  if condition =~ /^generic/
    klass = condition.split(/\-/)[1].pluralize.classify.constantize
    attribute = condition.split(/\-/)[2]
    tl('conditions.filter_on_attribute_of_class', attribute: klass.human_attribute_name(attribute), class: klass.model_name.human)
  else
    tl("conditions.#{condition}")
  end
end

#countriesObject


245
246
247
# File 'app/helpers/application_helper.rb', line 245

def countries
  nomenclature_as_options(:countries)
end

#currenciesObject


249
250
251
# File 'app/helpers/application_helper.rb', line 249

def currencies
  nomenclature_as_options(:currencies)
end

Yields:

  • (l)

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'app/helpers/application_helper.rb', line 518

def dropdown_button(*args)
  options = args.extract_options!
  l = Ekylibre::Support::Lister.new(:link_to)
  yield l
  minimum = 0
  if args[0].nil?
    return nil unless l.any?
    minimum = 1
    args = l.first.args
  end

  if l.size > minimum
    return (:div, class: 'btn-group') do # btn-group btn-group-dropdown  #{args[2][:class]}
      html = ''.html_safe
      html << tool_to(*args)
      html << dropdown_toggle_button
      html << (:ul, class: 'dropdown-menu', role: 'menu') do
        l.collect do |link|
          (:li, send(link.name, *link.args, &link.block))
        end.join.html_safe
      end
      html
    end
  else
    return tool_to(*args)
  end
end

453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'app/helpers/application_helper.rb', line 453

def dropdown_menu(items)
  (:ul, class: 'dropdown-menu') do
    items.map do |item|
      if item.name == :item
        args = item.args
        options = args.extract_options!
        item_options = {}
        item_options[:class] = options.delete(:as) if options.key?(:as)
        item_options.merge!(options.delete(:html_options)) if options.key?(:html_options)
        (:li, link_to(*args, options, &item.block), item_options)
      elsif item.name == :separator
        (:li, '', class: 'separator')
      else
        raise 'Cannot handle that type of menu item: ' + item.name.inspect
      end
    end.join.html_safe
  end
end

Yields:

  • (menu)

472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'app/helpers/application_helper.rb', line 472

def dropdown_menu_button(name, options = {})
  menu = Ekylibre::Support::Lister.new(:item, :separator)
  yield menu
  return nil unless menu.any?
  menu_size = menu.size
  default_item = menu.detect_and_extract! do |item|
    item.args[2].is_a?(Hash) && item.args[2][:by_default]
  end
  raise 'Need a name or a default item' unless name || default_item
  if name.is_a?(Symbol)
    options[:icon] ||= name unless options[:icon].is_a?(FalseClass)
    name = options[:label] || name.ta(default: ["labels.#{name}".to_sym])
  end
  item_options = default_item.args.third if default_item
  item_options ||= {}
  if options[:class]
    if item_options[:class]
      item_options[:class] << ' ' + options[:class].to_s
    else
      item_options[:class] = options[:class].to_s
    end
  end
  item_options[:tool] = options[:icon] if options.key?(:icon)
  html_options = { class: 'btn-group' + (options[:dropup] ? ' dropup' : '') }
  html_options[:class] << ' ' + options[:class].to_s if options[:class]
  html_options[:id] = options[:id] if options[:id]
  (:div, html_options) do
    if default_item
      html = tool_to(default_item.args.first, default_item.args.second,
                     item_options, &default_item.block)
      if menu_size > 1
        html << dropdown_toggle_button + dropdown_menu(menu.items)
      end
      html
    elsif menu.list.size == 1 && menu.first.type == :item && !options[:force_menu]
      default_item = menu.first
      tool_to(name, default_item.args.second,
              (default_item.args.third || {}).merge(item_options),
              &default_item.block)
    else
      dropdown_toggle_button(name, options.slice(:icon, :disable_with, :class)) +
        dropdown_menu(menu.list)
    end
  end
end

443
444
445
446
447
448
449
450
451
# File 'app/helpers/application_helper.rb', line 443

def dropdown_toggle_button(name = nil, options = {})
  class_attribute = 'btn btn-default dropdown-toggle'
  class_attribute << ' ' + options[:class].to_s if options[:class].present?
  class_attribute << ' sr-only' if name.blank?
  class_attribute << ' icn btn-' + options[:icon].to_s if options[:icon]
  (:button, name, class: class_attribute,
              data: { toggle: 'dropdown', disable_with: options[:disable_with] },
              aria: { haspopup: 'true', expanded: 'false' })
end

#ekylibre_form_for(object, *args, &block) ⇒ Object


917
918
919
920
921
922
923
924
925
926
927
928
# File 'app/helpers/application_helper.rb', line 917

def ekylibre_form_for(object, *args, &block)
  options = args.extract_options!

  if options[:namespace] == :none
    return simple_form_for(object, *(args << options.merge(builder: Backend::FormBuilder)), &block)
  end

  namespace = options[:namespace]
  namespace ||= :backend

  simple_form_for([namespace, object], *(args << options.merge(builder: Backend::FormBuilder)), &block)
end

#enumerize_as_options(model, attribute, *args) ⇒ Object

Returns a selection from names list


275
276
277
278
279
280
281
282
# File 'app/helpers/application_helper.rb', line 275

def enumerize_as_options(model, attribute, *args)
  options = args.extract_options!
  enum = model.to_s.camelize.constantize.send(attribute)
  items = args.shift || enum.values
  items.collect do |name|
    [name.l, name]
  end.sort_by(&:first)
end

#error_messages(object) ⇒ Object


867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'app/helpers/application_helper.rb', line 867

def error_messages(object)
  object = instance_variable_get("@#{object}") unless object.respond_to?(:errors)
  return unless object.respond_to?(:errors)
  if (count = object.errors.size).zero?
    ''
  else
    I18n.with_options scope: %i[errors template] do |locale|
      header_message = locale.t :header, count: count, model: object.class.model_name.human
      introduction = locale.t(:body)
      messages = object.errors.full_messages.map do |msg|
        (:li, msg)
      end.join.html_safe
      message = ''
      message << (:h3, header_message) if header_message.present?
      message << (:p, introduction) if introduction.present?
      message << (:ul, messages)

      html = ''
      html << (:div, '', class: :icon)
      html << (:div, message.html_safe, class: :message)
      html << (:div, '', class: :end)
      return (:div, html.html_safe, class: 'flash error')
    end
  end
end

#even_cells(*cells, **options) ⇒ Object


1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
# File 'app/helpers/application_helper.rb', line 1067

def even_cells(*cells, **options)
  options = default_evening_options(options)
  filler = (
    options[:filler_tag],
    options[:filler_content],
    class: options[:filler_class]
  )
  size = cells.size
  # Number of depth levels we're going to need
  # log2(number of elements)
  # +1 here for proper handling of odds
  n = Math.log(size + 1, 2).round

  unbalanced = cells.count(nil).odd? && size.even?

  # You can't balance a odd number of elements inside an odd numbered grid
  cells.delete_at(cells.find_index(nil)) if unbalanced

  empties = cells.count(nil)
  filled = size - empties
  return safe_join(cells.map { |_| filler }) if filled.zero?
  return safe_join(cells.map { |cell| (options[:cell_tag], cell, class: options[:cell_class]) }) if empties.zero?

  result = []
  # We strive to put everything in the middle
  # `filled <= (n - 1) * 2 - 1` tells us if there's
  # enough roomin the inner levels to handle the elements
  # or if we should take some of the burden.
  if filled <= (n - 1) * 2 - 1
    result << filler
    result << even_cells(*(cells.compact + [nil] * (empties - 2)), **options)
    result << filler
  else
    result << (
      options[:cell_tag],
      cells.compact.first,
      class: options[:cell_class]
    )
    result << even_cells(*(cells.compact[1...-1] + [nil] * empties), **options)
    result << (
      options[:cell_tag],
      cells.compact.last,
      class: options[:cell_class]
    )
  end
  # Continuation of the `odd in even` problem mentioned above.
  result << filler if unbalanced

  safe_join(result)
end

#field(label, input = nil, options = {}, &block) ⇒ Object

Wraps a label and its input in a standard wrapper


931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
# File 'app/helpers/application_helper.rb', line 931

def field(label, input = nil, options = {}, &block)
  ActiveSupport::Deprecation.warn('field helper is deprecated, its time to switch to form objects!')

  options[:label] ||= {}
  options[:controls] ||= {}

  if block_given?
    content = capture &block
  elsif input.is_a? Hash
    content = field_tag input
  else
    content = input
  end

  (:div,
              (:label, label, class: "control-label #{options[:label].fetch(:class, '')}") +
                (:div, content, class: "controls #{options[:controls].fetch(:class, '')}"),
              class: 'control-group')
end

#field_set(*args, &block) ⇒ Object


951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
# File 'app/helpers/application_helper.rb', line 951

def field_set(*args, &block)
  options = args.extract_options!
  options[:fields_class] ||= 'fieldset-fields'
  name = args.shift || 'general-informations'.to_sym
  buttons = [options[:buttons] || []].flatten
  buttons << link_to('', '#', :class => 'toggle', 'data-toggle' => 'fields')
  classes = ['fieldset', name.to_s, options.fetch(:class, [])].flatten
  classes << (options[:collapsed] ? ' collapsed' : ' not-collapsed')
  name_sym = name.to_s.tr('-', '_').to_sym
  wrap((:div,
                   (:div,
                               link_to((:i) + h(name.is_a?(Symbol) ? name_sym.tl(default: ["form.legends.#{name_sym}".to_sym, "attributes.#{name_sym}".to_sym, name_sym.to_s.humanize]) : name.to_s), '#', :class => 'title', 'data-toggle' => 'fields') +
                                 (:span, buttons.join.html_safe, class: :buttons),
                               class: 'fieldset-legend') +
                   (:div, capture(&block), class: options[:fields_class]), class: classes, id: name), options[:in])
end

#flash_message_tag(mode, message) ⇒ Object


746
747
748
749
750
751
752
753
754
# File 'app/helpers/application_helper.rb', line 746

def flash_message_tag(mode, message)
   :div, { class: "flash #{mode}", data: { alert: true } } do
    (:a, "&times;".html_safe, { class: :close, href: '#' }) +
      (:div, '', { class: :icon }) +
      (:div, { class: :message }) do
        (:h3, mode.t(scope: 'notifications.levels').html_safe) + (:p, message)
      end
  end
end

#form_actions(options = {}, &block) ⇒ Object


893
894
895
896
897
898
899
900
901
# File 'app/helpers/application_helper.rb', line 893

def form_actions(options = {}, &block)
  (:div, class: "form-actions #{options[:class]}") do
    html = ''.html_safe
    html << content_for(:before_form_actions) if content_for?(:before_form_actions)
    html << capture(&block)
    html << content_for(:after_form_actions) if content_for?(:after_form_actions)
    html
  end
end

#form_fields(&block) ⇒ Object


903
904
905
# File 'app/helpers/application_helper.rb', line 903

def form_fields(&block)
  (:div, capture(&block), class: 'form-fields')
end

#heading_tagObject


711
712
713
# File 'app/helpers/application_helper.rb', line 711

def heading_tag
  (:h1, main_title, id: :title)
end

#heading_toolbar_tagObject

Build the heading toolbar


842
843
844
# File 'app/helpers/application_helper.rb', line 842

def heading_toolbar_tag
  toolbar_tag(:heading)
end

#human_age(born_at, options = {}) ⇒ Object


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/helpers/application_helper.rb', line 88

def human_age(born_at, options = {})
  options[:default] ||= '&ndash;'.html_safe
  return options[:default] if born_at.nil? || !born_at.is_a?(Time)
  at = options[:at] || Time.zone.now
  sign = ''
  if born_at > at
    sign = '-'
    at, born_at = born_at, at
  end
  vals = []
  remaining_at = born_at + 0.seconds
  %w[year month day hour minute second].each do |magnitude|
    count = 0
    while remaining_at + 1.send(magnitude) < at
      remaining_at += 1.send(magnitude)
      count += 1
    end
    if count > 0 && (!options[:display] || vals.size < options[:display])
      vals << "x_#{magnitude.pluralize}".tl(count: count)
    end
  end
  sign + vals.to_sentence
end

#human_duration(seconds, options = {}) ⇒ Object


134
135
136
137
138
139
140
141
142
143
# File 'app/helpers/application_helper.rb', line 134

def human_duration(seconds, options = {})
  return options[:default] || '&ndash;'.html_safe if seconds.nil?
  vals = []
  vals << (seconds / 1.hour).floor
  seconds -= 1.hour * (seconds / 1.hour).floor
  vals << (seconds / 1.minute).round.to_s.rjust(2, '0')
  seconds -= 1.minute * (seconds / 1.minute).floor
  # vals << seconds.round.to_s.rjust(2, "0")
  vals.join(':')
end

#human_interval(seconds, options = {}) ⇒ Object


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/helpers/application_helper.rb', line 112

def human_interval(seconds, options = {})
  return options[:default] || '&ndash;'.html_safe if seconds.nil?
  vals = []
  if (seconds.to_f / 1.year).floor > 0.0 && (!options[:display] || vals.size < options[:display])
    vals << :x_years.tl(count: (seconds / 1.year).floor)
    seconds -= 1.year * (seconds / 1.year).floor
  end
  if (seconds.to_f / 1.month).floor > 0.0 && (!options[:display] || vals.size < options[:display])
    vals << :x_months.tl(count: (seconds / 1.month).floor)
    seconds -= 1.month * (seconds / 1.month).floor
  end
  if (seconds.to_f / 1.day).floor > 0.0 && (!options[:display] || vals.size < options[:display])
    vals << :x_days.tl(count: (seconds / 1.day).floor)
    seconds -= 1.day * (seconds / 1.day).floor
  end
  if (seconds.to_f / 1.hour).floor > 0.0 && (!options[:display] || vals.size < options[:display])
    vals << :x_hours.tl(count: (seconds / 1.hour).floor)
    seconds -= 1.hour * (seconds / 1.hour).floor
  end
  vals.to_sentence
end

#icon_tags(options = {}) ⇒ Object


623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
# File 'app/helpers/application_helper.rb', line 623

def icon_tags(options = {})
  # Favicon
  html = tag(:link, rel: 'icon', type: 'image/png', href: image_path('icon/favicon.png'), 'data-turbolinks-track' => true)
  html << "\n".html_safe + tag(:link, rel: 'shortcut icon', href: image_path('icon/favicon.ico'), 'data-turbolinks-track' => true)
  # Apple touch icon
  icon_sizes = { iphone: '57x57', ipad: '72x72', 'iphone-retina' => '114x114', 'ipad-retina' => '144x144' }
  unless options[:app].is_a?(FalseClass)
    for name, sizes in icon_sizes
      html << "\n".html_safe + tag(:link, rel: 'apple-touch-icon', sizes: sizes, href: image_path("icon/#{name}.png"), 'data-turbolinks-track' => true)
    end
  end
  if options[:precomposed]
    for name, sizes in icon_sizes
      html << "\n".html_safe + tag(:link, rel: 'apple-touch-icon-precomposed', sizes: sizes, href: image_path("icon/precomposed-#{name}.png"), 'data-turbolinks-track' => true)
    end
  end
  html
end

#languagesObject


253
254
255
# File 'app/helpers/application_helper.rb', line 253

def languages
  nomenclature_as_options(:languages)
end

#last_page(menu) ⇒ Object


571
572
573
574
# File 'app/helpers/application_helper.rb', line 571

def last_page(menu)
  # session[:last_page][menu.to_s]||
  url_for(controller: :dashboards, action: menu)
end

#legals_sentenceObject

LEGALS_ITEMS = [h(“Ekylibre ” + Ekylibre.version), h(“Ruby on Rails ” + Rails.version), h(“Ruby ”+ RUBY_VERSION.to_s)].join(“ &ndash; ”.html_safe).freeze


53
54
55
56
57
58
# File 'app/helpers/application_helper.rb', line 53

def legals_sentence
  # "Ekylibre " << Ekylibre.version << " - Ruby on Rails " << Rails.version << " - Ruby #{RUBY_VERSION} - " << ActiveRecord::Base.connection.adapter_name << " - " << ActiveRecord::Migrator.current_version.to_s
  nbsp = '&nbsp;'.html_safe # ,  h("Ruby on Rails") + nbsp + Rails.version, ("HTML" + nbsp + "5").html_sa, h("CSS 3")
  [h('Ekylibre') + nbsp + Ekylibre.version].join(' &ndash; ').html_safe # ,  h("Ruby") + nbsp + RUBY_VERSION.to_s
  # return content_tag(:span, content_tag(:i, '') + nbsp + h("Ekylibre"), class: "brand") + nbsp + h(Ekylibre.version)
end

235
236
237
238
239
240
241
242
243
# File 'app/helpers/application_helper.rb', line 235

def li_link_to(*args)
  options = args[1] || {}
  # if authorized?({:controller => controller_name, :action => action_name}.merge(options))
  if authorized?({ controller: controller_path, action: :index }.merge(options))
    (:li, link_to(*args).html_safe)
  else
    ''
  end
end

Re-writing of link_to helper


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
224
225
226
227
228
229
230
231
232
233
# File 'app/helpers/application_helper.rb', line 186

def link_to(*args, &block)
  if block_given?
    options = args.first || {}
    html_options = args.second
    link_to(capture(&block), options, html_options)
  else
    name = args[0]
    options = args[1] || {}
    html_options = args[2] || {}

    if options.is_a?(Hash) && !authorized?(options)
      if html_options[:remove]
        return ''
      else
        html_options[:class] = if html_options[:class].is_a?(Array)
                                 html_options[:class] + ['forbidden']
                               else
                                 html_options[:class].to_s + ' forbidden'
                               end
        html_options.delete('disabled')
        html_options[:disabled] = true
        return (:a, name, html_options)
      end
    end

    html_options = convert_options_to_data_attributes(options, html_options)
    begin
      url = url_for(options)
    rescue ActionController::UrlGenerationError => uge
      # Trying to fail gracefully in production
      raise uge unless Rails.env.production?
      ExceptionNotifier::Notifier.exception_notification(request.env, uge).deliver
      request.env['exception_notifier.delivered'] = true
      return (:a, name, class: html_options[:class].to_s + ' invalid invalid-route', disabled: true)
    end

    if html_options
      html_options = html_options.stringify_keys
      href = html_options['href']
      tag_options = tag_options(html_options)
    else
      tag_options = nil
    end

    href_attr = 'href="' + url + '"' unless href
    "<a #{href_attr}#{tag_options}>".html_safe + (name || url) + '</a>'.html_safe
  end
end

288
289
290
291
# File 'app/helpers/application_helper.rb', line 288

def link_to_back(options = {})
  options[:label] ||= :back
  link_to(options[:label].is_a?(String) ? options[:label] : options[:label].tl, back_url)
end

181
182
183
# File 'app/helpers/application_helper.rb', line 181

def link_to_remove_nested_association(name, f, options = {})
  link_to_remove_association((:i) + h("labels.remove_#{name}".t(default: :destroy.ta)), f, options.deep_merge(data: { no_turbolink: true }, class: 'nested-remove'))
end

#locale_selector_tagObject

def locale_selector

# , :selected => ::I18n.locale)
locales = ::I18n.available_locales.sort{|a,b| a.to_s <=> b.to_s}
locale = nil # ::I18n.locale
if params[:locale].to_s.match(/^[a-z][a-z][a-z]$/)
  locale = params[:locale].to_sym if locales.include? params[:locale].to_sym
end
locale ||= ::I18n.locale||::I18n.default_locale
options = locales.collect do |l|
  (:option, ::I18n.translate("i18n.name", :locale => l), {:value => l, :dir => ::I18n.translate("i18n.dir", :locale => l)}.merge(locale == l ? {:selected => true} : {}))
end.join.html_safe
select_tag("locale", options, "data-redirect" => url_for())

end


167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'app/helpers/application_helper.rb', line 167

def locale_selector_tag
  locales = ::I18n.available_locales.sort_by(&:to_s)
  # locales = ::I18n.valid_locales.sort{|a,b| a.to_s <=> b.to_s}
  locale = nil # ::I18n.locale
  if params[:locale].to_s =~ /^[a-z][a-z][a-z]$/
    locale = params[:locale].to_sym if locales.include? params[:locale].to_sym
  end
  locale ||= ::I18n.locale || ::I18n.default_locale
  options = locales.collect do |l|
    (:option, ::I18n.translate('i18n.name', locale: l), { :value => l, :dir => ::I18n.translate('i18n.dir', locale: l), :selected => false, 'data-redirect' => url_for(locale: l) }.merge(locale == l ? { selected: true } : {}))
  end.join.html_safe
  select_tag('locale', options, 'data-use-redirect' => 'true')
end

#main_attachmentsObject


675
676
677
678
679
680
681
682
# File 'app/helpers/application_helper.rb', line 675

def main_attachments
  # Modal to display file
  modal(:file_preview, data: { attachment_thumblink_target: true }) do
     :div, nil, class: 'modal-body'
  end

  render(partial: 'attachments')
end

#main_informations(options = {}, &block) ⇒ Object


666
667
668
669
670
671
672
673
# File 'app/helpers/application_helper.rb', line 666

def main_informations(options = {}, &block)
  html = (:div, class: 'panel', id: 'main-informations') do
    partial = (:div, class: 'panel-body', &block)
    partial += (:div, main_attachments, class: 'panel-footer') if options[:attachment]
    partial
  end
  html
end

#main_title(value = nil) ⇒ Object


684
685
686
687
688
689
690
691
692
693
694
# File 'app/helpers/application_helper.rb', line 684

def main_title(value = nil)
  if value || block_given?
    if block_given?
      content_for(:main_title, &block)
    else
      content_for(:main_title, value)
    end
  else
    (content_for?(:main_title) ? content_for(:main_title) : controller.human_action_name)
  end
end

#main_toolbar(**options, &block) ⇒ Object

Create the main toolbar with the same API as toolbar


862
863
864
865
# File 'app/helpers/application_helper.rb', line 862

def main_toolbar(**options, &block)
  content_for(:main_toolbar, toolbar({class: 'main-toolbar', **options}, &block))
  nil
end

#main_toolbar_tagObject

Build the main toolbar


857
858
859
# File 'app/helpers/application_helper.rb', line 857

def main_toolbar_tag
  toolbar_tag(:main, wrap: false)
end

TOOLBAR

Raises:

  • (ArgumentError)

782
783
784
785
786
787
788
789
790
791
# File 'app/helpers/application_helper.rb', line 782

def menu_to(name, url, options = {})
  raise ArgumentError, "##{__method__} cannot use blocks" if block_given?
  icon = (options.key?(:menu) ? options.delete(:menu) : url.is_a?(Hash) ? url[:action] : nil)
  sprite = options.delete(:sprite) || 'icons-16'
  options[:class] = (options[:class].blank? ? 'mn' : options[:class] + ' mn')
  options[:class] += ' ' + icon.to_s if icon
  link_to(url, options) do
    (icon ? (:span, '', class: 'icon') + (:span, name, class: 'text') : (:span, name, class: 'text'))
  end
end

#meta_toolbar_tagObject

Build the meta toolbar


847
848
849
# File 'app/helpers/application_helper.rb', line 847

def meta_toolbar_tag
  toolbar_tag(:meta)
end

Define a simple frame for modals


994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
# File 'app/helpers/application_helper.rb', line 994

def modal(*args, &block)
  options = args.extract_options!
  options[:aria] ||= {}
  options[:aria][:hidden] ||= 'true'
  options[:aria][:labelledby] ||= options.delete(:labelledby) if options[:labelledby]
  if options[:class].is_a? Array
    options[:class] << 'modal'
    options[:class] << 'fade'
  elsif options[:class].nil?
    options[:class] = 'modal fade'
  else
    options[:class] = options[:class].to_s + ' modal fade'
  end
  if (id = args.shift) && !options[:id]
    if id.is_a?(Symbol)
      options[:id] = id.to_s.dasherize
      options[:title] ||= id.tl
    else
      options[:id] = id
    end
  end

  title = options.delete(:title) || options.delete(:heading)
  options[:aria][:labelledby] ||= options[:id].underscore.camelcase(:lower)
  options[:tabindex] ||= '-1'
  options[:role] ||= 'dialog'
  header_options = options.slice(:close_button, :close_html).merge(title_id: options[:aria][:labelledby])
  content_for(:popover) do
    (:div, options) do
      (:div, class: 'modal-dialog' + (options[:size] == :large ? ' modal-lg' : options[:size] == :small ? ' modal-sm' : '')) do
        (:div, class: 'modal-content') do
          if title
            modal_header(title, header_options) + capture(&block)
          else
            capture(&block)
          end
        end
      end
    end
  end
end

1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
# File 'app/helpers/application_helper.rb', line 1036

def modal_header(title, options = {})
  title_id = options[:title_id] || title.parameterize.underscore.camelcase(:lower)
  (:div, class: 'modal-header') do
    if options[:close_button].is_a? FalseClass
      (:h4, title, class: 'modal-title', id: title_id)
    else

      title = (:h4, title, class: 'modal-title', id: title_id)

      close_button = button_tag({ class: 'close', aria: { label: :close.tl }, data: { dismiss: 'modal' }, type: 'button' }.deep_merge(options[:close_html] || {})) do
        (:span, '&times;'.html_safe, aria: { hidden: 'true' })
      end

      if options[:flex]
        title + close_button
      else
        close_button + title
      end
    end
  end
end

#no_turbolink?Boolean

Returns:

  • (Boolean)

1118
1119
1120
1121
1122
1123
1124
# File 'app/helpers/application_helper.rb', line 1118

def no_turbolink?
  if content_for(:no_turbolink)
    { data: { no_turbolink: true } }
  else
    { data: nil }
  end
end

#nomenclature_as_options(nomenclature_name, *args) ⇒ Object

Returns a selection from names list


264
265
266
267
268
269
270
271
272
# File 'app/helpers/application_helper.rb', line 264

def nomenclature_as_options(nomenclature_name, *args)
  options = args.extract_options!
  nomenclature = Nomen[nomenclature_name]
  items = args.shift || nomenclature.all
  items.collect do |name|
    item = nomenclature.find(name)
    [item.human_name, item.name]
  end.sort_by(&:first)
end

#notification_tag(mode, messages = nil) ⇒ Object


731
732
733
734
735
736
737
738
739
740
741
742
743
744
# File 'app/helpers/application_helper.rb', line 731

def notification_tag(mode, messages = nil)
  unless messages
    if flash[:notifications].is_a?(Hash) && flash[:notifications][mode.to_s].is_a?(Array)
      messages = flash[:notifications][mode.to_s]
    end
  end
  messages = [messages] if messages.is_a?(String)
  code = ''.html_safe
  return code unless messages
  messages.each do |message|
    code << flash_message_tag(mode, h(message).gsub(/\n/, '<br/>').html_safe)
  end
  code
end

#notifications_tagObject


756
757
758
759
760
761
# File 'app/helpers/application_helper.rb', line 756

def notifications_tag
  notification_tag(:error) <<
    notification_tag(:warning) <<
    notification_tag(:success) <<
    notification_tag(:information)
end

#number_to_accountancy(value, currency = nil) ⇒ Object


78
79
80
81
# File 'app/helpers/application_helper.rb', line 78

def number_to_accountancy(value, currency = nil)
  number = value.to_f
  (number.zero? ? '' : number.l(currency: currency || Preference[:currency]))
end

#number_to_management(value) ⇒ Object


83
84
85
86
# File 'app/helpers/application_helper.rb', line 83

def number_to_management(value)
  number = value.to_f
  number.l
end

#pop_menu(options = {}) {|menu| ... } ⇒ Object

Yields:

  • (menu)

546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# File 'app/helpers/application_helper.rb', line 546

def pop_menu(options = {})
  menu = Ekylibre::Support::Lister.new(:item, :separator)
  default_class = options[:class] || 'pop-menu'

  yield menu

  (:nav, '', class: default_class) do
    (:ul, class: 'menu', role: 'menu') do
      html = ''.html_safe
      menu.list.each do |item|
        if item.name == :item

          options = item.args.extract_options!
          html << (:li, link_to(*item.args, options[:link_url], options[:link_options]), options[:item_options])

        elsif item.name == :separator
          html << (:li, '', class: 'separator')
        end
      end

      html
    end
  end
end

#product_stocks_options(product) ⇒ Object


976
977
978
979
980
981
# File 'app/helpers/application_helper.rb', line 976

def product_stocks_options(product)
  options = []
  options += product.stocks.collect { |x| [x.label, x.id] }
  options += Building.of_product(product).collect { |x| [x.name, -x.id] }
  options
end

#radio_check_box(object_name, method, _options = {}, checked_value = '1', unchecked_value = '0') ⇒ Object


71
72
73
74
75
76
# File 'app/helpers/application_helper.rb', line 71

def radio_check_box(object_name, method, _options = {}, checked_value = '1', unchecked_value = '0')
  radio_button_tag(object_name, method, TrueClass, id: "#{object_name}_#{method}_#{checked_value}") << ' ' <<
    (:label, ::I18n.translate('general.y'), for: "#{object_name}_#{method}_#{checked_value}") << ' ' <<
    radio_button_tag(object_name, method, FalseClass, id: "#{object_name}_#{method}_#{unchecked_value}") << ' ' <<
    (:label, ::I18n.translate('general.n'), for: "#{object_name}_#{method}_#{unchecked_value}")
end

#radio_yes_no(name, value = nil) ⇒ Object


64
65
66
67
68
69
# File 'app/helpers/application_helper.rb', line 64

def radio_yes_no(name, value = nil)
  radio_button_tag(name, 1, value.to_s == '1', id => "#{name}_1") <<
    (:label, ::I18n.translate('general.y'), for: "#{name}_1") <<
    radio_button_tag(name, 0, value.to_s == '0', id => "#{name}_0") <<
    (:label, ::I18n.translate('general.n'), for: "#{name}_0")
end

#reading_directionObject


145
146
147
# File 'app/helpers/application_helper.rb', line 145

def reading_direction
  t('i18n.dir')
end

#reading_ltr?Boolean

Returns:

  • (Boolean)

149
150
151
# File 'app/helpers/application_helper.rb', line 149

def reading_ltr?
  reading_direction == 'ltr'
end

#relative_distance_in_words(time) ⇒ Object


1058
1059
1060
1061
1062
1063
1064
1065
# File 'app/helpers/application_helper.rb', line 1058

def relative_distance_in_words(time)
  now = Time.zone.now
  if time > now
    'datetime.relative_distance_in_words.in_sometime'.t(distance: time_ago_in_words(time))
  else
    'datetime.relative_distance_in_words.sometime_ago'.t(distance: time_ago_in_words(time))
  end
end

#search_results(search, _options = {}, &block) ⇒ Object


576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'app/helpers/application_helper.rb', line 576

def search_results(search, _options = {}, &block)
  (:div, class: :search) do
    # Show results
    html = ''.html_safe
    if search[:records]
      html << (:ul, class: :results) do
        counter = 'a'
        search[:records].collect do |result|
          id = 'result-' + counter
          counter.succ!
          (:li, class: 'result', id: id) do
            (block.arity == 2 ? capture(result, id, &block) : capture(result, &block)).html_safe
          end
        end.join.html_safe
      end
    end

    # Pagination
    if search[:last_page] && search[:last_page] > 1
      html << (:span, class: :pagination) do
        padding = 9
        gap = 4
        page_min = params[:page].to_i - padding
        page_min = 1 if page_min < gap
        page_max = params[:page].to_i + padding
        page_max = search[:last_page] if page_max > search[:last_page]

        pagination = ''
        if page_min > 1
          pagination << link_to((:i) + tl(:beginning), { q: params[:q], page: 1 }, class: :beginning)
          pagination << (:span, '&hellip;'.html_safe) if page_min >= gap
        end
        for p in page_min..page_max
          attrs = {}
          attrs[:class] = 'active' if p == params[:page]
          pagination << link_to(p.to_s, { q: params[:q], page: p }, attrs)
        end
        pagination << (:span, '&hellip;'.html_safe) if page_max < search[:last_page]
        pagination.html_safe
      end
    end

    # Return HTML
    html
  end
end

#selector(object_name, association, choices, options = {}, html_options = {}) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/application_helper.rb', line 39

def selector(object_name, association, choices, options = {}, html_options = {})
  object = options[:object] || instance_variable_get("@#{object_name}")
  model = object.class
  unless reflection = object.class.reflect_on_association(association)
    raise ArgumentError, "Unknown reflection for #{model.name}: #{association.inspect}"
  end
  if reflection.macro != :belongs_to
    raise ArgumentError, "Reflection #{reflection.name} must be a belongs_to"
  end
  text_field(object_name, reflection.foreign_key, html_options.merge('data-selector' => url_for(choices)))
end

#selector_tag(name, choices = nil, options = {}, html_options = {}) ⇒ Object


30
31
32
33
34
35
36
37
# File 'app/helpers/application_helper.rb', line 30

def selector_tag(name, choices = nil, options = {}, html_options = {})
  choices ||= :unroll
  choices = { action: choices } if choices.is_a?(Symbol)
  html_options[:data] ||= {}
  html_options[:data][:selector] = url_for(choices)
  html_options[:data][:selector_new_item] = url_for(options[:new]) if options[:new]
  text_field_tag(name, options[:value], html_options)
end

#subheading(i18n_key, options = {}) ⇒ Object

Raises:

  • (StandardError)

715
716
717
718
719
720
721
722
# File 'app/helpers/application_helper.rb', line 715

def subheading(i18n_key, options = {})
  raise StandardError, 'A subheading has already been given.' if content_for?(:subheading)
  if options[:here]
    return subheading_tag(tl(i18n_key, options))
  else
    content_for(:subheading, tl(i18n_key, options))
  end
end

#subheading_tag(title = nil) ⇒ Object


724
725
726
727
728
729
# File 'app/helpers/application_helper.rb', line 724

def subheading_tag(title = nil)
  if content_for?(:subheading) || title
    return (:h2, title || content_for(:subheading), id: :subtitle)
  end
  nil
end

#svg(_options = {}, &block) ⇒ Object


434
435
436
# File 'app/helpers/application_helper.rb', line 434

def svg(_options = {}, &block)
  (:svg, capture(&block))
end

#table_of(array, html_options = {}, &block) ⇒ Object


763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
# File 'app/helpers/application_helper.rb', line 763

def table_of(array, html_options = {}, &block)
  coln = html_options.delete(:columns) || 3
  html = ''
  item = ''
  size = 0
  for item in array
    item << (:td, capture(item, &block))
    size += 1
    next unless size >= coln
    html << (:tr, item).html_safe
    item = ''
    size = 0
  end
  html << (:tr, item).html_safe if item.present?
  (:table, html, html_options).html_safe
end

#theme_button(name, theme = nil) ⇒ Object


653
654
655
# File 'app/helpers/application_helper.rb', line 653

def theme_button(name, theme = nil)
  image_path(theme_path("buttons/#{name}.png", theme))
end

Permits to use themes for Ekylibre

stylesheet_link_tag 'application', 'list', 'list-colors'
stylesheet_link_tag 'print', :media => 'print'

645
646
647
648
649
650
651
# File 'app/helpers/application_helper.rb', line 645

def theme_link_tag(theme = nil)
  theme ||= current_theme
  return nil unless theme
  html = ''
  html << stylesheet_link_tag(theme_path('all.css', theme), media: :all, 'data-turbolinks-track' => true)
  html.html_safe
end

#theme_path(name, theme = nil) ⇒ Object


657
658
659
660
# File 'app/helpers/application_helper.rb', line 657

def theme_path(name, theme = nil)
  theme ||= current_theme
  "themes/#{theme}/#{name}"
end

#title_tagObject


696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'app/helpers/application_helper.rb', line 696

def title_tag
  r = [] # reverse_menus
  title = if current_user
            code = request.url.split(/(\:\/\/|\.)/).third
            if r.empty?
              :page_title_special.tl(company_code: code, action: main_title)
            else
              :page_title.tl(company_code: code, action: main_title, menu: "menus.#{r[0]}".tl)
            end
          else
            :page_title_by_default.tl(action: main_title)
          end
  (:title, title)
end

#tool_to(name, url, options = {}) ⇒ Object

def tool(code = nil, &block)

raise ArgumentError.new("Arguments XOR block code are accepted, but not together.") if (code and block_given?) or (code.blank? and !block_given?)
code = capture(&block) if block_given?
content_for(:main_toolbar_default, code)
return true

end

Raises:

  • (ArgumentError)

807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
# File 'app/helpers/application_helper.rb', line 807

def tool_to(name, url, options = {})
  raise ArgumentError, "##{__method__} cannot use blocks" if block_given?
  icon = options.key?(:tool) ? options.delete(:tool) : options.key?(:icon) ? options.delete(:icon) : nil
  icon ||= url[:action] if url.is_a?(Hash) && !icon.is_a?(FalseClass)
  options[:class] = (options[:class].blank? ? 'btn btn-default' : options[:class].to_s + ' btn btn-default')
  options[:class] << ' icn btn-' + icon.to_s if icon
  if url.is_a?(Hash)
    if url.key?(:redirect)
      url.delete(:redirect) if url[:redirect].nil?
    else
      url[:redirect] = request.fullpath
    end
  end
  link_to(name, url, options)
end

#toolbar_tag(name, wrap: true) ⇒ Object


823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
# File 'app/helpers/application_helper.rb', line 823

def toolbar_tag(name, wrap: true)
  toolbar = "#{name}_toolbar".to_sym
  return unless content_for?(toolbar)

  if wrap.is_a? TrueClass
    (:div, content_for(toolbar), class: "#{name.to_s.parameterize}-toolbar toolbar toolbar-wrapper")
  else
    html = content_for(toolbar)
    noko = Nokogiri::HTML.fragment(html)
    wrapper = noko.children.select { |e| e.matches?(".toolbar-wrapper") }.first
    return toolbar_tag(name, wrap: true) if wrapper.nil? # If no wrapper element and wrap is false, thats an error, just wrap everything

    other_content = noko.children.select { |e| e.matches?(":not(.toolbar-wrapper)") }
    other_content.each { |node| wrapper.add_child node }
    noko.to_html.html_safe
  end
end

#view_toolbar_tagObject

Build the view toolbar


852
853
854
# File 'app/helpers/application_helper.rb', line 852

def view_toolbar_tag
  toolbar_tag(:view)
end

#viewport_tagObject


662
663
664
# File 'app/helpers/application_helper.rb', line 662

def viewport_tag
  tag(:meta, name: 'viewport', content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0')
end

#wrap(html, *levels) ⇒ Object


968
969
970
971
972
973
974
# File 'app/helpers/application_helper.rb', line 968

def wrap(html, *levels)
  if levels.any?
    level = levels.shift
    return wrap((:div, html, class: level), *levels)
  end
  html
end