asciidoctor 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,10 +18,25 @@ context "Paragraphs" do
18
18
  end
19
19
 
20
20
  context "code" do
21
- test "literal paragraph" do
21
+ test "single-line literal paragraphs" do
22
+ output = render_string(" LITERALS\n\n ARE LITERALLY\n\n AWESOMMMME.")
22
23
  assert_xpath "//pre/tt", render_string(" LITERALS\n\n ARE LITERALLY\n\n AWESOMMMME.")
23
24
  end
24
25
 
26
+ test "multi-line literal paragraph" do
27
+ input = <<-EOS
28
+ Install instructions:
29
+
30
+ yum install ruby rubygems
31
+ gem install asciidoctor
32
+
33
+ You're good to go!
34
+ EOS
35
+ output = render_string(input)
36
+ assert_xpath "//pre/tt", output, 1
37
+ assert_match /^gem install asciidoctor/, output, "Indentation should be trimmed from literal block"
38
+ end
39
+
25
40
  test "listing paragraph" do
26
41
  assert_xpath "//div[@class='highlight']", render_string("----\nblah blah blah\n----")
27
42
  end
@@ -31,13 +46,98 @@ context "Paragraphs" do
31
46
  end
32
47
  end
33
48
 
49
+ context "quote" do
50
+ test "quote block" do
51
+ output = render_string("____\nFamous quote.\n____")
52
+ assert_xpath '//*[@class = "quoteblock"]', output, 1
53
+ assert_xpath '//*[@class = "quoteblock"]//p[text() = "Famous quote."]', output, 1
54
+ end
55
+
56
+ test "quote block with attribution" do
57
+ output = render_string("[quote, A famous person, A famous book]\n____\nFamous quote.\n____")
58
+ assert_xpath '//*[@class = "quoteblock"]', output, 1
59
+ assert_xpath '//*[@class = "quoteblock"]/*[@class = "attribution"]', output, 1
60
+ assert_xpath '//*[@class = "quoteblock"]/*[@class = "attribution"]/em[text() = "A famous book"]', output, 1
61
+ # TODO I can't seem to match the attribution (author) w/ xpath
62
+ end
63
+
64
+ test "quote block with section body" do
65
+ output = render_string("____\nFamous quote.\n\nNOTE: That was inspiring.\n____")
66
+ assert_xpath '//*[@class = "quoteblock"]', output, 1
67
+ assert_xpath '//*[@class = "quoteblock"]//*[@class = "admonitionblock"]', output, 1
68
+ end
69
+
70
+ test "single-line quote paragraph" do
71
+ output = render_string("[quote]\nFamous quote.")
72
+ assert_xpath '//*[@class = "quoteblock"]', output, 1
73
+ assert_xpath '//*[@class = "quoteblock"]//p', output, 0
74
+ assert_xpath '//*[@class = "quoteblock"]//*[contains(text(), "Famous quote.")]', output, 1
75
+ end
76
+
77
+ test "verse paragraph" do
78
+ output = render_string("[verse]\nFamous verse.")
79
+ assert_xpath '//*[@class = "verseblock"]', output, 1
80
+ assert_xpath '//*[@class = "verseblock"]/pre', output, 1
81
+ assert_xpath '//*[@class = "verseblock"]//p', output, 0
82
+ assert_xpath '//*[@class = "verseblock"]/pre[normalize-space(text()) = "Famous verse."]', output, 1
83
+ end
84
+
85
+ test "single-line verse block" do
86
+ output = render_string("[verse]\n____\nFamous verse.\n____")
87
+ assert_xpath '//*[@class = "verseblock"]', output, 1
88
+ assert_xpath '//*[@class = "verseblock"]/pre', output, 1
89
+ assert_xpath '//*[@class = "verseblock"]//p', output, 0
90
+ assert_xpath '//*[@class = "verseblock"]/pre[normalize-space(text()) = "Famous verse."]', output, 1
91
+ end
92
+
93
+ test "multi-line verse block" do
94
+ output = render_string("[verse]\n____\nFamous verse.\n\nStanza two.\n____")
95
+ assert_xpath '//*[@class = "verseblock"]', output, 1
96
+ assert_xpath '//*[@class = "verseblock"]/pre', output, 1
97
+ assert_xpath '//*[@class = "verseblock"]//p', output, 0
98
+ assert_xpath '//*[@class = "verseblock"]/pre[contains(text(), "Famous verse.")]', output, 1
99
+ assert_xpath '//*[@class = "verseblock"]/pre[contains(text(), "Stanza two.")]', output, 1
100
+ end
101
+
102
+ test "verse block does not contain block elements" do
103
+ output = render_string("[verse]\n____\nFamous verse.\n\n....\nnot a literal\n....\n____")
104
+ assert_xpath '//*[@class = "verseblock"]', output, 1
105
+ assert_xpath '//*[@class = "verseblock"]/pre', output, 1
106
+ assert_xpath '//*[@class = "verseblock"]//p', output, 0
107
+ assert_xpath '//*[@class = "verseblock"]//*[@class = "literalblock"]', output, 0
108
+ end
109
+ end
110
+
34
111
  context "special" do
35
112
  test "note multiline syntax" do
36
- assert_xpath "//div[@class='admonitionblock']", render_string("[NOTE]\nThis is a winner.")
113
+ Asciidoctor::ADMONITION_STYLES.each do |style|
114
+ assert_xpath "//div[@class='admonitionblock']", render_string("[#{style}]\nThis is a winner.")
115
+ end
116
+ end
117
+
118
+ test "note block syntax" do
119
+ Asciidoctor::ADMONITION_STYLES.each do |style|
120
+ assert_xpath "//div[@class='admonitionblock']", render_string("[#{style}]\n====\nThis is a winner.\n====")
121
+ end
37
122
  end
38
123
 
39
124
  test "note inline syntax" do
40
- assert_xpath "//div[@class='admonitionblock']", render_string("NOTE: This is important, fool!")
125
+ Asciidoctor::ADMONITION_STYLES.each do |style|
126
+ assert_xpath "//div[@class='admonitionblock']", render_string("#{style}: This is important, fool!")
127
+ end
128
+ end
129
+
130
+ test "sidebar block" do
131
+ input = <<-EOS
132
+ == Section
133
+
134
+ .Sidebar
135
+ ****
136
+ Content goes here
137
+ ****
138
+ EOS
139
+ result = render_string(input)
140
+ assert_xpath "//*[@class='sidebarblock']//p", result, 1
41
141
  end
42
142
  end
43
143
 
@@ -0,0 +1,88 @@
1
+ require 'test_helper'
2
+
3
+ context 'Preamble' do
4
+
5
+ test 'title and single paragraph preamble before section' do
6
+ input = <<-EOS
7
+ Title
8
+ =====
9
+
10
+ Preamble paragraph 1.
11
+
12
+ == First Section
13
+
14
+ Section paragraph 1.
15
+ EOS
16
+ result = render_string(input)
17
+ assert_xpath '//p', result, 2
18
+ assert_xpath '//*[@id="preamble"]', result, 1
19
+ assert_xpath '//*[@id="preamble"]//p', result, 1
20
+ assert_xpath '//*[@id="preamble"]/following-sibling::*//h2[@id="_first_section"]', result, 1
21
+ assert_xpath '//*[@id="preamble"]/following-sibling::*//p', result, 1
22
+ end
23
+
24
+ test 'title and multi-paragraph preamble before section' do
25
+ input = <<-EOS
26
+ Title
27
+ =====
28
+
29
+ Preamble paragraph 1.
30
+
31
+ Preamble paragraph 2.
32
+
33
+ == First Section
34
+
35
+ Section paragraph 1.
36
+ EOS
37
+ result = render_string(input)
38
+ assert_xpath '//p', result, 3
39
+ assert_xpath '//*[@id="preamble"]', result, 1
40
+ assert_xpath '//*[@id="preamble"]//p', result, 2
41
+ assert_xpath '//*[@id="preamble"]/following-sibling::*//h2[@id="_first_section"]', result, 1
42
+ assert_xpath '//*[@id="preamble"]/following-sibling::*//p', result, 1
43
+ end
44
+
45
+ test 'title and preamble only' do
46
+ input = <<-EOS
47
+ Title
48
+ =====
49
+
50
+ Preamble paragraph 1.
51
+ EOS
52
+ result = render_string(input)
53
+ assert_xpath '//p', result, 1
54
+ assert_xpath '//*[@id="preamble"]', result, 1
55
+ assert_xpath '//*[@id="preamble"]//p', result, 1
56
+ assert_xpath '//*[@id="preamble"]/following-sibling::*', result, 0
57
+ end
58
+
59
+ test 'title and section without preamble' do
60
+ input = <<-EOS
61
+ Title
62
+ =====
63
+
64
+ == First Section
65
+
66
+ Section paragraph 1.
67
+ EOS
68
+ result = render_string(input)
69
+ assert_xpath '//p', result, 1
70
+ assert_xpath '//*[@id="preamble"]', result, 0
71
+ assert_xpath '//h2[@id="_first_section"]', result, 1
72
+ end
73
+
74
+ test 'no title with preamble and section' do
75
+ input = <<-EOS
76
+ Preamble paragraph 1.
77
+
78
+ == First Section
79
+
80
+ Section paragraph 1.
81
+ EOS
82
+ result = render_string(input)
83
+ assert_xpath '//p', result, 2
84
+ assert_xpath '//*[@id="preamble"]', result, 0
85
+ assert_xpath '//h2[@id="_first_section"]/preceding::p', result, 1
86
+ end
87
+
88
+ end
data/test/test_helper.rb CHANGED
@@ -50,7 +50,8 @@ class Test::Unit::TestCase
50
50
  end
51
51
 
52
52
  def assert_xpath(xpath, html, count = nil)
53
- results = Nokogiri::HTML::DocumentFragment.parse(html).xpath(".#{xpath}")
53
+ doc = (html =~ /\s*<!DOCTYPE/) ? Nokogiri::HTML::Document.parse(html) : Nokogiri::HTML::DocumentFragment.parse(html)
54
+ results = doc.xpath("#{xpath.sub('/', './')}")
54
55
 
55
56
  if (count && results.length != count)
56
57
  flunk "XPath #{xpath} yielded #{results.length} elements rather than #{count} for:\n#{html}"
@@ -61,12 +62,12 @@ class Test::Unit::TestCase
61
62
  end
62
63
  end
63
64
 
64
- def document_from_string(src)
65
- Asciidoctor::Document.new(src.split("\n"))
65
+ def document_from_string(src, opts = {})
66
+ Asciidoctor::Document.new(src.lines.entries, opts)
66
67
  end
67
68
 
68
- def render_string(src)
69
- document_from_string(src).render
69
+ def render_string(src, opts = {})
70
+ document_from_string(src, opts).render
70
71
  end
71
72
  end
72
73
 
data/test/text_test.rb CHANGED
@@ -16,7 +16,8 @@ context "Text" do
16
16
  end
17
17
 
18
18
  test "separator" do
19
- assert_xpath "//hr", render_string("This is separated.\n\n'''\n\n...from this!"), 1
19
+ # for some reason, the html enclosure breaks the xpath //*[@id='content']//hr
20
+ assert_xpath "//*[@id='content']//hr", render_string("This is separated.\n\n'''\n\n...from this!"), 1
20
21
  end
21
22
 
22
23
  test "emphasized text" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-11 00:00:00.000000000 Z
13
+ date: 2012-12-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -118,7 +118,7 @@ extra_rdoc_files:
118
118
  - LICENSE
119
119
  files:
120
120
  - LICENSE
121
- - README.md
121
+ - README.asciidoc
122
122
  - Rakefile
123
123
  - asciidoctor.gemspec
124
124
  - bin/asciidoctor
@@ -145,8 +145,9 @@ files:
145
145
  - test/headers_test.rb
146
146
  - test/lexer_test.rb
147
147
  - test/links_test.rb
148
- - test/list_elements_test.rb
148
+ - test/lists_test.rb
149
149
  - test/paragraphs_test.rb
150
+ - test/preamble_test.rb
150
151
  - test/reader_test.rb
151
152
  - test/test_helper.rb
152
153
  - test/text_test.rb
@@ -181,7 +182,8 @@ test_files:
181
182
  - test/headers_test.rb
182
183
  - test/lexer_test.rb
183
184
  - test/links_test.rb
184
- - test/list_elements_test.rb
185
+ - test/lists_test.rb
185
186
  - test/paragraphs_test.rb
187
+ - test/preamble_test.rb
186
188
  - test/reader_test.rb
187
189
  - test/text_test.rb
data/README.md DELETED
@@ -1,154 +0,0 @@
1
- Asciidoctor
2
- ===========
3
-
4
- Asciidoctor is a pure-ruby processor for turning
5
- [Asciidoc](http://www.methods.co.nz/asciidoc/index.html) documents
6
- into HTML (and, eventually, other formats perhaps).
7
-
8
- Asciidoctor uses simple built-in ERB templates to style the output in
9
- a way that roughly matches the default HTML output of the native
10
- Python processor. You can override this behavior by providing
11
- [Tilt]-compatible templates. See the Usage section for more details.
12
-
13
- Asciidoctor currently works with Ruby 1.8.7 and 1.9.3, though I don't
14
- know of any reason it shouldn't work with more exotic Ruby versions,
15
- and would welcome help in testing that out.
16
-
17
- The initial code from which asciidoctor started was from the [Git SCM
18
- site repo][gitscm-next].
19
-
20
- [gitscm-next]: https://github.com/github/gitscm-next
21
-
22
- # Installation
23
-
24
- NOTE: This gem is very immature, and as yet only supports a small
25
- subset of Asciidoc features. Thus, you should only use it if you have
26
- a high tolerance for bugs, failures, and generally bad and intemperate
27
- behavior.
28
-
29
- To install the gem:
30
-
31
- gem install 'asciidoctor'
32
-
33
- Or if you prefer bundler:
34
-
35
- bundle install 'asciidoctor'
36
-
37
- # Usage
38
-
39
- To render a file of Asciidoc-marked-up text to html
40
-
41
- lines = File.readlines("your_file.asc")
42
- doc = Asciidoctor::Document.new(lines)
43
- html = doc.render
44
- File.open("your_file.html", "w+") do |file|
45
- file.puts html
46
- end
47
-
48
- Render an Asciidoc-formatted string
49
-
50
- doc = Asciidoctor::Document.new("*This* is it.")
51
- puts doc.render
52
-
53
- Asciidoctor allows you to override the default template used to render
54
- almost any individual Asciidoc elements. If you provide a directory of
55
- [Tilt]-compatible templates, named in a way Asciidoctor can figure out
56
- which template goes with which element, Asciidoctor will use the
57
- templates in this directory instead of its built-in templates for any
58
- elements for which it finds a matching template. It will use its
59
- default templates for everything else.
60
-
61
- doc = Asciidoctor::Document.new("*This* is it.", :template_dir => 'templates')
62
- puts doc.render
63
-
64
- The Document and Section templates should begin with `document.` and
65
- `section.`, respectively. The file extension will depend on which
66
- Tilt-compatible format you've chosen. For ERB, they would be
67
- `document.html.erb` and `section.html.erb`, for instance.
68
-
69
- Specific elements, like a Paragraph or Anchor, would begin with
70
- `section_<element>.`. So to override the default Paragraph template
71
- with an ERB template you'd put a file called
72
- `section_paragraph.html.erb` in the template directory you pass in to
73
- `Document.new`.
74
-
75
- For more usage examples, see the test suite.
76
-
77
- [Tilt]: https://github.com/rtomayko/tilt
78
-
79
- ## Contributing
80
- In the spirit of [free software][free-sw], **everyone** is encouraged to help
81
- improve this project.
82
-
83
- [free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
84
-
85
- Here are some ways *you* can contribute:
86
-
87
- * by using alpha, beta, and prerelease versions
88
- * by reporting bugs
89
- * by suggesting new features
90
- * by writing or editing documentation
91
- * by writing specifications
92
- * by writing code (**no patch is too small**: fix typos, add comments, clean up
93
- inconsistent whitespace)
94
- * by refactoring code
95
- * by fixing [issues][]
96
- * by reviewing patches
97
-
98
- [issues]: https://github.com/erebor/asciidoctor/issues
99
-
100
- ## Submitting an Issue
101
- We use the [GitHub issue tracker][issues] to track bugs and
102
- features. Before submitting a bug report or feature request, check to
103
- make sure it hasn't already been submitted. When submitting a bug
104
- report, please include a [Gist][] that includes any details that may
105
- help reproduce the bug, including your gem version, Ruby version, and
106
- operating system.
107
-
108
- Most importantly, since asciidoctor is a text processor, reproducing
109
- most bugs requires that we have some snippet of text on which
110
- asciidoctor exhibits the bad behavior.
111
-
112
- An ideal bug report would include a pull request with failing
113
- specs.
114
-
115
- [gist]: https://gist.github.com/
116
-
117
- ## Submitting a Pull Request
118
- 1. [Fork the repository.][fork]
119
- 2. [Create a topic branch.][branch]
120
- 3. Add tests for your unimplemented feature or bug fix.
121
- 4. Run `bundle exec rake`. If your tests pass, return to step 3.
122
- 5. Implement your feature or bug fix.
123
- 6. Run `bundle exec rake`. If your tests fail, return to step 5.
124
- 7. Add documentation for your feature or bug fix.
125
- 8. If your changes are not 100% documented, go back to step 7.
126
- 9. Add, commit, and push your changes.
127
- 10. [Submit a pull request.][pr]
128
-
129
- [fork]: http://help.github.com/fork-a-repo/
130
- [branch]: http://learn.github.com/p/branching.html
131
- [pr]: http://help.github.com/send-pull-requests/
132
-
133
- ## Supported Ruby Versions
134
- This library aims to support the following Ruby implementations:
135
-
136
- * Ruby 1.8.7
137
- * Ruby 1.9.3
138
-
139
- If something doesn't work on one of these interpreters, it should be
140
- considered a bug.
141
-
142
- If you would like this library to support another Ruby version, you
143
- may volunteer to be a maintainer. Being a maintainer entails making
144
- sure all tests run and pass on that implementation. When something
145
- breaks on your implementation, you will be personally responsible for
146
- providing patches in a timely fashion. If critical issues for a
147
- particular implementation exist at the time of a major release,
148
- support for that Ruby version may be dropped.
149
-
150
- ## Copyright
151
- Copyright (c) 2012 Ryan Waldron.
152
- See [LICENSE][] for details.
153
-
154
- [license]: https://github.com/erebor/asciidoctor/blob/master/LICENSE