caramelize 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +19 -24
- data/bin/caramelize +48 -2
- data/caramelize.gemspec +2 -1
- data/lib/caramelize.rb +12 -0
- data/lib/caramelize/caramel.rb +33 -29
- data/lib/caramelize/content_transferer.rb +78 -111
- data/lib/caramelize/filter_processor.rb +31 -0
- data/lib/caramelize/input_wiki/redmine_wiki.rb +97 -0
- data/lib/caramelize/{wiki → input_wiki}/trac_converter.rb +0 -0
- data/lib/caramelize/input_wiki/wiki.rb +61 -0
- data/lib/caramelize/input_wiki/wikkawiki.rb +57 -0
- data/lib/caramelize/output_wiki/gollum.rb +73 -0
- data/lib/caramelize/page.rb +10 -4
- data/lib/caramelize/services/page_builder.rb +20 -0
- data/lib/caramelize/version.rb +1 -1
- data/spec/lib/caramelize/content_transferer_spec.rb +9 -0
- data/spec/lib/caramelize/filter_processor_spec.rb +32 -0
- data/spec/lib/caramelize/filters/wikka_to_markdown_spec.rb +25 -13
- data/spec/lib/caramelize/{wiki → input_wiki}/wiki_spec.rb +30 -4
- data/spec/lib/caramelize/output_wiki/gollum_spec.rb +113 -0
- data/spec/lib/caramelize/page_spec.rb +49 -0
- data/spec/lib/caramelize/services/page_builder.rb +29 -0
- data/spec/spec_helper.rb +1 -1
- metadata +38 -17
- data/lib/caramelize/cli.rb +0 -89
- data/lib/caramelize/cli/create_command.rb +0 -36
- data/lib/caramelize/cli/run_command.rb +0 -33
- data/lib/caramelize/gollum_output.rb +0 -79
- data/lib/caramelize/wiki/redmine_wiki.rb +0 -88
- data/lib/caramelize/wiki/wiki.rb +0 -63
- data/lib/caramelize/wiki/wikkawiki.rb +0 -48
- data/spec/lib/caramelize/gollum_output_spec.rb +0 -64
@@ -1,9 +1,34 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Caramelize::
|
3
|
+
describe Caramelize::InputWiki::Wiki do
|
4
|
+
subject(:wiki) { described_class.new }
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
|
7
|
+
describe '#latest_revisions' do
|
8
|
+
let(:page1) { double }
|
9
|
+
let(:page2) { double }
|
10
|
+
let(:page3) { double }
|
11
|
+
|
12
|
+
context 'no pages' do
|
13
|
+
it 'return empty array' do
|
14
|
+
expect(wiki.latest_revisions).to eq []
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'pages with revisions' do
|
19
|
+
it 'returns list of latest pages' do
|
20
|
+
wiki.titles = ['allosaurus', 'brachiosaurus']
|
21
|
+
allow(wiki).to receive(:revisions_by_title)
|
22
|
+
.with('allosaurus').and_return([page1, page2])
|
23
|
+
allow(wiki).to receive(:revisions_by_title)
|
24
|
+
.with('brachiosaurus').and_return([page3])
|
25
|
+
|
26
|
+
expect(wiki.latest_revisions).to eq([page2, page3])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#revisions_by_author' do
|
7
32
|
context 'revisions is empty' do
|
8
33
|
context 'and titles is empty' do
|
9
34
|
it 'returns empty array' do
|
@@ -12,6 +37,7 @@ describe Caramelize::GollumOutput do
|
|
12
37
|
end
|
13
38
|
end
|
14
39
|
end
|
40
|
+
|
15
41
|
context 'revisions are given' do
|
16
42
|
context 'and title given' do
|
17
43
|
it 'returns empty array' do
|
@@ -28,4 +54,4 @@ describe Caramelize::GollumOutput do
|
|
28
54
|
end
|
29
55
|
end
|
30
56
|
end
|
31
|
-
end
|
57
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caramelize::OutputWiki::Gollum do
|
4
|
+
let(:gollum_output) { described_class.new('wiki.git') }
|
5
|
+
before do
|
6
|
+
allow(gollum_output).to receive(:initialize_repository).and_return true
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#commit_revision' do
|
10
|
+
let(:title) { 'title' }
|
11
|
+
let(:input_page) do
|
12
|
+
double(author_name: 'Steven Universe',
|
13
|
+
author_email: 'steven@example.com',
|
14
|
+
body: 'body',
|
15
|
+
commit_message: 'done',
|
16
|
+
time: Time.now,
|
17
|
+
title: title)
|
18
|
+
end
|
19
|
+
let(:gollum_page) do
|
20
|
+
double(:gollum_page,
|
21
|
+
name: 'title',
|
22
|
+
format: :markdown)
|
23
|
+
end
|
24
|
+
let(:markup) { :markdown }
|
25
|
+
let(:gollum) { double(:gollum) }
|
26
|
+
|
27
|
+
before do
|
28
|
+
allow(Gollum::Wiki).to receive(:new).and_return(gollum)
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'page exists' do
|
32
|
+
before do
|
33
|
+
allow(gollum).to receive(:page).with(title).and_return(gollum_page)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'updates page' do
|
37
|
+
expect(gollum).to receive(:update_page).once.and_return(true)
|
38
|
+
gollum_output.commit_revision(input_page, markup)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'page does not exist yet' do
|
43
|
+
before do
|
44
|
+
allow(gollum).to receive(:page).with(title).and_return(nil)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'creates page' do
|
48
|
+
expect(gollum).to receive(:write_page).once
|
49
|
+
gollum_output.commit_revision(input_page, markup)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#commit_history' do
|
55
|
+
pending
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#commit_namespace_overview' do
|
59
|
+
let(:namespaces) do
|
60
|
+
[
|
61
|
+
OpenStruct.new(identifier: 'velociraptors', name: 'Velociraptor'),
|
62
|
+
OpenStruct.new(identifier: 'allosaurus', name: 'Allosaurus')
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
context '2 pages in namespaces' do
|
67
|
+
it 'commits page' do
|
68
|
+
allow(gollum_output).to receive(:commit_revision)
|
69
|
+
gollum_output.commit_namespace_overview(namespaces)
|
70
|
+
expect(gollum_output).to have_received(:commit_revision)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#build_commit' do
|
76
|
+
let(:page) do
|
77
|
+
Caramelize::Page.new( title: 'Feathered Dinosaurs',
|
78
|
+
message: 'Dinosaurs really had feathers, do not forget!',
|
79
|
+
time: Time.parse('2015-02-12'),
|
80
|
+
body: 'Dinosaurs are awesome and have feathers!',
|
81
|
+
author: OpenStruct.new(name: 'Jeff Goldblum', email: 'jeff.g@example.com') )
|
82
|
+
end
|
83
|
+
|
84
|
+
let(:expected_hash) do
|
85
|
+
{
|
86
|
+
message: 'Dinosaurs really had feathers, do not forget!',
|
87
|
+
authored_date: Time.parse('2015-02-12'),
|
88
|
+
committed_date: Time.parse('2015-02-12'),
|
89
|
+
name: 'Jeff Goldblum',
|
90
|
+
email: 'jeff.g@example.com'
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'builds commit hash' do
|
95
|
+
expect(gollum_output.build_commit(page)).to eq expected_hash
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'page has message' do
|
99
|
+
it 'uses page.title' do
|
100
|
+
expect(gollum_output.build_commit(page)[:message])
|
101
|
+
.to eq 'Dinosaurs really had feathers, do not forget!'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'page has no message' do
|
106
|
+
it 'should create message "Edit in page Feathered Dinosaurs"' do
|
107
|
+
page.message = ''
|
108
|
+
expect(gollum_output.build_commit(page)[:message])
|
109
|
+
.to eq 'Edit in page Feathered Dinosaurs'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caramelize::Page do
|
4
|
+
|
5
|
+
let(:message) { 'Dinosaurs really had feathers, do not forget!' }
|
6
|
+
let(:author) { OpenStruct.new(name: 'Jeff Goldblum', email: 'jeff.g@example.com') }
|
7
|
+
subject(:page) do
|
8
|
+
Caramelize::Page.new( title: 'Feathered Dinosaurs',
|
9
|
+
message: message,
|
10
|
+
time: Time.parse('2015-02-12'),
|
11
|
+
body: 'Dinosaurs are awesome and have feathers!',
|
12
|
+
author: author )
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
describe '#author' do
|
17
|
+
context 'no author is set' do
|
18
|
+
let(:author) { nil }
|
19
|
+
|
20
|
+
it 'fills with Caramelize user' do
|
21
|
+
expect(page.author.name).to eql('Caramelize')
|
22
|
+
expect(page.author.email).to eql('mail@example.com')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'author is set' do
|
27
|
+
it 'fills with Caramelize user' do
|
28
|
+
expect(page.author.name).to eql(author.name)
|
29
|
+
expect(page.author.email).to eql(author.email)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#commit_message' do
|
35
|
+
context 'page has message' do
|
36
|
+
it 'uses page.title' do
|
37
|
+
expect(page.commit_message).to eq 'Dinosaurs really had feathers, do not forget!'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'page has no message' do
|
42
|
+
let(:message) { '' }
|
43
|
+
|
44
|
+
it 'creates message "Edit in page Feathered Dinosaurs"' do
|
45
|
+
expect(page.commit_message).to eq 'Edit in page Feathered Dinosaurs'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caramelize::Service::Pagebuilder do
|
4
|
+
describe '.build_namespace_overview' do
|
5
|
+
let(:body) do
|
6
|
+
"## Overview of namespaces\n\n* [[Velociraptor|velociraptors/Wiki]] \n* [[Allosaurus|allosaurus/Wiki]] \n"
|
7
|
+
end
|
8
|
+
let(:expected_page) do
|
9
|
+
Caramelize::Page.new(title: 'Home',
|
10
|
+
body: body,
|
11
|
+
message: 'Create Namespace Overview',
|
12
|
+
latest: true)
|
13
|
+
end
|
14
|
+
let(:namespaces) do
|
15
|
+
[
|
16
|
+
OpenStruct.new(identifier: 'velociraptors', name: 'Velociraptor'),
|
17
|
+
OpenStruct.new(identifier: 'allosaurus', name: 'Allosaurus')
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns page with expected attributes' do
|
22
|
+
page = described_class.build_namespace_overview
|
23
|
+
expected(page.title).to eql(expected_page.title)
|
24
|
+
expected(page.body).to eql(expected_page.body)
|
25
|
+
expected(page.latest).to eql(expected_page.latest)
|
26
|
+
expected(page.message).to eql(expected_page.message)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caramelize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Senff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: commander
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: guard
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -181,33 +195,37 @@ files:
|
|
181
195
|
- Rakefile
|
182
196
|
- bin/caramelize
|
183
197
|
- caramelize.gemspec
|
198
|
+
- lib/caramelize.rb
|
184
199
|
- lib/caramelize/caramel.rb
|
185
|
-
- lib/caramelize/cli.rb
|
186
|
-
- lib/caramelize/cli/create_command.rb
|
187
|
-
- lib/caramelize/cli/run_command.rb
|
188
200
|
- lib/caramelize/content_transferer.rb
|
189
201
|
- lib/caramelize/database_connector.rb
|
190
202
|
- lib/caramelize/ext.rb
|
203
|
+
- lib/caramelize/filter_processor.rb
|
191
204
|
- lib/caramelize/filters/remove_table_tab_line_endings.rb
|
192
205
|
- lib/caramelize/filters/swap_wiki_links.rb
|
193
206
|
- lib/caramelize/filters/trac_to_markdown.rb
|
194
207
|
- lib/caramelize/filters/wikka_to_markdown.rb
|
195
|
-
- lib/caramelize/
|
208
|
+
- lib/caramelize/input_wiki/redmine_wiki.rb
|
209
|
+
- lib/caramelize/input_wiki/trac_converter.rb
|
210
|
+
- lib/caramelize/input_wiki/wiki.rb
|
211
|
+
- lib/caramelize/input_wiki/wikkawiki.rb
|
212
|
+
- lib/caramelize/output_wiki/gollum.rb
|
196
213
|
- lib/caramelize/page.rb
|
214
|
+
- lib/caramelize/services/page_builder.rb
|
197
215
|
- lib/caramelize/version.rb
|
198
|
-
- lib/caramelize/wiki/redmine_wiki.rb
|
199
|
-
- lib/caramelize/wiki/trac_converter.rb
|
200
|
-
- lib/caramelize/wiki/wiki.rb
|
201
|
-
- lib/caramelize/wiki/wikkawiki.rb
|
202
216
|
- spec/fixtures/markup/swap-links-input.textile
|
203
217
|
- spec/fixtures/markup/swap-links-output.textile
|
204
218
|
- spec/fixtures/markup/table-tab-line-endings-input.textile
|
205
219
|
- spec/fixtures/markup/table-tab-line-endings-output.textile
|
220
|
+
- spec/lib/caramelize/content_transferer_spec.rb
|
221
|
+
- spec/lib/caramelize/filter_processor_spec.rb
|
206
222
|
- spec/lib/caramelize/filters/remove_table_tab_line_endings_spec.rb
|
207
223
|
- spec/lib/caramelize/filters/swap_wiki_links_spec.rb
|
208
224
|
- spec/lib/caramelize/filters/wikka_to_markdown_spec.rb
|
209
|
-
- spec/lib/caramelize/
|
210
|
-
- spec/lib/caramelize/
|
225
|
+
- spec/lib/caramelize/input_wiki/wiki_spec.rb
|
226
|
+
- spec/lib/caramelize/output_wiki/gollum_spec.rb
|
227
|
+
- spec/lib/caramelize/page_spec.rb
|
228
|
+
- spec/lib/caramelize/services/page_builder.rb
|
211
229
|
- spec/spec_helper.rb
|
212
230
|
homepage: http://github.com/Dahie/caramelize
|
213
231
|
licenses:
|
@@ -228,8 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
246
|
- !ruby/object:Gem::Version
|
229
247
|
version: '0'
|
230
248
|
requirements: []
|
231
|
-
|
232
|
-
rubygems_version: 2.4.5
|
249
|
+
rubygems_version: 3.0.6
|
233
250
|
signing_key:
|
234
251
|
specification_version: 4
|
235
252
|
summary: Flexible and modular wiki conversion tool
|
@@ -238,9 +255,13 @@ test_files:
|
|
238
255
|
- spec/fixtures/markup/swap-links-output.textile
|
239
256
|
- spec/fixtures/markup/table-tab-line-endings-input.textile
|
240
257
|
- spec/fixtures/markup/table-tab-line-endings-output.textile
|
258
|
+
- spec/lib/caramelize/content_transferer_spec.rb
|
259
|
+
- spec/lib/caramelize/filter_processor_spec.rb
|
241
260
|
- spec/lib/caramelize/filters/remove_table_tab_line_endings_spec.rb
|
242
261
|
- spec/lib/caramelize/filters/swap_wiki_links_spec.rb
|
243
262
|
- spec/lib/caramelize/filters/wikka_to_markdown_spec.rb
|
244
|
-
- spec/lib/caramelize/
|
245
|
-
- spec/lib/caramelize/
|
263
|
+
- spec/lib/caramelize/input_wiki/wiki_spec.rb
|
264
|
+
- spec/lib/caramelize/output_wiki/gollum_spec.rb
|
265
|
+
- spec/lib/caramelize/page_spec.rb
|
266
|
+
- spec/lib/caramelize/services/page_builder.rb
|
246
267
|
- spec/spec_helper.rb
|
data/lib/caramelize/cli.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'cmdparse'
|
2
|
-
require 'caramelize/version'
|
3
|
-
|
4
|
-
module Caramelize
|
5
|
-
require 'caramelize/content_transferer'
|
6
|
-
module CLI
|
7
|
-
require 'caramelize/cli/run_command'
|
8
|
-
require 'caramelize/cli/create_command'
|
9
|
-
|
10
|
-
# This is the command parser class used for handling the webgen command line interface. After
|
11
|
-
# creating an instance, the inherited #parse method can be used for parsing the command line
|
12
|
-
# arguments and executing the requested command.
|
13
|
-
class CommandParser < CmdParse::CommandParser
|
14
|
-
|
15
|
-
# The verbosity level. Default: <tt>:normal</tt>
|
16
|
-
attr_reader :verbosity
|
17
|
-
|
18
|
-
# Create a new CommandParser class. T
|
19
|
-
def initialize
|
20
|
-
super(true)
|
21
|
-
@verbosity = :normal
|
22
|
-
|
23
|
-
self.program_name = "caramelize"
|
24
|
-
self.program_version = Caramelize::VERSION
|
25
|
-
self.options = CmdParse::OptionParserWrapper.new do |opts|
|
26
|
-
opts.separator "Global options:"
|
27
|
-
opts.on("--verbose", "-v", "Print more output") { @verbosity = :verbose }
|
28
|
-
opts.on("--quiet", "-q", "No output") { @verbosity = :quiet }
|
29
|
-
end
|
30
|
-
self.add_command(CmdParse::HelpCommand.new)
|
31
|
-
self.add_command(CmdParse::VersionCommand.new)
|
32
|
-
end
|
33
|
-
|
34
|
-
KNOWN_CONFIG_LOCATIONS = ['config/caramel.rb', "config/caramel.config", "caramel.rb", "src/caramel.rb"]
|
35
|
-
|
36
|
-
# Finds the configuration file, if it exists in a known location.
|
37
|
-
def detect_configuration_file(config_path = nil)
|
38
|
-
possible_files = []
|
39
|
-
possible_files << config_path if config_path
|
40
|
-
possible_files |= KNOWN_CONFIG_LOCATIONS
|
41
|
-
possible_files.detect{|f| File.exists?(f)}
|
42
|
-
end
|
43
|
-
|
44
|
-
# Utility method for sub-commands to transfer wiki contents
|
45
|
-
def transfer_content(config_file = "")
|
46
|
-
time_start = Time.now
|
47
|
-
|
48
|
-
file = detect_configuration_file config_file
|
49
|
-
puts "Read config file: #{file}" if verbose?
|
50
|
-
|
51
|
-
unless file && File.exists?(file)
|
52
|
-
puts "No config file found."
|
53
|
-
return false
|
54
|
-
end
|
55
|
-
|
56
|
-
commence_transfer file
|
57
|
-
|
58
|
-
puts "Time required: #{Time.now - time_start} s" if verbose?
|
59
|
-
end
|
60
|
-
|
61
|
-
def commence_transfer(file)
|
62
|
-
#load file
|
63
|
-
#original_wiki = Configuration.instance.input_wiki
|
64
|
-
instance_eval(File.read(file))
|
65
|
-
original_wiki = input_wiki
|
66
|
-
|
67
|
-
options = original_wiki.options
|
68
|
-
options[:verbosity] = @verbosity
|
69
|
-
ContentTransferer.execute(original_wiki, options)
|
70
|
-
end
|
71
|
-
|
72
|
-
def verbose?
|
73
|
-
@verbosity == :verbose
|
74
|
-
end
|
75
|
-
|
76
|
-
# :nodoc:
|
77
|
-
def parse(argv = ARGV)
|
78
|
-
Caramelize::CLI.constants.select {|c| c =~ /.+Command$/ }.each do |c|
|
79
|
-
# set runcommand as default
|
80
|
-
self.add_command(Caramelize::CLI.const_get(c).new, (c.to_s == 'RunCommand' ? false : false))
|
81
|
-
end
|
82
|
-
super
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|