caramelize 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Caramelize::AddNewlineOnPageEnd do
6
+ describe '#run' do
7
+ subject(:run) { filter.run }
8
+
9
+ let(:filter) { described_class.new(body) }
10
+
11
+ context 'with newline on body end' do
12
+ let(:body) { "Here is a sample body\n" }
13
+
14
+ it 'adds no newline character' do
15
+ expect(run).to eq "Here is a sample body\n"
16
+ end
17
+ end
18
+
19
+ context 'without newline on body end' do
20
+ let(:body) { 'Here is a sample body' }
21
+
22
+ it 'adds newline character' do
23
+ expect(run).to eq "Here is a sample body\n"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Caramelize::CamelCaseToWikiLinks do
6
+ describe '#run' do
7
+ subject(:run) { filter.run }
8
+
9
+ let(:filter) { described_class.new(body) }
10
+
11
+ context 'with camel case text' do
12
+ let(:body) { 'Hier ein CamelCaseExample, bitte [[DankeDanke]]' }
13
+
14
+ it 'does wiki link' do
15
+ expect(run).to eq 'Hier ein [[CamelCaseExample]], bitte [[DankeDanke]]'
16
+ end
17
+ end
18
+
19
+ context 'with camel case text downcased' do
20
+ let(:body) { 'Hier ein camelCaseExample, bitte [[DankeDanke]]' }
21
+
22
+ it 'does not to wiki link' do
23
+ expect(run).to eq 'Hier ein camelCaseExample, bitte [[DankeDanke]]'
24
+ end
25
+ end
26
+
27
+ context 'with camel case text at document end' do
28
+ let(:body) { 'Hier ein CamelCaseExample' }
29
+
30
+ # NOTE: this is sortof expected behavior - a wiki page should end on a newline in which case this does not happen
31
+ it 'cuts last character' do
32
+ expect(run).to eq 'Hier ein [[CamelCaseExampl]]e'
33
+ end
34
+ end
35
+
36
+ context 'with camel case text at document end with newline' do
37
+ let(:body) { "Hier ein CamelCaseExample\n" }
38
+
39
+ it 'does wiki link' do
40
+ expect(run).to eq "Hier ein [[CamelCaseExample]]\n"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,15 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Caramelize::RemoveTableTabLineEndings do
6
+ subject(:run) { filter.run }
7
+
4
8
  let(:filter) { described_class.new(body) }
5
- subject { filter.run}
6
9
 
7
10
  describe '#run' do
8
11
  context 'table with tabs at unix line-endings' do
9
12
  let(:body) { "cell1\t|cell2\t|\t\t\n" }
10
13
 
11
14
  it 'removes tabs at end of line' do
12
- is_expected.to eq "cell1\t|cell2\t|\n"
15
+ expect(run).to eq "cell1\t|cell2\t|\n"
13
16
  end
14
17
  end
15
18
 
@@ -17,24 +20,26 @@ describe Caramelize::RemoveTableTabLineEndings do
17
20
  let(:body) { "cell1\t|cell2\t|\t \n" }
18
21
 
19
22
  it 'removes spaces at end of line' do
20
- is_expected.to eq "cell1\t|cell2\t|\n"
23
+ expect(run).to eq "cell1\t|cell2\t|\n"
21
24
  end
22
25
 
23
26
  context 'replace in full file' do
24
- let(:body) { File.open(File.join(['spec', 'fixtures', 'markup', 'table-tab-line-endings-input.textile']), 'r').read }
27
+ let(:body) do
28
+ File.read(File.join(['spec', 'fixtures', 'markup', 'table-tab-line-endings-input.textile']))
29
+ end
25
30
 
26
31
  it 'returns as expected' do
27
- output_text = File.open(File.join(['spec', 'fixtures', 'markup', 'table-tab-line-endings-output.textile']), 'r').read
28
- is_expected.to eq output_text
32
+ output_text = File.read(File.join(['spec', 'fixtures', 'markup', 'table-tab-line-endings-output.textile']))
33
+ expect(run).to eq output_text
29
34
  end
30
35
  end
31
36
  end
32
37
 
33
- context 'table with tabs at windows line-endings' do
38
+ context 'with table having tabs at windows line-endings' do
34
39
  let(:body) { "cell1\t|cell2\t|\t\t\r\n" }
35
40
 
36
41
  it 'removes tabs at end of line' do
37
- is_expected.to eq "cell1\t|cell2\t|\n"
42
+ expect(run).to eq "cell1\t|cell2\t|\n"
38
43
  end
39
44
  end
40
45
 
@@ -42,7 +47,7 @@ describe Caramelize::RemoveTableTabLineEndings do
42
47
  let(:body) { "cell1\t|cell2\t|\t \r\n" }
43
48
 
44
49
  it 'removes spaces at end of line' do
45
- is_expected.to eq "cell1\t|cell2\t|\n"
50
+ expect(run).to eq "cell1\t|cell2\t|\n"
46
51
  end
47
52
  end
48
53
  end
@@ -1,47 +1,50 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Caramelize::SwapWikiLinks do
4
6
  describe '#run' do
7
+ subject(:run) { filter.run }
8
+
5
9
  let(:filter) { described_class.new(body) }
6
- subject { filter.run }
7
10
 
8
- context 'wiki link with title' do
11
+ context 'with wiki link with title' do
9
12
  let(:body) { '[[statistics|Driver & Team Statistics]]' }
10
13
 
11
14
  it 'swaps title and target' do
12
- is_expected.to eq '[[Driver & Team Statistics|statistics]]'
15
+ expect(run).to eq '[[Driver & Team Statistics|statistics]]'
13
16
  end
14
17
  end
15
18
 
16
- context 'wiki title with spaces' do
19
+ context 'with wiki title with spaces' do
17
20
  let(:body) { '[[Release 1 0]]' }
18
21
 
19
22
  it 'replaces space with dashes' do
20
- is_expected.to eq '[[Release 1 0|release_1_0]]'
23
+ expect(run).to eq '[[Release 1 0|release_1_0]]'
21
24
  end
22
25
  end
23
26
 
24
- context 'wiki title with dashes' do
27
+ context 'with wiki title with dashes' do
25
28
  let(:body) { '[[Release-1.0]]' }
26
29
 
27
30
  it 'removes dots' do
28
- is_expected.to eq '[[Release-1.0|release-10]]'
31
+ expect(run).to eq '[[Release-1.0|release-10]]'
29
32
  end
30
33
  end
31
34
 
32
- context 'wiki link with spaces and without title' do
35
+ context 'with wiki link with spaces and without title' do
33
36
  let(:body) { '[[Intra wiki link]]' }
34
37
 
35
38
  it 'simples link to hyperlink' do
36
- is_expected.to eq '[[Intra wiki link|intra_wiki_link]]'
39
+ expect(run).to eq '[[Intra wiki link|intra_wiki_link]]'
37
40
  end
38
41
 
39
- context 'replace in full file' do
40
- let(:body) { File.open(File.join(['spec', 'fixtures', 'markup', 'swap-links-input.textile']), 'r').read }
42
+ context 'with replace in full file' do
43
+ let(:body) { File.read(File.join(['spec', 'fixtures', 'markup', 'swap-links-input.textile'])) }
41
44
 
42
45
  it 'returns as expected' do
43
- output_text = File.open(File.join(['spec', 'fixtures', 'markup', 'swap-links-output.textile']), 'r').read
44
- is_expected.to eq output_text
46
+ output_text = File.read(File.join(['spec', 'fixtures', 'markup', 'swap-links-output.textile']))
47
+ expect(run).to eq output_text
45
48
  end
46
49
  end
47
50
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Caramelize::Wikka2Markdown do
@@ -6,188 +8,251 @@ describe Caramelize::Wikka2Markdown do
6
8
  describe '#run' do
7
9
  subject { filter.run }
8
10
 
9
- xcontext 'keep line breaks' do
11
+ xcontext 'when keep line breaks' do
10
12
  let(:body) { "line1\nline2" }
11
13
 
12
14
  it { is_expected.to eq "line1 \nline2" }
13
15
  end
14
16
 
15
- context 'headline h1' do
17
+ context 'when headline h1' do
16
18
  let(:body) { '======Headline======' }
17
19
 
18
20
  it { is_expected.to eq '# Headline' }
19
21
  end
20
22
 
21
- context 'headline h2' do
23
+ context 'when headline h2' do
22
24
  let(:body) { '=====Headline=====' }
23
25
 
24
26
  it { is_expected.to eq '## Headline' }
25
27
  end
26
28
 
27
- context 'headline h3' do
28
- let(:body) { '====Headline===='}
29
+ context 'when headline h3' do
30
+ let(:body) { '====Headline====' }
29
31
 
30
32
  it { is_expected.to eq '### Headline' }
31
33
  end
32
34
 
33
- context 'headline h4' do
35
+ context 'when headline h4' do
34
36
  let(:body) { '===Headline===' }
35
37
 
36
38
  it { is_expected.to eq '#### Headline' }
37
39
  end
38
40
 
39
- context 'headline h5' do
41
+ context 'when headline h5' do
40
42
  let(:body) { '==Headline==' }
41
43
 
42
44
  it { is_expected.to eq '##### Headline' }
43
45
  end
44
46
 
45
- context 'bold' do
47
+ context 'when bold' do
46
48
  let(:body) { '**Text is bold**' }
47
49
 
48
50
  it { is_expected.to eq '**Text is bold**' }
49
51
  end
50
52
 
51
- context 'italic' do
53
+ context 'when italic' do
52
54
  let(:body) { '//Text is italic//' }
53
55
 
54
56
  it { is_expected.to eq '*Text is italic*' }
55
57
  end
56
58
 
57
- context 'underline' do
59
+ context 'when underline' do
58
60
  let(:body) { '__Text is underlined__' }
59
61
 
60
62
  it { is_expected.to eq '<u>Text is underlined</u>' }
61
63
  end
62
64
 
63
- context 'line break' do
65
+ context 'when line break' do
64
66
  let(:body) { 'Text is---\nbroken to two lines.' }
65
67
 
66
68
  it { is_expected.to eq 'Text is \nbroken to two lines.' }
67
69
  end
68
70
 
69
- context 'unordered list entry' do
70
- context 'tab based' do
71
+ context 'when unordered list entry' do
72
+ context 'with tab based' do
71
73
  let(:body) { "\t-unordered list entry" }
72
74
 
73
- it { is_expected.to eq '* unordered list entry' }
75
+ it { is_expected.to eq '- unordered list entry' }
74
76
  end
75
77
 
76
- context 'also tab based' do
77
- let(:body) { "~-unordered list entry" }
78
+ context 'with tabs' do
79
+ let(:body) { '~-unordered list entry' }
78
80
 
79
- it { is_expected.to eq '* unordered list entry' }
81
+ it { is_expected.to eq '- unordered list entry' }
80
82
  end
81
83
 
82
- context 'space based' do
83
- let(:body) { " -unordered list entry" }
84
+ context 'with spaces' do
85
+ let(:body) { ' -unordered list entry' }
84
86
 
85
- it { is_expected.to eq '* unordered list entry' }
87
+ it { is_expected.to eq '- unordered list entry' }
86
88
  end
87
89
 
88
- context 'tab based with space' do
90
+ context 'with tab based with space' do
89
91
  let(:body) { "\t- unordered list entry" }
90
92
 
91
- it { is_expected.to eq '* unordered list entry' }
93
+ it { is_expected.to eq '- unordered list entry' }
92
94
  end
93
95
 
94
- context 'also tab based with space' do
95
- let(:body) { "~- unordered list entry" }
96
+ context 'with another tab based with space' do
97
+ let(:body) { '~- unordered list entry' }
96
98
 
97
- it { is_expected.to eq '* unordered list entry' }
99
+ it { is_expected.to eq '- unordered list entry' }
98
100
  end
99
101
 
100
- context 'space based with space' do
101
- let(:body) { " - unordered list entry" }
102
+ context 'with space based with space' do
103
+ let(:body) { ' - unordered list entry' }
102
104
 
103
- it { is_expected.to eq '* unordered list entry' }
105
+ it { is_expected.to eq '- unordered list entry' }
104
106
  end
105
107
  end
106
108
 
107
- context 'ordered list entry' do
109
+ context 'when ordered list entry' do
108
110
  context 'without space' do
109
- let(:body) { "~1)ordered list entry" }
111
+ let(:body) { '~1)ordered list entry' }
110
112
 
111
113
  it { is_expected.to eq '1. ordered list entry' }
112
114
  end
113
115
 
114
116
  context 'with space' do
115
- let(:body) { "~1) ordered list entry" }
117
+ let(:body) { '~1) ordered list entry' }
116
118
 
117
119
  it { is_expected.to eq '1. ordered list entry' }
118
120
  end
119
121
  end
120
122
 
121
- context 'wikilink' do
122
- context 'only url' do
123
+ context 'when wikilink' do
124
+ context 'with only url' do
123
125
  let(:body) { '[[LemmaLemma]]' }
124
126
 
125
127
  it { is_expected.to eq '[[LemmaLemma]]' }
126
128
  end
127
129
 
128
- context 'url and pipe title' do
130
+ context 'with only url sklfs' do
131
+ let(:body) { "\n [[ComunitySiteIdeas]] \n" }
132
+
133
+ it { is_expected.to eq "\n [[ComunitySiteIdeas]] \n" }
134
+ end
135
+
136
+ context 'with url and pipe title' do
129
137
  let(:body) { '[[SandBox|Test your formatting skills]]' }
130
138
 
131
139
  it { is_expected.to eq '[[Test your formatting skills|SandBox]]' }
132
140
  end
133
141
 
134
- context 'url and title' do
142
+ context 'with url and title' do
135
143
  let(:body) { '[[SandBox Test your formatting skills]]' }
136
144
 
137
145
  it { is_expected.to eq '[[Test your formatting skills|SandBox]]' }
138
146
  end
139
147
  end
140
148
 
141
- context 'hyperlink' do
142
- context 'only url' do
149
+ context 'when hyperlink' do
150
+ context 'with only url' do
143
151
  let(:body) { '[[http://target]]' }
144
152
 
145
153
  it { is_expected.to eq '<http://target>' }
146
154
  end
147
155
 
148
- context 'url with title' do
156
+ context 'with url with title' do
149
157
  let(:body) { '[[http://target Title]]' }
150
158
 
151
159
  it { is_expected.to eq '[Title](http://target)' }
152
160
  end
153
161
 
154
- context 'url with pipe' do
162
+ context 'with url with title and special characters' do
163
+ let(:body) { '- [[http://www.sourcepole.com/sources/programming/cpp/cppqref.html C++ Syntax Reference]]' }
164
+
165
+ it { is_expected.to eq '- [C++ Syntax Reference](http://www.sourcepole.com/sources/programming/cpp/cppqref.html)' }
166
+ end
167
+
168
+ context 'with url with pipe' do
155
169
  let(:body) { '[[http://target|Title]]' }
156
170
 
157
171
  it { is_expected.to eq '[Title](http://target)' }
158
172
  end
159
173
  end
160
174
 
161
- context 'code block' do
175
+ context 'when inline code' do
176
+ let(:body) { 'Code: %%Hello World%% // done' }
177
+
178
+ it { is_expected.to eq 'Code: `Hello World` // done' }
179
+ end
180
+
181
+ context 'when code block' do
182
+ let(:body) do
183
+ <<~EOS
184
+ Text before
185
+
186
+ %%
187
+ std::cin >> input;
188
+ ++stat[input];
189
+ %%
190
+
191
+ Text after
192
+
193
+ %%
194
+ std::cin >> input;
195
+ ++stat[input];
196
+ %%
197
+
198
+ EOS
199
+ end
200
+ let(:expected_result) do
201
+ <<~EOS
202
+ Text before
203
+
204
+ ```
205
+ std::cin >> input;
206
+ ++stat[input];
207
+ ```
208
+
209
+ Text after
210
+
211
+ ```
212
+ std::cin >> input;
213
+ ++stat[input];
214
+ ```
215
+
216
+ EOS
217
+ end
218
+
219
+ it { is_expected.to eq expected_result }
220
+ end
221
+
222
+ context 'when code block with language' do
162
223
  let(:body) do
163
- <<-EOS
164
- Text before
224
+ <<~EOS
225
+ Text before
165
226
 
166
- %%
167
- std::cin >> input;
168
- ++stat[input];
169
- %%
227
+ %%(php)
228
+ std::cin >> input;
229
+ ++stat[input];
230
+ %%
170
231
 
171
- Text after
232
+ Text after
172
233
 
173
- %%
174
- std::cin >> input;
175
- ++stat[input];
176
- %%
234
+ %%(java)
235
+ std::cin >> input;
236
+ ++stat[input];
237
+ %%
177
238
 
178
239
  EOS
179
240
  end
180
241
  let(:expected_result) do
181
- <<-EOS
182
- Text before
242
+ <<~EOS
243
+ Text before
183
244
 
184
- std::cin >> input;
185
- ++stat[input];
245
+ ```php
246
+ std::cin >> input;
247
+ ++stat[input];
248
+ ```
186
249
 
187
- Text after
250
+ Text after
188
251
 
189
- std::cin >> input;
190
- ++stat[input];
252
+ ```java
253
+ std::cin >> input;
254
+ ++stat[input];
255
+ ```
191
256
 
192
257
  EOS
193
258
  end
@@ -1,21 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Caramelize::InputWiki::Wiki do
4
6
  subject(:wiki) { described_class.new }
5
7
 
6
-
7
8
  describe '#latest_revisions' do
8
9
  let(:page1) { double }
9
10
  let(:page2) { double }
10
11
  let(:page3) { double }
11
12
 
12
- context 'no pages' do
13
+ context 'without pages' do
13
14
  it 'return empty array' do
14
15
  expect(wiki.latest_revisions).to eq []
15
16
  end
16
17
  end
17
18
 
18
- context 'pages with revisions' do
19
+ context 'with pages with revisions' do
19
20
  it 'returns list of latest pages' do
20
21
  wiki.titles = %w[allosaurus brachiosaurus]
21
22
  allow(wiki).to receive(:revisions_by_title)
@@ -29,8 +30,8 @@ describe Caramelize::InputWiki::Wiki do
29
30
  end
30
31
 
31
32
  describe '#revisions_by_author' do
32
- context 'revisions is empty' do
33
- context 'and titles is empty' do
33
+ context 'with revisions is empty' do
34
+ context 'with titles is empty' do
34
35
  it 'returns empty array' do
35
36
  allow(wiki).to receive(:titles).and_return []
36
37
  expect(wiki.revisions_by_title('title')).to eq []
@@ -38,18 +39,18 @@ describe Caramelize::InputWiki::Wiki do
38
39
  end
39
40
  end
40
41
 
41
- context 'revisions are given' do
42
- context 'and title given' do
42
+ context 'with revisions are given' do
43
+ context 'with title given' do
43
44
  it 'returns empty array' do
44
45
  pages = []
45
- home_1 = OpenStruct.new(title: 'Home', time: Time.parse('2015-01-23'))
46
- pages << home_1
47
- pages << OpenStruct.new(title: 'Example', time: Time.parse('2015-01-20'))
48
- pages << OpenStruct.new(title: 'Authors', time: Time.parse('2015-01-30'))
49
- home_2 = OpenStruct.new(title: 'Home', time: Time.parse('2014-01-23'))
50
- pages << home_2
46
+ home1 = double(title: 'Home', time: Time.parse('2015-01-23'))
47
+ pages << home1
48
+ pages << double(title: 'Example', time: Time.parse('2015-01-20'))
49
+ pages << double(title: 'Authors', time: Time.parse('2015-01-30'))
50
+ home2 = double(title: 'Home', time: Time.parse('2014-01-23'))
51
+ pages << home2
51
52
  allow(wiki).to receive(:revisions).and_return pages
52
- expect(wiki.revisions_by_title('Home')).to eq [home_2, home_1]
53
+ expect(wiki.revisions_by_title('Home')).to eq [home2, home1]
53
54
  end
54
55
  end
55
56
  end