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



108
109
110
111
112
113
114
115
116
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 108

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


118
119
120
121
122
123
124
125
126
127
128
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 118

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



130
131
132
133
134
135
136
137
138
139
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 130

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



72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 72

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 33

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



96
97
98
99
100
101
102
103
104
105
106
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 96

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.



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

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



62
63
64
65
66
67
68
69
70
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 62

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, alternative: opts[:alternative]))
end


92
93
94
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 92

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

#page_date_range(page) ⇒ Object



25
26
27
28
29
30
31
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 25

def page_date_range(page)
  if page.all_day?
    date_range(page.starts_at.to_date, page.ends_at.to_date)
  else
    date_range(page.starts_at, page.ends_at)
  end
end

#rich_text_area_tag(name, content = nil, options = {}) ⇒ Object



85
86
87
88
89
90
# File 'app/helpers/pages_core/admin/admin_helper.rb', line 85

def rich_text_area_tag(name, content = nil, options = {})
  react_component("RichTextArea",
                  options.merge(id: sanitize_to_id(name),
                                name: name,
                                value: content))
end