Module: Comable::ApplicationHelper

Included in:
OrderMailer
Defined in:
app/helpers/comable/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_comable_userObject



7
8
9
10
11
12
# File 'app/helpers/comable/application_helper.rb', line 7

def current_comable_user
  resource = current_admin_user if defined? Comable::Backend
  resource ||= current_user if defined? Comable::Frontend
  resource ||= Comable::User.new
  resource.with_cookies(cookies)
end

#current_navigationsObject



22
23
24
# File 'app/helpers/comable/application_helper.rb', line 22

def current_navigations
  @current_navigations ||= Comable::Navigation.all
end

#current_orderObject



14
15
16
# File 'app/helpers/comable/application_helper.rb', line 14

def current_order
  current_comable_user.incomplete_order
end

#current_storeObject



3
4
5
# File 'app/helpers/comable/application_helper.rb', line 3

def current_store
  @current_store ||= Comable::Store.instance
end

#current_trackersObject



18
19
20
# File 'app/helpers/comable/application_helper.rb', line 18

def current_trackers
  @curent_trackers ||= (controller_name == 'orders' && action_name == 'create') ? Comable::Tracker.activated : Comable::Tracker.activated.with_place(:everywhere)
end

#liquid_assignsObject

To use the functionality of liquid-rails



58
59
60
61
62
63
64
65
66
# File 'app/helpers/comable/application_helper.rb', line 58

def liquid_assigns
  view_context.assigns.merge(
    current_store: current_store,
    current_comable_user: current_comable_user,
    current_order: current_order,
    current_trackers: current_trackers,
    form_authenticity_token: form_authenticity_token
  ).stringify_keys
end

#liquidize(content, arguments) ⇒ Object



52
53
54
55
# File 'app/helpers/comable/application_helper.rb', line 52

def liquidize(content, arguments)
  string = Liquid::Template.parse(content).render(arguments.stringify_keys)
  string.respond_to?(:html_safe) ? string.html_safe : string
end

#name_with_honorific(name) ⇒ Object



39
40
41
# File 'app/helpers/comable/application_helper.rb', line 39

def name_with_honorific(name)
  Comable.t('honorific', name: name)
end

#name_with_quantity(name, quantity) ⇒ Object



43
44
45
46
47
48
49
50
# File 'app/helpers/comable/application_helper.rb', line 43

def name_with_quantity(name, quantity)
  return name unless quantity
  return name if quantity <= 1
  [
    name,
    "x#{quantity}"
  ].join(' ')
end

#next_order_pathObject



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

def next_order_path
  comable.next_order_path(state: current_order.state)
end

#page_nameObject



68
69
70
# File 'app/helpers/comable/application_helper.rb', line 68

def page_name
  [controller_name, action_name].join(':')
end

#store_locationObject



35
36
37
# File 'app/helpers/comable/application_helper.rb', line 35

def store_location
  session[:user_return_to] = request.fullpath.gsub('//', '/')
end

#update_order_pathObject



30
31
32
33
# File 'app/helpers/comable/application_helper.rb', line 30

def update_order_path
  return next_order_path unless params[:state]
  comable.next_order_path(state: params[:state])
end