Class: ActiveAdmin::Cms::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/active_admin/cms/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_url(url) ⇒ Object



14
15
16
# File 'lib/active_admin/cms/page.rb', line 14

def for_url(url)
  where(:url => url).first if where(:url => url).any?
end

Instance Method Details

#content_for(content_key) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_admin/cms/page.rb', line 20

def content_for content_key
  ret = nil
  if recipe
    if recipe.contains_content_key?(content_key)
      ret = Cms::Content.where(:page_id => id, :key => content_key)
      if ret.length == 0
        ret = Cms::Content.new(:page => self, :key => content_key)
        ret.content_type = recipe.ingredient_for(content_key).content_type
      else
        ret = ret[0]
      end
    #else
      #raise Cms::Exceptions::InvalidContentKey
    end
  end
  return ret
end

#meta_dataObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/active_admin/cms/page.rb', line 38

def 
  data = {}
  if meta_title and !meta_title.blank?
    data[:title] = meta_title
  elsif title and !title.blank?
    data[:title] = "#{Cms::SITE_TITLE} | #{title}"
  else
    data[:title] = Cms::SITE_TITLE
  end
  data[:description] = meta_description || Cms::DEFAULT_META_DESCRIPTION
  data[:keywords] = meta_keywords || Cms::DEFAULT_META_KEYWORDS
  data
end

#set_content(content_key, content) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/active_admin/cms/page.rb', line 66

def set_content content_key, content
  if content.kind_of? Cms::Content
    content.key = content_key
    content.page = self
    content.content_type = recipe.ingredient_for(content_key).content_type
    content.save
  end
end

#set_value(content_hash) ⇒ Object

Takes a content_key => text hash and sets the text value for each of the content records



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/active_admin/cms/page.rb', line 53

def set_value content_hash
  if content_hash
    content_hash.each do |key, value|
      c = content_for(key)
      #debugger
      if c
        c.set_content value
        c.save
      end
    end
  end
end