Class: SpreenWiki::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 SpreenWiki::Application

Instance Method Details

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

This method returns an undefined value.

Parameters:

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


33
34
35
36
# File 'lib/spreen_wiki/sidebar.rb', line 33

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.



11
12
13
14
# File 'lib/spreen_wiki/sidebar.rb', line 11

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)


41
42
43
44
45
46
# File 'lib/spreen_wiki/sidebar.rb', line 41

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.



24
25
26
27
# File 'lib/spreen_wiki/sidebar.rb', line 24

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])


19
20
21
# File 'lib/spreen_wiki/sidebar.rb', line 19

def wiki_list
  @wiki_list ||= []
end