literati 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
 
3
3
  module Literati
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
 
6
6
  # Render the given content to HTML.
7
7
  #
@@ -13,20 +13,57 @@ module Literati
13
13
  end
14
14
 
15
15
  # A simple class to wrap passing the right arguments to RedCarpet.
16
- class RedCarpetRenderer
16
+ class MarkdownRenderer
17
+ class GitHubWrapper
18
+ def initialize(content)
19
+ @content = content
20
+ end
21
+
22
+ def to_html
23
+ GitHub::Markdown.render(@content)
24
+ end
25
+ end
26
+
17
27
  # Create a new compatibility instance.
18
28
  #
19
29
  # content - The Markdown content to render.
20
30
  def initialize(content)
21
- require 'redcarpet/compat'
22
31
  @content = content
23
32
  end
24
33
 
34
+ def determine_markdown_renderer
35
+ @markdown = if installed?('github/markdown')
36
+ GitHubWrapper.new(@content)
37
+ elsif installed?('redcarpet/compat')
38
+ Markdown.new(@content, :fenced_code, :safelink, :autolink)
39
+ elsif installed?('redcarpet')
40
+ RedcarpetCompat.new(@content)
41
+ elsif installed?('rdiscount')
42
+ RDiscount.new(@content)
43
+ elsif installed?('maruku')
44
+ Maruku.new(@content)
45
+ elsif installed?('kramdown')
46
+ Kramdown::Document.new(@content)
47
+ elsif installed?('bluecloth')
48
+ BlueCloth.new(@content)
49
+ end
50
+ end
51
+
52
+ def installed?(file)
53
+ begin
54
+ require file
55
+ true
56
+ rescue LoadError
57
+ false
58
+ end
59
+ end
60
+
25
61
  # Render the Markdown content to HTML. We use GFM-esque options here.
26
62
  #
27
63
  # Returns an HTML string.
28
64
  def to_html
29
- Markdown.new(@content, :fenced_code, :safelink, :autolink).to_html
65
+ determine_markdown_renderer
66
+ @markdown.to_html
30
67
  end
31
68
  end
32
69
 
@@ -43,7 +80,7 @@ module Literati
43
80
  # content - The literate Haskell code string
44
81
  # markdowner - The class we'll use to render the HTML (defaults
45
82
  # to our RedCarpet wrapper).
46
- def initialize(content, markdowner = RedCarpetRenderer)
83
+ def initialize(content, markdowner = MarkdownRenderer)
47
84
  @bare_content = content
48
85
  @markdown = to_markdown
49
86
  @markdown_class = markdowner
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'literati'
16
- s.version = '0.0.1'
16
+ s.version = '0.0.2'
17
17
  s.date = '2012-10-31'
18
18
  s.rubyforge_project = 'literati'
19
19
 
@@ -44,15 +44,11 @@ class LiteratiTest < Test::Unit::TestCase
44
44
  end
45
45
 
46
46
  context "HTML rendering" do
47
- test "renders to HTML using RedCarpet by default" do
48
- Literati::RedCarpetRenderer.any_instance.expects(:to_html)
47
+ test "renders to HTML using our Smart Renderer™ by default" do
48
+ Literati::MarkdownRenderer.any_instance.expects(:to_html)
49
49
  Literati.render("markdown\n\n> codes\n\nmoar markdown")
50
50
  end
51
-
52
- test "RedCarpet options are turned on properly" do
53
- assert_match /class=\"haskell\"/m, Literati.render("markdown\n\n> codes\n\nmoar markdown")
54
- end
55
-
51
+
56
52
  test "can use other Markdown class" do
57
53
  DummyRenderer.any_instance.expects(:to_html)
58
54
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: literati
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy McAnally