Class: Spreen::Wiki::Home

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

Overview

Generates the wiki Home page, optionally splitting per-owner content out into wikis-by-owner/<owner>.md when home_overflow is enabled. Returns the configured wiki URL (if any) so callers can point at the result.

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_block(passage, namespace, wikis, owned:) ⇒ void

This method returns an undefined value.

Parameters:

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


74
75
76
77
78
79
# File 'lib/spreen/wiki/home.rb', line 74

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

#heading_for(namespace, owned:) ⇒ String

Parameters:

  • namespace (String)
  • owned: (Boolean)

Returns:

  • (String)


94
95
96
97
98
99
# File 'lib/spreen/wiki/home.rb', line 94

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

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

#home_passageArray[String]

Returns:

  • (Array[String])


37
38
39
# File 'lib/spreen/wiki/home.rb', line 37

def home_passage
  @home_passage ||= File.readlines(path_to_home_template).append("\n")
end

#path_to_home_templateString

Returns:

  • (String)


27
28
29
30
31
32
33
34
# File 'lib/spreen/wiki/home.rb', line 27

def path_to_home_template
  path = config.path_to_template(group_by, language)
  unless File.exist?(path)
    raise ArgumentError, "Missing Home template: `#{path}`. Ship one there or configure template_dir."
  end

  path
end

#path_to_wikis_by_ownerString

Returns:

  • (String)


22
23
24
# File 'lib/spreen/wiki/home.rb', line 22

def path_to_wikis_by_owner
  @path_to_wikis_by_owner ||= File.join(base_path, 'wikis-by-owner')
end

#runString?

Returns:

  • (String, nil)


14
15
16
17
# File 'lib/spreen/wiki/home.rb', line 14

def run
  home_overflow ? write_concise_home_passage : write_home_passage
  config.wiki_url
end

#write_concise_home_passagevoid

This method returns an undefined value.



50
51
52
53
54
# File 'lib/spreen/wiki/home.rb', line 50

def write_concise_home_passage
  FileUtils.mkdir_p(path_to_wikis_by_owner)
  write_per_namespace_files
  write_home_table_of_contents
end

#write_home_passagevoid

This method returns an undefined value.



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

def write_home_passage
  FileUtils.rm_rf(path_to_wikis_by_owner)
  owned_wiki_maps.each { |namespace, wikis| append_block(home_passage, namespace, wikis, owned: true) }
  plain_wiki_maps.each { |namespace, wikis| append_block(home_passage, namespace, wikis, owned: false) }
  File.write(path_to_home, home_passage.join.chomp)
end

#write_home_table_of_contentsvoid

This method returns an undefined value.



63
64
65
66
67
# File 'lib/spreen/wiki/home.rb', line 63

def write_home_table_of_contents
  (owned_wiki_maps.keys + plain_wiki_maps.keys).each { |namespace| home_passage << "- [[#{namespace}]]\n" }
  home_passage << "\n"
  File.write(path_to_home, home_passage.join.chomp)
end

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

This method returns an undefined value.

Parameters:

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


85
86
87
88
89
# File 'lib/spreen/wiki/home.rb', line 85

def write_overflow_block(namespace, wikis, owned:)
  scratch = [] #: Array[String]
  append_block(scratch, namespace, wikis, owned:)
  File.write(File.join(path_to_wikis_by_owner, "#{namespace}.md"), scratch.join.chomp)
end

#write_per_namespace_filesvoid

This method returns an undefined value.



57
58
59
60
# File 'lib/spreen/wiki/home.rb', line 57

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