Module: Mokio::Concerns::Models::Content

Extended by:
ActiveSupport::Concern
Included in:
Mokio::Content
Defined in:
lib/mokio/concerns/models/content.rb

Overview

Concern for Content model

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#author_nameObject



66
67
68
# File 'lib/mokio/concerns/models/content.rb', line 66

def author_name
  author.name_view unless author.blank?
end

Specify what’s showed in breadcrumb



125
126
127
# File 'lib/mokio/concerns/models/content.rb', line 125

def breadcrumb_name
  title
end

#can_add_to_sitemap?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/mokio/concerns/models/content.rb', line 62

def can_add_to_sitemap?
  true
end

#compare_datesObject

Compare dates from display_from and display_to fields



107
108
109
110
111
112
113
# File 'lib/mokio/concerns/models/content.rb', line 107

def compare_dates
  if self[:display_from] && self[:display_to]
    if self[:display_from] > self[:display_to]
      errors.add(:display_from)
    end
  end
end

#editor_nameObject



70
71
72
# File 'lib/mokio/concerns/models/content.rb', line 70

def editor_name
  editor.name_view unless editor.blank?
end

#sitemap_url_strategyObject



58
59
60
# File 'lib/mokio/concerns/models/content.rb', line 58

def sitemap_url_strategy
  {loc: "#{self.title}",priority: 1,lastmod: self.updated_at }
end

#title_viewObject

Output for title field



95
96
97
98
99
100
# File 'lib/mokio/concerns/models/content.rb', line 95

def title_view
  html = ""
  html << "<span class=\"icon12 icomoon-icon-home home_page\"></span>" if self[:home_page]
  html << (ActionController::Base.helpers.link_to self[:title], ApplicationController.helpers.edit_url(self.class.base_class, self))
  html.html_safe
end

#type_viewObject

Output for type field



118
119
120
# File 'lib/mokio/concerns/models/content.rb', line 118

def type_view
  I18n.t("contents.types.#{self[:type]}")
end

#update_display_toObject

Update display_to field: set time to 23:59:59 if time is set to 00:00:00



85
86
87
88
89
90
# File 'lib/mokio/concerns/models/content.rb', line 85

def update_display_to
  if self.display_to && self.display_to.time.strftime("%H:%M") == "00:00"
    updated = self.display_to.end_of_day
    self.display_to = updated
  end
end

#update_etagObject

Touching etag field



77
78
79
# File 'lib/mokio/concerns/models/content.rb', line 77

def update_etag
  self.touch(:etag)
end