multimarkdown-cli 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.gitmodules +3 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +17 -0
- data/LICENSE +20 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/multimarkdown-cli/version.rb +3 -0
- data/lib/multimarkdown-cli.rb +49 -0
- data/multimarkdown-cli.gemspec +26 -0
- data/test/all_tests.rb +9 -0
- data/test/test_beamer.rb +13 -0
- data/test/test_compat.rb +13 -0
- data/test/test_markdown.rb +13 -0
- data/test/test_memoir.rb +13 -0
- data/test/test_mmd.rb +14 -0
- data/test/test_writer.rb +58 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 09aae7f2a12d2b2bde33ddc689d422e69a672e70
|
4
|
+
data.tar.gz: 8ab81ce10a0e9c99860f1cf5a00244a45319b842
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ef7c2c5d3542e91d2c47fe5c0cb487e453ca2d864703a9507001ab7e35c091154054c8655d1d5319bb23d1a0325293ad927eea0cf1179e144ecd5955df6c6268
|
7
|
+
data.tar.gz: e52683072e60768366714142bbca08da14eed4c3a6eb755ad62d70c9b45c37f4964fdef5934b62dbae3288cb82915ae859113bea028b843a02523db0a09bea91
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Tom Torsney-Weir
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Multimarkdown
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'multimarkdown-cli'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install multimarkdown-cli
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "multimarkdown-cli/version"
|
2
|
+
|
3
|
+
# check that the command line tool is installed when requiring
|
4
|
+
# from http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
|
5
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
6
|
+
mmd_cmd_found = false
|
7
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
8
|
+
exts.each do |ext|
|
9
|
+
exe = File.join(path, "multimarkdown#{ext}")
|
10
|
+
if File.executable? exe
|
11
|
+
mmd_cmd_found = true
|
12
|
+
break
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
raise "Can't find the multimarkdown command in your path. Please install it" if !mmd_cmd_found
|
17
|
+
|
18
|
+
module MultiMarkdownCLI
|
19
|
+
class Parser
|
20
|
+
attr_reader :source
|
21
|
+
|
22
|
+
attr_accessor :compatibility
|
23
|
+
|
24
|
+
attr_accessor :snippet
|
25
|
+
|
26
|
+
def initialize(source, *options)
|
27
|
+
@source = source
|
28
|
+
|
29
|
+
@compatibility = false
|
30
|
+
@snippet = false
|
31
|
+
options.each {|o| send("#{o}=", true)}
|
32
|
+
end
|
33
|
+
def convert(format)
|
34
|
+
cmd = "multimarkdown"
|
35
|
+
cmd += " -c" if @compatibility
|
36
|
+
cmd += " -s" if @snippet
|
37
|
+
require 'open3'
|
38
|
+
stdout, stderr, status = Open3.capture3("#{cmd} -t #{format}",
|
39
|
+
:stdin_data=>@source)
|
40
|
+
if status.exitstatus != 0
|
41
|
+
raise stderr
|
42
|
+
end
|
43
|
+
stdout
|
44
|
+
end
|
45
|
+
def to_html
|
46
|
+
self.convert("html")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'multimarkdown-cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "multimarkdown-cli"
|
8
|
+
spec.version = MultimarkdownCLI::VERSION
|
9
|
+
spec.authors = ["Thomas Torsney-Weir"]
|
10
|
+
spec.email = ["torsneyt@gmail.com"]
|
11
|
+
spec.description = <<-EOF
|
12
|
+
A Ruby extension that can process MultiMarkdown-formatted
|
13
|
+
text using the multimarkdown command line tool.
|
14
|
+
EOF
|
15
|
+
spec.summary = %q{An interface to the multimarkdown command line tool}
|
16
|
+
spec.homepage = "https://github.com/gabysbrain/rb-MultiMarkdown-4"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files`.split($/)
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
data/test/all_tests.rb
ADDED
data/test/test_beamer.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'multimarkdown-cli'
|
6
|
+
require_relative 'test_writer'
|
7
|
+
|
8
|
+
class BeamerSuiteTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
# dynamically create the test functions based on the source files
|
11
|
+
build_tests("BeamerTests", {:exclude_exts => ["html"], :ext_map => {'tex'=>'beamer'}})
|
12
|
+
end
|
13
|
+
|
data/test/test_compat.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'multimarkdown-cli'
|
6
|
+
require_relative 'test_writer'
|
7
|
+
|
8
|
+
class CompatSuiteTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
# dynamically create the test functions based on the source files
|
11
|
+
build_tests("CompatibilityTests", options: [:compatibility])
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'multimarkdown-cli'
|
6
|
+
require_relative 'test_writer'
|
7
|
+
|
8
|
+
class MarkdownSuiteTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
# dynamically create the test functions based on the source files
|
11
|
+
build_tests("Tests", {:use_tidy => true, :options => [:compatibility]})
|
12
|
+
end
|
13
|
+
|
data/test/test_memoir.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'multimarkdown-cli'
|
6
|
+
require_relative 'test_writer'
|
7
|
+
|
8
|
+
class MemoirSuiteTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
# dynamically create the test functions based on the source files
|
11
|
+
build_tests("MemoirTests", {:exclude_exts => ["html"]})
|
12
|
+
end
|
13
|
+
|
data/test/test_mmd.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
$: << File.join(File.dirname(__FILE__), "../lib")
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'multimarkdown-cli'
|
6
|
+
require_relative 'test_writer'
|
7
|
+
|
8
|
+
class MultiMarkdownSuiteTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
# dynamically create the test functions based on the source files
|
11
|
+
build_tests("MultiMarkdownTests")
|
12
|
+
|
13
|
+
end
|
14
|
+
|
data/test/test_writer.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
BASE_TEST_DIR = File.absolute_path(File.join(File.dirname(__FILE__), "MMD-Test-Suite"))
|
3
|
+
|
4
|
+
EXT_MAP = {
|
5
|
+
'tex' => 'latex',
|
6
|
+
'fodt' => 'odf'
|
7
|
+
}
|
8
|
+
|
9
|
+
def build_tests(subdir, use_tidy: false, exclude_exts: [], ext_map: {}, options: [])
|
10
|
+
# merge the extension map
|
11
|
+
ext_map = EXT_MAP.merge(ext_map)
|
12
|
+
|
13
|
+
test_dir = File.join(BASE_TEST_DIR, subdir)
|
14
|
+
Dir.glob(File.join(test_dir, "*.text")).each do |source|
|
15
|
+
test_rawname = File.basename(source, ".text")
|
16
|
+
test_targets = Dir.glob(File.join(test_dir, test_rawname+".*"))
|
17
|
+
test_targets.select! {|fname| not fname.end_with?(".text")}
|
18
|
+
target_formats = test_targets.map {|fn| File.extname(fn)[1..-1]}
|
19
|
+
exclude_exts.each do |ext|
|
20
|
+
target_formats.select! {|tgt| tgt != ext}
|
21
|
+
end
|
22
|
+
target_formats.each do |target|
|
23
|
+
test_name = test_rawname.gsub(" ", "_").gsub(',', '').downcase
|
24
|
+
test_name = "test_#{test_name}_to_#{target}"
|
25
|
+
target_file = test_rawname + '.' + target
|
26
|
+
|
27
|
+
# filter some of the target => extension maps
|
28
|
+
target = if ext_map.include? target
|
29
|
+
ext_map[target]
|
30
|
+
else
|
31
|
+
target
|
32
|
+
end
|
33
|
+
|
34
|
+
# test code is here
|
35
|
+
define_method(test_name) do
|
36
|
+
orig_dir = Dir.pwd
|
37
|
+
Dir.chdir(File.join(BASE_TEST_DIR, subdir))
|
38
|
+
source_txt = File.read(source)
|
39
|
+
target_txt = File.read(target_file)
|
40
|
+
parser = MultiMarkdownCLI::Parser.new(source_txt, *options)
|
41
|
+
|
42
|
+
parsed_src = parser.convert(target)
|
43
|
+
|
44
|
+
# clean up both outputs
|
45
|
+
target_txt.gsub!(/\s+\z/, "")
|
46
|
+
parsed_src.gsub!(/\s+\z/, "")
|
47
|
+
if use_tidy
|
48
|
+
tidy_cmd = "tidy --show-body-only 1 --quiet 1 --show-warnings 0"
|
49
|
+
target_txt, status = Open3.capture2(tidy_cmd, :stdin_data=> target_txt)
|
50
|
+
parsed_src, status = Open3.capture2(tidy_cmd, :stdin_data=> parsed_src)
|
51
|
+
end
|
52
|
+
|
53
|
+
Dir.chdir(orig_dir)
|
54
|
+
assert_equal(target_txt, parsed_src)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multimarkdown-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Torsney-Weir
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: |2
|
42
|
+
A Ruby extension that can process MultiMarkdown-formatted
|
43
|
+
text using the multimarkdown command line tool.
|
44
|
+
email:
|
45
|
+
- torsneyt@gmail.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- .gitignore
|
51
|
+
- .gitmodules
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/multimarkdown-cli.rb
|
58
|
+
- lib/multimarkdown-cli/version.rb
|
59
|
+
- multimarkdown-cli.gemspec
|
60
|
+
- test/all_tests.rb
|
61
|
+
- test/test_beamer.rb
|
62
|
+
- test/test_compat.rb
|
63
|
+
- test/test_markdown.rb
|
64
|
+
- test/test_memoir.rb
|
65
|
+
- test/test_mmd.rb
|
66
|
+
- test/test_writer.rb
|
67
|
+
homepage: https://github.com/gabysbrain/rb-MultiMarkdown-4
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.0.3
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: An interface to the multimarkdown command line tool
|
91
|
+
test_files:
|
92
|
+
- test/all_tests.rb
|
93
|
+
- test/test_beamer.rb
|
94
|
+
- test/test_compat.rb
|
95
|
+
- test/test_markdown.rb
|
96
|
+
- test/test_memoir.rb
|
97
|
+
- test/test_mmd.rb
|
98
|
+
- test/test_writer.rb
|