caramelize 1.1.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/main.yml +48 -0
- data/.rubocop.yml +29 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +37 -25
- data/README.md +2 -3
- data/Rakefile +3 -1
- data/bin/caramelize +6 -5
- data/caramelize.gemspec +14 -19
- data/lib/caramelize/caramel.rb +32 -32
- data/lib/caramelize/content_transferer.rb +55 -32
- data/lib/caramelize/database_connector.rb +8 -8
- data/lib/caramelize/filter_processor.rb +2 -0
- data/lib/caramelize/filters/add_newline_to_page_end.rb +22 -0
- data/lib/caramelize/filters/camel_case_to_wiki_links.rb +26 -0
- data/lib/caramelize/filters/remove_table_tab_line_endings.rb +3 -2
- data/lib/caramelize/filters/swap_wiki_links.rb +5 -3
- data/lib/caramelize/filters/wikka_to_markdown.rb +26 -20
- data/lib/caramelize/health_check.rb +6 -68
- data/lib/caramelize/health_checks/home_page_check.rb +23 -0
- data/lib/caramelize/health_checks/orphaned_pages_check.rb +56 -0
- data/lib/caramelize/health_checks/page.rb +28 -0
- data/lib/caramelize/input_wiki/redmine_wiki.rb +18 -15
- data/lib/caramelize/input_wiki/wiki.rb +11 -5
- data/lib/caramelize/input_wiki/wikkawiki.rb +23 -14
- data/lib/caramelize/output_wiki/gollum.rb +10 -10
- data/lib/caramelize/page.rb +14 -10
- data/lib/caramelize/services/page_builder.rb +11 -8
- data/lib/caramelize/version.rb +3 -1
- data/lib/caramelize.rb +5 -0
- data/spec/lib/caramelize/content_transferer_spec.rb +3 -1
- data/spec/lib/caramelize/filter_processor_spec.rb +9 -4
- data/spec/lib/caramelize/filters/add_newline_to_page_end_spec.rb +29 -0
- data/spec/lib/caramelize/filters/camel_case_to_wiki_links_spec.rb +46 -0
- data/spec/lib/caramelize/filters/remove_table_tab_line_endings_spec.rb +19 -12
- data/spec/lib/caramelize/filters/swap_wiki_links_spec.rb +19 -14
- data/spec/lib/caramelize/filters/wikka2markdown_spec.rb +265 -0
- data/spec/lib/caramelize/input_wiki/wiki_spec.rb +24 -23
- data/spec/lib/caramelize/output_wiki/gollum_spec.rb +36 -34
- data/spec/lib/caramelize/page_spec.rb +34 -26
- data/spec/lib/caramelize/services/page_builder_spec.rb +41 -0
- data/spec/spec_helper.rb +4 -2
- metadata +19 -121
- data/.travis.yml +0 -5
- data/spec/lib/caramelize/filters/wikka_to_markdown_spec.rb +0 -198
- data/spec/lib/caramelize/services/page_builder.rb +0 -29
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Caramelize
|
4
|
+
module Filter
|
5
|
+
class AddNewlineToPageEnd
|
6
|
+
def initialize(body)
|
7
|
+
@body = body
|
8
|
+
end
|
9
|
+
|
10
|
+
# take an input stream and convert all wikka syntax to markdown syntax
|
11
|
+
def run
|
12
|
+
return @body if @body[@body.length - 1] == "\n"
|
13
|
+
|
14
|
+
migrated_body = @body.dup
|
15
|
+
|
16
|
+
migrated_body << "\n"
|
17
|
+
|
18
|
+
migrated_body
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Caramelize
|
4
|
+
class CamelCaseToWikiLinks
|
5
|
+
def initialize(body)
|
6
|
+
@body = body
|
7
|
+
end
|
8
|
+
|
9
|
+
# take an input stream and convert all wikka syntax to markdown syntax
|
10
|
+
def run
|
11
|
+
migrated_body = @body.dup
|
12
|
+
|
13
|
+
migrated_body.gsub!(/([^\[\|\w\S])([A-Z]\w+[A-Z]\w+)([^\]])/) { "#{::Regexp.last_match(1)}#{format_link(::Regexp.last_match(2))}#{::Regexp.last_match(3)}" }
|
14
|
+
|
15
|
+
migrated_body
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def format_link(link)
|
21
|
+
link.gsub!(' ', '_')
|
22
|
+
link.gsub!('.', '')
|
23
|
+
"[[#{link}]]"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Caramelize
|
2
4
|
class RemoveTableTabLineEndings
|
3
|
-
|
4
5
|
def initialize(body)
|
5
6
|
@body = body
|
6
7
|
end
|
@@ -8,7 +9,7 @@ module Caramelize
|
|
8
9
|
# take an input stream and convert all wikka syntax to markdown syntax
|
9
10
|
def run
|
10
11
|
migrated_body = @body.dup
|
11
|
-
migrated_body.gsub!(/\|[\t ]*\r
|
12
|
+
migrated_body.gsub!(/\|[\t ]*\r?\n/, "|\n")
|
12
13
|
migrated_body
|
13
14
|
end
|
14
15
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Caramelize
|
2
4
|
class SwapWikiLinks
|
3
5
|
def initialize(body)
|
@@ -8,8 +10,8 @@ module Caramelize
|
|
8
10
|
def run
|
9
11
|
migrated_body = @body.dup
|
10
12
|
|
11
|
-
migrated_body.gsub!(/\[\[(\S+)\|(.+?)\]\]/) { format_link(
|
12
|
-
migrated_body.gsub!(/\[\[([\w\s
|
13
|
+
migrated_body.gsub!(/\[\[(\S+)\|(.+?)\]\]/) { format_link(::Regexp.last_match(2), ::Regexp.last_match(1)) }
|
14
|
+
migrated_body.gsub!(/\[\[([\w\s\-.]*)\]\]/) { format_link(::Regexp.last_match(1), ::Regexp.last_match(1).dup) }
|
13
15
|
|
14
16
|
migrated_body
|
15
17
|
end
|
@@ -19,7 +21,7 @@ module Caramelize
|
|
19
21
|
def format_link(label, link)
|
20
22
|
link.downcase!
|
21
23
|
link.gsub!(' ', '_')
|
22
|
-
link.gsub!(
|
24
|
+
link.gsub!('.', '')
|
23
25
|
"[[#{label}|#{link}]]"
|
24
26
|
end
|
25
27
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Caramelize
|
2
4
|
class Wikka2Markdown
|
3
5
|
attr_reader :source_body
|
@@ -7,7 +9,7 @@ module Caramelize
|
|
7
9
|
end
|
8
10
|
|
9
11
|
def run
|
10
|
-
# TODO images: ({{image)(url\=?)?(.*)(}})
|
12
|
+
# TODO: images: ({{image)(url\=?)?(.*)(}})
|
11
13
|
# markdown: ![Tux, the Linux mascot](/assets/images/tux.png)
|
12
14
|
|
13
15
|
replace_headlines
|
@@ -15,49 +17,53 @@ module Caramelize
|
|
15
17
|
replace_lists
|
16
18
|
replace_wiki_links
|
17
19
|
replace_links
|
20
|
+
replace_inline_code
|
18
21
|
replace_code_block
|
19
22
|
|
20
23
|
target_body
|
21
24
|
end
|
22
25
|
|
23
26
|
def replace_headlines
|
24
|
-
target_body.gsub!(/(======)(.*?)(======)/
|
25
|
-
target_body.gsub!(/(=====)(.*?)(=====)/) {|
|
26
|
-
target_body.gsub!(/(====)(.*?)(====)/) {|
|
27
|
-
target_body.gsub!(/(===)(.*?)(===)/) {|
|
28
|
-
target_body.gsub!(/(==)(.*?)(==)/) {|
|
27
|
+
target_body.gsub!(/(======)(.*?)(======)/) { |_s| "# #{::Regexp.last_match(2)}" } # h1
|
28
|
+
target_body.gsub!(/(=====)(.*?)(=====)/) { |_s| "## #{::Regexp.last_match(2)}" } # h2
|
29
|
+
target_body.gsub!(/(====)(.*?)(====)/) { |_s| "### #{::Regexp.last_match(2)}" } # h3
|
30
|
+
target_body.gsub!(/(===)(.*?)(===)/) { |_s| "#### #{::Regexp.last_match(2)}" } # h4
|
31
|
+
target_body.gsub!(/(==)(.*?)(==)/) { |_s| "##### #{::Regexp.last_match(2)}" } # h5
|
29
32
|
end
|
30
33
|
|
31
34
|
def replace_formatting
|
32
|
-
target_body.gsub!(/(\*\*)(.*?)(\*\*)/) {|
|
33
|
-
target_body.gsub!(
|
34
|
-
target_body.gsub!(/(__)(.*?)(__)/) {|
|
35
|
-
target_body.gsub!(/(---)/, ' ')
|
35
|
+
target_body.gsub!(/(\*\*)(.*?)(\*\*)/) { |_s| "**#{::Regexp.last_match(2)}**" } # bold
|
36
|
+
target_body.gsub!(%r{(//)(.*?)(//)}, '*\2*') # italic
|
37
|
+
target_body.gsub!(/(__)(.*?)(__)/) { |_s| "<u>#{::Regexp.last_match(2)}</u>" } # underline
|
38
|
+
target_body.gsub!(/(---)/, ' ') # forced linebreak
|
36
39
|
end
|
37
40
|
|
38
41
|
def replace_lists
|
39
|
-
target_body.gsub!(/(\t-\s?)(.*)/, '
|
40
|
-
target_body.gsub!(/(~-\s?)(.*)/, '
|
41
|
-
target_body.gsub!(/( -\s?)(.*)/, '
|
42
|
+
target_body.gsub!(/(\t-\s?)(.*)/, '- \2') # unordered list
|
43
|
+
target_body.gsub!(/(~-\s?)(.*)/, '- \2') # unordered list
|
44
|
+
target_body.gsub!(/( -\s?)(.*)/, '- \2') # unordered list
|
42
45
|
|
43
46
|
target_body.gsub!(/(~1\)\s?)(.*)/, '1. \2') # unordered list
|
44
47
|
# TODO ordered lists
|
45
48
|
end
|
46
49
|
|
47
50
|
def replace_wiki_links
|
48
|
-
target_body.gsub!(
|
51
|
+
target_body.gsub!(/\[{2}(\w+)[\s|](.+?)\]{2}/, '[[\2|\1]]')
|
49
52
|
end
|
50
53
|
|
51
54
|
def replace_links
|
52
|
-
target_body.gsub!(
|
53
|
-
|
54
|
-
target_body.gsub!(
|
55
|
+
target_body.gsub!(/\[{2}((\w+):\S[^| ]*)[| ](.*)\]{2}/,
|
56
|
+
'[\3](\1)')
|
57
|
+
target_body.gsub!(/\[{2}((\w+):.*)\]{2}/, '<\1>')
|
58
|
+
end
|
59
|
+
|
60
|
+
def replace_inline_code
|
61
|
+
target_body.gsub!(/(%%)(.*?)(%%)/) { |_s| "`#{::Regexp.last_match(2)}`" } # h1
|
55
62
|
end
|
56
63
|
|
57
64
|
def replace_code_block
|
58
|
-
target_body.gsub!(/^%%\s(.*?)%%\s?/m)
|
59
|
-
|
60
|
-
end
|
65
|
+
target_body.gsub!(/^%%\(?(\w+)\)?\s(.*?)%%\s?/m) { "```#{::Regexp.last_match(1)}\n#{::Regexp.last_match(2)}```\n" }
|
66
|
+
target_body.gsub!(/^%%\s(.*?)%%\s?/m) { "```\n#{::Regexp.last_match(1)}```\n" }
|
61
67
|
end
|
62
68
|
|
63
69
|
def target_body
|
@@ -1,85 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Caramelize
|
2
4
|
class HealthCheck
|
3
5
|
attr_reader :wiki_path, :options
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(wiki_path, options={})
|
7
|
+
def initialize(wiki_path, options = {})
|
8
8
|
@wiki_path = wiki_path
|
9
9
|
@options = options
|
10
10
|
end
|
11
11
|
|
12
12
|
def execute
|
13
|
-
|
14
|
-
|
15
|
-
check_pages
|
16
|
-
|
17
|
-
#puts intra_wiki_paths.sort.inspect
|
18
|
-
|
19
|
-
puts "\n # Pages not linked within Wiki:"
|
20
|
-
puts page_paths_without_intra_wiki_path.sort.inspect
|
13
|
+
HealthChecks::HomePageCheck.new(gollum).check
|
14
|
+
HealthChecks::OrphanedPagesCheck.new(gollum).check
|
21
15
|
end
|
22
16
|
|
23
17
|
private
|
24
18
|
|
25
|
-
def files
|
26
|
-
@files ||= Dir.glob([wiki_path, '**/*.md'].join('/'))
|
27
|
-
end
|
28
|
-
|
29
|
-
def file_names
|
30
|
-
files.map do |file|
|
31
|
-
file.gsub("#{wiki_path}/", '').split('.').first
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def check_pages
|
36
|
-
pages.each do |page|
|
37
|
-
puts "\n## #{page.path}"
|
38
|
-
check_page(page)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def check_page(page)
|
43
|
-
intra_wiki_links = intra_wiki_links(page.text_data)
|
44
|
-
available = 0
|
45
|
-
intra_wiki_links.each do |link|
|
46
|
-
intra_wiki_link = page.path.split('/').first == page.path ? link : [page.path.split('/').first, link].join('/')
|
47
|
-
if !page_paths.include?(intra_wiki_link)
|
48
|
-
puts "#{intra_wiki_link} expected, but missing"
|
49
|
-
else
|
50
|
-
available += 1
|
51
|
-
intra_wiki_paths << intra_wiki_link
|
52
|
-
end
|
53
|
-
end
|
54
|
-
puts "#{available}/#{intra_wiki_links.count} available"
|
55
|
-
end
|
56
|
-
|
57
|
-
def intra_wiki_links(body)
|
58
|
-
body.scan(/\[\[(.+\|)?(\S+)\]\]/).map { |match| match[1] }.uniq
|
59
|
-
end
|
60
|
-
|
61
|
-
def pages
|
62
|
-
gollum.pages
|
63
|
-
end
|
64
|
-
|
65
|
-
def page_paths
|
66
|
-
pages.map(&:path).map { |path| path.split('.').first }
|
67
|
-
end
|
68
|
-
|
69
|
-
def intra_wiki_paths
|
70
|
-
@intra_wiki_paths ||= []
|
71
|
-
end
|
72
|
-
|
73
|
-
def page_paths_without_intra_wiki_path
|
74
|
-
page_paths - intra_wiki_paths
|
75
|
-
end
|
76
|
-
|
77
|
-
def check_home_page
|
78
|
-
puts "Home.md missing" if File.exist?('wiki-export/Home.md')
|
79
|
-
end
|
80
|
-
|
81
19
|
def gollum
|
82
|
-
@gollum ||= ::Gollum::Wiki.new(wiki_path)
|
20
|
+
@gollum ||= ::Gollum::Wiki.new(wiki_path, { ref: 'main' })
|
83
21
|
end
|
84
22
|
end
|
85
23
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Caramelize
|
4
|
+
module HealthChecks
|
5
|
+
class HomePageCheck
|
6
|
+
attr_reader :gollum
|
7
|
+
|
8
|
+
def initialize(gollum)
|
9
|
+
@gollum = gollum
|
10
|
+
end
|
11
|
+
|
12
|
+
def check
|
13
|
+
puts 'Home.md missing' unless has_home_page?
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def has_home_page? # rubocop:todo Naming/PredicateName
|
19
|
+
gollum.file('Home')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Caramelize
|
4
|
+
module HealthChecks
|
5
|
+
class OrphanedPagesCheck
|
6
|
+
attr_reader :gollum, :all_intra_wiki_paths, :intra_wiki_paths
|
7
|
+
|
8
|
+
def initialize(gollum)
|
9
|
+
@gollum = gollum
|
10
|
+
@intra_wiki_paths = []
|
11
|
+
@all_intra_wiki_paths = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def check
|
15
|
+
puts "\n # Pages not linked within Wiki:"
|
16
|
+
puts page_paths_without_intra_wiki_path.sort.inspect
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def check_page(page) # rubocop:todo Metrics/MethodLength
|
22
|
+
0.tap do |available_count|
|
23
|
+
page.intra_wiki_links.each do |intra_wiki_path|
|
24
|
+
if page_paths.include?(intra_wiki_path)
|
25
|
+
available_count += 1
|
26
|
+
intra_wiki_paths << intra_wiki_path
|
27
|
+
else
|
28
|
+
puts "#{intra_wiki_path} expected, but missing"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
puts "#{available_count}/#{intra_wiki_links.count} available"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def page_paths
|
36
|
+
pages.map(&:path).map { |path| path.split('.').first }
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_pages
|
40
|
+
pages.map do |page|
|
41
|
+
check_page(page)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def pages
|
46
|
+
@pages ||= gollum.pages.map do |gollum_page|
|
47
|
+
HealthChecks::Page.new(gollum_page)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def page_paths_without_intra_wiki_path
|
52
|
+
page_paths - intra_wiki_paths
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Caramelize
|
4
|
+
module HealthChecks
|
5
|
+
class Page
|
6
|
+
attr_reader :gollum_page
|
7
|
+
|
8
|
+
def initialize(gollum_page)
|
9
|
+
@gollum_page = gollum_page
|
10
|
+
end
|
11
|
+
|
12
|
+
def intra_wiki_links
|
13
|
+
gollum_page.text_data.scan(/\[\[(.+\|)?(\S+)\]\]/).map do |match|
|
14
|
+
link = match[1]
|
15
|
+
filename == path ? link : [filename, link].join('/')
|
16
|
+
end.uniq
|
17
|
+
end
|
18
|
+
|
19
|
+
def filename
|
20
|
+
path.split('/').first
|
21
|
+
end
|
22
|
+
|
23
|
+
def path
|
24
|
+
gollum_page.path
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'caramelize/input_wiki/wiki'
|
2
4
|
require 'caramelize/filters/swap_wiki_links'
|
3
5
|
require 'caramelize/filters/remove_table_tab_line_endings'
|
@@ -23,7 +25,7 @@ module Caramelize
|
|
23
25
|
build_page(row_page)
|
24
26
|
end
|
25
27
|
titles.uniq!
|
26
|
-
revisions.sort! { |a,b| a.time <=> b.time }
|
28
|
+
revisions.sort! { |a, b| a.time <=> b.time }
|
27
29
|
|
28
30
|
revisions
|
29
31
|
end
|
@@ -31,25 +33,26 @@ module Caramelize
|
|
31
33
|
def read_authors
|
32
34
|
results = database.query(authors_query)
|
33
35
|
results.each do |row|
|
34
|
-
authors[row[
|
35
|
-
|
36
|
-
|
36
|
+
authors[row['id']] = { id: row['id'],
|
37
|
+
name: row['login'],
|
38
|
+
email: row['mail'] }
|
37
39
|
end
|
38
40
|
authors
|
39
41
|
end
|
40
42
|
|
41
43
|
private
|
42
44
|
|
43
|
-
|
45
|
+
# rubocop:todo Metrics/MethodLength
|
46
|
+
def build_page(row_page) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
|
44
47
|
results_contents = database.query(single_page_query(row_page['id']))
|
45
48
|
|
46
|
-
wiki = wikis.select{ |row| row['id'] == row_page['wiki_id'] }.first
|
49
|
+
wiki = wikis.select { |row| row['id'] == row_page['wiki_id'] }.first
|
47
50
|
|
48
51
|
project_identifier = ''
|
49
52
|
|
50
53
|
if wiki
|
51
|
-
project = projects.select{ |row| row['id'] == wiki['project_id'] }.first
|
52
|
-
project_identifier = project['identifier']
|
54
|
+
project = projects.select { |row| row['id'] == wiki['project_id'] }.first
|
55
|
+
project_identifier = "#{project['identifier']}/"
|
53
56
|
end
|
54
57
|
|
55
58
|
title = project_identifier + row_page['title']
|
@@ -60,11 +63,12 @@ module Caramelize
|
|
60
63
|
revisions << page
|
61
64
|
end
|
62
65
|
end
|
66
|
+
# rubocop:enable Metrics/MethodLength
|
63
67
|
|
64
68
|
def add_projects_as_namespaces
|
65
69
|
projects.each do |row_project|
|
66
|
-
namespace =
|
67
|
-
|
70
|
+
namespace = { identifier: row_project['identifier'],
|
71
|
+
name: row_project['name'] }
|
68
72
|
namespaces << namespace
|
69
73
|
end
|
70
74
|
end
|
@@ -101,18 +105,17 @@ module Caramelize
|
|
101
105
|
@wikis ||= database.query(wikis_query)
|
102
106
|
end
|
103
107
|
|
104
|
-
def build_properties(title, row_content)
|
105
|
-
author = authors.fetch(row_content[
|
108
|
+
def build_properties(title, row_content) # rubocop:todo Metrics/MethodLength
|
109
|
+
author = authors.fetch(row_content['author_id'], nil)
|
106
110
|
{
|
107
111
|
id: row_content['id'],
|
108
|
-
title
|
112
|
+
title:,
|
109
113
|
body: row_content['data'],
|
110
114
|
markup: :textile,
|
111
115
|
latest: false,
|
112
116
|
time: row_content['updated_on'],
|
113
117
|
message: row_content['comments'],
|
114
|
-
author:
|
115
|
-
author_name: author.name
|
118
|
+
author:
|
116
119
|
}
|
117
120
|
end
|
118
121
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Caramelize
|
2
4
|
module InputWiki
|
3
5
|
class Wiki
|
@@ -5,7 +7,7 @@ module Caramelize
|
|
5
7
|
|
6
8
|
attr_accessor :revisions, :wiki_title, :titles, :description, :namespaces, :options
|
7
9
|
|
8
|
-
def initialize(options={})
|
10
|
+
def initialize(options = {})
|
9
11
|
@options = options
|
10
12
|
@options[:filters] = []
|
11
13
|
@namespaces = []
|
@@ -15,7 +17,7 @@ module Caramelize
|
|
15
17
|
# new array only containing pages by this name sorted by time asc
|
16
18
|
# this does not support renamed pages
|
17
19
|
revisions.select { |revision| revision.title == title }
|
18
|
-
.sort { |x,y| x.time <=> y.time }
|
20
|
+
.sort { |x, y| x.time <=> y.time }
|
19
21
|
end
|
20
22
|
|
21
23
|
# return an empty array in case this action was not overridden
|
@@ -23,7 +25,7 @@ module Caramelize
|
|
23
25
|
[]
|
24
26
|
end
|
25
27
|
|
26
|
-
def namespaces
|
28
|
+
def namespaces # rubocop:todo Lint/DuplicateMethods
|
27
29
|
@namespaces ||= {}
|
28
30
|
end
|
29
31
|
|
@@ -31,14 +33,18 @@ module Caramelize
|
|
31
33
|
@authors ||= {}
|
32
34
|
end
|
33
35
|
|
34
|
-
def revisions
|
36
|
+
def revisions # rubocop:todo Lint/DuplicateMethods
|
35
37
|
@revisions ||= []
|
36
38
|
end
|
37
39
|
|
38
|
-
def titles
|
40
|
+
def titles # rubocop:todo Lint/DuplicateMethods
|
39
41
|
@titles ||= []
|
40
42
|
end
|
41
43
|
|
44
|
+
def excluded_pages
|
45
|
+
[]
|
46
|
+
end
|
47
|
+
|
42
48
|
def convert_markup?(to_markup)
|
43
49
|
markup != to_markup
|
44
50
|
end
|
@@ -1,4 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'caramelize/database_connector'
|
4
|
+
require 'caramelize/filters/add_newline_to_page_end'
|
5
|
+
require 'caramelize/filters/camel_case_to_wiki_links'
|
2
6
|
require 'caramelize/filters/wikka_to_markdown'
|
3
7
|
|
4
8
|
module Caramelize
|
@@ -6,13 +10,16 @@ module Caramelize
|
|
6
10
|
class WikkaWiki < Wiki
|
7
11
|
include DatabaseConnector
|
8
12
|
|
9
|
-
SQL_PAGES = 'SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;'
|
10
|
-
SQL_AUTHORS = 'SELECT name, email FROM wikka_users;'
|
13
|
+
SQL_PAGES = 'SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;'
|
14
|
+
SQL_AUTHORS = 'SELECT name, email FROM wikka_users;'
|
15
|
+
FUNCTION_PAGES = %w[AdminBadWords AdminPages AdminUsers AdminSpamLog CategoryAdmin CategoryCategory CategoryWiki DatabaseInfo FormattingRules HighScores InterWiki MyChanges MyPages OrphanedPages OwnedPages PageIndex PasswordForgotten RecentChanges RecentlyCommented Sandbox SysInfo TableMarkup TableMarkupReference TextSearch TextSearchExpanded UserSettings WantedPages WikiCategory WikkaInstaller WikkaConfig WikkaDocumentation WikkaMenulets WikkaReleaseNotes].freeze
|
11
16
|
|
12
17
|
def initialize(options = {})
|
13
18
|
super(options)
|
14
19
|
@options[:markup] = :wikka
|
20
|
+
@options[:filters] << Caramelize::AddNewlineOnPageEnd
|
15
21
|
@options[:filters] << Caramelize::Wikka2Markdown
|
22
|
+
@options[:filters] << Caramelize::CamelCaseToWikiLinks
|
16
23
|
end
|
17
24
|
|
18
25
|
# after calling this action, titles and @revisions are expected to be filled
|
@@ -23,7 +30,7 @@ module Caramelize
|
|
23
30
|
revisions << page
|
24
31
|
end
|
25
32
|
titles.uniq!
|
26
|
-
#revisions.sort! { |a,b| a.time <=> b.time }
|
33
|
+
# revisions.sort! { |a,b| a.time <=> b.time }
|
27
34
|
|
28
35
|
revisions
|
29
36
|
end
|
@@ -31,11 +38,14 @@ module Caramelize
|
|
31
38
|
def read_authors
|
32
39
|
results = database.query(authors_query)
|
33
40
|
results.each do |row|
|
34
|
-
authors[row['name']] =
|
35
|
-
email: row['email'] )
|
41
|
+
authors[row['name']] = { name: row['name'], email: row['email'] }
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
45
|
+
def excluded_pages
|
46
|
+
FUNCTION_PAGES
|
47
|
+
end
|
48
|
+
|
39
49
|
private
|
40
50
|
|
41
51
|
def pages_query
|
@@ -50,18 +60,17 @@ module Caramelize
|
|
50
60
|
@pages ||= database.query(pages_query)
|
51
61
|
end
|
52
62
|
|
53
|
-
def build_properties(row)
|
63
|
+
def build_properties(row) # rubocop:todo Metrics/MethodLength
|
54
64
|
author = authors[row['user']]
|
55
65
|
{
|
56
|
-
id: row[
|
57
|
-
title: row[
|
58
|
-
body: row[
|
66
|
+
id: row['id'],
|
67
|
+
title: row['tag'],
|
68
|
+
body: row['body'],
|
59
69
|
markup: :wikka,
|
60
|
-
latest: row[
|
61
|
-
time: row[
|
62
|
-
message: row[
|
63
|
-
author:
|
64
|
-
author_name: row["user"]
|
70
|
+
latest: row['latest'] == 'Y',
|
71
|
+
time: row['time'],
|
72
|
+
message: row['note'],
|
73
|
+
author:
|
65
74
|
}
|
66
75
|
end
|
67
76
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gollum-lib'
|
2
4
|
|
3
5
|
module Caramelize
|
4
6
|
module OutputWiki
|
5
7
|
class Gollum
|
6
|
-
|
7
8
|
attr_reader :wiki_path
|
8
9
|
|
9
10
|
SUPPORTED_TARGET_MARKUP =
|
@@ -11,9 +12,9 @@ module Caramelize
|
|
11
12
|
|
12
13
|
# Initialize a new gollum-wiki-repository at the given path.
|
13
14
|
def initialize(new_wiki_path)
|
14
|
-
# TODO use sanitized name as wiki-repository-title
|
15
|
+
# TODO: use sanitized name as wiki-repository-title
|
15
16
|
@wiki_path = new_wiki_path
|
16
|
-
initialize_repository
|
17
|
+
initialize_repository unless File.exist?(wiki_path)
|
17
18
|
end
|
18
19
|
|
19
20
|
# Commit the given page into the gollum-wiki-repository.
|
@@ -28,9 +29,9 @@ module Caramelize
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
|
-
def rename_page(page_title,
|
32
|
+
def rename_page(page_title, new_title)
|
32
33
|
gollum_page = gollum.page(page_title)
|
33
|
-
gollum.rename_page(gollum_page,
|
34
|
+
gollum.rename_page(gollum_page, new_title, { message: 'Rename home page' })
|
34
35
|
end
|
35
36
|
|
36
37
|
# Commit all revisions of the given history into this gollum-wiki-repository.
|
@@ -53,8 +54,8 @@ module Caramelize
|
|
53
54
|
def build_commit(page)
|
54
55
|
{
|
55
56
|
message: page.commit_message,
|
56
|
-
name: page.
|
57
|
-
email: page.
|
57
|
+
name: page.author_name,
|
58
|
+
email: page.author_email,
|
58
59
|
time: page.time
|
59
60
|
}
|
60
61
|
end
|
@@ -66,13 +67,12 @@ module Caramelize
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def gollum
|
69
|
-
@gollum ||= ::Gollum::Wiki.new(wiki_path, {repo_is_bare: true})
|
70
|
+
@gollum ||= ::Gollum::Wiki.new(wiki_path, { repo_is_bare: true, ref: 'main' })
|
70
71
|
end
|
71
72
|
|
72
73
|
def initialize_repository
|
73
|
-
return if File.exist?(wiki_path)
|
74
74
|
Dir.mkdir(wiki_path)
|
75
|
-
|
75
|
+
# ::Gollum::Git::Repo.new(wiki_path, { is_bare: true })
|
76
76
|
::Gollum::Git::Repo.init(wiki_path)
|
77
77
|
end
|
78
78
|
end
|