multi_markdown 0.1.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.*
3
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ doc/
3
+ pkg/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title "multi_markdown Documentation" --protected
data/ChangeLog.md ADDED
@@ -0,0 +1,4 @@
1
+ ### 0.1.0 / 2012-05-17
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'rspec', '~> 2.4'
6
+
7
+ gem 'kramdown', :require => nil, :group => [:kramdown]
8
+ gem 'rdiscount', :require => nil, :group => [:rdiscount]
9
+ gem 'redcarpet', :require => nil, :group => [:redcarpet]
10
+ gem 'rpeg-markdown', :require => nil, :group => [:rpeg_markdown]
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Hal Brodigan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # multi_markdown
2
+
3
+ * [Homepage](https://github.com/postmodern/multi_markdown#readme)
4
+ * [Issues](https://github.com/postmodern/multi_markdown/issues)
5
+ * [Documentation](http://rubydoc.info/gems/multi_markdown/frames)
6
+ * [Email](mailto:postmodern.mod3 at gmail.com)
7
+
8
+ ## Description
9
+
10
+ multi_markdown allows projects to use a wide variety of Markdown libraries,
11
+ without having to depend on a specific one.
12
+
13
+ ## Supported
14
+
15
+ * [kramdown](http://kramdown.rubyforge.org/)
16
+ * [rdiscount](https://github.com/rtomayko/rdiscount#readme)
17
+ * [redcarpet](https://github.com/tanoku/redcarpet#readme)
18
+ * [rpeg_markdown](https://github.com/rtomayko/rpeg-markdown#readme)
19
+
20
+ ## Examples
21
+
22
+ require 'multi_markdown'
23
+
24
+ MultiMarkdown.new('hello _world_').to_html
25
+ # => "<p>hello <em>world</em></p>\n"
26
+
27
+ ## Install
28
+
29
+ $ gem install multi_markdown
30
+
31
+ ## Copyright
32
+
33
+ Copyright (c) 2012 Hal Brodigan
34
+
35
+ See {file:LICENSE.txt} for details.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+
6
+ begin
7
+ gem 'rubygems-tasks', '~> 0.2'
8
+ require 'rubygems/tasks'
9
+
10
+ Gem::Tasks.new
11
+ rescue LoadError => e
12
+ warn e.message
13
+ warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
14
+ end
15
+
16
+ begin
17
+ gem 'rspec', '~> 2.4'
18
+ require 'rspec/core/rake_task'
19
+
20
+ RSpec::Core::RakeTask.new('spec:multi_markdown') do |spec|
21
+ spec.pattern = 'spec/multi_markdown_spec.rb'
22
+ end
23
+ task :spec => 'spec:multi_markdown'
24
+
25
+ Dir.glob('spec/libraries/*_spec.rb') do |path|
26
+ name = File.basename(path).chomp('_spec.rb')
27
+
28
+ namespace :spec do
29
+ RSpec::Core::RakeTask.new(name) do |spec|
30
+ spec.pattern = path
31
+ end
32
+ end
33
+
34
+ task :spec => "spec:#{name}"
35
+ end
36
+ rescue LoadError => e
37
+ task :spec do
38
+ abort "Please run `gem install rspec` to install RSpec."
39
+ end
40
+ end
41
+
42
+ task :test => :spec
43
+ task :default => :spec
44
+
45
+ begin
46
+ gem 'yard', '~> 0.7'
47
+ require 'yard'
48
+
49
+ YARD::Rake::YardocTask.new
50
+ rescue LoadError => e
51
+ task :yard do
52
+ abort "Please run `gem install yard` to install YARD."
53
+ end
54
+ end
55
+ task :doc => :yard
data/gemspec.yml ADDED
@@ -0,0 +1,15 @@
1
+ name: multi_markdown
2
+ summary: Allows switching between multiple Markdown libraries.
3
+ description:
4
+ multi_markdown allows projects to use a wide variety of Markdown libraries,
5
+ without having to depend on a specific one.
6
+
7
+ license: MIT
8
+ authors: Postmodern
9
+ email: postmodern.mod3@gmail.com
10
+ homepage: https://github.com/postmodern/multi_markdown#readme
11
+
12
+ development_dependencies:
13
+ rubygems-tasks: ~> 0.2
14
+ rspec: ~> 2.4
15
+ yard: ~> 0.7
@@ -0,0 +1,2 @@
1
+ require 'multi_markdown/multi_markdown'
2
+ require 'multi_markdown/version'
@@ -0,0 +1,125 @@
1
+ module MultiMarkdown
2
+ # Markdown library names
3
+ LIBRARIES = {
4
+ :kramdown => 'kramdown',
5
+ :rdiscount => 'rdiscount',
6
+ :redcarpet => 'redcarpet',
7
+ :rpeg_markdown => 'peg_markdown'
8
+ }
9
+
10
+ # Markdown Constants
11
+ CONSTANTS = {
12
+ :kramdown => 'Kramdown::Document',
13
+ :rdiscount => 'RDiscount',
14
+ :redcarpet => 'RedcarpetCompat',
15
+ :rpeg_markdown => 'PEGMarkdown'
16
+ }
17
+
18
+ # The loading priority
19
+ PRIORITY = [
20
+ :kramdown,
21
+ :rdiscount,
22
+ :redcarpet,
23
+ :rpeg_markdown
24
+ ]
25
+
26
+ @@markdown = nil
27
+
28
+ #
29
+ # Attempts to find the specific Markdown library.
30
+ #
31
+ # @param [Symbol] library
32
+ # The name of the markdown library.
33
+ #
34
+ # @raise [ArgumentError]
35
+ # Unknown Markdown library name.
36
+ #
37
+ # @raise [NameError]
38
+ # The constant for the Markdown library could not be found.
39
+ #
40
+ def self.find(library)
41
+ unless CONSTANTS.has_key?(library)
42
+ raise(ArgumentError,"unknown Markdown library: #{library}")
43
+ end
44
+
45
+ eval(CONSTANTS[library])
46
+ end
47
+
48
+ #
49
+ # Uses a specific Markdown library.
50
+ #
51
+ # @param [Symbol] library
52
+ # The name of the markdown library.
53
+ #
54
+ # @return [#new]
55
+ # The Markdown class.
56
+ #
57
+ # @raise [ArgumentError]
58
+ # Unknown Markdown library name.
59
+ #
60
+ # @raise [LoadError]
61
+ # The Markdown library could not be loaded.
62
+ #
63
+ # @raise [NameError]
64
+ # The constant for the Markdown library could not be found.
65
+ #
66
+ def self.use(library)
67
+ unless LIBRARIES.has_key?(library)
68
+ raise(ArgumentError,"unknown Markdown library: #{library}")
69
+ end
70
+
71
+ require LIBRARIES[library]
72
+
73
+ @@markdown = find(library)
74
+ end
75
+
76
+ #
77
+ # Attempts to find or load the first available Markdown library.
78
+ #
79
+ # @return [#new]
80
+ # The Markdown class.
81
+ #
82
+ # @raise [LoadError]
83
+ # None of the supported Markdown libraries could be found or loaded.
84
+ #
85
+ def self.load
86
+ # attempt to find an already loaded markdown library
87
+ PRIORITY.each do |library|
88
+ begin
89
+ return(@@markdown = find(library))
90
+ rescue NameError
91
+ end
92
+ end
93
+
94
+ PRIORITY.each do |library|
95
+ begin
96
+ return use(library)
97
+ rescue Gem::LoadError => e
98
+ # re-raise Gem::LoadErrors, as they are a sign of dependency issues
99
+ raise(e)
100
+ rescue LoadError
101
+ end
102
+ end
103
+
104
+ raise(LoadError,"could not load any of the markdown libraries")
105
+ end
106
+
107
+ #
108
+ # Loads the first available Markdown library and creates a Markdown document.
109
+ #
110
+ # @param [String] text
111
+ # Markdown text.
112
+ #
113
+ # @param [Hash{Symbol => Object}] options
114
+ # Additional options for the Markdown document.
115
+ #
116
+ # @return [#to_html]
117
+ # The Markdown document.
118
+ #
119
+ def self.new(text,options={})
120
+ load unless @@markdown
121
+
122
+ @@markdown.new(text,options)
123
+ end
124
+
125
+ end
@@ -0,0 +1,4 @@
1
+ module MultiMarkdown
2
+ # multi_markdown version
3
+ VERSION = "0.1.0.pre1"
4
+ end
@@ -0,0 +1,104 @@
1
+ # encoding: utf-8
2
+
3
+ require 'yaml'
4
+
5
+ Gem::Specification.new do |gemspec|
6
+ root = File.dirname(__FILE__)
7
+ lib_dir = File.join(root,'lib')
8
+ files = `git ls-files`.split($/)
9
+
10
+ filter_files = lambda { |paths|
11
+ files & case paths
12
+ when Array
13
+ paths
14
+ when String
15
+ Dir[paths]
16
+ end
17
+ }
18
+
19
+ version = {
20
+ :file => 'multi_markdown/version',
21
+ :constant => 'MultiMarkdown::VERSION'
22
+ }
23
+
24
+ defaults = {
25
+ 'name' => File.basename(root),
26
+ 'files' => files,
27
+ 'require_paths' => ['ext', 'lib'].select { |dir| File.directory?(dir) },
28
+ 'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
29
+ 'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
30
+ 'doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
31
+ 'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}']
32
+ }
33
+
34
+ metadata = defaults.merge(YAML.load_file('gemspec.yml'))
35
+
36
+ gemspec.name = metadata['name']
37
+ gemspec.version = if metadata['version']
38
+ metadata['version']
39
+ else
40
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
41
+
42
+ require version[:file]
43
+ eval(version[:constant])
44
+ end
45
+
46
+ gemspec.summary = metadata.fetch('summary',metadata['description'])
47
+ gemspec.description = metadata.fetch('description',metadata['summary'])
48
+
49
+ gemspec.licenses = Array(metadata['license'])
50
+ gemspec.authors = Array(metadata['authors'])
51
+
52
+ gemspec.email = metadata['email']
53
+ gemspec.homepage = metadata['homepage']
54
+
55
+ gemspec.require_paths = Array(metadata['require_paths'])
56
+ gemspec.files = filter_files[metadata['files']]
57
+ gemspec.executables = metadata['executables']
58
+ gemspec.extensions = metadata['extensions']
59
+
60
+ if Gem::VERSION < '1.7.'
61
+ gemspec.default_executable = gemspec.executables.first
62
+ end
63
+
64
+ gemspec.test_files = filter_files[metadata['test_files']]
65
+ gemspec.extra_rdoc_files = Array(metadata['extra_doc_files'])
66
+
67
+ gemspec.post_install_message = metadata['post_install_message']
68
+ gemspec.requirements = metadata['requirements']
69
+
70
+ if gemspec.respond_to?(:required_ruby_version=)
71
+ gemspec.required_ruby_version = metadata['required_ruby_version']
72
+ end
73
+
74
+ if gemspec.respond_to?(:required_rubygems_version=)
75
+ gemspec.required_rubygems_version = metadata['required_ruby_version']
76
+ end
77
+
78
+ parse_versions = lambda { |versions|
79
+ case versions
80
+ when Array
81
+ versions.map { |v| v.to_s }
82
+ when String
83
+ versions.split(/,\s*/)
84
+ end
85
+ }
86
+
87
+ if metadata['dependencies']
88
+ metadata['dependencies'].each do |name,versions|
89
+ gemspec.add_dependency(name,parse_versions[versions])
90
+ end
91
+ end
92
+
93
+ if metadata['runtime_dependencies']
94
+ metadata['runtime_dependencies'].each do |name,versions|
95
+ gemspec.add_runtime_dependency(name,parse_versions[versions])
96
+ end
97
+ end
98
+
99
+ if metadata['development_dependencies']
100
+ metadata['development_dependencies'].each do |name,versions|
101
+ gemspec.add_development_dependency(name,parse_versions[versions])
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe MultiMarkdown do
4
+ context "with kramdown" do
5
+ let(:library) { :kramdown }
6
+ let(:constant) { 'Kramdown::Document' }
7
+
8
+ before { Bundler.setup(library) }
9
+
10
+ describe "find" do
11
+ before { require 'kramdown' }
12
+
13
+ it "should find the Kramdown::Document" do
14
+ subject.find(library).name.should == constant
15
+ end
16
+ end
17
+
18
+ describe "use" do
19
+ it "should load and find Kramdown::Document" do
20
+ subject.use(library).name.should == constant
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe MultiMarkdown do
4
+ context "with rdiscount" do
5
+ let(:library) { :rdiscount }
6
+ let(:constant) { 'RDiscount' }
7
+
8
+ before { Bundler.setup(library) }
9
+
10
+ describe "find" do
11
+ before { require 'rdiscount' }
12
+
13
+ it "should find the RDiscount" do
14
+ subject.find(library).name.should == constant
15
+ end
16
+ end
17
+
18
+ describe "use" do
19
+ it "should load and find RDiscount" do
20
+ subject.use(library).name.should == constant
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe MultiMarkdown do
4
+ context "with redcarpet" do
5
+ let(:library) { :redcarpet }
6
+ let(:constant) { 'RedcarpetCompat' }
7
+
8
+ before { Bundler.setup(library) }
9
+
10
+ describe "find" do
11
+ before { require 'redcarpet' }
12
+
13
+ it "should find the RedcarpetCompat" do
14
+ subject.find(library).name.should == constant
15
+ end
16
+ end
17
+
18
+ describe "use" do
19
+ it "should load and find RedcarpetCompat" do
20
+ subject.use(library).name.should == constant
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe MultiMarkdown do
4
+ context "with rpeg_markdown" do
5
+ let(:library) { :rpeg_markdown }
6
+ let(:constant) { 'PEGMarkdown' }
7
+
8
+ before { Bundler.setup(library) }
9
+
10
+ describe "find" do
11
+ before { require 'peg_markdown' }
12
+
13
+ it "should find the PEGMarkdown" do
14
+ subject.find(library).name.should == constant
15
+ end
16
+ end
17
+
18
+ describe "use" do
19
+ it "should load and find PEGMarkdown" do
20
+ subject.use(library).name.should == constant
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'multi_markdown'
3
+
4
+ describe MultiMarkdown do
5
+ it "should have a VERSION constant" do
6
+ subject.const_get('VERSION').should_not be_empty
7
+ end
8
+
9
+ describe "find" do
10
+ it "should raise an ArgumentError for unknown libraries" do
11
+ lambda {
12
+ subject.find(:foo)
13
+ }.should raise_error(ArgumentError)
14
+ end
15
+
16
+ it "should raise a NameError when the library could not be found" do
17
+ lambda {
18
+ subject.find(:kramdown)
19
+ }.should raise_error(NameError)
20
+ end
21
+ end
22
+
23
+ describe "use" do
24
+ it "should raise an ArgumentError for unknown libraries" do
25
+ lambda {
26
+ subject.use(:foo)
27
+ }.should raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should raise a LoadError when the library could not be found" do
31
+ lambda {
32
+ subject.use(:kramdown)
33
+ }.should raise_error(LoadError)
34
+ end
35
+ end
36
+
37
+ describe "load" do
38
+ before { Bundler.setup(:redcarpet, :rdiscount) }
39
+
40
+ it "should load the first available library" do
41
+ subject.load.name.should == 'RDiscount'
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,18 @@
1
+ begin
2
+ require 'bundler'
3
+ rescue LoadError => e
4
+ warn e.message
5
+ warn "Run `gem install bundler` to install Bundler."
6
+ exit e.status_code
7
+ end
8
+
9
+ begin
10
+ Bundler.setup(:default)
11
+ rescue Bundler::BundlerError => e
12
+ warn e.message
13
+ warn "Run `bundle install` to install missing gems"
14
+ exit e.status_code
15
+ end
16
+
17
+ require 'rspec'
18
+ require 'multi_markdown'
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multi_markdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Postmodern
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rubygems-tasks
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.2'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.4'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.4'
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.7'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ description: multi_markdown allows projects to use a wide variety of Markdown libraries,
63
+ without having to depend on a specific one.
64
+ email: postmodern.mod3@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files:
68
+ - ChangeLog.md
69
+ - LICENSE.txt
70
+ - README.md
71
+ files:
72
+ - .document
73
+ - .gitignore
74
+ - .rspec
75
+ - .yardopts
76
+ - ChangeLog.md
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - gemspec.yml
82
+ - lib/multi_markdown.rb
83
+ - lib/multi_markdown/multi_markdown.rb
84
+ - lib/multi_markdown/version.rb
85
+ - multi_markdown.gemspec
86
+ - spec/libraries/kramdown_spec.rb
87
+ - spec/libraries/rdiscount_spec.rb
88
+ - spec/libraries/redcarpet_spec.rb
89
+ - spec/libraries/rpeg_markdown_spec.rb
90
+ - spec/multi_markdown_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://github.com/postmodern/multi_markdown#readme
93
+ licenses:
94
+ - MIT
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.24
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Allows switching between multiple Markdown libraries.
117
+ test_files:
118
+ - spec/libraries/kramdown_spec.rb
119
+ - spec/libraries/rdiscount_spec.rb
120
+ - spec/libraries/redcarpet_spec.rb
121
+ - spec/libraries/rpeg_markdown_spec.rb
122
+ - spec/multi_markdown_spec.rb