caramelize 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +19 -24
  3. data/bin/caramelize +48 -2
  4. data/caramelize.gemspec +2 -1
  5. data/lib/caramelize.rb +12 -0
  6. data/lib/caramelize/caramel.rb +33 -29
  7. data/lib/caramelize/content_transferer.rb +78 -111
  8. data/lib/caramelize/filter_processor.rb +31 -0
  9. data/lib/caramelize/input_wiki/redmine_wiki.rb +97 -0
  10. data/lib/caramelize/{wiki → input_wiki}/trac_converter.rb +0 -0
  11. data/lib/caramelize/input_wiki/wiki.rb +61 -0
  12. data/lib/caramelize/input_wiki/wikkawiki.rb +57 -0
  13. data/lib/caramelize/output_wiki/gollum.rb +73 -0
  14. data/lib/caramelize/page.rb +10 -4
  15. data/lib/caramelize/services/page_builder.rb +20 -0
  16. data/lib/caramelize/version.rb +1 -1
  17. data/spec/lib/caramelize/content_transferer_spec.rb +9 -0
  18. data/spec/lib/caramelize/filter_processor_spec.rb +32 -0
  19. data/spec/lib/caramelize/filters/wikka_to_markdown_spec.rb +25 -13
  20. data/spec/lib/caramelize/{wiki → input_wiki}/wiki_spec.rb +30 -4
  21. data/spec/lib/caramelize/output_wiki/gollum_spec.rb +113 -0
  22. data/spec/lib/caramelize/page_spec.rb +49 -0
  23. data/spec/lib/caramelize/services/page_builder.rb +29 -0
  24. data/spec/spec_helper.rb +1 -1
  25. metadata +38 -17
  26. data/lib/caramelize/cli.rb +0 -89
  27. data/lib/caramelize/cli/create_command.rb +0 -36
  28. data/lib/caramelize/cli/run_command.rb +0 -33
  29. data/lib/caramelize/gollum_output.rb +0 -79
  30. data/lib/caramelize/wiki/redmine_wiki.rb +0 -88
  31. data/lib/caramelize/wiki/wiki.rb +0 -63
  32. data/lib/caramelize/wiki/wikkawiki.rb +0 -48
  33. data/spec/lib/caramelize/gollum_output_spec.rb +0 -64
@@ -1,36 +0,0 @@
1
- require 'caramelize/cli'
2
- require 'fileutils'
3
-
4
- module Caramelize::CLI
5
-
6
- # The CLI command for creating a caramelize config file.
7
- class CreateCommand < CmdParse::Command
8
-
9
- # The website config-file. Default: the current working directory.
10
- attr_reader :config_file
11
-
12
- def initialize #:nodoc:
13
- super('create', false)
14
- self.description = "If the verbosity level is set to verbose, the created files are listed."
15
- self.short_desc = 'Create a default config file for caramelize'
16
- self.options = CmdParse::OptionParserWrapper.new do |opts|
17
- opts.separator "Arguments:"
18
- opts.on("--config <file>", "-f", String, "The config file (default: caramel.rb)") {|p| @config_file = p}
19
- end
20
- end
21
-
22
- def usage # :nodoc:
23
- "Usage: #{commandparser.program_name} [global options] create [options]"
24
- end
25
-
26
- # Create a caramelize config file.
27
- def execute(args)
28
- # create dummy config file
29
- target_file = @config_file.nil? ? "caramel.rb" : @config_file
30
- FileUtils.cp(File.dirname(__FILE__) +"/../caramel.rb", target_file)
31
- if commandparser.verbosity == :normal
32
- puts "Created new configuration file: #{target_file}"
33
- end
34
- end
35
- end
36
- end
@@ -1,33 +0,0 @@
1
- #Encoding: UTF-8
2
- require 'caramelize/cli'
3
-
4
- module Caramelize::CLI
5
-
6
- # The CLI command for rendering a webgen website.
7
- class RunCommand < CmdParse::Command
8
-
9
- # The website config-file. Default: the current working directory.
10
- attr_reader :config_file
11
-
12
- def initialize # :nodoc:
13
- super('run', false)
14
- self.short_desc = 'Run the wiki content transfer based on the given config file'
15
- self.options = CmdParse::OptionParserWrapper.new do |opts|
16
- opts.separator "Arguments:"
17
- #opts.separator opts.summary_indent + "DIR: the directory in which the website should be created"
18
- opts.on("--config <file>", "-f", String, "The config file (default: caramel.rb)") {|p| @config_file = p}
19
- end
20
- end
21
-
22
- def usage # :nodoc:
23
- "Usage: #{commandparser.program_name} [global options] run [options]"
24
- end
25
-
26
- # Transfer Wiki contents
27
- def execute(args)
28
- commandparser.transfer_content @config_file
29
- end
30
-
31
- end
32
-
33
- end
@@ -1,79 +0,0 @@
1
- require 'caramelize/ext'
2
- module Caramelize
3
- class GollumOutput
4
-
5
- def supported_markup
6
- [:markdown, :textile]
7
- end
8
-
9
- # Initialize a new gollum-wiki-repository at the given path.
10
- def initialize(new_wiki_path)
11
- # TODO use sanitized name as wiki-repository-title
12
- @wiki_path = new_wiki_path
13
- initialize_repository
14
- end
15
-
16
- def wiki_path
17
- @wiki_path
18
- end
19
-
20
- # Commit the given page into the gollum-wiki-repository.
21
- # Make sure the target markup is correct before calling this method.
22
- def commit_revision(page, markup)
23
- gollum_page = gollum.page(page.title)
24
- if gollum_page
25
- gollum.update_page(gollum_page, gollum_page.name, gollum_page.format, page.body, build_commit(page))
26
- else
27
- gollum.write_page(page.title, markup, page.body, build_commit(page))
28
- end
29
- end
30
-
31
- # Commit all revisions of the given history into this gollum-wiki-repository.
32
- def commit_history(revisions, options = {}, &block)
33
- options[:markup] = :markdown if !options[:markup] # target markup
34
- revisions.each_with_index do |page, index|
35
- # call debug output from outside
36
- block.call(page, index) if block_given?
37
- commit_revision(page, options[:markup])
38
- end
39
- end
40
-
41
- def create_namespace_overview(namespaces)
42
- body = "## Overview of namespaces\n\n"
43
- namespaces.each do |namespace|
44
- # TODO change wiki as configurable default home
45
- # TODO support other markup syntaxes
46
- body << "* [[#{namespace[:name]}|#{namespace[:identifier]}/Wiki]] \n"
47
- end
48
- page = Page.new(title: "Home",
49
- body: body,
50
- message: 'Create Namespace Overview',
51
- latest: true)
52
- commit_revision(page, :markdown)
53
- page
54
- end
55
-
56
-
57
- private
58
-
59
- def gollum
60
- @gollum ||= Gollum::Wiki.new(wiki_path)
61
- end
62
-
63
- def initialize_repository
64
- # TODO ask if we should replace existing paths
65
- Grit::Repo.init(wiki_path) unless File.exists?(wiki_path)
66
- end
67
-
68
- def build_commit(page)
69
- message = page.message.empty? ? "Edit in page #{page.title}" : page.message
70
-
71
- { message: message,
72
- name: page.author_name,
73
- email: page.author_email,
74
- authored_date: page.time,
75
- committed_date: page.time }
76
- end
77
-
78
- end
79
- end
@@ -1,88 +0,0 @@
1
- require 'caramelize/wiki/wiki'
2
- require 'caramelize/filters/swap_wiki_links'
3
- require 'caramelize/filters/remove_table_tab_line_endings'
4
- module Caramelize
5
-
6
- class RedmineWiki < Wiki
7
- include DatabaseConnector
8
-
9
- def initialize options={}
10
- super(options)
11
- @options[:markup] = :textile
12
- @options[:filters] << Caramelize::SwapWikiLinks.new
13
- @options[:filters] << Caramelize::RemoveTableTabLineEndings.new
14
- @options[:create_namespace_overview] = true
15
- end
16
-
17
- # after calling this action, I expect the titles and revisions to be filled
18
- def read_pages
19
- # get all projects
20
- results_projects = database.query("SELECT id, identifier, name FROM projects;")
21
- results_projects.each do |row_project|
22
- #collect all namespaces
23
- namespaces << OpenStruct.new(identifier: row_project["identifier"], name: row_project["name"])
24
- end
25
-
26
- # get all wikis
27
- results_wikis = database.query("SELECT id, project_id FROM wikis;")
28
-
29
- # get all lemmas
30
- results_pages = database.query("SELECT id, title, wiki_id FROM wiki_pages;")
31
- results_pages.each do |row_page|
32
- results_contents = database.query("SELECT * FROM wiki_content_versions WHERE page_id='#{row_page["id"]}' ORDER BY updated_on;")
33
-
34
- # get wiki for page
35
- wiki_row = nil
36
- project_row = nil
37
- results_wikis.each do |wiki|
38
- wiki_row = wiki if wiki["id"] == row_page["wiki_id"]
39
- end
40
-
41
- if wiki_row
42
- # get project from wiki-id
43
- results_projects.each do |project|
44
- project_row = project if project["id"] == wiki_row["project_id"]
45
- end
46
- end
47
-
48
- project_identifier = project_row ? project_row["identifier"] + '/' : ""
49
-
50
- title = project_identifier + row_page["title"]
51
- titles << title
52
-
53
- @latest_revisions = {}
54
- results_contents.each do |row_content|
55
- author = authors[row_content["author_id"]] ? @authors[row_content["author_id"]] : nil
56
- page = Page.new({:id => row_content["id"],
57
- :title => title,
58
- :body => row_content["data"],
59
- :markup => :textile,
60
- :latest => false,
61
- :time => row_content["updated_on"],
62
- :message => row_content["comments"],
63
- :author => author,
64
- :author_name => author.name})
65
- revisions << page
66
- @latest_revisions[title] = page
67
- end
68
- end
69
- titles.uniq!
70
- @latest_revisions.each { |rev| rev[1].set_latest }
71
- revisions.sort! { |a,b| a.time <=> b.time }
72
-
73
- # TODO find latest revision for each limit
74
-
75
- revisions
76
- end
77
-
78
- def read_authors
79
- results = database.query("SELECT id, login, mail FROM users;")
80
- results.each do |row|
81
- authors[row["id"]] = OpenStruct.new(id: row["id"],
82
- name: row["login"],
83
- email: row["mail"])
84
- end
85
- authors
86
- end
87
- end
88
- end
@@ -1,63 +0,0 @@
1
- module Caramelize
2
- class Wiki
3
- include DatabaseConnector
4
-
5
- attr_accessor :revisions, :wiki_title, :titles, :description, :namespaces, :options
6
-
7
- def initialize options={}
8
- @options = options
9
- @options[:filters] = []
10
- @namespaces = []
11
- end
12
-
13
- def revisions_by_title(title)
14
- # new array only containing pages by this name sorted by time asc
15
- # TODO this is probably bad for renamed pages if supported
16
- return revisions.select { |revision| revision.title == title }.sort { |x,y| x.time <=> y.time }
17
- []
18
- end
19
-
20
- # return an empty array in case this action was not overridden
21
- def read_authors
22
- return []
23
- end
24
-
25
- def namespaces
26
- @namespaces ||= {}
27
- end
28
-
29
- def authors
30
- @authors ||= {}
31
- end
32
-
33
- def revisions
34
- @revisions ||= []
35
- end
36
-
37
- def titles
38
- @titles ||= []
39
- end
40
-
41
- def convert_markup?(to_markup)
42
- markup != to_markup
43
- end
44
-
45
- def filters
46
- @options[:filters]
47
- end
48
-
49
- def latest_revisions
50
- @latest_revisions = []
51
- titles.each do |title|
52
- # pick first revision by descending date
53
- @latest_revisions << revisions_by_title(title).last
54
- end
55
- @latest_revisions
56
- end
57
-
58
- def markup
59
- @options[:markup]
60
- end
61
-
62
- end
63
- end
@@ -1,48 +0,0 @@
1
- module Caramelize
2
- require 'caramelize/wiki/wiki'
3
- require 'caramelize/database_connector'
4
- require 'caramelize/filters/wikka_to_markdown'
5
-
6
- class WikkaWiki < Wiki
7
- include DatabaseConnector
8
-
9
- def initialize options={}
10
- super(options)
11
- @options[:markup] = :wikka
12
- @options[:filters] << Caramelize::Wikka2Markdown.new
13
- end
14
-
15
- # after calling this action, I expect the titles and @revisions to be filled
16
- def read_pages
17
- sql = "SELECT id, tag, body, time, latest, user, note FROM wikka_pages ORDER BY time;"
18
- results = database.query(sql)
19
- results.each do |row|
20
- titles << row["tag"]
21
- author = authors[row["user"]]
22
- page = Page.new({:id => row["id"],
23
- :title => row["tag"],
24
- :body => row["body"],
25
- :markup => :wikka,
26
- :latest => row["latest"] == "Y",
27
- :time => row["time"],
28
- :message => row["note"],
29
- :author => author,
30
- :author_name => row["user"]})
31
- revisions << page
32
- end
33
- titles.uniq!
34
- #revisions.sort! { |a,b| a.time <=> b.time }
35
-
36
- revisions
37
- end
38
-
39
- def read_authors
40
- sql = "SELECT name, email FROM wikka_users;"
41
- results = database.query(sql)
42
- results.each do |row|
43
- authors[row["name"]] = OpenStruct.new(name: row["name"],
44
- email: row["email"] )
45
- end
46
- end
47
- end
48
- end
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Caramelize::GollumOutput do
4
-
5
- let(:gollum_output) { Caramelize::GollumOutput.new('wiki.git') }
6
- before do
7
- allow(gollum_output).to receive(:initialize_repository).and_return true
8
- end
9
-
10
- describe :commit_history do
11
- end
12
-
13
- describe :create_namespace_overview do
14
-
15
- context '3 pages in namespaces' do
16
- it 'commits page' do
17
- namespaces= [
18
- OpenStruct.new(identifier: 'velociraptors', name: 'Velociraptor'),
19
- OpenStruct.new(identifier: 'allosaurus', name: 'Allosaurus')
20
- ]
21
- body = "## Overview of namespaces\n\n* [[Velociraptor|velociraptors/Wiki]] \n* [[Allosaurus|allosaurus/Wiki]] \n"
22
- expected_page = Caramelize::Page.new(title: 'Home',
23
- body: body,
24
- message: 'Create Namespace Overview',
25
- latest: true
26
- )
27
- allow(gollum_output).to receive(:commit_revision).with(expected_page, :markdown)
28
- gollum_output.create_namespace_overview(namespaces)
29
- expect(gollum_output).to have_receive(:commit_revision).with(expected_body, :markdown)
30
- end
31
- end
32
- end
33
-
34
- describe :build_commit do
35
- let(:page) do
36
- Caramelize::Page.new( title: 'Feathered Dinosaurs',
37
- message: 'Dinosaurs really had feathers, do not forget!',
38
- time: Time.parse('2015-02-12'),
39
- body: 'Dinosaurs are awesome and have feathers!',
40
- author: OpenStruct.new(name: 'Jeff Goldblum', email: 'jeff.g@example.com') )
41
- end
42
-
43
- it 'builds commit hash' do
44
- expected_hash = { message: 'Dinosaurs really had feathers, do not forget!',
45
- authored_date: Time.parse('2015-02-12'),
46
- committed_date: Time.parse('2015-02-12'),
47
- name: 'Jeff Goldblum',
48
- email: 'jeff.g@example.com' }
49
- expect(gollum_output.send(:build_commit, page)).to eq expected_hash
50
- end
51
- context 'page has message' do
52
- it 'uses page.title' do
53
- expect(gollum_output.send(:build_commit, page)[:message]).to eq 'Dinosaurs really had feathers, do not forget!'
54
- end
55
- end
56
- context 'page has no message' do
57
- it 'should create message "Edit in page Feathered Dinosaurs"' do
58
- page.message = ''
59
- expect(gollum_output.send(:build_commit, page)[:message]).to eq 'Edit in page Feathered Dinosaurs'
60
- end
61
- end
62
- end
63
-
64
- end