Class: SoupCMS::CLI::Model::Page

Inherits:
Markdown show all
Defined in:
lib/soupcms/cli/model/page.rb

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

#build, #content_flavor

Methods inherited from Base

#app_name, #build, #coll, #conn, #create, create_model, #db, #doc, #doc_name, #hero_image, #initialize, #model, #old_doc, #publish_in_future?, #slug, #type, #update_old_doc

Constructor Details

This class inherits a constructor from SoupCMS::CLI::Model::Base

Instance Method Details

#descriptionObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/soupcms/cli/model/page.rb', line 51

def description
  return doc['description'] if doc['description']

  post_description = ''
  data = doc['areas'][0]['modules'][0]['recipes'][0]['data']
  content_lines = data['content']['value'].lines
  index = 0
  while post_description.length < 300 && content_lines[index] do
    post_description.concat(content_lines[index].chomp.gsub(/\A[\d_\W]+|[\d_\W]+\Z/, ''))
    index += 1
  end
  post_description + '...'
end

#parse_fileObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/soupcms/cli/model/page.rb', line 7

def parse_file
  @attributes, @content = SoupCMS::CLI::FrontMatterParser.new.parse(file.read)
  {
      'areas' => [
          {
              'name' => 'body',
              'modules' => [
                  {
                      'recipes' => [
                          {
                              'type' => 'inline',
                              'data' => {
                                  'content' => {
                                      'type' => 'markdown',
                                      'flavor' => content_flavor,
                                      'value' => @content
                                  }
                              },
                              'return' => 'article'
                          }
                      ],
                      'template' => {
                          'type' => 'slim',
                          'name' => 'bootstrap/article'
                      }
                  }
              ]
          }
      ]
  }
end

#titleObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/soupcms/cli/model/page.rb', line 39

def title
  return doc['title'] if doc['title']

  data = doc['areas'][0]['modules'][0]['recipes'][0]['data']
  content_lines = data['content']['value'].lines
  doc_title = content_lines.first.chomp
  data['content']['value'] = content_lines[2] ? content_lines[2..-1].join("\n") : ''
  doc_title = doc_title.gsub('_', ' ').gsub('#', '').strip
  data['title'] = doc_title
  doc_title
end