Class: Spreen::Wiki::Sidebar

Inherits:
Application show all
Defined in:
lib/spreen/wiki/sidebar.rb,
sig/generated/spreen/wiki/sidebar.rbs

Overview

Generates the wiki _Sidebar.md as a nested list of owners/categories and their wiki pages.

Instance Attribute Summary

Attributes inherited from Application

#base_path, #config, #excluded_paths, #group_by, #home_overflow, #language, #path_to_home, #path_to_sidebar, #paths_to_wikis

Instance Method Summary collapse

Methods inherited from Application

#initialize, #namespace_for, #no_declaration, #owned_wiki_maps, #parse_home_overflow, #plain_wiki_maps, #populate_namespace, run, #target_paths, #target_regexp, #validate!, #validate_home_overflow!, #wiki_maps_with_namespace

Constructor Details

This class inherits a constructor from Spreen::Wiki::Application

Instance Method Details

#append_section(namespace, wikis, owned:) ⇒ void

This method returns an undefined value.

Parameters:

  • namespace (String)
  • wikis (Array[String])
  • owned: (Boolean)


34
35
36
37
# File 'lib/spreen/wiki/sidebar.rb', line 34

def append_section(namespace, wikis, owned:)
  wiki_list << "#{section_heading(namespace, owned:)}\n"
  wikis.each { |wiki| wiki_list << "  - [[#{wiki.gsub('.md', '')}]]\n" }
end

#runvoid

This method returns an undefined value.



12
13
14
15
# File 'lib/spreen/wiki/sidebar.rb', line 12

def run
  update_wiki_list
  File.write(path_to_sidebar, wiki_list.join)
end

#section_heading(namespace, owned:) ⇒ String

Parameters:

  • namespace (String)
  • owned: (Boolean)

Returns:

  • (String)


42
43
44
45
46
47
# File 'lib/spreen/wiki/sidebar.rb', line 42

def section_heading(namespace, owned:)
  owner_base_url = config.owner_base_url
  return "- #{namespace}" unless owned && owner_base_url

  "- [#{namespace}](#{owner_base_url + namespace.delete('@')})"
end

#update_wiki_listvoid

This method returns an undefined value.



25
26
27
28
# File 'lib/spreen/wiki/sidebar.rb', line 25

def update_wiki_list
  owned_wiki_maps.each { |namespace, wikis| append_section(namespace, wikis, owned: true) }
  plain_wiki_maps.each { |namespace, wikis| append_section(namespace, wikis, owned: false) }
end

#wiki_listArray[String]

Returns:

  • (Array[String])


20
21
22
# File 'lib/spreen/wiki/sidebar.rb', line 20

def wiki_list
  @wiki_list ||= []
end