md2pdf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of md2pdf might be problematic. Click here for more details.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/bin/md2pdf +9 -0
- data/examples/example.md +65 -0
- data/examples/example.pdf +0 -0
- data/lib/md2pdf.rb +4 -0
- data/lib/md2pdf/cli.rb +33 -0
- data/lib/md2pdf/converter.rb +44 -0
- data/lib/md2pdf/template.rb +54 -0
- data/lib/md2pdf/version.rb +3 -0
- data/lib/test_file.rb +1 -0
- data/lib/test_file/builder.rb +78 -0
- data/md2pdf.gemspec +26 -0
- data/spec/md2pdf/cli_spec.rb +40 -0
- data/spec/md2pdf/converter_spec.rb +66 -0
- data/spec/md2pdf/template_spec.rb +70 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/test_file/builder_spec.rb +32 -0
- metadata +172 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
md2doc
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3-p327
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Rob Westgeest
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Md2Pdf
|
2
|
+
|
3
|
+
This gem lets you create a nicely formatted document from a markdown
|
4
|
+
source.
|
5
|
+
|
6
|
+
Primarily we created this gem to enable us to quickly write markdown
|
7
|
+
documents for offers for clients without worrying about layout and
|
8
|
+
formatting and while being able to use a light weight text editor like
|
9
|
+
vim, emacs, gedit, notepad whatever.
|
10
|
+
|
11
|
+
We have worked with markdown in combination with pandoc with a latex
|
12
|
+
template for pdf creation and pdftk for adding a background for each
|
13
|
+
page (like a kind of printed template page with a logo and address
|
14
|
+
footer.
|
15
|
+
|
16
|
+
We found ourselves copying and pasting a simple rakefile, templates and logos
|
17
|
+
everywhere we needed to create an offer or similar document.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
desc "preview offerte"
|
21
|
+
task :view => :offerte do
|
22
|
+
sh "evince VoorstelPairProgrammingWorkshop#{today}.pdf"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "create offerte"
|
26
|
+
task :offerte do
|
27
|
+
sh "pandoc offerte.md --number-sections --template=template.tex -o offerte_temp.pdf"
|
28
|
+
sh "pdftk offerte_temp.pdf multibackground QwanFront.pdf output VoorstelPairProgrammingWorkshop#{today}.pdf"
|
29
|
+
rm 'offerte_temp.pdf'
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def today
|
34
|
+
Date.today.strftime("%F")
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
This gem more or less encapsulates this in an executable script (which
|
39
|
+
is in your path after installation) and enables you to manage several
|
40
|
+
templates.
|
41
|
+
|
42
|
+
## Installation
|
43
|
+
|
44
|
+
Add this line to your application's Gemfile:
|
45
|
+
|
46
|
+
```bash
|
47
|
+
$ gem install md2doc
|
48
|
+
```
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
Use md2doc --help to show help for options - should be self documenting
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/md2pdf
ADDED
data/examples/example.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
% Example md
|
2
|
+
% Rob Westgeest
|
3
|
+
% April 2013
|
4
|
+
|
5
|
+
# Md2doc
|
6
|
+
|
7
|
+
This gem lets you create a nicely formatted document from a markdown
|
8
|
+
source.
|
9
|
+
|
10
|
+
Primarily we created this gem to enable us to quickly write markdown
|
11
|
+
documents for offers for clients without worrying about layout and
|
12
|
+
formatting and while being able to use a light weight text editor like
|
13
|
+
vim, emacs, gedit, notepad whatever.
|
14
|
+
|
15
|
+
We have worked with markdown in combination with pandoc with a latex
|
16
|
+
template for pdf creation and pdftk for adding a background for each
|
17
|
+
page (like a kind of printed template page with a logo and address
|
18
|
+
footer.
|
19
|
+
|
20
|
+
We found ourselves copying and pasting a simple rakefile, templates and logos
|
21
|
+
everywhere we needed to create an offer or similar document.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
desc "preview offerte"
|
25
|
+
task :view => :offerte do
|
26
|
+
sh "evince VoorstelPairProgrammingWorkshop#{today}.pdf"
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "create offerte"
|
30
|
+
task :offerte do
|
31
|
+
sh "pandoc offerte.md --number-sections --template=template.tex -o offerte_temp.pdf"
|
32
|
+
sh "pdftk offerte_temp.pdf multibackground QwanFront.pdf output VoorstelPairProgrammingWorkshop#{today}.pdf"
|
33
|
+
rm 'offerte_temp.pdf'
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def today
|
38
|
+
Date.today.strftime("%F")
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
This gem more or less encapsulates this in an executable script (which
|
43
|
+
is in your path after installation) and enables you to manage several
|
44
|
+
templates.
|
45
|
+
|
46
|
+
## Installation
|
47
|
+
|
48
|
+
Add this line to your application's Gemfile:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
$ gem install md2doc
|
52
|
+
```
|
53
|
+
|
54
|
+
## Usage
|
55
|
+
|
56
|
+
Use md2doc --help to show help for options - should be self documenting
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create new Pull Request
|
65
|
+
|
Binary file
|
data/lib/md2pdf.rb
ADDED
data/lib/md2pdf/cli.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Md2Pdf
|
4
|
+
class CLI < Thor
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
desc "pdf input_file, template", "Creates a pdf from input file with template"
|
8
|
+
def pdf(input_file, template='default')
|
9
|
+
Converter.new(
|
10
|
+
Shell.new,
|
11
|
+
Template.new(template,
|
12
|
+
TemplateLocation.new(File.expand_path('~/.md2doc'))),
|
13
|
+
TempFileCreator.new).convert(input_file, output_file(input_file))
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "create_template template name", "Creates a template dir with an initial tex template"
|
17
|
+
def create_template(template)
|
18
|
+
Template.new(template,
|
19
|
+
TemplateLocation.new(File.expand_path('~/.md2doc'))).create(Shell.new)
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "list_templates", "List teplates"
|
23
|
+
def list_templates
|
24
|
+
puts TemplateLocation.new(File.expand_path('~/.md2doc')).list.join($/)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def output_file(input_file)
|
29
|
+
File.join(File.dirname(input_file), File.basename(input_file, File.extname(input_file)) + '.pdf')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Md2Pdf
|
2
|
+
|
3
|
+
class Converter < Struct.new(:shell, :templater, :temp_filename_creator)
|
4
|
+
def convert(input_filename, output_filename)
|
5
|
+
templater.create_pdf_converter(shell, temp_filename_creator).convert(input_filename, output_filename)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
class PandocConverter < Struct.new(:shell, :template_path)
|
11
|
+
def convert(input_filename, output_filename)
|
12
|
+
shell.exec("pandoc#{options} #{input_filename} -o #{output_filename}")
|
13
|
+
end
|
14
|
+
private
|
15
|
+
def options
|
16
|
+
template_path.empty? && "" || " --template=#{template_path}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class BackGrounder < Struct.new(:wrapped_converter, :shell, :temp_filename_creator, :background_path)
|
21
|
+
def convert(input_filename, output_filename)
|
22
|
+
wrapped_converter.convert(input_filename, temp_filename)
|
23
|
+
shell.exec("pdftk #{temp_filename} multibackground #{background_path} output #{output_filename}")
|
24
|
+
end
|
25
|
+
def temp_filename
|
26
|
+
@temp_filename ||= temp_filename_creator.create_file_name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class TempFileCreator
|
31
|
+
def create_file_name
|
32
|
+
Tempfile.new('temp.pdf').path + '.pdf'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Shell
|
37
|
+
def exec(command_line)
|
38
|
+
require 'open3'
|
39
|
+
stdin, stdout, stderr = Open3.popen3(command_line)
|
40
|
+
return stdout.read
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Md2Pdf
|
4
|
+
|
5
|
+
class TemplateExistsError < Exception; end
|
6
|
+
|
7
|
+
class Template < Struct.new(:name, :template_location)
|
8
|
+
def create_pdf_converter(shell, temp_filename_creator = TempFileCreator)
|
9
|
+
wrap_in_backgrounder PandocConverter.new(shell, pandoc_tex_template), shell, temp_filename_creator
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(shell)
|
13
|
+
raise TemplateExistsError.new("template #{name} already exists") if exists?
|
14
|
+
FileUtils.mkdir_p(template_location.path_for(name))
|
15
|
+
shell.exec("pandoc -D latex > #{template_location.path_for(tex_template_path)}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def exists?
|
19
|
+
template_location.contains?(tex_template_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def wrap_in_backgrounder(converter, shell, temp_filename_creator)
|
24
|
+
template_location.contains?(multibackground_path) && BackGrounder.new(converter, shell, temp_filename_creator, template_location.path_for(multibackground_path)) || converter
|
25
|
+
end
|
26
|
+
|
27
|
+
def pandoc_tex_template
|
28
|
+
template_location.contains?(tex_template_path) && template_location.path_for(tex_template_path) || ""
|
29
|
+
end
|
30
|
+
|
31
|
+
def multibackground_path
|
32
|
+
"#{name}/multibackground.pdf"
|
33
|
+
end
|
34
|
+
|
35
|
+
def tex_template_path
|
36
|
+
"#{name}/template.tex"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class TemplateLocation < Struct.new(:location)
|
41
|
+
def path_for(path)
|
42
|
+
File.join(location, path)
|
43
|
+
end
|
44
|
+
def contains?(path)
|
45
|
+
File.exists?(path_for(path))
|
46
|
+
end
|
47
|
+
def list
|
48
|
+
Dir[File.join(location,"*")].map {|f| File.basename(f)}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
data/lib/test_file.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'test_file/builder'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'pdf-reader'
|
2
|
+
|
3
|
+
module TestFile
|
4
|
+
def self.included(base)
|
5
|
+
base.after { remove_test_files } if base.respond_to?(:after)
|
6
|
+
end
|
7
|
+
|
8
|
+
def a_file(name)
|
9
|
+
test_files << Builder.new(name)
|
10
|
+
test_files.last
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_files
|
14
|
+
@test_files ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def remove_test_files
|
19
|
+
test_files.each {|file| file.delete}
|
20
|
+
end
|
21
|
+
|
22
|
+
class Builder < Struct.new(:name)
|
23
|
+
def with_content(content)
|
24
|
+
writer.write(content)
|
25
|
+
writer.flush
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def as_pdf
|
30
|
+
PDFBuilder.new(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def writer
|
34
|
+
@writer ||= File.new(path, 'w+')
|
35
|
+
end
|
36
|
+
|
37
|
+
def reader
|
38
|
+
@reader ||= File.new(path, 'r')
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete
|
42
|
+
File.delete(path) if exist?
|
43
|
+
end
|
44
|
+
|
45
|
+
def exist?
|
46
|
+
File.exists?(path)
|
47
|
+
end
|
48
|
+
|
49
|
+
def include?(content)
|
50
|
+
reader.read.include?(content)
|
51
|
+
end
|
52
|
+
|
53
|
+
def path
|
54
|
+
name
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_s
|
58
|
+
"TestFile #{path}"
|
59
|
+
end
|
60
|
+
alias_method :inspect, :to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
class PDFBuilder < Struct.new(:builder)
|
64
|
+
def delete
|
65
|
+
builder.delete
|
66
|
+
end
|
67
|
+
def exists?
|
68
|
+
builder.exists?
|
69
|
+
end
|
70
|
+
def reader
|
71
|
+
PDF::Reader.new(builder.reader)
|
72
|
+
end
|
73
|
+
def include?(content)
|
74
|
+
reader.pages.map { |page| page.text }.join.include? content
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
data/md2pdf.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'md2pdf/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "md2pdf"
|
8
|
+
gem.version = Md2Pdf::VERSION
|
9
|
+
gem.authors = ["Rob Westgeest"]
|
10
|
+
gem.email = ["rob@qwan.it"]
|
11
|
+
gem.description = %q{creates pdf documents from markdown documents}
|
12
|
+
gem.summary = %q{creates pdf documents from markdown documents}
|
13
|
+
gem.homepage = "https://github.com/rwestgeest/md2pdf"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_development_dependency 'rspec'
|
20
|
+
gem.add_development_dependency 'rb-inotify'
|
21
|
+
gem.add_development_dependency 'guard'
|
22
|
+
gem.add_development_dependency 'guard-rspec'
|
23
|
+
|
24
|
+
gem.add_development_dependency 'pdf-reader'
|
25
|
+
gem.add_dependency 'thor'
|
26
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'md2pdf'
|
3
|
+
require 'test_file'
|
4
|
+
|
5
|
+
module Md2Pdf
|
6
|
+
|
7
|
+
describe CLI do
|
8
|
+
include TestFile
|
9
|
+
let(:cli) { CLI.new }
|
10
|
+
let!(:markdown_file) { a_file('input.md').with_content("#my heading") }
|
11
|
+
|
12
|
+
it "the pdf contains the text" do
|
13
|
+
capture(:stdout) { cli.pdf(markdown_file.path) }
|
14
|
+
a_file('input.pdf').as_pdf.should include("my heading")
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when it contains a title" do
|
18
|
+
let!(:markdown_file) { a_file('input.md').with_content("%my title\n%my author\n%\n#my heading") }
|
19
|
+
|
20
|
+
it "should put the title in the output" do
|
21
|
+
capture(:stdout) { cli.pdf(markdown_file.path) }
|
22
|
+
output = a_file('input.pdf').as_pdf
|
23
|
+
output.should include("my title")
|
24
|
+
output.should_not include("%")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def capture(*streams)
|
29
|
+
streams.map! { |stream| stream.to_s }
|
30
|
+
begin
|
31
|
+
result = StringIO.new
|
32
|
+
streams.each { |stream| eval "$#{stream} = result" }
|
33
|
+
yield
|
34
|
+
ensure
|
35
|
+
streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
|
36
|
+
end
|
37
|
+
result.string
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'md2pdf'
|
3
|
+
|
4
|
+
module Md2Pdf
|
5
|
+
|
6
|
+
describe Converter do
|
7
|
+
|
8
|
+
describe 'converting path' do
|
9
|
+
let(:shell) { mock('Shell') }
|
10
|
+
let(:template_location) { stub('template_location', :contains? => false) }
|
11
|
+
let(:temp_filename_creator) { stub('temp_filename_creator', :create_file_name => 'temp_filename') }
|
12
|
+
let(:template) { Template.new('my_template', template_location) }
|
13
|
+
let(:converter) { Converter.new(shell, template, temp_filename_creator) }
|
14
|
+
|
15
|
+
it "converts a file to pdf using pandoc" do
|
16
|
+
shell.should_receive(:exec).with("pandoc inputfile.md -o outputfile.pdf")
|
17
|
+
converter.convert('inputfile.md','outputfile.pdf')
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when template tex is available" do
|
21
|
+
before do
|
22
|
+
template_location.stub(:contains?).with('my_template/template.tex').and_return true
|
23
|
+
template_location.stub(:path_for).with('my_template/template.tex').and_return 'my_template_path'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "uses a template path option" do
|
27
|
+
shell.should_receive(:exec).with("pandoc --template=my_template_path inputfile.md -o outputfile.pdf")
|
28
|
+
converter.convert('inputfile.md','outputfile.pdf')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when background is available" do
|
33
|
+
before do
|
34
|
+
template_location.stub(:contains?).with('my_template/multibackground.pdf').and_return true
|
35
|
+
template_location.stub(:path_for).with('my_template/multibackground.pdf').and_return 'my_background_path'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "creates a PandocConverter wrapped in a BackGrounder when a background is available" do
|
39
|
+
shell.should_receive(:exec).with("pandoc inputfile.md -o temp_filename").ordered
|
40
|
+
shell.should_receive(:exec).with("pdftk temp_filename multibackground my_background_path output outputfile.pdf").ordered
|
41
|
+
converter.convert('inputfile.md','outputfile.pdf')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe Shell do
|
49
|
+
describe "exec" do
|
50
|
+
let(:shell) { Shell.new }
|
51
|
+
it "executes a command" do
|
52
|
+
shell.exec('echo hello world').strip.should == 'hello world'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe TempFileCreator do
|
58
|
+
describe "create_file_name" do
|
59
|
+
it "creates a temporary pdf file" do
|
60
|
+
TempFileCreator.new.create_file_name.should match %r{\/tmp\/.*\.pdf$}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'md2pdf'
|
3
|
+
require 'test_file'
|
4
|
+
|
5
|
+
module Md2Pdf
|
6
|
+
|
7
|
+
describe Template do
|
8
|
+
let(:template_location) { TemplateLocation.new 'my_templates' }
|
9
|
+
|
10
|
+
include TestFile
|
11
|
+
include FileUtils
|
12
|
+
|
13
|
+
after { rm_r 'my_templates' if File.exists?('my_templates') }
|
14
|
+
describe "create template" do
|
15
|
+
let(:new_template) { Template.new "my_new_template", template_location }
|
16
|
+
it "creates a tex template" do
|
17
|
+
new_template.create(Shell.new)
|
18
|
+
new_template.should exist
|
19
|
+
end
|
20
|
+
context "when template exists" do
|
21
|
+
before { Template.new("my_new_template", template_location).create(Shell.new) }
|
22
|
+
it "refuses to create the template" do
|
23
|
+
expect { new_template.create(Shell.new) }.to raise_exception(TemplateExistsError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe TemplateLocation do
|
30
|
+
include FileUtils
|
31
|
+
let(:template_location) { TemplateLocation.new 'my_templates' }
|
32
|
+
after { rm_r 'my_templates' if File.exists?('my_templates') }
|
33
|
+
describe "path_for" do
|
34
|
+
it "constructs the path in the template location" do
|
35
|
+
template_location.path_for('some/path.txt').should == "my_templates/some/path.txt"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "contains?" do
|
40
|
+
include TestFile
|
41
|
+
describe "when path does not exist" do
|
42
|
+
it "returns false" do
|
43
|
+
template_location.contains?('some/path.txt').should be_false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
context "when path exists" do
|
47
|
+
before do
|
48
|
+
mkdir_p 'my_templates/some'
|
49
|
+
a_file('my_templates/some/path.txt').with_content "blah"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns true" do
|
53
|
+
template_location.contains?('some/path.txt').should be_true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
describe "list" do
|
58
|
+
let(:shell) { Shell.new }
|
59
|
+
it "is emppty initially" do
|
60
|
+
template_location.list.should == []
|
61
|
+
end
|
62
|
+
it "lists the template names" do
|
63
|
+
Template.new("template1", template_location).create(shell)
|
64
|
+
Template.new("template2", template_location).create(shell)
|
65
|
+
template_location.list.should == ["template1", "template2"]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'test_file'
|
3
|
+
|
4
|
+
describe TestFile::Builder do
|
5
|
+
include TestFile
|
6
|
+
describe 'creating a file with text' do
|
7
|
+
it "creates a file" do
|
8
|
+
a_file('test_file.txt').with_content('text').should exist
|
9
|
+
end
|
10
|
+
|
11
|
+
it "contains the content" do
|
12
|
+
a_file('test_file.txt').with_content('text').should include("text")
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "and after that" do
|
16
|
+
it "removes the file" do
|
17
|
+
a_file('test_file.txt').with_content('text')
|
18
|
+
remove_test_files
|
19
|
+
a_file('test_file.txt').should_not exist
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "including it in a non rspec module" do
|
25
|
+
class SomeModule
|
26
|
+
include TestFile
|
27
|
+
end
|
28
|
+
it "makes it respond to a_file" do
|
29
|
+
SomeModule.new.should respond_to(:a_file)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: md2pdf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rob Westgeest
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
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'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rb-inotify
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
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: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: guard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
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'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard-rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: pdf-reader
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: thor
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: creates pdf documents from markdown documents
|
111
|
+
email:
|
112
|
+
- rob@qwan.it
|
113
|
+
executables:
|
114
|
+
- md2pdf
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .rspec
|
120
|
+
- .ruby-gemset
|
121
|
+
- .ruby-version
|
122
|
+
- Gemfile
|
123
|
+
- Guardfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/md2pdf
|
128
|
+
- examples/example.md
|
129
|
+
- examples/example.pdf
|
130
|
+
- lib/md2pdf.rb
|
131
|
+
- lib/md2pdf/cli.rb
|
132
|
+
- lib/md2pdf/converter.rb
|
133
|
+
- lib/md2pdf/template.rb
|
134
|
+
- lib/md2pdf/version.rb
|
135
|
+
- lib/test_file.rb
|
136
|
+
- lib/test_file/builder.rb
|
137
|
+
- md2pdf.gemspec
|
138
|
+
- spec/md2pdf/cli_spec.rb
|
139
|
+
- spec/md2pdf/converter_spec.rb
|
140
|
+
- spec/md2pdf/template_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
- spec/test_file/builder_spec.rb
|
143
|
+
homepage: https://github.com/rwestgeest/md2pdf
|
144
|
+
licenses: []
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ! '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ! '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 1.8.24
|
164
|
+
signing_key:
|
165
|
+
specification_version: 3
|
166
|
+
summary: creates pdf documents from markdown documents
|
167
|
+
test_files:
|
168
|
+
- spec/md2pdf/cli_spec.rb
|
169
|
+
- spec/md2pdf/converter_spec.rb
|
170
|
+
- spec/md2pdf/template_spec.rb
|
171
|
+
- spec/spec_helper.rb
|
172
|
+
- spec/test_file/builder_spec.rb
|