Module: CMS::ViewHelper

Defined in:
app/helpers/cms/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#cms_body_class(*args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/cms/view_helper.rb', line 3

def cms_body_class(*args)
  controller_name = controller_path.gsub('/','-')
  classes = [
    params[:cms_view_type],
    controller_name,
    "#{controller_name}-#{action_name}",
    I18n.locale,
  ]
  classes << 'cms-edit-mode' if cms_edit_mode?
  classes.concat(args) if args.any?
  classes.compact.join(' ')
end

#cms_flash_messages(*args) ⇒ Object



16
17
18
19
20
# File 'app/helpers/cms/view_helper.rb', line 16

def cms_flash_messages(*args)
   :div, cms_data_js('cms-flash', true, class: 'cms-flash-messages') do
    flash_messages(*args)
  end
end

#cms_meta_data_tags(default = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/cms/view_helper.rb', line 26

def (default = nil)
  if @cms_page_meta_keywords || @cms_page_meta_description
    html = tag(:meta, name: 'meta_keywords', content: @cms_page_meta_keywords)
    html << "\n"
    html << tag(:meta, name: 'meta_description', content: @cms_page_meta_description)
    html.html_safe
  else
    default
  end
end

#cms_meta_og_tags(title = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/cms/view_helper.rb', line 37

def cms_meta_og_tags(title = nil)
  tags = {}
  if @product # TODO: move to Solidus connector
    tags[:title] = @product.name
    tags[:description] = @product.description
    tags[:url] = product_url(@product, only_path: false)
    image = @product.images.first.try(:attachment)
    tags[:image] = image.try(:url, :product)
  else
    tags[:title] = title.blank? ? Setting['cms_og_tag_title'] : title
  end
  %{
    <meta property="og:title" content="#{tags[:title]}" />
    <meta property="og:type" content="website" />
    <meta property="og:description" content="#{tags[:description] || Setting['cms_og_tag_description']}" />
    <meta property="og:url" content="#{tags[:url] || request.original_url }" />
    <meta property="og:image" content="#{image_url(tags[:image] || 'ogimage.jpg', only_path: false)}" />
  }.html_safe
end

#cms_title(default = nil) ⇒ Object



22
23
24
# File 'app/helpers/cms/view_helper.rb', line 22

def cms_title(default = nil)
  @cms_page_title || default
end

#current_url_without_paramsObject



81
82
83
# File 'app/helpers/cms/view_helper.rb', line 81

def current_url_without_params
  "#{request.base_url}#{request.path}"
end

#full_name(object, prefix = nil) ⇒ Object



73
74
75
76
77
78
79
# File 'app/helpers/cms/view_helper.rb', line 73

def full_name(object, prefix = nil)
  if prefix
    "#{object.send("#{prefix}_firstname")} #{object.send("#{prefix}_lastname")}"
  else
    "#{object.firstname} #{object.lastname}"
  end
end

#to_currency(value) ⇒ Object



65
66
67
# File 'app/helpers/cms/view_helper.rb', line 65

def to_currency(value)
  number_to_currency(value, separator: '.', delimiter: '', format: '%n $')
end

#to_int_if_whole(float) ⇒ Object



69
70
71
# File 'app/helpers/cms/view_helper.rb', line 69

def to_int_if_whole(float)
  (float % 1 == 0) ? float.to_i : float
end

#to_nbsp(value) ⇒ Object



61
62
63
# File 'app/helpers/cms/view_helper.rb', line 61

def to_nbsp(value)
  value.kind_of?(String) ? value.gsub(' ', '&nbsp;').gsub('-', '&#8209;') : (value || '')
end

#yes_no(boolean) ⇒ Object



57
58
59
# File 'app/helpers/cms/view_helper.rb', line 57

def yes_no(boolean)
  boolean ? t('yes') : t('no')
end