Class: Adva::Static::Import::Source::Post
- Inherits:
-
Base
- Object
- Base
- Adva::Static::Import::Source::Post
show all
- Defined in:
- lib/adva/static/import/source/post.rb
Constant Summary
collapse
- PERMALINK =
%r((?:^|/)(\d{4})(?:\-|\/)(\d{1,2})(?:\-|\/)(\d{1,2})(?:\-|\/)(.*)$)
Instance Attribute Summary
Attributes inherited from Base
#path
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#<=>, #initialize, #model_name, #to_hash
Class Method Details
.permalink?(path) ⇒ Boolean
18
19
20
|
# File 'lib/adva/static/import/source/post.rb', line 18
def permalink?(path)
path.to_s =~ PERMALINK
end
|
.recognize(paths) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/adva/static/import/source/post.rb', line 11
def recognize(paths)
posts = paths.map { |path| path.self_and_descendants }.flatten.select { |path| permalink?(path) }
posts = posts.map { |path| new(path) }
paths.replace(paths - posts.map(&:permalink_paths).flatten)
posts
end
|
Instance Method Details
#categories ⇒ Object
23
24
25
|
# File 'lib/adva/static/import/source/post.rb', line 23
def categories
@categories ||= Array(read.categories).map { |category| category.split(',') }.flatten.map(&:strip)
end
|
#data ⇒ Object
51
52
53
|
# File 'lib/adva/static/import/source/post.rb', line 51
def data
super.merge(:categories => categories, :title => title, :slug => slug, :published_at => published_at)
end
|
#permalink ⇒ Object
39
40
41
|
# File 'lib/adva/static/import/source/post.rb', line 39
def permalink
@permalink ||= path_tokens.to_a[0..-2] << slug
end
|
#permalink_paths ⇒ Object
43
44
45
|
# File 'lib/adva/static/import/source/post.rb', line 43
def permalink_paths
path.self_and_parents - path.root.self_and_parents
end
|
#published_at ⇒ Object
35
36
37
|
# File 'lib/adva/static/import/source/post.rb', line 35
def published_at
@published_at ||= DateTime.civil(*permalink[0..-2].map(&:to_i))
end
|
#slug ⇒ Object
31
32
33
|
# File 'lib/adva/static/import/source/post.rb', line 31
def slug
@slug ||= read.slug || SimpleSlugs::Slug.new(title).to_s
end
|
#strip_permalink ⇒ Object
47
48
49
|
# File 'lib/adva/static/import/source/post.rb', line 47
def strip_permalink
path.gsub(Post::PERMALINK, '')
end
|
#title ⇒ Object
27
28
29
|
# File 'lib/adva/static/import/source/post.rb', line 27
def title
@title ||= read.title || path_tokens.last.titleize
end
|