mediacloth 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mediacloth.rb~ DELETED
@@ -1,23 +0,0 @@
1
- require 'mediacloth/mediawikilexer'
2
- require 'mediacloth/mediawikiparser'
3
- require 'mediacloth/mediawikiast'
4
- require 'mediacloth/mediawikiparams'
5
- require 'mediacloth/mediawikiwalker'
6
- require 'mediacloth/mediawikihtmlgenerator'
7
-
8
- #Helper module to facilitate MediaCloth usage.
9
- module MediaCloth
10
-
11
-
12
- def wiki_to_html(input)
13
- parser = MediaWikiParser.new
14
- parser.lexer = MediaWikiLexer.new
15
- ast = parser.parse(input)
16
- walker = MediaWikiHTMLGenerator.new
17
- walker.parse(ast)
18
- walker.html
19
- end
20
-
21
- module_function :wiki_to_html
22
-
23
- end
@@ -1,23 +0,0 @@
1
- require 'mediawikilexer'
2
- require 'mediawikiparser'
3
- require 'mediawikiparams'
4
- require 'mediawikihtmlgenerator'
5
-
6
- def produce(index)
7
- file = File.new("../data/html#{index}", "w")
8
- inputFile = File.new("../data/input#{index}", "r")
9
- input = inputFile.read
10
-
11
- parser = MediaWikiParser.new
12
- parser.lexer = MediaWikiLexer.new
13
- ast = parser.parse(input)
14
- MediaWikiParams.instance.time = Time.mktime(2000, 1, 1, 1, 1, 1, 1)
15
- generator = MediaWikiHTMLGenerator.new
16
- generator.parse(ast)
17
-
18
- file.write(generator.html)
19
- file.close
20
- end
21
-
22
- # (3..5).each { |i| produce(i) }
23
- produce(1)
data/test/debugwalker.rb~ DELETED
@@ -1,63 +0,0 @@
1
- require 'mediawikiwalker'
2
-
3
- #A walker to build textual representation of the parse tree.
4
- #
5
- #Use as any other walker and then query for tree:
6
- # parser = MediaWikiParser.new
7
- # parser.lexer = MediaWikiLexer.new
8
- # ast = parser.parse(input)
9
- # walker = DebugWalker.new
10
- # walker.parse(ast)
11
- # puts walker.tree
12
- class DebugWalker < MediaWikiWalker
13
-
14
- #The textual representation of the parse tree.
15
- attr_reader :tree
16
-
17
- def initialize
18
- super
19
- @tree = ""
20
- end
21
-
22
- protected
23
-
24
- def parse_wiki_ast(ast)
25
- info(ast)
26
- super(ast)
27
- end
28
-
29
- def parse_text(ast)
30
- info(ast, ast.formatting)
31
- super(ast)
32
- end
33
-
34
- def parse_list(ast)
35
- info(ast, ast.type)
36
- super(ast)
37
- end
38
-
39
- def parse_list_item(ast)
40
- info(ast)
41
- super(ast)
42
- end
43
-
44
- def parse_preformatted(ast)
45
- info(ast)
46
- end
47
-
48
- def parse_section(ast)
49
- info(ast)
50
- end
51
-
52
- private
53
- #Pretty-print ast node information
54
- def info(ast, *args)
55
- @tree += "#{ast.class}"
56
- if args.length > 0
57
- @tree += ": "
58
- args.each { |arg| @tree += "#{arg} " }
59
- end
60
- @tree += "\n"
61
- end
62
-
63
- end
@@ -1,25 +0,0 @@
1
- require 'mediawikilexer'
2
- require 'mediawikiparser'
3
- require 'mediawikihtmlgenerator'
4
-
5
- require 'test/unit'
6
- require 'testhelper'
7
-
8
- class Parser_Test < Test::Unit::TestCase
9
-
10
- include TestHelper
11
-
12
- def test_input
13
- test_files("html") { |input,result|
14
- parser = MediaWikiParser.new
15
- parser.lexer = MediaWikiLexer.new
16
- ast = parser.parse(input)
17
- MediaWikiParams.instance.time = Time.mktime(2000, 1, 1, 1, 1, 1, 1)
18
- generator = MediaWikiHTMLGenerator.new
19
- generator.parse(ast)
20
- assert_equal generator.html, result
21
- # puts generator.html
22
- }
23
- end
24
-
25
- end
data/test/lexer.rb~ DELETED
@@ -1,57 +0,0 @@
1
- require 'mediawikilexer'
2
- require 'test/unit'
3
- require 'testhelper'
4
-
5
- class Lexer_Test < Test::Unit::TestCase
6
-
7
- include TestHelper
8
-
9
- def test_input
10
- test_files("lex") { |input,result|
11
- lexer = MediaWikiLexer.new
12
- tokens = lexer.tokenize(input)
13
- assert_equal(tokens.to_s, result)
14
- }
15
- end
16
-
17
- def test_empty
18
- assert_equal(lex(""), [[false,false]])
19
- end
20
-
21
- def test_preformatted
22
- #assure preformatted text works as expected at the start of the text
23
- assert_equal(lex(" Foo\n"), [[:PRE, "Foo\n"], [false, false]])
24
- assert_equal(lex(" Foo"), [[:PRE, "Foo"], [false, false]])
25
- end
26
-
27
- def test_hline
28
- #assure that at the start of the text hline still works
29
- assert_equal(lex("----"), [[:HLINE, "----"], [false, false]])
30
- assert_equal(lex("\n----"), [[:HLINE, "----"], [false, false]])
31
- end
32
-
33
- def test_ending_text_token
34
- #check for a problem when the last token is TEXT and it's not included
35
- assert_equal(lex("\n----\nfoo\n"), [[:HLINE, "----"], [:TEXT, "\nfoo\n"], [false, false]])
36
- assert_equal(lex("\n----\nfoo\n Hehe"),
37
- [[:HLINE, "----"], [:TEXT, "\nfoo\n"], [:PRE, "Hehe"], [false, false]])
38
- end
39
-
40
- def test_bullets
41
- assert_equal(lex("* Foo"),
42
- [[:UL_START, ""], [:LI_START, ""], [:TEXT, "Foo"], [:LI_END, ""], [:UL_END, ""], [false, false]])
43
- end
44
-
45
- def test_nested_bullets
46
- assert_equal(lex("**Foo"), [[:UL_START, ""], [:LI_START, ""],
47
- [:UL_START, ""], [:LI_START, ""], [:TEXT, "Foo"], [:LI_END, ""],
48
- [:UL_END, ""], [:LI_END, ""], [:UL_END, ""], [false, false]])
49
- end
50
-
51
- private
52
- def lex(string)
53
- lexer = MediaWikiLexer.new
54
- lexer.tokenize(string)
55
- end
56
-
57
- end
data/test/parser.rb~ DELETED
@@ -1,23 +0,0 @@
1
- require 'mediawikilexer'
2
- require 'mediawikiparser'
3
-
4
- require 'test/unit'
5
- require 'testhelper'
6
- require 'debugwalker'
7
-
8
- class Parser_Test < Test::Unit::TestCase
9
-
10
- include TestHelper
11
-
12
- def test_input
13
- test_files("result") { |input,result|
14
- parser = MediaWikiParser.new
15
- parser.lexer = MediaWikiLexer.new
16
- ast = parser.parse(input)
17
- walker = DebugWalker.new
18
- walker.parse(ast)
19
- puts walker.tree
20
- }
21
- end
22
-
23
- end
data/test/testhelper.rb~ DELETED
@@ -1,28 +0,0 @@
1
- module TestHelper
2
-
3
- #Helper method for file-based comparison tests.
4
- #
5
- #Looks in "data/" directory for files named "inputXXX",
6
- #substitutes "input" with baseName and loads the contents
7
- #of "inputXXX" file into the "input" variable and the
8
- #contents of "baseNameXXX" into the "result" variable.
9
- #
10
- #Then it calls the block with input and result as parameters.
11
- def test_files(baseName, &action)
12
- puts File.dirname(__FILE__) + "/data/input*"
13
- Dir.glob(File.dirname(__FILE__) + "/data/input*").each do |filename|
14
- resultname = filename.gsub(/input(.*)/, "#{baseName}\\1")
15
- #exclude backup files
16
- if not resultname.include?("~")
17
- input_file = File.new(filename, "r")
18
- input = input_file.read
19
- if File.exists?(resultname)
20
- result_file = File.new(resultname, "r")
21
- result = result_file.read
22
-
23
- yield(input, result)
24
- end
25
- end
26
- end
27
- end
28
- end