lilac 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9ba7b0c9acb613529808fee0ed9d298393805ea
4
+ data.tar.gz: 9d6eaf1830d69253ac70a57a632fbac053a934f8
5
+ SHA512:
6
+ metadata.gz: ef2de1600cc3e66d7775d7fc9a610fca7a7e33aac4ba281f280f0d697d4348f8e47732f38b2c1ec1d1acc9fc44bd56e2c7c58a32b43b3b634eb74d6aa2e67ce7
7
+ data.tar.gz: 576328c54533f17f83e3e138032914b91bdd1afe1d7bd80a5952cc3a45a41ac42eb0ae55a64a1d57f29c1d4ba02656b11e16efd91a2bee528feb4a0980f0bbef
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014,2015 Yasuhiro Asaka
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,112 @@
1
+ # Lilac
2
+
3
+ Lilac (luxury indented list another converter) is list converter
4
+ that supports list styles of several lightweight markup languages.
5
+
6
+
7
+ ## Supported syntax
8
+
9
+ * Asciidoc
10
+ * Markdown
11
+
12
+
13
+ ## Installation
14
+
15
+ ```sh
16
+ $ git clone https://github.com/grauwoelfchen/lilac.git
17
+ ```
18
+
19
+
20
+ ## Usage
21
+
22
+ ### Ruby
23
+
24
+ ```ruby
25
+ text = <<TEXT
26
+ * foo
27
+ ** bar
28
+ *** baz
29
+ **** qux
30
+ ** quux
31
+ TEXT
32
+
33
+ list = Lilac::List.new(text)
34
+ puts list.to_html #=> <ul><li>foo<li><li><ul><li>...</li></ul></li></ul>
35
+ ```
36
+
37
+ ### Command line
38
+
39
+ ```sh
40
+ $ lilac
41
+ * foo
42
+ ** bar
43
+ *** baz
44
+ ;; press ^D
45
+ <ul><li>foo</li><li><ul><li>bar</li><li><ul><li>baz</li></ul></li></ul></li></ul>
46
+ ```
47
+
48
+ ### Supported list styles
49
+
50
+ #### Asciidoc
51
+
52
+ ```
53
+ - foo
54
+ - bar
55
+ - baz
56
+
57
+ ;; p list.to_html
58
+ <ul>
59
+ <li>foo</li>
60
+ <li>bar</li>
61
+ <li>baz</li>
62
+ </ul>
63
+ ```
64
+
65
+ ```
66
+ * foo
67
+ ** bar
68
+ *** baz
69
+
70
+ ;; p list.to_html
71
+ <ul>
72
+ <li>foo</li>
73
+ <li>
74
+ <ul>
75
+ <li>bar</li>
76
+ <li>
77
+ <ul>
78
+ <li>baz</li>
79
+ </ul>
80
+ </li>
81
+ </ul>
82
+ </li>
83
+ </ul>
84
+ ```
85
+
86
+ #### Markdown
87
+
88
+ ```
89
+ * foo
90
+ * bar
91
+ * baz
92
+
93
+ ;; p list.to_html
94
+ <ul>
95
+ <li>foo</li>
96
+ <li>
97
+ <ul>
98
+ <li>bar</li>
99
+ <li>
100
+ <ul>
101
+ <li>baz</li>
102
+ </ul>
103
+ </li>
104
+ </ul>
105
+ </li>
106
+ </ul>
107
+ ```
108
+
109
+
110
+ ## License
111
+
112
+ [MIT](LICENSE.txt)
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.pattern = "test/**/*_test.rb"
7
+ end
8
+
9
+ desc "Run tests"
10
+ task default: :test
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pathname"
4
+ require "optparse"
5
+
6
+ root = Pathname.new(__FILE__).realpath.parent.parent
7
+ $:.unshift root.join("lib") if $0 == __FILE__
8
+
9
+ require "lilac"
10
+
11
+ def name
12
+ $0.gsub(/.*\//, "")
13
+ end
14
+
15
+ def help
16
+ <<-MESSAGE
17
+ Useage:
18
+ #{name} [input|option]
19
+ -v, --version Show version of gem.
20
+ -h, --helf Show this message.
21
+ MESSAGE
22
+ end
23
+
24
+ opts = {
25
+ path: nil
26
+ }
27
+
28
+ input = nil
29
+
30
+ filter = lambda do |v|
31
+ unless File.exists?(v)
32
+ puts "#{name}: cannot access #{v}: No such file"
33
+ exit 1
34
+ end
35
+ opts[key] = v
36
+ end
37
+
38
+ parser = OptionParser.new
39
+ parser.on("-v", "--version") { puts Lilac::VERSION; exit }
40
+ parser.on_tail("-h", "--help") { puts help; exit }
41
+
42
+ begin
43
+ args = ARGV.dup
44
+ if args.length > 1
45
+ parser.parse!(args)
46
+ else
47
+ input = ARGF.each_line.to_a.join
48
+ end
49
+ unless input
50
+ raise OptionParser::MissingArgument
51
+ end
52
+ rescue
53
+ puts help
54
+ exit 1
55
+ end
56
+
57
+ cli = Lilac::Cli.new(opts, input)
58
+ cli.run
@@ -0,0 +1,6 @@
1
+ require "lilac/version"
2
+ require "lilac/cli"
3
+ require "lilac/list"
4
+
5
+ module Lilac
6
+ end
@@ -0,0 +1,13 @@
1
+ require "lilac/list"
2
+
3
+ module Lilac
4
+ class Cli
5
+ def initialize(opts={}, text=nil)
6
+ @list = Lilac::List.new(text)
7
+ end
8
+
9
+ def run
10
+ puts @list.to_html
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ require "lilac/parser"
2
+ require "lilac/renderer"
3
+
4
+ module Lilac
5
+ class List
6
+ def initialize(text)
7
+ @text = text
8
+ @data = nil
9
+ end
10
+
11
+ def to_html
12
+ parse! unless @data
13
+ renderer = Lilac::Renderer.new(@data)
14
+ renderer.render
15
+ end
16
+
17
+ private
18
+
19
+ def parse!
20
+ parser = Lilac::Parser.new(@text)
21
+ @data = parser.parse
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,66 @@
1
+ module Lilac
2
+ class Parser
3
+ def initialize(text = nil)
4
+ @text = text ? text.each_line.lazy : []
5
+ end
6
+
7
+ def parse
8
+ @text.inject([]) { |acc, line|
9
+ line = handle_bullet(line)
10
+ begin
11
+ handle_line(line, acc)
12
+ rescue
13
+ # pass
14
+ end
15
+ acc
16
+ }.lazy
17
+ end
18
+
19
+ private
20
+
21
+ def handle_bullet(line)
22
+ # md to adoc, -|+ to *
23
+ line.gsub(/^(\s*)([\*\-\+]+)/) { |bullet|
24
+ level = $1.to_s.length
25
+ if level == 0 && $2 =~ /[\-\+]+/
26
+ "*"
27
+ elsif level > 1
28
+ "*" * (level / 2 + 1)
29
+ else
30
+ bullet.gsub(/-/, "*")
31
+ end
32
+ }
33
+ end
34
+
35
+ def handle_line(line, acc)
36
+ if line =~ /^(\*+)\s/
37
+ level = $1.length
38
+ text = line.gsub($1, "")
39
+ if level == 1
40
+ acc << [:li, handle_text(text)]
41
+ elsif !acc.empty?
42
+ cur = ul = acc
43
+ # progression
44
+ # ** -> 2
45
+ # *** -> 5
46
+ # **** -> 8
47
+ # ***** -> 11
48
+ inspection = level * 3 - 4
49
+ inspection.times { cur = cur.last if cur }
50
+ case cur.first
51
+ when :ul
52
+ cur.last << [:li, handle_text(text)]
53
+ else
54
+ # current ul
55
+ (inspection - 2).times { ul = ul.last }
56
+ ul << [:li, [:ul, [[:li, handle_text(text)]]]]
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def handle_text(line)
63
+ [:text, line.strip.chomp.gsub(/^\s*/, "")]
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,42 @@
1
+ module Lilac
2
+ class Renderer
3
+ def initialize(data = nil)
4
+ @data = data ? data : []
5
+ end
6
+
7
+ def render
8
+ @data.inject("") { |acc, (t, b)|
9
+ acc << build(t, b, 1)
10
+ acc
11
+ }.instance_eval { |rendered_list|
12
+ "<ul>#{rendered_list}</ul>"
13
+ }
14
+ end
15
+
16
+ private
17
+
18
+ def build(tag, block, lv=1)
19
+ case tag
20
+ when :ul
21
+ block.map { |t, b|
22
+ build(t, b, lv)
23
+ }.join.instance_eval { |li|
24
+ "<ul>#{li}</ul>"
25
+ }
26
+ when :li
27
+ case block.first
28
+ when :text
29
+ build(:text, "<li>" + block.last.to_s + "</li>")
30
+ when :ul
31
+ block.last.map { |t, b|
32
+ build(t, b, lv + 1)
33
+ }.join.instance_eval { |li|
34
+ "<li><ul>#{li}</ul></li>"
35
+ }
36
+ end
37
+ else # text
38
+ block
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Lilac
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "lilac/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "lilac"
7
+ spec.version = Lilac::VERSION
8
+ spec.authors = ["Yasuhiro Asaka"]
9
+ spec.email = ["grauwoelfchen@gmail.com"]
10
+ spec.summary = %q{Luxury Indented List Another Converter}
11
+ spec.description = %q{The Converter for various list text}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "minitest"
23
+ end
@@ -0,0 +1,100 @@
1
+ require "test_helper"
2
+
3
+ class AsciidocTest < Minitest::Unit::TestCase
4
+ def test_asterisk_bullet_flat_list
5
+ text = <<-TEXT.gsub(/^\s{4}/, "")
6
+ * foo
7
+ * bar
8
+ * baz
9
+ TEXT
10
+ expected = <<-LIST.gsub(/\n|\s/, "")
11
+ <ul>
12
+ <li>foo</li>
13
+ <li>bar</li>
14
+ <li>baz</li>
15
+ </ul>
16
+ LIST
17
+ list = Lilac::List.new(text)
18
+ assert_equal expected, list.to_html
19
+ end
20
+
21
+ def test_hyphen_bullet_flat_list
22
+ text = <<-TEXT.gsub(/^\s{4}/, "")
23
+ - foo
24
+ - bar
25
+ - baz
26
+ TEXT
27
+ expected = <<-LIST.gsub(/\n|\s/, "")
28
+ <ul>
29
+ <li>foo</li>
30
+ <li>bar</li>
31
+ <li>baz</li>
32
+ </ul>
33
+ LIST
34
+ list = Lilac::List.new(text)
35
+ assert_equal expected, list.to_html
36
+ end
37
+
38
+ def test_mixed_bullet_flat_list
39
+ text = <<-TEXT.gsub(/^\s{4}/, "")
40
+ * foo
41
+ - bar
42
+ * baz
43
+ TEXT
44
+ expected = <<-LIST.gsub(/\n|\s/, "")
45
+ <ul>
46
+ <li>foo</li>
47
+ <li>bar</li>
48
+ <li>baz</li>
49
+ </ul>
50
+ LIST
51
+ list = Lilac::List.new(text)
52
+ assert_equal expected, list.to_html
53
+ end
54
+
55
+ def test_asterisk_bullet_2_level_depth_list
56
+ text = <<-TEXT.gsub(/^\s{4}/, "")
57
+ * foo
58
+ ** bar
59
+ ** baz
60
+ TEXT
61
+ expected = <<-LIST.gsub(/\n|\s/, "")
62
+ <ul>
63
+ <li>foo</li>
64
+ <li>
65
+ <ul>
66
+ <li>bar</li>
67
+ <li>baz</li>
68
+ </ul>
69
+ </li>
70
+ </ul>
71
+ LIST
72
+ list = Lilac::List.new(text)
73
+ assert_equal expected, list.to_html
74
+ end
75
+
76
+ def test_asterisk_bullet_3_level_depth_list
77
+ text = <<-TEXT.gsub(/^\s{4}/, "")
78
+ * foo
79
+ ** bar
80
+ *** baz
81
+ TEXT
82
+ expected = <<-LIST.gsub(/\n|\s/, "")
83
+ <ul>
84
+ <li>foo</li>
85
+ <li>
86
+ <ul>
87
+ <li>bar</li>
88
+ <li>
89
+ <ul>
90
+ <li>baz</li>
91
+ </ul>
92
+ </li>
93
+ </ul>
94
+ </li>
95
+ </ul>
96
+ LIST
97
+ list = Lilac::List.new(text)
98
+ assert_equal expected, list.to_html
99
+ end
100
+ end
@@ -0,0 +1,101 @@
1
+ require "test_helper"
2
+
3
+ class MarkdownTest < Minitest::Unit::TestCase
4
+ def test_asterisk_bullet_flat_list
5
+ text = <<-TEXT.gsub(/^\s{4}/, "")
6
+ * foo
7
+ * bar
8
+ * baz
9
+ TEXT
10
+ expected = <<-LIST.gsub(/\n|\s/, "")
11
+ <ul>
12
+ <li>foo</li>
13
+ <li>bar</li>
14
+ <li>baz</li>
15
+ </ul>
16
+ LIST
17
+ list = Lilac::List.new(text)
18
+ assert_equal expected, list.to_html
19
+ end
20
+
21
+ def test_hyphen_bullet_flat_list
22
+ text = <<-TEXT.gsub(/^\s{4}/, "")
23
+ - foo
24
+ - bar
25
+ - baz
26
+ TEXT
27
+ expected = <<-LIST.gsub(/\n|\s/, "")
28
+ <ul>
29
+ <li>foo</li>
30
+ <li>bar</li>
31
+ <li>baz</li>
32
+ </ul>
33
+ LIST
34
+ list = Lilac::List.new(text)
35
+ assert_equal expected, list.to_html
36
+ end
37
+
38
+ def test_plus_bullet_flat_list
39
+ text = <<-TEXT.gsub(/^\s{4}/, "")
40
+ + foo
41
+ + bar
42
+ + baz
43
+ TEXT
44
+ expected = <<-LIST.gsub(/\n|\s/, "")
45
+ <ul>
46
+ <li>foo</li>
47
+ <li>bar</li>
48
+ <li>baz</li>
49
+ </ul>
50
+ LIST
51
+ list = Lilac::List.new(text)
52
+ assert_equal expected, list.to_html
53
+ end
54
+
55
+
56
+ def test_asterisk_bullet_2_level_depth_list
57
+ text = <<-TEXT.gsub(/^\s{4}/, "")
58
+ * foo
59
+ * bar
60
+ * baz
61
+ TEXT
62
+ expected = <<-LIST.gsub(/\n|\s/, "")
63
+ <ul>
64
+ <li>foo</li>
65
+ <li>
66
+ <ul>
67
+ <li>bar</li>
68
+ <li>baz</li>
69
+ </ul>
70
+ </li>
71
+ </ul>
72
+ LIST
73
+ list = Lilac::List.new(text)
74
+ assert_equal expected, list.to_html
75
+ end
76
+
77
+ def test_asterisk_bullet_3_level_depth_list_creation
78
+ text = <<-TEXT.gsub(/^\s{4}/, "")
79
+ * foo
80
+ * bar
81
+ * baz
82
+ TEXT
83
+ expected = <<-LIST.gsub(/\n|\s/, "")
84
+ <ul>
85
+ <li>foo</li>
86
+ <li>
87
+ <ul>
88
+ <li>bar</li>
89
+ <li>
90
+ <ul>
91
+ <li>baz</li>
92
+ </ul>
93
+ </li>
94
+ </ul>
95
+ </li>
96
+ </ul>
97
+ LIST
98
+ list = Lilac::List.new(text)
99
+ assert_equal expected, list.to_html
100
+ end
101
+ end
@@ -0,0 +1,31 @@
1
+ require "stringio"
2
+ require "test_helper"
3
+
4
+ class LilacTest < Minitest::Unit::TestCase
5
+ def test_output_from_cli_input
6
+ text = <<-TEXT.gsub(/^\s{4}/, "")
7
+ * foo
8
+ * bar
9
+ * baz
10
+ TEXT
11
+ cli = Lilac::Cli.new({}, text)
12
+ result = capture_stdout { cli.run }
13
+ expected = <<-LIST.gsub(/\n|\s/, "")
14
+ <ul>
15
+ <li>foo</li>
16
+ <li>bar</li>
17
+ <li>baz</li>
18
+ </ul>
19
+ LIST
20
+ assert_equal expected, result
21
+ end
22
+
23
+ def capture_stdout
24
+ origin = $stdout
25
+ $stdout = StringIO.new
26
+ yield
27
+ result = $stdout.string.strip
28
+ $stdout = origin
29
+ result
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ require "test_helper"
2
+
3
+ class Lilac::ListTest < Minitest::Unit::TestCase
4
+ def test_should_returns_string
5
+ list = Lilac::List.new("* foo\n")
6
+ assert_instance_of String, list.to_html
7
+ end
8
+
9
+ def test_should_prepare_parsed_data
10
+ list = Lilac::List.new("* foo\n")
11
+ list.send(:parse!)
12
+ assert_instance_of Enumerator::Lazy, list.instance_variable_get(:@data)
13
+ end
14
+ end
@@ -0,0 +1,124 @@
1
+ require "test_helper"
2
+
3
+ class Lilac::ParserTest < Minitest::Unit::TestCase
4
+ def test_should_returns_enumerator_lazy_object
5
+ parser = Lilac::Parser.new("* foo")
6
+ assert_instance_of Enumerator::Lazy, parser.parse
7
+ end
8
+
9
+ def test_should_replace_hyphen_as_asterisk
10
+ parser = Lilac::Parser.new
11
+ assert_equal "* foo", parser.send(:handle_bullet, "- foo")
12
+ end
13
+
14
+ def test_should_remove_asciidoc_hyphen_indent
15
+ parser = Lilac::Parser.new
16
+ assert_equal "* foo", parser.send(:handle_bullet, "--- foo")
17
+ end
18
+
19
+ def test_should_not_replace_invalid_indent
20
+ parser = Lilac::Parser.new
21
+ assert_equal " * foo", parser.send(:handle_bullet, " * foo")
22
+ end
23
+
24
+ def test_should_keep_asterisk_bullet_without_indent
25
+ parser = Lilac::Parser.new
26
+ assert_equal "* foo", parser.send(:handle_bullet, "* foo")
27
+ end
28
+
29
+ def test_should_replace_indent_by_2_spaces_as_2_asterisks
30
+ parser = Lilac::Parser.new
31
+ assert_equal "** foo", parser.send(:handle_bullet, " * foo")
32
+ end
33
+
34
+ def test_should_replace_indent_of_4_spaces_as_3_asterisks
35
+ parser = Lilac::Parser.new
36
+ assert_equal "*** foo", parser.send(:handle_bullet, " * foo")
37
+ end
38
+
39
+ def test_should_ignore_line_without_be_not_started_with_asterisk_bullet
40
+ parser = Lilac::Parser.new
41
+ acc = []
42
+ parser.send(:handle_line, "- foo", acc)
43
+ assert_equal [], acc
44
+ end
45
+
46
+ def test_should_ignore_line_without_whitespace_after_bullet
47
+ parser = Lilac::Parser.new
48
+ acc = []
49
+ parser.send(:handle_line, "*foo", acc)
50
+ assert_equal [], acc
51
+ end
52
+
53
+ def test_should_ignore_line_that_has_too_many_bullets
54
+ parser = Lilac::Parser.new
55
+ acc = []
56
+ parser.send(:handle_line, "** foo", acc)
57
+ assert_equal [], acc
58
+ end
59
+
60
+ def test_should_extract_valid_1_level_depth_line
61
+ parser = Lilac::Parser.new
62
+ acc = []
63
+ parser.send(:handle_line, "* foo", acc)
64
+ expected = [
65
+ [:li, [:text, "foo"]]
66
+ ]
67
+ assert_equal expected, acc
68
+ end
69
+
70
+ def test_should_extract_valid_1_level_depth_multiple_lines
71
+ parser = Lilac::Parser.new
72
+ acc = [[:li, [:text, "foo"]]]
73
+ parser.send(:handle_line, "* bar", acc)
74
+ expected = [
75
+ [:li, [:text, "foo"]],
76
+ [:li, [:text, "bar"]]
77
+ ]
78
+ assert_equal expected, acc
79
+ end
80
+
81
+ def test_should_extract_valid_2_level_depth_lines
82
+ parser = Lilac::Parser.new
83
+ acc = [[:li, [:text, "foo"]]]
84
+ parser.send(:handle_line, "** bar", acc)
85
+ expected = [
86
+ [:li, [:text, "foo"]],
87
+ [:li, [:ul, [
88
+ [:li, [:text, "bar"]]
89
+ ]]]
90
+ ]
91
+ assert_equal expected, acc
92
+ end
93
+
94
+ def test_should_extract_valid_3_level_depth_lines
95
+ parser = Lilac::Parser.new
96
+ acc = [
97
+ [:li, [:text, "foo"]],
98
+ [:li, [:ul, [
99
+ [:li, [:text, "bar"]]]]
100
+ ]
101
+ ]
102
+ parser.send(:handle_line, "*** baz", acc)
103
+ expected = [
104
+ [:li, [:text, "foo"]],
105
+ [:li, [:ul, [
106
+ [:li, [:text, "bar"]],
107
+ [:li, [:ul, [
108
+ [:li, [:text, "baz"]]
109
+ ]]]
110
+ ]]]
111
+ ]
112
+ assert_equal expected, acc
113
+ end
114
+
115
+ def test_should_remove_line_break
116
+ parser = Lilac::Parser.new
117
+ assert_equal [:text, "foo"], parser.send(:handle_text, "foo\n")
118
+ end
119
+
120
+ def test_should_remove_whitespaces_in_both_side
121
+ parser = Lilac::Parser.new
122
+ assert_equal [:text, "foo"], parser.send(:handle_text, " foo \n")
123
+ end
124
+ end
@@ -0,0 +1,42 @@
1
+ require "test_helper"
2
+
3
+ class Lilac::RendererTest < Minitest::Unit::TestCase
4
+ def test_should_return_html_string
5
+ data = [[:li, [:text, "foo"]]]
6
+ renderer = Lilac::Renderer.new(data)
7
+ assert_instance_of String, renderer.render
8
+ end
9
+
10
+ def test_should_raise_error_without_enumerable_data
11
+ data = "invalid"
12
+ renderer = Lilac::Renderer.new(data)
13
+ assert_raises NoMethodError do
14
+ renderer.render
15
+ end
16
+ end
17
+
18
+ def test_should_append_ul_tag
19
+ data = [[:li, [:text, "foo"]]]
20
+ renderer = Lilac::Renderer.new(data)
21
+ expected = "<ul><li>foo</li></ul>"
22
+ assert_equal expected, renderer.render
23
+ end
24
+
25
+ def test_should_build_ul_tag
26
+ renderer = Lilac::Renderer.new
27
+ expected = "<ul><li>foo</li></ul>"
28
+ assert_equal expected, renderer.send(:build, :ul, [[:li, [:text, "foo"]]])
29
+ end
30
+
31
+ def test_should_build_li_tag
32
+ renderer = Lilac::Renderer.new
33
+ expected = "<li>foo</li>"
34
+ assert_equal expected, renderer.send(:build, :li, [:text, "foo"])
35
+ end
36
+
37
+ def test_should_build_plain_text
38
+ renderer = Lilac::Renderer.new
39
+ expected = "foo"
40
+ assert_equal expected, renderer.send(:build, :text, "foo")
41
+ end
42
+ end
@@ -0,0 +1,2 @@
1
+ require "minitest/autorun"
2
+ require "lilac"
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lilac
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yasuhiro Asaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: The Converter for various list text
56
+ email:
57
+ - grauwoelfchen@gmail.com
58
+ executables:
59
+ - lilac
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/lilac
69
+ - lib/lilac.rb
70
+ - lib/lilac/cli.rb
71
+ - lib/lilac/list.rb
72
+ - lib/lilac/parser.rb
73
+ - lib/lilac/renderer.rb
74
+ - lib/lilac/version.rb
75
+ - lilac.gemspec
76
+ - test/integration/asciidoc_test.rb
77
+ - test/integration/markdown_test.rb
78
+ - test/lilac_test.rb
79
+ - test/list_test.rb
80
+ - test/parser_test.rb
81
+ - test/renderer_test.rb
82
+ - test/test_helper.rb
83
+ homepage: ''
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.2.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Luxury Indented List Another Converter
107
+ test_files:
108
+ - test/integration/asciidoc_test.rb
109
+ - test/integration/markdown_test.rb
110
+ - test/lilac_test.rb
111
+ - test/list_test.rb
112
+ - test/parser_test.rb
113
+ - test/renderer_test.rb
114
+ - test/test_helper.rb