Module: RailsI18nManager::ApplicationHelper

Defined in:
app/helpers/rails_i18n_manager/application_helper.rb

Constant Summary collapse

ASSET_VERSION =
`git show -s --format=%ci`.parameterize.freeze

Instance Method Summary collapse

Instance Method Details



25
26
27
28
29
30
31
# File 'app/helpers/rails_i18n_manager/application_helper.rb', line 25

def breadcrumb_item(title, url=nil)
  if url.nil?
    %Q(<span class="breadcrumb-item">#{title}</span>).html_safe
  else
    %Q(<span class="breadcrumb-item"><a href="#{url}">#{title}</a></span>).html_safe
  end
end

#custom_asset_path(path) ⇒ Object



21
22
23
# File 'app/helpers/rails_i18n_manager/application_helper.rb', line 21

def custom_asset_path(path)
  "#{path}?v=#{Rails.env.development? ? Time.now.to_i : ASSET_VERSION}"
end

#custom_fields_for(*args, **options, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'app/helpers/rails_i18n_manager/application_helper.rb', line 12

def custom_fields_for(*args, **options, &block)
  options[:builder] = CustomFormBuilder
  if options.has_key?(:defaults)
    @_custom_form_for_defaults = options.delete(:defaults)
  end
  fields_for(*args, options, &block)
end

#custom_form_for(*args, **options, &block) ⇒ Object



4
5
6
7
8
9
10
# File 'app/helpers/rails_i18n_manager/application_helper.rb', line 4

def custom_form_for(*args, **options, &block)
  options[:builder] = CustomFormBuilder
  if options.has_key?(:defaults)
    @_custom_form_for_defaults = options.delete(:defaults)
  end
  form_for(*args, options, &block)
end


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/rails_i18n_manager/application_helper.rb', line 43

def nav_link(name, url, html_options={}, &block)
  url = url_for(url)

  if html_options.has_key?(:active)
    active = html_options.delete(:active)
  elsif url == (url.include?("?") ? request.fullpath : request.path)
    active = true
  end

  html_options[:class] ||= ""

  html_options[:class] += " nav-link"

  if active
    html_options[:class] += " active"
  end

  html_options[:class].strip!

  (:li, class: "nav-item #{'active' if active}".strip) do
    link_to(name, url, html_options) + (
      if block_given?
        (:ul) do
          capture(&block)
        end
      end
    )
  end
end


33
34
35
36
37
38
39
40
41
# File 'app/helpers/rails_i18n_manager/application_helper.rb', line 33

def sort_link(attr_name, label=nil)
  if label.blank?
    label = attr_name.to_s.titleize
  end

  direction = params[:direction].present? && params[:direction].casecmp?("asc") ? 'desc' : 'asc'

  link_to label, params.to_unsafe_h.merge(sort: attr_name, direction: direction)
end