Permalink
Browse files

register embedded engine for asciidoc

- asciidoc content handled by Asciidoctor by way of Tilt 1.3.4
- document embedded asciidoc engine to README.md
- add asciidoctor as development dependency
  • Loading branch information...
1 parent c2c2c80 commit 536f5501674ca8dd1155477c741058a175b09c00 @mojavelinux mojavelinux committed Mar 2, 2013
Showing with 58 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +5 −0 README.md
  3. +1 −0 lib/slim/embedded.rb
  4. +51 −0 test/core/test_embedded_engines.rb
View
@@ -39,6 +39,7 @@ gem 'minitest'
gem 'kramdown'
gem 'creole'
gem 'builder'
+gem 'asciidoctor'
if ENV['TASK'] == 'bench'
gem 'erubis'
View
@@ -573,6 +573,7 @@ Supported engines:
<tr><td>less:</td><td>less</td><td>Compile time</td><td>Embed less css code and wrap in style tag</td></tr>
<tr><td>styl:</td><td>styl</td><td>Compile time</td><td>Embed stylus css code and wrap in style tag</td></tr>
<tr><td>coffee:</td><td>coffee-script</td><td>Compile time</td><td>Compile coffee script code and wrap in script tag</td></tr>
+<tr><td>asciidoc:</td><td>asciidoctor</td><td>Compile time + Interpolation</td><td>Compile AsciiDoc code and interpolate #\{variables} in text</td></tr>
<tr><td>markdown:</td><td>redcarpet/rdiscount/kramdown</td><td>Compile time + Interpolation</td><td>Compile markdown code and interpolate #\{variables} in text</td></tr>
<tr><td>textile:</td><td>redcloth</td><td>Compile time + Interpolation</td><td>Compile textile code and interpolate #\{variables} in text</td></tr>
<tr><td>creole:</td><td>creole</td><td>Compile time + Interpolation</td><td>Compile creole code and interpolate #\{variables} in text</td></tr>
@@ -588,6 +589,10 @@ The embedded engines can be configured in Slim by setting the options directly o
Slim::Embedded.default_options[:markdown] = {:auto_ids => false}
+Similarly, you can configure the AsciiDoc engine as follows:
+
+ Slim::Embedded.default_options[:asciidoc] = {:header_footer => true, :attributes => {'sectids!' => ''}}
+
## Configuring Slim
Slim and the underlying [Temple](https://github.com/judofyr/temple) framework are highly configurable.
View
@@ -241,6 +241,7 @@ def on_slim_embedded(engine, body)
end
# These engines are executed at compile time, embedded ruby is interpolated
+ register :asciidoc, InterpolateTiltEngine
register :markdown, InterpolateTiltEngine
register :textile, InterpolateTiltEngine
register :rdoc, InterpolateTiltEngine
@@ -14,6 +14,57 @@ def test_render_with_erb
assert_html "<p><b>Hello from BEFORE ERB BLOCK!</b>\nSecond Line!\ntrue</p>", source
end
+ def test_wip_render_with_asciidoc
+ source = %q{
+asciidoc:
+ == Header
+ Hello from #{"AsciiDoc!"}
+
+ #{1+2}
+
+ * one
+ * two
+}
+
+ expected = <<-EOS
+<div class="sect1">
+<h2 id="_header">Header</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>Hello from AsciiDoc!</p>
+</div>
+<div class="paragraph">
+<p>3</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p>one</p>
+</li>
+<li>
+<p>two</p>
+</li>
+</ul>
+</div>
+</div>
+</div>
+ EOS
+ # render, then remove blank lines and unindent the remaining lines
+ output = render(source).gsub(/^ *(\n|(?=[^ ]))/, '')
+
+ assert_equal expected, output
+
+ Slim::Embedded.with_options(:asciidoc => {:compact => true, :attributes => {'sectids!' => ''}}) do
+ # render, then unindent lines
+ output = render(source).gsub(/^ *(?=[^ ])/, '')
+ assert_equal expected.gsub('<h2 id="_header">', '<h2>'), output
+ end
+
+ # render again, then remove blank lines and unindent the remaining lines
+ output = render(source).gsub(/^ *(\n|(?=[^ ]))/, '')
+ assert_equal expected, output
+ end
+
def test_render_with_markdown
source = %q{
markdown:

0 comments on commit 536f550

Please sign in to comment.