Class: SoupCMS::CLI::Model::Chapter
Constant Summary
Constants inherited
from Base
Base::SEVERITY_COLOR_MAP
Instance Attribute Summary
Attributes inherited from Base
#file
Instance Method Summary
collapse
Methods inherited from Markdown
#content_flavor, #description, #parse_file, #title
Methods inherited from Base
#app_name, #coll, #conn, #create, create_model, #db, #doc, #hero_image, #initialize, #model, #parse_file, #publish_in_future?, #slug, #type
Instance Method Details
#build ⇒ Object
29
30
31
32
33
34
|
# File 'lib/soupcms/cli/model/chapter.rb', line 29
def build
doc['release'] = release
super
doc['chapter_number'] = chapter_number
build_chapter_links
end
|
#build_chapter_links ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/soupcms/cli/model/chapter.rb', line 36
def build_chapter_links
chapters = Dir.glob(File.join(File.dirname(file), '/*.{json,md,yml}')).to_a
index = chapters.index(file.path)
if index > 0
model = SoupCMS::CLI::Model::Chapter.new(File.new(chapters[index-1]))
doc['prev_chapter'] = {'label' => model.title, 'link' => {'model_name' => 'chapters', 'match' => {'slug' => model.slug}}}
end
if index < (chapters.size-1)
model = SoupCMS::CLI::Model::Chapter.new(File.new(chapters[index+1]))
doc['next_chapter'] = {'label' => model.title, 'link' => {'model_name' => 'chapters', 'match' => {'slug' => model.slug}}}
end
end
|
#chapter_number ⇒ Object
16
17
18
|
# File 'lib/soupcms/cli/model/chapter.rb', line 16
def chapter_number
File.basename(file).match('^[\d]')[0].to_i
end
|
#doc_name ⇒ Object
11
12
13
14
|
# File 'lib/soupcms/cli/model/chapter.rb', line 11
def doc_name
document_name = super
document_name.match('^[\d]-').post_match
end
|
#old_doc ⇒ Object
20
21
22
|
# File 'lib/soupcms/cli/model/chapter.rb', line 20
def old_doc
@old_doc ||= (coll.find({'doc_id' => doc['doc_id'], 'release' => doc['release'], 'latest' => true}).to_a[0] || {})
end
|
#release ⇒ Object
7
8
9
|
# File 'lib/soupcms/cli/model/chapter.rb', line 7
def release
file.path.split('/')[3]
end
|
#update_old_doc ⇒ Object
24
25
26
|
# File 'lib/soupcms/cli/model/chapter.rb', line 24
def update_old_doc
coll.update({'_id' => old_doc['_id'], 'release' => old_doc['release']}, {'$set' => {'latest' => false}}) unless old_doc.empty?
end
|