Class: Alula::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/alula/content.rb,
lib/alula/contents/item.rb,
lib/alula/contents/page.rb,
lib/alula/contents/post.rb,
lib/alula/contents/metadata.rb,
lib/alula/contents/attachment.rb

Defined Under Namespace

Classes: Attachment, Item, Metadata, Page, Post

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Content

Returns a new instance of Content.



15
16
17
18
19
20
21
22
23
# File 'lib/alula/content.rb', line 15

def initialize(opts = {})
  @site = opts.delete(:site)
  @config = @site.config
  
  @pages = []
  @posts = []
  @attachments = []
  @statics = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/alula/content.rb', line 38

def method_missing(meth, *args, &blk)
  if m = /^by_(\S+)$/.match(meth)
    return (self.pages + self.posts + self.attachments).find do |item|
      item.send(m[1]) == args.first
    end
  end
  
  super
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



12
13
14
# File 'lib/alula/content.rb', line 12

def attachments
  @attachments
end

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/alula/content.rb', line 8

def config
  @config
end

#pagesObject (readonly)

Returns the value of attribute pages.



10
11
12
# File 'lib/alula/content.rb', line 10

def pages
  @pages
end

#postsObject (readonly)

Returns the value of attribute posts.



11
12
13
# File 'lib/alula/content.rb', line 11

def posts
  @posts
end

#siteObject (readonly)

Returns the value of attribute site.



7
8
9
# File 'lib/alula/content.rb', line 7

def site
  @site
end

#staticsObject (readonly)

Returns the value of attribute statics.



13
14
15
# File 'lib/alula/content.rb', line 13

def statics
  @statics
end

Instance Method Details

#loadObject

Load our site content



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/alula/content.rb', line 26

def load
  # Load everything we can have
  read_content(:posts, :pages, :attachments, :statics)
  
  # Generate our dynamic content (pages, categories, archives, etc. etc.)
  generate_content
  
  # Write slugs to config
  self.config.slugs = (@posts + @pages).collect{|c| c..slug}
  self.config.slugs.count
end