caramelize 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +29 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +25 -13
  5. data/README.md +2 -3
  6. data/Rakefile +3 -1
  7. data/bin/caramelize +6 -5
  8. data/caramelize.gemspec +23 -19
  9. data/lib/caramelize/caramel.rb +26 -30
  10. data/lib/caramelize/content_transferer.rb +48 -29
  11. data/lib/caramelize/database_connector.rb +8 -8
  12. data/lib/caramelize/filter_processor.rb +2 -0
  13. data/lib/caramelize/filters/camel_case_to_wiki_links.rb +26 -0
  14. data/lib/caramelize/filters/remove_table_tab_line_endings.rb +3 -2
  15. data/lib/caramelize/filters/swap_wiki_links.rb +5 -3
  16. data/lib/caramelize/filters/wikka_to_markdown.rb +26 -20
  17. data/lib/caramelize/health_check.rb +6 -68
  18. data/lib/caramelize/health_checks/home_page_check.rb +23 -0
  19. data/lib/caramelize/health_checks/orphaned_pages_check.rb +56 -0
  20. data/lib/caramelize/health_checks/page.rb +28 -0
  21. data/lib/caramelize/input_wiki/redmine_wiki.rb +14 -13
  22. data/lib/caramelize/input_wiki/wiki.rb +8 -2
  23. data/lib/caramelize/input_wiki/wikkawiki.rb +22 -13
  24. data/lib/caramelize/output_wiki/gollum.rb +10 -10
  25. data/lib/caramelize/page.rb +13 -9
  26. data/lib/caramelize/services/page_builder.rb +11 -8
  27. data/lib/caramelize/version.rb +3 -1
  28. data/lib/caramelize.rb +5 -0
  29. data/spec/lib/caramelize/content_transferer_spec.rb +3 -1
  30. data/spec/lib/caramelize/filter_processor_spec.rb +5 -2
  31. data/spec/lib/caramelize/filters/add_newline_on_page_end_spec.rb +27 -0
  32. data/spec/lib/caramelize/filters/camel_case_to_wiki_links_spec.rb +44 -0
  33. data/spec/lib/caramelize/filters/remove_table_tab_line_endings_spec.rb +14 -9
  34. data/spec/lib/caramelize/filters/swap_wiki_links_spec.rb +16 -13
  35. data/spec/lib/caramelize/filters/wikka_to_markdown_spec.rb +123 -58
  36. data/spec/lib/caramelize/input_wiki/wiki_spec.rb +15 -14
  37. data/spec/lib/caramelize/output_wiki/gollum_spec.rb +31 -31
  38. data/spec/lib/caramelize/page_spec.rb +34 -26
  39. data/spec/lib/caramelize/services/page_builder_spec.rb +41 -0
  40. data/spec/spec_helper.rb +4 -2
  41. metadata +48 -27
  42. data/.travis.yml +0 -5
  43. data/spec/lib/caramelize/services/page_builder.rb +0 -29
@@ -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!(/(======)(.*?)(======)/ ) {|s| '# ' + $2 } #h1
25
- target_body.gsub!(/(=====)(.*?)(=====)/) {|s| '## ' + $2 } #h2
26
- target_body.gsub!(/(====)(.*?)(====)/) {|s| '### ' + $2 } #h3
27
- target_body.gsub!(/(===)(.*?)(===)/) {|s| '#### ' + $2 } #h4
28
- target_body.gsub!(/(==)(.*?)(==)/) {|s| '##### ' + $2 } #h5
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!(/(\*\*)(.*?)(\*\*)/) {|s| '**' + $2 + '**' } #bold
33
- target_body.gsub!(/(\/\/)(.*?)(\/\/)/, '*\2*') #italic
34
- target_body.gsub!(/(__)(.*?)(__)/) {|s| '<u>' + $2 + '</u>'} #underline
35
- target_body.gsub!(/(---)/, ' ') #forced linebreak
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?)(.*)/, '* \2') # unordered list
40
- target_body.gsub!(/(~-\s?)(.*)/, '* \2') # unordered list
41
- target_body.gsub!(/( -\s?)(.*)/, '* \2') # unordered list
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!(/[\[]{2}(\w+)[\s|](.+?)[\]]{2}/, '[[\2|\1]]')
51
+ target_body.gsub!(/\[{2}(\w+)[\s|](.+?)\]{2}/, '[[\2|\1]]')
49
52
  end
50
53
 
51
54
  def replace_links
52
- target_body.gsub!(/[\[]{2}((\w+):[\S][^\| ]*)[\| ](.*)[\]]{2}/,
53
- '[\3](\1)')
54
- target_body.gsub!(/[\[]{2}((\w+):.*)[\]]{2}/, '<\1>')
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) do
59
- $1.gsub(/^/, ' ')
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
- DEFAULT_GOLLUM_HOME_TITLE = 'Home'.freeze
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
- #puts page_paths.sort.inspect
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?
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)
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,9 +33,9 @@ module Caramelize
31
33
  def read_authors
32
34
  results = database.query(authors_query)
33
35
  results.each do |row|
34
- authors[row["id"]] = OpenStruct.new(id: row["id"],
35
- name: row["login"],
36
- email: row["mail"])
36
+ authors[row['id']] = { id: row['id'],
37
+ name: row['login'],
38
+ email: row['mail'] }
37
39
  end
38
40
  authors
39
41
  end
@@ -43,13 +45,13 @@ module Caramelize
43
45
  def build_page(row_page)
44
46
  results_contents = database.query(single_page_query(row_page['id']))
45
47
 
46
- wiki = wikis.select{ |row| row['id'] == row_page['wiki_id'] }.first
48
+ wiki = wikis.select { |row| row['id'] == row_page['wiki_id'] }.first
47
49
 
48
50
  project_identifier = ''
49
51
 
50
52
  if wiki
51
- project = projects.select{ |row| row['id'] == wiki['project_id'] }.first
52
- project_identifier = project['identifier'] + '/'
53
+ project = projects.select { |row| row['id'] == wiki['project_id'] }.first
54
+ project_identifier = "#{project['identifier']}/"
53
55
  end
54
56
 
55
57
  title = project_identifier + row_page['title']
@@ -63,8 +65,8 @@ module Caramelize
63
65
 
64
66
  def add_projects_as_namespaces
65
67
  projects.each do |row_project|
66
- namespace = OpenStruct.new(identifier: row_project['identifier'],
67
- name: row_project['name'])
68
+ namespace = { identifier: row_project['identifier'],
69
+ name: row_project['name'] }
68
70
  namespaces << namespace
69
71
  end
70
72
  end
@@ -102,17 +104,16 @@ module Caramelize
102
104
  end
103
105
 
104
106
  def build_properties(title, row_content)
105
- author = authors.fetch(row_content["author_id"], nil)
107
+ author = authors.fetch(row_content['author_id'], nil)
106
108
  {
107
109
  id: row_content['id'],
108
- title: title,
110
+ title:,
109
111
  body: row_content['data'],
110
112
  markup: :textile,
111
113
  latest: false,
112
114
  time: row_content['updated_on'],
113
115
  message: row_content['comments'],
114
- author: author,
115
- author_name: author.name
116
+ author:
116
117
  }
117
118
  end
118
119
  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
@@ -39,6 +41,10 @@ module Caramelize
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_on_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;'.freeze
10
- SQL_AUTHORS = 'SELECT name, email FROM wikka_users;'.freeze
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 Callbacks CategoryAdmin CategoryCategory CategoryWiki DatabaseInfo FormattingRules HighScores InterWiki MyChanges MyPages OrphanedPages OwnedPages PageIndex PasswordForgotten RecentChanges RecentlyCommented Sandbox SysInfo 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']] = OpenStruct.new(name: 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
@@ -53,15 +63,14 @@ module Caramelize
53
63
  def build_properties(row)
54
64
  author = authors[row['user']]
55
65
  {
56
- id: row["id"],
57
- title: row["tag"],
58
- body: row["body"],
66
+ id: row['id'],
67
+ title: row['tag'],
68
+ body: row['body'],
59
69
  markup: :wikka,
60
- latest: row["latest"] == "Y",
61
- time: row["time"],
62
- message: row["note"],
63
- author: 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, rename)
32
+ def rename_page(page_title, new_title)
32
33
  gollum_page = gollum.page(page_title)
33
- gollum.rename_page(gollum_page, rename, { message: 'Rename home 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.author.name,
57
- email: page.author.email,
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
- #::Gollum::Git::Repo.new(wiki_path, { is_bare: true })
75
+ # ::Gollum::Git::Repo.new(wiki_path, { is_bare: true })
76
76
  ::Gollum::Git::Repo.init(wiki_path)
77
77
  end
78
78
  end
@@ -1,8 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Caramelize
2
4
  class Page
3
-
4
- attr_accessor :title, :body, :id, :markup, :latest, :time, :message,
5
- :author, :author_name
5
+ attr_accessor :title, :body, :id, :markup, :latest, :time, :message, :author
6
6
 
7
7
  def initialize(page = {})
8
8
  @id = page[:id]
@@ -13,20 +13,18 @@ module Caramelize
13
13
  @time = page.fetch(:time, Time.now)
14
14
  @message = page.fetch(:message, '')
15
15
  @author = page[:author]
16
- @author_name = page[:author_name]
17
16
  end
18
17
 
19
18
  def author_email
20
- author.email
19
+ author[:email]
21
20
  end
22
21
 
23
22
  def author_name
24
- author.name
23
+ author[:name]
25
24
  end
26
25
 
27
26
  def author
28
- @author ||= OpenStruct.new(name: @author_name || "Caramelize",
29
- email: "mail@example.com")
27
+ @author ||= { name: 'Caramelize', email: 'mail@example.com' }
30
28
  end
31
29
 
32
30
  def latest?
@@ -35,7 +33,12 @@ module Caramelize
35
33
 
36
34
  def path
37
35
  return @title unless @title.index('/')
38
- @title.split('/').first + '/' + @title.split('/').last.downcase
36
+
37
+ "#{title_pieces.first}/#{title_pieces.last.downcase}"
38
+ end
39
+
40
+ def title_pieces
41
+ @title.split('/')
39
42
  end
40
43
 
41
44
  def set_latest
@@ -48,6 +51,7 @@ module Caramelize
48
51
 
49
52
  def commit_message
50
53
  return "Edit in page #{title}" if message.empty?
54
+
51
55
  message
52
56
  end
53
57
  end
@@ -1,17 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Caramelize
2
4
  module Services
3
5
  class PageBuilder
6
+ HEADLINE = "## Overview of namespaces\n"
7
+
4
8
  def self.build_namespace_overview(namespaces)
5
- body = "## Overview of namespaces\n\n"
9
+ # TODO: change wiki as configurable default home
10
+ # TODO support other markup syntaxes
6
11
 
7
- namespaces.each do |namespace|
8
- # TODO change wiki as configurable default home
9
- # TODO support other markup syntaxes
10
- body << "* [[#{namespace[:name]}|#{namespace[:identifier]}/wiki]] \n"
11
- end
12
+ body = namespaces.map do |namespace|
13
+ "* [[#{namespace[:name]}|#{namespace[:identifier]}/wiki]]"
14
+ end.prepend(HEADLINE).join(" \n")
12
15
 
13
- Page.new(title: "Home",
14
- body: body,
16
+ Page.new(title: 'Home',
17
+ body:,
15
18
  message: 'Create Namespace Overview',
16
19
  latest: true)
17
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Caramelize
2
- VERSION = '1.1.1'
4
+ VERSION = '1.2.0'
3
5
  end
data/lib/caramelize.rb CHANGED
@@ -1,9 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'caramelize/version'
2
4
  require 'caramelize/page'
3
5
  require 'caramelize/content_transferer'
4
6
  require 'caramelize/filter_processor'
5
7
  require 'caramelize/database_connector'
6
8
  require 'caramelize/health_check'
9
+ require 'caramelize/health_checks/home_page_check'
10
+ require 'caramelize/health_checks/orphaned_pages_check'
11
+ require 'caramelize/health_checks/page'
7
12
  require 'caramelize/output_wiki/gollum'
8
13
  require 'caramelize/services/page_builder'
9
14
  require 'caramelize/input_wiki/wiki'
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Caramelize::ContentTransferer do
4
6
  describe '#execute' do
5
7
  context 'with original_wiki' do
6
- pending
8
+ pending('test full transfer')
7
9
  end
8
10
  end
9
11
  end
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Caramelize::FilterProcessor do
6
+ subject(:processor) { described_class.new(input_wiki) }
7
+
4
8
  let(:filters) { [] }
5
- let(:input_wiki) { double(filters: filters) }
9
+ let(:input_wiki) { double(filters:) }
6
10
  let(:body) { 'body' }
7
- subject(:processor) { described_class.new(input_wiki) }
8
11
 
9
12
  class ReverseFilter
10
13
  def initialize(body)