paperwrap 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paperwrap (0.0.1)
4
+ paperwrap (0.0.2)
5
+ rubypants (>= 0.2.0)
5
6
 
6
7
  GEM
7
8
  remote: http://rubygems.org/
@@ -16,6 +17,7 @@ GEM
16
17
  rspec-expectations (2.8.0)
17
18
  diff-lcs (~> 1.1.2)
18
19
  rspec-mocks (2.8.0)
20
+ rubypants (0.2.0)
19
21
 
20
22
  PLATFORMS
21
23
  java
data/README.md CHANGED
@@ -3,4 +3,24 @@ Paperwrap
3
3
 
4
4
  A JRuby wrapper around the [MarkdownPapers](https://github.com/lruiz/MarkdownPapers) Java library.
5
5
 
6
- This wrapper was created so it could be used as a Markdown processor in the [jrucco](https://github.com/mindscratch/jrucco) documentation library.
6
+ This wrapper was created so it could be used as a Markdown processor in the [rocco](https://github.com/rtomayko/rocco) documentation library.
7
+
8
+ Usage
9
+ -----
10
+
11
+ ````ruby
12
+ # get some Markdown text
13
+ markdown_file = "" # file with markdown
14
+ markdown_text = File.open(markdown_file).read
15
+
16
+ # create the processor
17
+ m = Paperwrap::Markdown.new markdown_text
18
+
19
+ # generate HTML
20
+ html = m.to_html
21
+
22
+ # save it
23
+ File.open('sample.html', 'w') do |fh|
24
+ fh.write html
25
+ end
26
+ ````
@@ -0,0 +1,15 @@
1
+ require 'rubypants'
2
+
3
+ module Paperwrap
4
+ module Extensions
5
+ class SmartyHTML
6
+ def initialize(html, options=[1])
7
+ @pants = RubyPants.new html, options
8
+ end
9
+
10
+ def to_html
11
+ @pants.to_html
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require 'paperwrap/extensions/smarty_html'
2
+
3
+ module Paperwrap
4
+ module Extensions
5
+
6
+ HTML_EXT_MAP = {
7
+ :smart => Paperwrap::Extensions::SmartyHTML
8
+ }
9
+
10
+ end
11
+ end
@@ -5,12 +5,14 @@ Dir.glob("#{jars_path}/**/*.jar").each {|jar| require jar}
5
5
 
6
6
  module Paperwrap
7
7
  class Markdown
8
+
8
9
  def initialize(text, *extensions)
9
10
  @text = text
10
- # TODO support extensions (such as :smarty)
11
+ @html_extensions = prepare_html_extensions(extensions) || []
11
12
  end
12
13
 
13
14
  def to_html
15
+ # convert the Markdown text into HTML
14
16
  reader = java.io.StringReader.new @text
15
17
  writer = java.io.StringWriter.new
16
18
  html = ''
@@ -23,6 +25,33 @@ module Paperwrap
23
25
  writer.close if writer
24
26
  end
25
27
  html = writer.to_string
28
+
29
+ # apply html extensions
30
+ apply_html_extensions html
31
+ end
32
+
33
+ #########
34
+ protected
35
+ #########
36
+
37
+ def prepare_html_extensions(extensions)
38
+ result = nil
39
+ unless extensions.nil? || extensions.empty?
40
+ result = extensions.map do |ext|
41
+ Paperwrap::Extensions::HTML_EXT_MAP.fetch(ext, nil)
42
+ end.compact.uniq
43
+ end
44
+ result
45
+ end
46
+
47
+ def apply_html_extensions(html)
48
+ @html_extensions.inject(html) do |extended_html, extension_class|
49
+ apply_html_extension extension_class, extended_html
50
+ end
51
+ end
52
+
53
+ def apply_html_extension(html_extension_class, html)
54
+ html_extension_class.new(html).to_html
26
55
  end
27
56
  end
28
57
  end
data/lib/paperwrap.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'java'
2
+ require 'paperwrap/extensions'
2
3
  require 'paperwrap/markdown'
3
4
 
4
5
  module Paperwrap
5
- VERSION = '0.0.1'
6
+ VERSION = '0.0.2'
6
7
  end
data/paperwrap.gemspec CHANGED
@@ -13,8 +13,8 @@ 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 = 'paperwrap'
16
- s.version = '0.0.1'
17
- s.date = '2012-02-25'
16
+ s.version = '0.0.2'
17
+ s.date = '2012-02-28'
18
18
  s.rubyforge_project = 'paperwrap'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
 
41
41
  ## List your runtime dependencies here. Runtime dependencies are those
42
42
  ## that are needed for an end user to actually USE your code.
43
- ## s.add_dependency('DEPNAME', [">= 1.1.0", "< 2.0.0"])
43
+ s.add_dependency 'rubypants', '>= 0.2.0'
44
44
 
45
45
  ## List your development dependencies here. Development dependencies are
46
46
  ## those that are only needed during development
@@ -59,8 +59,11 @@ Gem::Specification.new do |s|
59
59
  Rakefile
60
60
  ext/java/jar/markdownpapers-core-1.2.3.jar
61
61
  lib/paperwrap.rb
62
+ lib/paperwrap/extensions.rb
63
+ lib/paperwrap/extensions/smarty_html.rb
62
64
  lib/paperwrap/markdown.rb
63
65
  paperwrap.gemspec
66
+ spec/paperwrap/extensions/smarty_html_spec.rb
64
67
  spec/paperwrap/markdown_spec.rb
65
68
  spec/spec_helper.rb
66
69
  ]
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'paperwrap'
3
+
4
+ module Paperwrap::Extensions
5
+ describe SmartyHTML do
6
+
7
+ context "given :smart option" do
8
+ it "generates HTML with SmartyPants extension applied" do
9
+ text = "Hello 'this' is a test!"
10
+ m = Paperwrap::Markdown.new text, :smart
11
+ html = m.to_html
12
+ first_quote = html.index("&#8216;")
13
+ last_quote = html.index("&#8217;")
14
+ first_quote.should be > 0
15
+ last_quote.should be > first_quote
16
+ end
17
+ end
18
+
19
+ end
20
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: paperwrap
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Craig Wickesser
@@ -10,21 +10,21 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-25 00:00:00 Z
13
+ date: 2012-02-28 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rake
16
+ name: rubypants
17
17
  prerelease: false
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
24
- type: :development
23
+ version: 0.2.0
24
+ type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
- name: rspec
27
+ name: rake
28
28
  prerelease: false
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
30
  none: false
@@ -34,6 +34,17 @@ dependencies:
34
34
  version: "0"
35
35
  type: :development
36
36
  version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id003
37
48
  description: A JRuby wrapper around [MarkdownPapers](https://github.com/lruiz/MarkdownPapers).
38
49
  email: craig@mindscratch.org
39
50
  executables: []
@@ -49,8 +60,11 @@ files:
49
60
  - Rakefile
50
61
  - ext/java/jar/markdownpapers-core-1.2.3.jar
51
62
  - lib/paperwrap.rb
63
+ - lib/paperwrap/extensions.rb
64
+ - lib/paperwrap/extensions/smarty_html.rb
52
65
  - lib/paperwrap/markdown.rb
53
66
  - paperwrap.gemspec
67
+ - spec/paperwrap/extensions/smarty_html_spec.rb
54
68
  - spec/paperwrap/markdown_spec.rb
55
69
  - spec/spec_helper.rb
56
70
  homepage: https://github.com/mindscratch/paperwrap