Class: SemiStatic::Page

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion
Defined in:
lib/semi_static/page.rb

Direct Known Subclasses

Backend, News

Defined Under Namespace

Modules: WithLocale

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, args) ⇒ Page

Returns a new instance of Page.



26
27
28
29
30
31
# File 'lib/semi_static/page.rb', line 26

def initialize(body, args)
  @body = body
  args.each_pair do |k,v|
    send("#{k}=", v)
  end
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



10
11
12
# File 'lib/semi_static/page.rb', line 10

def body
  @body
end

#slugObject



37
38
39
# File 'lib/semi_static/page.rb', line 37

def slug
  @slug || title.to_slug.normalize.to_s.gsub("", "")
end

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/semi_static/page.rb', line 10

def title
  @title
end

Class Method Details

.allObject



13
14
15
# File 'lib/semi_static/page.rb', line 13

def self.all
  SemiStatic.backend.all(self)
end

.find(param) ⇒ Object



21
22
23
24
# File 'lib/semi_static/page.rb', line 21

def self.find(param)
  param = CGI.unescape(param) if param =~ /%/
  all.find {|a| a.to_param == param }
end

.firstObject



17
18
19
# File 'lib/semi_static/page.rb', line 17

def self.first
  all.first
end

Instance Method Details

#persisted?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/semi_static/page.rb', line 49

def persisted?
  true
end

#render(source) ⇒ Object



45
46
47
# File 'lib/semi_static/page.rb', line 45

def render(source)
  body.render(source).html_safe
end

#to_paramObject



33
34
35
# File 'lib/semi_static/page.rb', line 33

def to_param
  slug
end

#to_sObject



41
42
43
# File 'lib/semi_static/page.rb', line 41

def to_s
  title.to_s
end