asciidoctor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of asciidoctor might be problematic. Click here for more details.

@@ -0,0 +1,32 @@
1
+ AsciiDoc User Guide
2
+ ===================
3
+ Stuart Rackham <srackham@gmail.com>
4
+ :Author Initials: SJR
5
+ :toc:
6
+ :icons:
7
+ :numbered:
8
+ :website: http://www.methods.co.nz/asciidoc/
9
+
10
+ AsciiDoc is a text document format for writing notes, documentation,
11
+ articles, books, ebooks, slideshows, web pages, blogs and UNIX man
12
+ pages.
13
+
14
+ .This document
15
+ **********************************************************************
16
+ This is an overly large document, it probably needs to be refactored
17
+ into a Tutorial, Quick Reference and Formal Reference.
18
+
19
+ If you're new to AsciiDoc read this section and the <<X6,Getting
20
+ Started>> section and take a look at the example AsciiDoc (`*.txt`)
21
+ source files in the distribution `doc` directory.
22
+ **********************************************************************
23
+
24
+
25
+ Introduction
26
+ ------------
27
+ AsciiDoc is a plain text human readable/writable document format that
28
+ can be translated to DocBook or HTML using the asciidoc(1) command.
29
+
30
+ asciidoc(1) comes with a set of configuration files to translate
31
+ AsciiDoc articles, books and man pages to HTML or DocBook backend
32
+ formats.
@@ -0,0 +1,10 @@
1
+ AsciiDoc Home Page
2
+ ==================
3
+
4
+ Example Articles
5
+ ~~~~~~~~~~~~~~~~
6
+ - Item 1
7
+
8
+ - Item 2
9
+
10
+ - Item 3
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ context "Headers" do
4
+ test "main header" do
5
+ assert_xpath "//h1", render_string("My Title\n=======")
6
+ end
7
+
8
+ context "level 1" do
9
+ test "with multiline syntax" do
10
+ assert_xpath "//h2", render_string("My Section\n-----------")
11
+ end
12
+
13
+ test "with single line syntax" do
14
+ assert_xpath "//h2", render_string("== My Title")
15
+ end
16
+ end
17
+
18
+ context "level 2" do
19
+ test "with multiline syntax" do
20
+ assert_xpath "//h3", render_string("My Section\n~~~~~~~~~~~")
21
+ end
22
+
23
+ test "with single line syntax" do
24
+ assert_xpath "//h3", render_string("=== My Title")
25
+ end
26
+ end
27
+
28
+ context "level 3" do
29
+ test "with multiline syntax" do
30
+ assert_xpath "//h4", render_string("My Section\n^^^^^^^^^^")
31
+ end
32
+
33
+ test "with single line syntax" do
34
+ assert_xpath "//h4", render_string("==== My Title")
35
+ end
36
+ end
37
+
38
+ context "level 4" do
39
+ test "with multiline syntax" do
40
+ assert_xpath "//h5", render_string("My Section\n++++++++++")
41
+ end
42
+
43
+ test "with single line syntax" do
44
+ assert_xpath "//h5", render_string("===== My Title")
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ context "Bulleted lists (:ulist)" do
4
+ context "Simple lists" do
5
+ test "dash elements with no blank lines" do
6
+ output = render_string("Blah\n====\n- Foo\n- Boo\n- Blech")
7
+ assert_xpath '//ul', output, 1
8
+ assert_xpath '//ul/li', output, 3
9
+ end
10
+
11
+ test "dash elements with blank lines" do
12
+ assert_xpath '//ul/li', render_string("Blah\n====\n- Foo\n\n- Boo\n\n- Blech"), 3
13
+ end
14
+
15
+ test "asterisk elements with no blank lines" do
16
+ assert_xpath '//ul/li', render_string("Blah\n====\n* Foo\n* Boo\n* Blech"), 3
17
+ end
18
+
19
+ test "asterisk elements with blank lines" do
20
+ assert_xpath '//ul/li', render_string("Blah\n====\n* Foo\n\n* Boo\n\n* Blech"), 3
21
+ end
22
+ end
23
+
24
+ context "Nested lists" do
25
+ test "nested mixed elements (asterisk and dash)" do
26
+ output = render_string("Blah\n====\n- Foo\n* Boo\n- Blech")
27
+ assert_xpath '//ul', output, 1
28
+ assert_xpath '//ul/li', output, 3
29
+ end
30
+
31
+ test "nested elements (2) with asterisks" do
32
+ output = render_string("Blah\n====\n* Foo\n** Boo\n* Blech")
33
+ assert_xpath '//ul', output, 2
34
+ assert_xpath '//ul/li', output, 3
35
+ end
36
+
37
+ test "nested elements (3) with asterisks" do
38
+ output = render_string("Blah\n====\n* Foo\n** Boo\n*** Snoo\n* Blech")
39
+ assert_xpath '//ul', output, 3
40
+ assert_xpath '//ul/li', output, 4
41
+ end
42
+
43
+ test "nested elements (4) with asterisks" do
44
+ output = render_string("Blah\n====\n* Foo\n** Boo\n*** Snoo\n**** Froo\n* Blech")
45
+ assert_xpath '//ul', output, 4
46
+ assert_xpath '//ul/li', output, 5
47
+ end
48
+
49
+ test "nested elements (5) with asterisks" do
50
+ output = render_string("Blah\n====\n* Foo\n** Boo\n*** Snoo\n**** Froo\n***** Groo\n* Blech")
51
+ assert_xpath '//ul', output, 5
52
+ assert_xpath '//ul/li', output, 6
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ context "Paragraphs" do
4
+ test "rendered correctly" do
5
+ assert_xpath "//p", render_string("Plain text for the win.\n\nYes, plainly."), 2
6
+ end
7
+
8
+ test "with title" do
9
+ rendered = render_string(".Titled\nParagraph.\n\nWinning")
10
+
11
+ assert_xpath "//div[@class='title']", rendered
12
+ assert_xpath "//p", rendered, 2
13
+ end
14
+
15
+ context "code" do
16
+ test "literal paragraph" do
17
+ assert_xpath "//pre/tt", render_string(" LITERALS\n\n ARE LITERALLY\n\n AWESOMMMME.")
18
+ end
19
+
20
+ test "listing paragraph" do
21
+ assert_xpath "//div[@class='highlight']", render_string("----\nblah blah blah\n----")
22
+ end
23
+
24
+ test "source code paragraph" do
25
+ assert_xpath "//div[@class='highlight']", render_string("[source, perl]\ndie 'zomg perl sucks';")
26
+ end
27
+ end
28
+
29
+ context "special" do
30
+ test "note multiline syntax" do
31
+ assert_xpath "//div[@class='admonitionblock']", render_string("[NOTE]\nThis is a winner.")
32
+ end
33
+
34
+ test "note inline syntax" do
35
+ assert_xpath "//div[@class='admonitionblock']", render_string("NOTE: This is important, fool!")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,143 @@
1
+ require 'fileutils'
2
+ require 'test/unit'
3
+
4
+ require "#{File.expand_path(File.dirname(__FILE__))}/../lib/asciidoctor.rb"
5
+
6
+ require 'mocha'
7
+ require 'htmlentities'
8
+ require 'nokogiri'
9
+
10
+ ENV['SUPPRESS_DEBUG'] = 'true'
11
+
12
+ class Test::Unit::TestCase
13
+ def sample_doc_path(name)
14
+ name = name.to_s
15
+ unless name.include?('.')
16
+ ['asciidoc', 'txt'].each do |ext|
17
+ if File.exist?(fixture_path("#{name}.#{ext}"))
18
+ name = "#{name}.#{ext}"
19
+ break
20
+ end
21
+ end
22
+ end
23
+ fixture_path(name)
24
+ end
25
+
26
+ def fixture_path(name)
27
+ File.join(File.dirname(__FILE__), "fixtures", name )
28
+ end
29
+
30
+ def example_document(name)
31
+ Asciidoctor::Document.new(File.readlines(sample_doc_path(name)))
32
+ end
33
+
34
+ def assert_difference(expression, difference = 1, message = nil, &block)
35
+ expressions = [expression]
36
+
37
+ exps = expressions.map { |e|
38
+ e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
39
+ }
40
+ before = exps.map { |e| e.call }
41
+
42
+ yield
43
+
44
+ expressions.zip(exps).each_with_index do |(code, e), i|
45
+ error = "#{code.inspect} didn't change by #{difference}"
46
+ error = "#{message}.\n#{error}" if message
47
+ assert_equal(before[i] + difference, e.call, error)
48
+ end
49
+ end
50
+
51
+ def assert_xpath(xpath, html, count = nil)
52
+ results = Nokogiri::HTML::DocumentFragment.parse(html).xpath(".#{xpath}")
53
+
54
+ if (count && results.length != count)
55
+ flunk "XPath #{xpath} yielded #{results.length} elements rather than #{count} for:\n#{html}"
56
+ elsif (count.nil? && results.empty?)
57
+ flunk "XPath #{xpath} not found in:\n#{html}"
58
+ else
59
+ assert true
60
+ end
61
+ end
62
+
63
+ def render_string(src)
64
+ Asciidoctor::Document.new(src.split("\n")).render
65
+ end
66
+ end
67
+
68
+ ###
69
+ #
70
+ # Context goodness provided by @citrusbyte's contest
71
+ #
72
+ ###
73
+
74
+ # Test::Unit loads a default test if the suite is empty, whose purpose is to
75
+ # fail. Since having empty contexts is a common practice, we decided to
76
+ # overwrite TestSuite#empty? in order to allow them. Having a failure when no
77
+ # tests have been defined seems counter-intuitive.
78
+ class Test::Unit::TestSuite
79
+ def empty?
80
+ false
81
+ end
82
+ end
83
+
84
+ # Contest adds +teardown+, +test+ and +context+ as class methods, and the
85
+ # instance methods +setup+ and +teardown+ now iterate on the corresponding
86
+ # blocks. Note that all setup and teardown blocks must be defined with the
87
+ # block syntax. Adding setup or teardown instance methods defeats the purpose
88
+ # of this library.
89
+ class Test::Unit::TestCase
90
+ def self.setup(&block)
91
+ define_method :setup do
92
+ super(&block)
93
+ instance_eval(&block)
94
+ end
95
+ end
96
+
97
+ def self.teardown(&block)
98
+ define_method :teardown do
99
+ instance_eval(&block)
100
+ super(&block)
101
+ end
102
+ end
103
+
104
+ def self.context(*name, &block)
105
+ subclass = Class.new(self)
106
+ remove_tests(subclass)
107
+ subclass.class_eval(&block) if block_given?
108
+ const_set(context_name(name.join(" ")), subclass)
109
+ end
110
+
111
+ def self.test(name, &block)
112
+ define_method(test_name(name), &block)
113
+ end
114
+
115
+ class << self
116
+ alias_method :should, :test
117
+ alias_method :describe, :context
118
+ end
119
+
120
+ private
121
+
122
+ def self.context_name(name)
123
+ "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
124
+ end
125
+
126
+ def self.test_name(name)
127
+ "test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym
128
+ end
129
+
130
+ def self.sanitize_name(name)
131
+ name.gsub(/\W+/, ' ').strip
132
+ end
133
+
134
+ def self.remove_tests(subclass)
135
+ subclass.public_instance_methods.grep(/^test_/).each do |meth|
136
+ subclass.send(:undef_method, meth.to_sym)
137
+ end
138
+ end
139
+ end
140
+
141
+ def context(*name, &block)
142
+ Test::Unit::TestCase.context(name, &block)
143
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ context "Text" do
4
+ test "line breaks" do
5
+ assert_xpath "//br", render_string("Well this is +\njust fine and dandy, isn't it?"), 1
6
+ end
7
+
8
+ test "quotes" do
9
+ rendered = render_string("``Where?,'' she said, flipping through her copy of `The New Yorker.'")
10
+ assert_match /&rdquo;/, rendered
11
+ assert_match /&ldquo;/, rendered
12
+ assert_match /&rsquo;/, rendered
13
+ assert_match /&lsquo;/, rendered
14
+ end
15
+
16
+ test "separator" do
17
+ assert_xpath "//hr", render_string("This is separated.\n\n''''\n\n...from this!"), 1
18
+ end
19
+
20
+ test "emphasized quotes" do
21
+ assert_xpath "//em", render_string("An 'emphatic' no")
22
+ end
23
+
24
+ test "unquoted text" do
25
+ assert_no_match /#/, render_string("An #unquoted# word")
26
+ end
27
+
28
+ context "basic styling" do
29
+ setup do
30
+ @rendered = render_string("A *BOLD* word. An _italic_ word. A +mono+ word. ^superscript!^ and some ~subscript~.")
31
+ end
32
+
33
+ test "bold" do
34
+ assert_xpath "//strong", @rendered
35
+ end
36
+
37
+ test "italic" do
38
+ assert_xpath "//em", @rendered
39
+ end
40
+
41
+ test "monospaced" do
42
+ assert_xpath "//tt", @rendered
43
+ end
44
+
45
+ test "superscript" do
46
+ assert_xpath "//sup", @rendered
47
+ end
48
+
49
+ test "subscript" do
50
+ assert_xpath "//sub", @rendered
51
+ end
52
+
53
+ test "backticks" do
54
+ assert_xpath "//tt", render_string("This is `totally cool`.")
55
+ end
56
+
57
+ test "combined styles" do
58
+ rendered = render_string("Winning *big _time_* in the +city *boyeeee*+.")
59
+
60
+ assert_xpath "//strong/em", rendered
61
+ assert_xpath "//tt/strong", rendered
62
+ end
63
+
64
+ test "characters" do
65
+ rendered_chars = render_string("**B**__I__++M++")
66
+ assert_xpath "//strong", rendered_chars
67
+ assert_xpath "//em", rendered_chars
68
+ assert_xpath "//tt", rendered_chars
69
+ end
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoctor
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ryan Waldron
14
+ - Jeremy McAnally
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-06-14 00:00:00 -05:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: json
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: nokogiri
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: mocha
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: nokogiri
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: htmlentities
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ description: Render all the AsciiDocs! The time, she is now, for all good renders.
93
+ email: rew@erebor.com
94
+ executables:
95
+ - asciidoctor
96
+ extensions: []
97
+
98
+ extra_rdoc_files:
99
+ - LICENSE
100
+ files:
101
+ - LICENSE
102
+ - README.md
103
+ - Rakefile
104
+ - asciidoctor.gemspec
105
+ - bin/asciidoctor
106
+ - lib/asciidoctor.rb
107
+ - lib/asciidoctor/block.rb
108
+ - lib/asciidoctor/debug.rb
109
+ - lib/asciidoctor/document.rb
110
+ - lib/asciidoctor/errors.rb
111
+ - lib/asciidoctor/list_item.rb
112
+ - lib/asciidoctor/render_templates.rb
113
+ - lib/asciidoctor/renderer.rb
114
+ - lib/asciidoctor/section.rb
115
+ - lib/asciidoctor/string.rb
116
+ - lib/asciidoctor/version.rb
117
+ - noof.rb
118
+ - test/document_test.rb
119
+ - test/fixtures/asciidoc.txt
120
+ - test/fixtures/asciidoc_index.txt
121
+ - test/fixtures/ascshort.txt
122
+ - test/fixtures/list_elements.asciidoc
123
+ - test/headers_test.rb
124
+ - test/list_elements_test.rb
125
+ - test/paragraphs_test.rb
126
+ - test/test_helper.rb
127
+ - test/text_test.rb
128
+ has_rdoc: true
129
+ homepage: http://github.com/erebor/asciidoctor
130
+ licenses: []
131
+
132
+ post_install_message:
133
+ rdoc_options:
134
+ - --charset=UTF-8
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 3
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ requirements: []
156
+
157
+ rubyforge_project: asciidoctor
158
+ rubygems_version: 1.6.2
159
+ signing_key:
160
+ specification_version: 2
161
+ summary: Pure Ruby Asciidoc to HTML rendering.
162
+ test_files:
163
+ - test/document_test.rb
164
+ - test/headers_test.rb
165
+ - test/list_elements_test.rb
166
+ - test/paragraphs_test.rb
167
+ - test/text_test.rb