Module: PagesCore::Admin::AdminHelper

Includes:
LabelledFieldHelper, TagEditorHelper
Included in:
Admin::AdminHelper
Defined in:
app/helpers/pages_core/admin/admin_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TagEditorHelper

#tag_editor_for

Methods included from LabelledFieldHelper

#image_upload_field, #labelled_field

Instance Attribute Details

#page_description(string = nil, class_name = nil) ⇒ Object


93
94
95
96
97
98
99
100
101
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 93

def page_description(string = nil, class_name = nil)
  deprecate_page_description_args(string, class_name)
  @page_description_class = class_name if class_name
  if string
    @page_description = string
  else
    @page_description
  end
end

#page_description_class=(value) ⇒ Object (writeonly)

Sets the attribute page_description_class

Parameters:

  • value

    the value to set the attribute page_description_class to.


9
10
11
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 9

def page_description_class=(value)
  @page_description_class = value
end

103
104
105
106
107
108
109
110
111
112
113
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 103

def page_description_links(links = nil)
  if links
    ActiveSupport::Deprecation.warn(
      "Setting page description_links with page_description_links " \
        "is deprecated, use page_description_links="
    )
    @page_description_links = links
  else
    @page_description_links
  end
end

#page_title(title = nil) ⇒ Object


115
116
117
118
119
120
121
122
123
124
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 115

def page_title(title = nil)
  if title
    ActiveSupport::Deprecation.warn(
      "Setting page title with page_title is deprecated, use page_title="
    )
    @page_title = title
  else
    @page_title
  end
end

Instance Method Details

#add_body_class(class_name) ⇒ Object


12
13
14
15
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 12

def add_body_class(class_name)
  @body_classes ||= []
  @body_classes << class_name
end

#body_classesObject


17
18
19
20
21
22
23
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 17

def body_classes
  classes = @body_classes || []
  classes << controller.class.to_s.underscore
  classes << "#{controller.action_name}_action" if controller.action_name
  classes << "with_notice" if flash[:notice]
  classes
end

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


64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 64

def content_tab(name, options = {}, &block)
  @content_tabs ||= []
  return unless block_given?
  tab = {
    name:    name.to_s.humanize,
    key:     options[:key] || name.to_s.underscore.gsub(/[\s]+/, "_"),
    options: options,
    content: capture(&block)
  }
  @content_tabs << tab
  content_tab_tag(tab[:key], tab[:content])
end

#date_range(starts_at, ends_at) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 25

def date_range(starts_at, ends_at)
  show_time = !(starts_at.is_a?(Date) && ends_at.is_a?(Date))
  dates = if starts_at.year != ends_at.year
            [l(starts_at, format: :pages_full), l(ends_at, format: :pages_full)]
          elsif starts_at.month != ends_at.month
            [l(starts_at, format: :pages_date), l(ends_at, format: :pages_full)]
          elsif starts_at.day != ends_at.day && !show_time
            [l(starts_at, format: :pages_day), l(ends_at, format: :pages_full)]
          elsif starts_at.day != ends_at.day
            [l(starts_at, format: :pages_date), l(ends_at, format: :pages_full)]
          elsif !show_time
            [l(starts_at, format: :pages_full)]
          else
            [l(starts_at, format: :pages_full), l(ends_at, format: :pages_time)]
          end
  safe_join(dates.map(&:strip), "&ndash;".html_safe)
end

#deprecate_page_description_args(string = nil, class_name = nil) ⇒ Object


81
82
83
84
85
86
87
88
89
90
91
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 81

def deprecate_page_description_args(string = nil, class_name = nil)
  if class_name
    ActiveSupport::Deprecation.warn("Setting class through " \
                                    "page_description is deprecated, " \
                                    "use page_description_class=")
  end
  return unless string
  ActiveSupport::Deprecation.warn("Setting description with " \
                                  "page_description is deprecated, " \
                                  "use page_description=")
end

#editable_dynamic_image_tag(image, width: 250, caption: false, locale: nil) ⇒ Object

Generates tags for an editable dynamic image.


44
45
46
47
48
49
50
51
52
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 44

def editable_dynamic_image_tag(image, width: 250, caption: false, locale: nil)
  react_component("EditableImage",
                  editable_image_options(
                    image,
                    width: width,
                    caption: caption,
                    locale: locale
                  ).merge(width: width))
end

#image_uploader_tag(name, image, options = {}) ⇒ Object


54
55
56
57
58
59
60
61
62
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 54

def image_uploader_tag(name, image, options = {})
  opts = { caption: false, locale: nil }.merge(options)
  react_component("ImageUploader",
                  editable_image_options(
                    image,
                    caption: opts[:caption],
                    locale: opts[:locale]
                  ).merge(attr: name))
end

77
78
79
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 77

def link_separator
  safe_join [" ", (:span, "|", class: "separator"), " "]
end