Class: SpreenWiki::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
Instance Method Details
#append_block(passage, namespace, wikis, owned:) ⇒ void
This method returns an undefined value.
73
74
75
76
77
78
|
# File 'lib/spreen_wiki/home.rb', line 73
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
93
94
95
96
97
98
|
# File 'lib/spreen_wiki/home.rb', line 93
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_passage ⇒ Array[String]
36
37
38
|
# File 'lib/spreen_wiki/home.rb', line 36
def home_passage
@home_passage ||= File.readlines(path_to_home_template).append("\n")
end
|
#path_to_home_template ⇒ String
26
27
28
29
30
31
32
33
|
# File 'lib/spreen_wiki/home.rb', line 26
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_owner ⇒ String
21
22
23
|
# File 'lib/spreen_wiki/home.rb', line 21
def path_to_wikis_by_owner
@path_to_wikis_by_owner ||= File.join(base_path, 'wikis-by-owner')
end
|
#run ⇒ String?
13
14
15
16
|
# File 'lib/spreen_wiki/home.rb', line 13
def run
home_overflow ? write_concise_home_passage : write_home_passage
config.wiki_url
end
|
#write_concise_home_passage ⇒ void
This method returns an undefined value.
49
50
51
52
53
|
# File 'lib/spreen_wiki/home.rb', line 49
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_passage ⇒ void
This method returns an undefined value.
41
42
43
44
45
46
|
# File 'lib/spreen_wiki/home.rb', line 41
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_contents ⇒ void
This method returns an undefined value.
62
63
64
65
66
|
# File 'lib/spreen_wiki/home.rb', line 62
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.
84
85
86
87
88
|
# File 'lib/spreen_wiki/home.rb', line 84
def write_overflow_block(namespace, wikis, owned:)
scratch = [] append_block(scratch, namespace, wikis, owned:)
File.write(File.join(path_to_wikis_by_owner, "#{namespace}.md"), scratch.join.chomp)
end
|
#write_per_namespace_files ⇒ void
This method returns an undefined value.
56
57
58
59
|
# File 'lib/spreen_wiki/home.rb', line 56
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
|