lilac 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d3e2ca3b43df7a9c39a3816d3c7907ab26a065e
4
- data.tar.gz: 70e0b3f6bf5580dde30e6b7bae3de95f6e700301
3
+ metadata.gz: ee5d4180a4c8db8c7c6202b2cbf417e5b470c919
4
+ data.tar.gz: fc84747b276a3c216517546169a25031fedc7e61
5
5
  SHA512:
6
- metadata.gz: b560d79a5f3b453dbeca6cce42df499fd0d66a38b121af329b29cf3a9227e4953178cd57aa5c68ed195c110c0889ac81df309906713f378f3834a80a19a38716
7
- data.tar.gz: 339ae8c54e374c342558212e3aeb7c1afbe169bfb6dfe71a3f07f6d7e8580e694b66109c283cacb3d1d224ae927edb3890a3fce17f1f5abd1a02259d7d2decfb
6
+ metadata.gz: 1cab0cdfa60254edcd25e6e49e0218ed64e70388053f279862830cf9260a9a5a51f3588c07680c7ff3af18152ecc5a25779a44731eb8c9beb85f122ddd3392c8
7
+ data.tar.gz: f3aea5a2486a662dd3e52d0f8c04e1734088fb7b878984beb36f42b922e035783b233df92845315bc4fba3cd3a1fd8c66cdbbef96e7411fcac974779762bb397
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.5
5
+ - 2.2.0
6
+ notifications:
7
+ email:
8
+ recipients:
9
+ - grauwoelfchen@gmail.com
10
+ on_success: change
11
+ on_failure: always
data/ChangeLog CHANGED
@@ -1,6 +1,13 @@
1
1
  # ChangeLog for lilac
2
2
  # Copyright 2014,2015 Yasuhiro Asaka; Distributed under the MIT License
3
3
 
4
+ 20 Mar 2015; Yasuhiro Asaka <grauwoelfchen@gmail.com> lilac/parser.rb,
5
+ lilac/renderer.rb, lilac/version.rb:
6
+ Fix list tag structure as standard HTML
7
+
8
+ 21 Jan 2015; Yasuhiro Asaka <grauwoelfchen@gmail.com> +.travis.yml:
9
+ Enter travis CI
10
+
4
11
  21 Jan 2015; Yasuhiro Asaka <grauwoelfchen@gmail.com> +ChangeLog:
5
12
  Add Homepage into gemspec and ChangeLog file.
6
13
 
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Lilac
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/grauwoelfchen/lilac.png)](http://travis-ci.org/grauwoelfchen/lilac)
4
+
3
5
  Lilac (luxury indented list another converter) is list converter
4
6
  that supports list styles of several lightweight markup languages.
5
7
 
@@ -12,6 +14,11 @@ that supports list styles of several lightweight markup languages.
12
14
 
13
15
  ## Installation
14
16
 
17
+ ```sh
18
+ $ gem install lilac
19
+ ```
20
+
21
+
15
22
  ```sh
16
23
  $ git clone https://github.com/grauwoelfchen/lilac.git
17
24
  ```
@@ -31,7 +38,14 @@ text = <<TEXT
31
38
  TEXT
32
39
 
33
40
  list = Lilac::List.new(text)
34
- puts list.to_html #=> <ul><li>foo<li><li><ul><li>...</li></ul></li></ul>
41
+ puts list.to_html #=>
42
+ <ul>
43
+ <li>foo
44
+ <ul>
45
+ <li>...</li>
46
+ </ul>
47
+ </li>
48
+ </ul>
35
49
  ```
36
50
 
37
51
  ### Command line
@@ -42,7 +56,13 @@ $ lilac
42
56
  ** bar
43
57
  *** baz
44
58
  ;; press ^D
45
- <ul><li>foo</li><li><ul><li>bar</li><li><ul><li>baz</li></ul></li></ul></li></ul>
59
+ <ul>
60
+ <li>foo
61
+ <ul>
62
+ <li>...</li>
63
+ </ul>
64
+ </li>
65
+ </ul>
46
66
  ```
47
67
 
48
68
  ### Supported list styles
@@ -69,11 +89,9 @@ $ lilac
69
89
 
70
90
  ;; p list.to_html
71
91
  <ul>
72
- <li>foo</li>
73
- <li>
92
+ <li>foo
74
93
  <ul>
75
- <li>bar</li>
76
- <li>
94
+ <li>bar
77
95
  <ul>
78
96
  <li>baz</li>
79
97
  </ul>
@@ -92,11 +110,9 @@ $ lilac
92
110
 
93
111
  ;; p list.to_html
94
112
  <ul>
95
- <li>foo</li>
96
- <li>
113
+ <li>foo
97
114
  <ul>
98
- <li>bar</li>
99
- <li>
115
+ <li>bar
100
116
  <ul>
101
117
  <li>baz</li>
102
118
  </ul>
@@ -106,6 +122,10 @@ $ lilac
106
122
  </ul>
107
123
  ```
108
124
 
125
+ ## Rendered List
126
+
127
+ see [HTML lists - W3C Wiki](http://www.w3.org/wiki/HTML_lists#Nesting_lists)
128
+
109
129
 
110
130
  ## License
111
131
 
@@ -32,28 +32,38 @@ module Lilac
32
32
  }
33
33
  end
34
34
 
35
+ # TODO
36
+ # * remove magic number
37
+ # * remove destructive method to reference
35
38
  def handle_line(line, acc)
36
39
  if line =~ /^(\*+)\s/
37
40
  level = $1.length
38
41
  text = line.gsub($1, "")
39
42
  if level == 1
40
- acc << [:li, handle_text(text)]
43
+ acc << [:li, [handle_text(text)]]
41
44
  elsif !acc.empty?
42
45
  cur = ul = acc
43
46
  # progression
44
- # ** -> 2
45
- # *** -> 5
46
- # **** -> 8
47
- # ***** -> 11
48
- inspection = level * 3 - 4
47
+ # ** -> 1
48
+ # *** -> 5
49
+ # **** -> 9
50
+ # ***** -> 13
51
+ inspection = 1 + (4 * (level - 2))
49
52
  inspection.times { cur = cur.last if cur }
50
53
  case cur.first
51
54
  when :ul
52
- cur.last << [:li, handle_text(text)]
55
+ cur.last << [:li, [handle_text(text)]]
53
56
  else
54
- # current ul
55
- (inspection - 2).times { ul = ul.last }
56
- ul << [:li, [:ul, [[:li, handle_text(text)]]]]
57
+ sib = nil
58
+ begin; sib = cur.last.last.last.last; rescue NoMethodError; end
59
+ if sib && sib.first == :li
60
+ # apeend as siblings
61
+ cur = cur.last.last
62
+ cur[-1] += [[:li, [handle_text(text)]]]
63
+ else
64
+ # nest
65
+ cur[-1] += [[:ul, [[:li, [handle_text(text)]]]]]
66
+ end
57
67
  end
58
68
  end
59
69
  end
@@ -5,37 +5,25 @@ module Lilac
5
5
  end
6
6
 
7
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
- }
8
+ build(:ul, @data)
14
9
  end
15
10
 
16
11
  private
17
12
 
18
- def build(tag, block, lv=1)
13
+ def build(tag, block)
14
+ wrap(tag, block.inject("") { |acc, elems|
15
+ acc << elems.each_cons(2).map { |t, b|
16
+ t == :text ? b : build(t, b)
17
+ }.join
18
+ acc
19
+ })
20
+ end
21
+
22
+ def wrap(tag, content)
19
23
  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
24
+ when :ul ; "<ul>#{content}</ul>"
25
+ when :li ; "<li>#{content}</li>"
26
+ else # pass
39
27
  end
40
28
  end
41
29
  end
@@ -1,3 +1,3 @@
1
1
  module Lilac
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -60,8 +60,7 @@ class AsciidocTest < Minitest::Test
60
60
  TEXT
61
61
  expected = <<-LIST.gsub(/\n|\s/, "")
62
62
  <ul>
63
- <li>foo</li>
64
- <li>
63
+ <li>foo
65
64
  <ul>
66
65
  <li>bar</li>
67
66
  <li>baz</li>
@@ -81,17 +80,44 @@ class AsciidocTest < Minitest::Test
81
80
  TEXT
82
81
  expected = <<-LIST.gsub(/\n|\s/, "")
83
82
  <ul>
84
- <li>foo</li>
85
- <li>
83
+ <li>foo
86
84
  <ul>
87
- <li>bar</li>
88
- <li>
85
+ <li>bar
86
+ <ul>
87
+ <li>baz</li>
88
+ </ul>
89
+ </li>
90
+ </ul>
91
+ </li>
92
+ </ul>
93
+ LIST
94
+ list = Lilac::List.new(text)
95
+ assert_equal expected, list.to_html
96
+ end
97
+
98
+ def test_asterisk_bullet_complicated_list
99
+ text = <<-TEXT.gsub(/^\s{4}/, "")
100
+ * foo
101
+ ** bar
102
+ *** baz
103
+ ** qux
104
+ ** quux
105
+ * bye
106
+ TEXT
107
+ expected = <<-LIST.gsub(/\n|\s/, "")
108
+ <ul>
109
+ <li>foo
110
+ <ul>
111
+ <li>bar
89
112
  <ul>
90
113
  <li>baz</li>
91
114
  </ul>
92
115
  </li>
116
+ <li>qux</li>
117
+ <li>quux</li>
93
118
  </ul>
94
119
  </li>
120
+ <li>bye</li>
95
121
  </ul>
96
122
  LIST
97
123
  list = Lilac::List.new(text)
@@ -61,8 +61,7 @@ class MarkdownTest < Minitest::Test
61
61
  TEXT
62
62
  expected = <<-LIST.gsub(/\n|\s/, "")
63
63
  <ul>
64
- <li>foo</li>
65
- <li>
64
+ <li>foo
66
65
  <ul>
67
66
  <li>bar</li>
68
67
  <li>baz</li>
@@ -82,11 +81,9 @@ class MarkdownTest < Minitest::Test
82
81
  TEXT
83
82
  expected = <<-LIST.gsub(/\n|\s/, "")
84
83
  <ul>
85
- <li>foo</li>
86
- <li>
84
+ <li>foo
87
85
  <ul>
88
- <li>bar</li>
89
- <li>
86
+ <li>bar
90
87
  <ul>
91
88
  <li>baz</li>
92
89
  </ul>
@@ -62,31 +62,49 @@ class Lilac::ParserTest < Minitest::Test
62
62
  acc = []
63
63
  parser.send(:handle_line, "* foo", acc)
64
64
  expected = [
65
- [:li, [:text, "foo"]]
65
+ [:li, [
66
+ [:text, "foo"]
67
+ ]]
66
68
  ]
67
69
  assert_equal expected, acc
68
70
  end
69
71
 
70
72
  def test_should_extract_valid_1_level_depth_multiple_lines
71
73
  parser = Lilac::Parser.new
72
- acc = [[:li, [:text, "foo"]]]
74
+ acc = [
75
+ [:li, [
76
+ [:text, "foo"]
77
+ ]]
78
+ ]
73
79
  parser.send(:handle_line, "* bar", acc)
74
80
  expected = [
75
- [:li, [:text, "foo"]],
76
- [:li, [:text, "bar"]]
81
+ [:li, [
82
+ [:text, "foo"]
83
+ ]],
84
+ [:li, [
85
+ [:text, "bar"]
86
+ ]]
77
87
  ]
78
88
  assert_equal expected, acc
79
89
  end
80
90
 
81
91
  def test_should_extract_valid_2_level_depth_lines
82
92
  parser = Lilac::Parser.new
83
- acc = [[:li, [:text, "foo"]]]
93
+ acc = [
94
+ [:li, [
95
+ [:text, "foo"]
96
+ ]]
97
+ ]
84
98
  parser.send(:handle_line, "** bar", acc)
85
99
  expected = [
86
- [:li, [:text, "foo"]],
87
- [:li, [:ul, [
88
- [:li, [:text, "bar"]]
89
- ]]]
100
+ [:li, [
101
+ [:text, "foo"],
102
+ [:ul, [
103
+ [:li, [
104
+ [:text, "bar"]
105
+ ]]
106
+ ]]
107
+ ]]
90
108
  ]
91
109
  assert_equal expected, acc
92
110
  end
@@ -94,24 +112,76 @@ class Lilac::ParserTest < Minitest::Test
94
112
  def test_should_extract_valid_3_level_depth_lines
95
113
  parser = Lilac::Parser.new
96
114
  acc = [
97
- [:li, [:text, "foo"]],
98
- [:li, [:ul, [
99
- [:li, [:text, "bar"]]]]
100
- ]
115
+ [:li, [
116
+ [:text, "foo"],
117
+ [:ul, [
118
+ [:li, [
119
+ [:text, "bar"]
120
+ ]]
121
+ ]]
122
+ ]]
101
123
  ]
102
124
  parser.send(:handle_line, "*** baz", acc)
103
125
  expected = [
104
- [:li, [:text, "foo"]],
105
- [:li, [:ul, [
106
- [:li, [:text, "bar"]],
107
- [:li, [:ul, [
108
- [:li, [:text, "baz"]]
109
- ]]]
110
- ]]]
126
+ [:li, [
127
+ [:text, "foo"],
128
+ [:ul, [
129
+ [:li, [
130
+ [:text, "bar"],
131
+ [:ul, [
132
+ [:li, [
133
+ [:text, "baz"]
134
+ ]]
135
+ ]]
136
+ ]]
137
+ ]]
138
+ ]]
111
139
  ]
112
140
  assert_equal expected, acc
113
141
  end
114
142
 
143
+ def test_should_extract_valid_4_level_depth_lines
144
+ parser = Lilac::Parser.new
145
+ acc = [
146
+ [:li, [
147
+ [:text, "foo"],
148
+ [:ul, [
149
+ [:li, [
150
+ [:text, "bar"],
151
+ [:ul, [
152
+ [:li, [
153
+ [:text, "baz"]
154
+ ]]
155
+ ]]
156
+ ]]
157
+ ]]
158
+ ]]
159
+ ]
160
+ parser.send(:handle_line, "**** qux", acc)
161
+ expected = [
162
+ [:li, [
163
+ [:text, "foo"],
164
+ [:ul, [
165
+ [:li, [
166
+ [:text, "bar"],
167
+ [:ul, [
168
+ [:li, [
169
+ [:text, "baz"],
170
+ [:ul, [
171
+ [:li, [
172
+ [:text, "qux"]
173
+ ]]
174
+ ]]
175
+ ]]
176
+ ]]
177
+ ]]
178
+ ]]
179
+ ]]
180
+ ]
181
+ assert_equal expected, acc
182
+ end
183
+
184
+
115
185
  def test_should_remove_line_break
116
186
  parser = Lilac::Parser.new
117
187
  assert_equal [:text, "foo"], parser.send(:handle_text, "foo\n")
@@ -1,42 +1,146 @@
1
1
  require "test_helper"
2
2
 
3
3
  class Lilac::RendererTest < Minitest::Test
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
4
  def test_should_raise_error_without_enumerable_data
11
5
  data = "invalid"
12
6
  renderer = Lilac::Renderer.new(data)
13
- assert_raises NoMethodError do
7
+ assert_raises(NoMethodError) do
14
8
  renderer.render
15
9
  end
16
10
  end
17
11
 
18
- def test_should_append_ul_tag
19
- data = [[:li, [:text, "foo"]]]
12
+ def test_should_wrap_rendered_list_with_ul_tag
13
+ data = [[:li, [[:text, "bar"]]]]
20
14
  renderer = Lilac::Renderer.new(data)
21
- expected = "<ul><li>foo</li></ul>"
22
- assert_equal expected, renderer.render
15
+ expected = <<-HTML.gsub(/^\s*|\n/, "")
16
+ <ul>
17
+ <li>bar</li>
18
+ </ul>
19
+ HTML
20
+ assert_equal(expected, renderer.render)
23
21
  end
24
22
 
25
- def test_should_build_ul_tag
23
+ # build
24
+
25
+ def test_should_build_text_tag
26
26
  renderer = Lilac::Renderer.new
27
- expected = "<ul><li>foo</li></ul>"
28
- assert_equal expected, renderer.send(:build, :ul, [[:li, [:text, "foo"]]])
27
+ expected = <<-HTML.gsub(/^\s*|\n/, "")
28
+ <li>foo</li>
29
+ HTML
30
+ block = [
31
+ [:text, "foo"]
32
+ ]
33
+ assert_equal(expected, renderer.send(:build, :li, block))
29
34
  end
30
35
 
31
36
  def test_should_build_li_tag
32
37
  renderer = Lilac::Renderer.new
33
- expected = "<li>foo</li>"
34
- assert_equal expected, renderer.send(:build, :li, [:text, "foo"])
38
+ expected = <<-HTML.gsub(/^\s*|\n/, "")
39
+ <ul>
40
+ <li>foo</li>
41
+ </ul>
42
+ HTML
43
+ block = [
44
+ [:li, [
45
+ [:text, "foo"]
46
+ ]]
47
+ ]
48
+ assert_equal expected, renderer.send(:build, :ul, block)
49
+ end
50
+
51
+ def test_should_build_multiple_li_tags
52
+ renderer = Lilac::Renderer.new
53
+ expected = <<-HTML.gsub(/^\s*|\n/, "")
54
+ <ul>
55
+ <li>foo</li>
56
+ <li>bar</li>
57
+ </ul>
58
+ HTML
59
+ block = [
60
+ [:li, [
61
+ [:text, "foo"]
62
+ ]],
63
+ [:li, [
64
+ [:text, "bar"]
65
+ ]]
66
+ ]
67
+ assert_equal expected, renderer.send(:build, :ul, block)
68
+ end
69
+
70
+ def test_should_build_ul_tag
71
+ renderer = Lilac::Renderer.new
72
+ expected = <<-HTML.gsub(/^\s*|\n/, "")
73
+ <ul>
74
+ <li>
75
+ <ul>foo</ul>
76
+ </li>
77
+ </ul>
78
+ HTML
79
+ block = [
80
+ [:li, [
81
+ [:ul, [
82
+ [:text, "foo"]
83
+ ]]
84
+ ]]
85
+ ]
86
+ assert_equal(expected, renderer.send(:build, :ul, block))
87
+ end
88
+
89
+ def test_should_build_nested_ul_tag
90
+ renderer = Lilac::Renderer.new
91
+ expected = <<-HTML.gsub(/^\s*|\n/, "")
92
+ <ul>
93
+ <li>foo
94
+ <ul>
95
+ <li>bar</li>
96
+ </ul>
97
+ </li>
98
+ </ul>
99
+ HTML
100
+ block = [
101
+ [:li, [
102
+ [:text, "foo"],
103
+ [:ul, [
104
+ [:li, [
105
+ [:text, "bar"]]]
106
+ ]]
107
+ ]]
108
+ ]
109
+ assert_equal(expected, renderer.send(:build, :ul, block))
35
110
  end
36
111
 
37
- def test_should_build_plain_text
112
+ def test_should_build_deep_nested_ul_tag
38
113
  renderer = Lilac::Renderer.new
39
- expected = "foo"
40
- assert_equal expected, renderer.send(:build, :text, "foo")
114
+ expected = <<-HTML.gsub(/^\s*|\n/, "")
115
+ <ul>
116
+ <li>foo</li>
117
+ <li>bar
118
+ <ul>
119
+ <li>baz</li>
120
+ <li>qux
121
+ <ul>
122
+ <li>quux</li>
123
+ </ul>
124
+ </li>
125
+ </ul>
126
+ </li>
127
+ </ul>
128
+ HTML
129
+ block = [
130
+ [:li, [[:text, "foo"]]],
131
+ [:li, [
132
+ [:text, "bar"],
133
+ [:ul, [
134
+ [:li, [[:text, "baz"]]],
135
+ [:li, [
136
+ [:text, "qux"],
137
+ [:ul, [
138
+ [:li, [[:text, "quux"]]]
139
+ ]]
140
+ ]]
141
+ ]]
142
+ ]]
143
+ ]
144
+ assert_equal(expected, renderer.send(:build, :ul, block))
41
145
  end
42
146
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lilac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuhiro Asaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-20 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,7 @@ extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
+ - ".travis.yml"
64
65
  - ChangeLog
65
66
  - Gemfile
66
67
  - LICENSE.txt
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  version: '0'
102
103
  requirements: []
103
104
  rubyforge_project:
104
- rubygems_version: 2.2.2
105
+ rubygems_version: 2.4.5
105
106
  signing_key:
106
107
  specification_version: 4
107
108
  summary: Luxury Indented List Another Converter