Class: JekyllSupport::Outline
- Inherits:
-
Object
- Object
- JekyllSupport::Outline
- Defined in:
- lib/structure/outline.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
Instance Method Summary collapse
- #add_entries(apages) ⇒ Object
- #add_section(section) ⇒ Object
- #add_sections(sections) ⇒ Object
-
#initialize(outline_options: OutlineOptions.new) ⇒ Outline
constructor
Sort all entries first so they are iteratable according to the desired order.
- #make_entries(docs) ⇒ Object
-
#sort(apages) ⇒ Object
Muliline String.
- #to_s ⇒ Object
Constructor Details
#initialize(outline_options: OutlineOptions.new) ⇒ Outline
Sort all entries first so they are iteratable according to the desired order. This presorts the entries for each section.
If options == :order then place each APage into it’s appropriate section. Otherwise place all entries into one section.
options defaults to [‘title’], but might be something like
- “”, “title”, “”, “–”, “”, “description”, “”
43 44 45 46 47 48 49 50 51 |
# File 'lib/structure/outline.rb', line 43 def initialize(outline_options: OutlineOptions.new) @add_sections_called = false @options = @logger = @options.logger @sections = @options.sort_by == :order ? [] : [Section.new(@options, [0, ''])] rescue StandardError => e error_short_trace @logger, e end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
33 34 35 |
# File 'lib/structure/outline.rb', line 33 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
33 34 35 |
# File 'lib/structure/outline.rb', line 33 def @options end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
33 34 35 |
# File 'lib/structure/outline.rb', line 33 def sections @sections end |
Instance Method Details
#add_entries(apages) ⇒ Object
53 54 55 56 57 |
# File 'lib/structure/outline.rb', line 53 def add_entries(apages) sorted_apages = make_entries sort apages sorted_apages.each { |apage| add_apage apage } self end |
#add_section(section) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/structure/outline.rb', line 59 def add_section(section) return unless @options.sort_by == :order @sections << section self end |
#add_sections(sections) ⇒ Object
66 67 68 69 70 |
# File 'lib/structure/outline.rb', line 66 def add_sections(sections) sections.each { |x| add_section x } @add_sections_called = true self end |
#make_entries(docs) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/structure/outline.rb', line 72 def make_entries(docs) docs.map do |doc| draft = Jekyll::Draft.draft_html doc JekyllSupport.apage_from( date: doc.date, description: doc.description, draft: draft, last_modified: doc.last_modified, order: doc.order, title: doc.title, url: doc.url ) end end |
#sort(apages) ⇒ Object
Returns muliline String.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/structure/outline.rb', line 89 def sort(apages) if @options.sort_by == :order apages_missing_order = apages.select { |x| x.order.nil? } apages_missing_order.each do |x| puts "Error: No value for order found in front matter for '#{x.title}' at #{x.url}; value temporarily set to 0".red JekyllSupport.new_attribute x, 'order', 0 # puts "x.order=#{x.order} for #{x.url}".yellow end if apages_missing_order.empty? && @die_if_order_field_missing puts "Sort aborted for #{collection_name}." return end apages.sort_by(&:order) else apages.sort_by { |apage| sort_property_value apage } end end |
#to_s ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/structure/outline.rb', line 107 def to_s return '' unless @sections&.count&.positive? result = [] result << "<div class='outer_posts'>" result << (@sections.map { |section| " #{section}" }) result << '</div>' result << @options.attribution if @options.enable_attribution result.join "\n" end |