Class: Adva::Static::Import::Source::Blog

Inherits:
Section
  • Object
show all
Defined in:
lib/adva/static/import/source/blog.rb

Constant Summary

Constants inherited from Section

Section::TYPES

Instance Attribute Summary collapse

Attributes inherited from Base

#path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Section

#name, #root?, #slug

Methods inherited from Base

#<=>, #model_name, #to_hash

Constructor Details

#initialize(path, posts = []) ⇒ Blog

Returns a new instance of Blog.



19
20
21
22
# File 'lib/adva/static/import/source/blog.rb', line 19

def initialize(path, posts = [])
  @posts = posts
  super(path)
end

Instance Attribute Details

#postsObject (readonly)

Returns the value of attribute posts.



17
18
19
# File 'lib/adva/static/import/source/blog.rb', line 17

def posts
  @posts
end

Class Method Details

.recognize(paths) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/adva/static/import/source/blog.rb', line 7

def recognize(paths)
  posts = Post.recognize(paths)
  blogs = posts.map { |post| post.strip_permalink }.flatten.uniq
  blogs = blogs.map { |blog| paths.detect { |path| blog.to_s == path.to_s } || blog }

  paths.replace(paths - blogs)
  blogs.map { |path| new(path, posts) }
end

Instance Method Details

#categoriesObject



24
25
26
# File 'lib/adva/static/import/source/blog.rb', line 24

def categories
  @categories ||= posts.map { |post| post.categories }.flatten.uniq.sort
end

#dataObject



28
29
30
# File 'lib/adva/static/import/source/blog.rb', line 28

def data
  super.merge(:posts => posts, :categories => categories)
end