caramelize 0.1.2 → 1.1.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 (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -53
  3. data/.travis.yml +5 -0
  4. data/CODE_OF_CONDUCT.md +76 -0
  5. data/Gemfile +3 -3
  6. data/LICENSE.md +1 -1
  7. data/README.md +48 -46
  8. data/Rakefile +8 -7
  9. data/bin/caramelize +73 -10
  10. data/caramelize.gemspec +28 -24
  11. data/lib/caramelize.rb +14 -0
  12. data/lib/caramelize/caramel.rb +48 -44
  13. data/lib/caramelize/content_transferer.rb +126 -69
  14. data/lib/caramelize/database_connector.rb +3 -6
  15. data/lib/caramelize/filter_processor.rb +27 -0
  16. data/lib/caramelize/filters/remove_table_tab_line_endings.rb +15 -0
  17. data/lib/caramelize/filters/swap_wiki_links.rb +26 -0
  18. data/lib/caramelize/filters/wikka_to_markdown.rb +67 -0
  19. data/lib/caramelize/health_check.rb +85 -0
  20. data/lib/caramelize/input_wiki/redmine_wiki.rb +120 -0
  21. data/lib/caramelize/input_wiki/wiki.rb +59 -0
  22. data/lib/caramelize/input_wiki/wikkawiki.rb +69 -0
  23. data/lib/caramelize/output_wiki/gollum.rb +80 -0
  24. data/lib/caramelize/page.rb +38 -14
  25. data/lib/caramelize/services/page_builder.rb +20 -0
  26. data/lib/caramelize/version.rb +1 -1
  27. data/spec/fixtures/markup/swap-links-input.textile +57 -0
  28. data/spec/fixtures/markup/swap-links-output.textile +57 -0
  29. data/spec/fixtures/markup/table-tab-line-endings-input.textile +145 -0
  30. data/spec/fixtures/markup/table-tab-line-endings-output.textile +145 -0
  31. data/spec/lib/caramelize/content_transferer_spec.rb +9 -0
  32. data/spec/lib/caramelize/filter_processor_spec.rb +34 -0
  33. data/spec/lib/caramelize/filters/remove_table_tab_line_endings_spec.rb +49 -0
  34. data/spec/lib/caramelize/filters/swap_wiki_links_spec.rb +49 -0
  35. data/spec/lib/caramelize/filters/wikka_to_markdown_spec.rb +198 -0
  36. data/spec/lib/caramelize/input_wiki/wiki_spec.rb +57 -0
  37. data/spec/lib/caramelize/output_wiki/gollum_spec.rb +113 -0
  38. data/spec/lib/caramelize/page_spec.rb +67 -0
  39. data/spec/lib/caramelize/services/page_builder.rb +29 -0
  40. data/spec/spec_helper.rb +8 -0
  41. metadata +165 -54
  42. data/lib/caramelize/author.rb +0 -8
  43. data/lib/caramelize/cli.rb +0 -80
  44. data/lib/caramelize/cli/create_command.rb +0 -52
  45. data/lib/caramelize/cli/run_command.rb +0 -33
  46. data/lib/caramelize/ext.rb +0 -17
  47. data/lib/caramelize/gollum_output.rb +0 -56
  48. data/lib/caramelize/wiki/redmine_wiki.rb +0 -60
  49. data/lib/caramelize/wiki/trac_converter.rb +0 -82
  50. data/lib/caramelize/wiki/wiki.rb +0 -41
  51. data/lib/caramelize/wiki/wikka_converter.rb +0 -38
  52. data/lib/caramelize/wiki/wikkawiki.rb +0 -55
  53. data/test/helper.rb +0 -18
  54. data/test/test_caramelize.rb +0 -7
@@ -1,52 +0,0 @@
1
- #Encoding: UTF-8
2
- require 'caramelize/cli'
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
- begin
29
-
30
- # create dummy config file
31
- target_file = @config_file.nil? ? "caramel.rb" : @config_file
32
-
33
-
34
- #puts args[0]
35
- require 'fileutils'
36
-
37
- FileUtils.cp(File.dirname(__FILE__) +"/../caramel.rb", target_file)
38
-
39
- rescue
40
- #require 'fileutils'
41
- #FileUtils.rm_rf(args[0])
42
- raise
43
- end
44
- if commandparser.verbosity == :normal
45
- puts "Created new configuration file: #{target_file}"
46
- #puts paths.sort.join("\n")
47
- end
48
- end
49
-
50
- end
51
-
52
- 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,17 +0,0 @@
1
- require 'gollum'
2
-
3
- module Gollum
4
- class Committer
5
- def commit
6
- @options[:parents] = parents
7
- @options[:actor] = actor
8
- @options[:last_tree] = nil
9
- @options[:head] = @wiki.ref
10
- sha1 = index.commit(@options[:message], @options)
11
- @callbacks.each do |cb|
12
- cb.call(self, sha1)
13
- end
14
- sha1
15
- end
16
- end
17
- end
@@ -1,56 +0,0 @@
1
- #Encoding: UTF-8
2
-
3
- module Caramelize
4
- class GollumOutput
5
-
6
- def supported_markup
7
- [:markdown, :textile]
8
- end
9
-
10
- # Initialize a new gollum-wiki-repository at the given path.
11
- def initialize wiki_path
12
- # TODO use sanitized name as wiki-repository-title
13
- repo = Grit::Repo.init(wiki_path) unless File.exists?(wiki_path)
14
- @gollum = Gollum::Wiki.new(wiki_path)
15
- end
16
-
17
- # Commit the given page into the gollum-wiki-repository.
18
- # Make sure the target markup is correct before calling this method.
19
- def commit_revision(page, markup)
20
- message = page.message.empty? ? "Edit in page #{page.title}" : page.message
21
-
22
- if page.author
23
- author = page.author
24
- else
25
- author = Author.new
26
- author.name = page.author_name
27
- author.email = "mail@example.com"
28
- end
29
-
30
- commit = {:message => message,
31
- :name => author.name,
32
- :email => author.email,
33
- :authored_date => page.time,
34
- :committed_date => page.time
35
- }
36
-
37
- gollum_page = @gollum.page(page.title)
38
- if gollum_page
39
- @gollum.update_page(gollum_page, gollum_page.name, gollum_page.format, page.body, commit)
40
- else
41
- @gollum.write_page(page.title, markup, page.body, commit)
42
- end
43
- end
44
-
45
- # Commit all revisions of the given history into this gollum-wiki-repository.
46
- def commit_history(revisions, options={}, &block)
47
- options[:markup] = :markdown if options[:markup].nil? # target markup
48
- revisions.each_with_index do |page, index|
49
- # call debug output from outside
50
- block.call(page, index) if block_given?
51
- commit_revision(page, options[:markup])
52
- end
53
- end
54
-
55
- end
56
- end
@@ -1,60 +0,0 @@
1
- #Encoding: UTF-8
2
- module Caramelize
3
- autoload :DatabaseConnector, 'caramelize/database_connector'
4
-
5
- class RedmineWiki < Wiki
6
- include DatabaseConnector
7
-
8
-
9
- # after calling this action, I expect the @titles and @revisions to be filled
10
- def read_pages
11
- sql = "SELECT id, title FROM wiki_pages;"
12
- @revisions = []
13
- @titles = []
14
- @latest_revisions = {}
15
- results_pages = database.query(sql)
16
- results_pages.each do |row_page|
17
- results_contents = database.query("SELECT * FROM wiki_content_versions WHERE page_id='#{row_page["id"]}' ORDER BY updated_on;")
18
- title = row_page["title"]
19
- @titles << title
20
-
21
- results_contents.each do |row_content|
22
- author = @authors[row_content["author_id"]] ? @authors[row_content["author_id"]] : nil
23
- page = Page.new({:id => row_content["id"],
24
- :title => title,
25
- :body => row_content["data"],
26
- :markup => :textile,
27
- :latest => false,
28
- :time => row_content["updated_on"],
29
- :message => row_content["comments"],
30
- :author => author,
31
- :author_name => author.name})
32
- @revisions << page
33
- @latest_revisions[title] = page
34
- end
35
- end
36
- @titles.uniq!
37
- @latest_revisions.each { |rev| rev[1].set_latest }
38
- @revisions.sort! { |a,b| a.time <=> b.time }
39
-
40
-
41
- # TODO find latest revision for each limit
42
-
43
- @revisions
44
- end
45
-
46
- def read_authors
47
- sql = "SELECT id, login, mail FROM users;"
48
- @authors = {}
49
- results = database.query(sql)
50
- results.each do |row|
51
- author = Author.new
52
- author.id = row["id"]
53
- author.name = row["login"]
54
- author.email = row["mail"]
55
- @authors[author.id] = author
56
- end
57
- @authors
58
- end
59
- end
60
- end
@@ -1,82 +0,0 @@
1
- module Caramelize
2
- module TracConverter
3
-
4
- # take an input stream and convert all wikka syntax to markdown syntax
5
- # taken from 'trac_wiki_to_textile' at
6
- def to_textile str
7
- body = body.dup
8
- body.gsub!(/\r/, '')
9
- body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '@\1@')
10
- body.gsub!(/\{\{\{\n#!([^\n]+?)(.+?)\}\}\}/m, '<pre><code class="\1">\2</code></pre>')
11
- body.gsub!(/\{\{\{(.+?)\}\}\}/m, '<pre>\1</pre>')
12
- # macro
13
- body.gsub!(/\[\[BR\]\]/, '')
14
- body.gsub!(/\[\[PageOutline.*\]\]/, '{{toc}}')
15
- body.gsub!(/\[\[Image\((.+?)\)\]\]/, '!\1!')
16
- # header
17
- body.gsub!(/=====\s(.+?)\s=====/, "h5. #{'\1'} \n\n")
18
- body.gsub!(/====\s(.+?)\s====/, "h4. #{'\1'} \n\n")
19
- body.gsub!(/===\s(.+?)\s===/, "h3. #{'\1'} \n\n")
20
- body.gsub!(/==\s(.+?)\s==/, "h2. #{'\1'} \n\n")
21
- body.gsub!(/=\s(.+?)\s=[\s\n]*/, "h1. #{'\1'} \n\n")
22
- # table
23
- body.gsub!(/\|\|/, "|")
24
- # link
25
- body.gsub!(/\[(http[^\s\[\]]+)\s([^\[\]]+)\]/, ' "\2":\1' )
26
- body.gsub!(/\[([^\s]+)\s(.+)\]/, ' [[\1 | \2]] ')
27
- body.gsub!(/([^"\/\!])(([A-Z][a-z0-9]+){2,})/, ' \1[[\2]] ')
28
- body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1')
29
- # text decoration
30
- body.gsub!(/'''(.+)'''/, '*\1*')
31
- body.gsub!(/''(.+)''/, '_\1_')
32
- body.gsub!(/`(.+)`/, '@\1@')
33
- # itemize
34
- body.gsub!(/^\s\s\s\*/, '***')
35
- body.gsub!(/^\s\s\*/, '**')
36
- body.gsub!(/^\s\*/, '*')
37
- body.gsub!(/^\s\s\s\d\./, '###')
38
- body.gsub!(/^\s\s\d\./, '##')
39
- body.gsub!(/^\s\d\./, '#')
40
- body
41
- end
42
-
43
- # TODO this is so far only copy of textile conversion
44
- # not tested!
45
- def to_markdown str
46
- body = body.dup
47
- body.gsub!(/\r/, '')
48
- body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '@\1@')
49
- body.gsub!(/\{\{\{\n#!([^\n]+?)(.+?)\}\}\}/m, '<pre><code class="\1">\2</code></pre>')
50
- body.gsub!(/\{\{\{(.+?)\}\}\}/m, '<pre>\1</pre>')
51
- # macro
52
- body.gsub!(/\[\[BR\]\]/, '')
53
- body.gsub!(/\[\[PageOutline.*\]\]/, '{{toc}}')
54
- body.gsub!(/\[\[Image\((.+?)\)\]\]/, '!\1!')
55
- # header
56
- body.gsub!(/=====\s(.+?)\s=====/, "== #{'\1'} ==\n\n")
57
- body.gsub!(/====\s(.+?)\s====/, "=== #{'\1'} ===\n\n")
58
- body.gsub!(/===\s(.+?)\s===/, "==== #{'\1'} ====\n\n")
59
- body.gsub!(/==\s(.+?)\s==/, "===== #{'\1'} =====\n\n")
60
- body.gsub!(/=\s(.+?)\s=[\s\n]*/, "====== #{'\1'} ======\n\n")
61
- # table
62
- body.gsub!(/\|\|/, "|")
63
- # link
64
- body.gsub!(/\[(http[^\s\[\]]+)\s([^\[\]]+)\]/, ' "\2":\1' )
65
- body.gsub!(/\[([^\s]+)\s(.+)\]/, ' [[\1 | \2]] ')
66
- body.gsub!(/([^"\/\!])(([A-Z][a-z0-9]+){2,})/, ' \1[[\2]] ')
67
- body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1')
68
- # text decoration
69
- body.gsub!(/'''(.+)'''/, '*\1*')
70
- body.gsub!(/''(.+)''/, '_\1_')
71
- body.gsub!(/`(.+)`/, '@\1@')
72
- # itemize
73
- body.gsub!(/^\s\s\s\*/, '***')
74
- body.gsub!(/^\s\s\*/, '**')
75
- body.gsub!(/^\s\*/, '*')
76
- body.gsub!(/^\s\s\s\d\./, '###')
77
- body.gsub!(/^\s\s\d\./, '##')
78
- body.gsub!(/^\s\d\./, '#')
79
- body
80
- end
81
- end
82
- end
@@ -1,41 +0,0 @@
1
- module Caramelize
2
- autoload :DatabaseConnector, 'caramelize/database_connector'
3
- class Wiki
4
- include DatabaseConnector
5
- attr_accessor :revisions, :wiki_title, :titles, :description
6
-
7
- def initialize options={}
8
- @options = options
9
- end
10
-
11
- def revisions_by_title title
12
- if @titles.index title
13
- # new array only containing pages by this name sorted by time
14
- # TODO this is probably bad for renamed pages if supported
15
- return @revisions.reject { |revision| revision.title != title }.sort { |x,y| x.time <=> y.time }
16
- end
17
- end
18
-
19
- # return an empty array in case this action was not overridden
20
- def read_authors
21
- return []
22
- end
23
-
24
- def convert_markup? to_markup
25
- markup != to_markup
26
- end
27
-
28
- def latest_revisions
29
- @latest_revisions = []
30
- for title in @titles
31
- # pick first revision by descending date
32
- @latest_revisions << revisions_by_title(title).last
33
- end
34
- @latest_revisions
35
- end
36
-
37
- def markup
38
- @options[:markup]
39
- end
40
- end
41
- end
@@ -1,38 +0,0 @@
1
- module Caramelize
2
- module WikkaConverter
3
-
4
- # take an input stream and convert all wikka syntax to markdown syntax
5
- def to_markdown body
6
- body = body.dup
7
- body.gsub!(/(======)(.*?)(======)/ ) {|s| '# ' + $2 } #h1
8
- body.gsub!(/(=====)(.*?)(=====)/) {|s| '## ' + $2 } #h2
9
- body.gsub!(/(====)(.*?)(====)/) {|s| '### ' + $2 } #h3
10
- body.gsub!(/(===)(.*?)(===)/) {|s| '#### ' + $2 } #h4
11
-
12
- body.gsub!(/(\*\*)(.*?)(\*\*)/) {|s| '**' + $2 + '**' } #bold
13
- body.gsub!(/(\/\/)(.*?)(\/\/)/) {|s| '_' + $2 + '_' } #italic
14
- #str.gsub!(/(===)(.*?)(===)/) {|s| '`' + $2 + '`'} #code
15
- body.gsub!(/(__)(.*?)(__)/) {|s| '<u>' + $2 + '</u>'} #underline
16
- body.gsub!(/(---)/, ' ') #forced linebreak
17
-
18
- #body.gsub!(/(.*?)(\n\t-)(.*?)/) {|s| $1 + $3 } #list
19
-
20
- body.gsub!(/(\t-)(.*)/, '*\2') # unordered list
21
- body.gsub!(/(~-)(.*)/, '*\2') # unordered list
22
- # TODO ordered lists
23
-
24
- # TODO images: ({{image)(url\=?)?(.*)(}})
25
-
26
- #str.gsub!(/(----)/) {|s| '~~~~'} #seperator
27
-
28
-
29
- body.gsub!(/(\[\[)(\w+)\s(.+?)(\]\])/, '[[\3|\2]]')
30
- #body.gsub!(/\[\[(\w+)\s(.+)\]\]/, ' [[\1 | \2]] ')
31
-
32
-
33
- # TODO more syntax conversion for links and images
34
-
35
- body
36
- end
37
- end
38
- end
@@ -1,55 +0,0 @@
1
- #Encoding: UTF-8
2
- module Caramelize
3
- autoload :DatabaseConnector, 'caramelize/database_connector'
4
- autoload :WikkaConverter, 'caramelize/wiki/wikka_converter'
5
-
6
- class WikkaWiki < Wiki
7
- include DatabaseConnector
8
- include WikkaConverter
9
-
10
- def initialize options={}
11
- super(options)
12
- options[:markup] = :wikka
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
- @revisions = []
19
- @titles = []
20
- results = database.query(sql)
21
- results.each do |row|
22
- @titles << row["tag"]
23
- author = @authors[row["user"]]
24
- page = Page.new({:id => row["id"],
25
- :title => row["tag"],
26
- :body => row["body"],
27
- :markup => :wikka,
28
- :latest => row["latest"] == "Y",
29
- :time => row["time"],
30
- :message => row["note"],
31
- :author => author,
32
- :author_name => row["user"]})
33
- @revisions << page
34
- end
35
- @titles.uniq!
36
- #@revisions.sort! { |a,b| a.time <=> b.time }
37
-
38
- @revisions
39
- end
40
-
41
- def read_authors
42
- sql = "SELECT name, email FROM wikka_users;"
43
- @authors = {}
44
- results = database.query(sql)
45
- results.each do |row|
46
- author = Author.new
47
- #author.id = row["id"]
48
- author.name = row["name"]
49
- author.email = row["email"]
50
- @authors[author.name] = author
51
- end
52
- @authors
53
- end
54
- end
55
- end
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'caramelize'
16
-
17
- class Test::Unit::TestCase
18
- end