erb_latex 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -10
- data/erb_latex.gemspec +4 -6
- data/lib/erb_latex/template.rb +15 -4
- data/lib/erb_latex/version.rb +1 -1
- data/yard_ext/templates/default/method_details/html/github_link.erb +1 -1
- metadata +10 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84304bc85e90020a761203b4bdddc2586c039cc
|
4
|
+
data.tar.gz: a9e53b0cf408eb643a2fcf9442e86817582cb4a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21ea773fdbff0b511714dc2582697dc80a027696ae31fb6379ce61c92819a7218b9dc9d455f83d6ae0c07395fe4b97efbfbe91ff0faaccf85a78fb03333f1ac2
|
7
|
+
data.tar.gz: a9d6ac79090d939e2f1b8515a06d50cfbd88fcb5de36ecc1edb7c6412316a4326f63627c8f63c1c0c2c197909b10f49cfc9f16aa849faa96e54ab95239bfd66a
|
data/README.md
CHANGED
@@ -10,13 +10,15 @@ Also supplies a Guard task to watch for modifications and auto-building files.
|
|
10
10
|
|
11
11
|
[Argosity](http://argosity.com/) uses this for several different projects
|
12
12
|
|
13
|
-
*
|
13
|
+
* I originally used a bare-bones & hacky version to generate my resume in both HTML & PDF
|
14
14
|
* [Stockor](http://stockor.org/), our open-source ERP platform. It's used for building all the form that output as PDF.
|
15
|
-
* Generating proposals for client projects.
|
15
|
+
* Generating proposals for client projects. Hit me up with a consulting request and you'll probably receive one!
|
16
16
|
|
17
|
-
##
|
17
|
+
## Links
|
18
18
|
|
19
|
-
|
19
|
+
API docs are hosted at [nathan.stitt.org/code/erb-latex/](http://nathan.stitt.org/code/erb-latex/)
|
20
|
+
|
21
|
+
The source is on github at [github.com/nathanstitt/erb_latex](https://github.com/nathanstitt/erb_latex)
|
20
22
|
|
21
23
|
## Installation
|
22
24
|
|
@@ -24,6 +26,8 @@ Add this line to your application's Gemfile:
|
|
24
26
|
|
25
27
|
gem 'erb_latex'
|
26
28
|
|
29
|
+
You'll also need a working tex installation, in particular the xelatex binary. You can get that from [TeX Live](https://www.tug.org/texlive/).
|
30
|
+
|
27
31
|
And then execute:
|
28
32
|
|
29
33
|
$ bundle
|
@@ -64,10 +68,10 @@ and a simple LaTeX body: ``body.tex``
|
|
64
68
|
\lettrine[lines=2]{T}{hank} you for your your consideration.
|
65
69
|
Please let us know if we can help you any further at all and don't forget to fill out the speakers notes.
|
66
70
|
|
67
|
-
<%=q message %>
|
71
|
+
<%=q @message %>
|
68
72
|
|
69
73
|
Thank you,
|
70
|
-
<%=q author %>
|
74
|
+
<%=q @author %>
|
71
75
|
```
|
72
76
|
The following will convert it to a pdf
|
73
77
|
|
@@ -75,10 +79,12 @@ The following will convert it to a pdf
|
|
75
79
|
require "erb_latex"
|
76
80
|
|
77
81
|
tmpl = ErbLatex::Template.new( 'body.tex', {
|
78
|
-
:
|
79
|
-
:
|
80
|
-
|
81
|
-
|
82
|
+
layout: 'layout.tex',
|
83
|
+
partial_path: '/my/partials/directory',
|
84
|
+
packages_path: '/location/of/custom/latex/packages',
|
85
|
+
data: {
|
86
|
+
author: "Nathan",
|
87
|
+
messge: "Please call our department at 555-5555"
|
82
88
|
}
|
83
89
|
})
|
84
90
|
tmpl.to_file('thank-you.pdf')
|
data/erb_latex.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["nathan@stitt.org"]
|
11
11
|
spec.summary = %q{Applies ERB template processing to a Latex file and compiles it to a PDF}
|
12
12
|
spec.description = %q{Applies ERB template processing to a Latex file and compiles it to a PDF. Supports layouts, partials, and string escaping. Also supplies a Guard task to watch for modifications and auto-building files.}
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "https://github.com/nathanstitt/erb_latex"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -18,10 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.
|
22
|
-
spec.add_development_dependency "rake", "~> 10"
|
23
|
-
spec.add_development_dependency "growl", "~> 1.0" # sorry Linux. Anyone have suggestions on how to do this multi-platform?
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
22
|
spec.add_development_dependency "yard", "~> 0.8"
|
25
|
-
spec.add_development_dependency "guard", "~> 2.
|
26
|
-
spec.add_development_dependency "guard-minitest", "~> 2.
|
23
|
+
spec.add_development_dependency "guard", "~> 2.13"
|
24
|
+
spec.add_development_dependency "guard-minitest", "~> 2.4"
|
27
25
|
end
|
data/lib/erb_latex/template.rb
CHANGED
@@ -25,7 +25,11 @@ module ErbLatex
|
|
25
25
|
attr_reader :log, :pass_count
|
26
26
|
# @attribute [rw] layout
|
27
27
|
# @return [String] path to a file to use for layout
|
28
|
-
|
28
|
+
# @attribute [rw] packages_path
|
29
|
+
# @return [String] path to a directory to search for packages
|
30
|
+
# @attribute [rw] partials_path
|
31
|
+
# @return [String] path to a directory to search for partials to include
|
32
|
+
attr_accessor :layout, :packages_path, :partials_path
|
29
33
|
|
30
34
|
# create a new Template
|
31
35
|
# @param view_file [String] path to the latex template
|
@@ -34,6 +38,8 @@ module ErbLatex
|
|
34
38
|
def initialize( view_file, options={} )
|
35
39
|
@data = options[:data] || {}
|
36
40
|
@layout = options[:layout]
|
41
|
+
@packages_path = options[:packages_path]
|
42
|
+
@partials_path = options[:partials_path]
|
37
43
|
@view = Pathname.new( view_file )
|
38
44
|
@log = ''
|
39
45
|
end
|
@@ -62,7 +68,7 @@ module ErbLatex
|
|
62
68
|
FileUtils.mv contents, file
|
63
69
|
else
|
64
70
|
file.write contents.read
|
65
|
-
|
71
|
+
file.rewind
|
66
72
|
end
|
67
73
|
end
|
68
74
|
file
|
@@ -70,7 +76,7 @@ module ErbLatex
|
|
70
76
|
|
71
77
|
# @return [StringIO] containing the the PDF
|
72
78
|
def to_stringio
|
73
|
-
to_file( ::ErbLatex::StringIO.new(suggested_filename) )
|
79
|
+
to_file( ::ErbLatex::StringIO.new(suggested_filename) )
|
74
80
|
end
|
75
81
|
|
76
82
|
# Compile the Latex template into a PDF file
|
@@ -91,6 +97,7 @@ module ErbLatex
|
|
91
97
|
yield pdf_file
|
92
98
|
else
|
93
99
|
errors = @log.scan(/\*\!\s(.*?)\n\s*\n/m).map{|e| e.first.gsub(/\n/,'') }.join("; ")
|
100
|
+
STDERR.puts @log
|
94
101
|
raise LatexError.new( errors.empty? ? "xelatex compile error" : errors, @log )
|
95
102
|
end
|
96
103
|
end
|
@@ -106,7 +113,7 @@ module ErbLatex
|
|
106
113
|
# @raise [LatexError] if the xelatex process does not complete successfully
|
107
114
|
def compile_latex
|
108
115
|
begin
|
109
|
-
context = ErbLatex::Context.new( @view.dirname, @data )
|
116
|
+
context = ErbLatex::Context.new( @partials_path || @view.dirname, @data )
|
110
117
|
content = ERB.new( @view.read, 0, '-' ).result( context.getBinding )
|
111
118
|
if layout
|
112
119
|
ERB.new( layout_file.read, nil, '-' ).result( context.getBinding{
|
@@ -133,6 +140,10 @@ module ErbLatex
|
|
133
140
|
def execute_xelatex( latex, dir )
|
134
141
|
success = false
|
135
142
|
@log = ''
|
143
|
+
|
144
|
+
if @packages_path
|
145
|
+
ENV['TEXINPUTS'] = "#{@packages_path}:"
|
146
|
+
end
|
136
147
|
Open3.popen2e( ErbLatex.xelatex_binary,
|
137
148
|
"--no-shell-escape", "-shell-restricted",
|
138
149
|
"-jobname=output", "-output-directory=#{dir}",
|
data/lib/erb_latex/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[<a href="https://github.com/nathanstitt/
|
1
|
+
[<a href="https://github.com/nathanstitt/erb_latex/blob/master/<%= object.file %><% if object.line %>#L<%= object.line %><% end %>">github</a>]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erb_latex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Stitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,42 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.10'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '10'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '10'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: growl
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.0'
|
26
|
+
version: '1.10'
|
55
27
|
- !ruby/object:Gem::Dependency
|
56
28
|
name: yard
|
57
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,28 +44,28 @@ dependencies:
|
|
72
44
|
requirements:
|
73
45
|
- - "~>"
|
74
46
|
- !ruby/object:Gem::Version
|
75
|
-
version: '2.
|
47
|
+
version: '2.13'
|
76
48
|
type: :development
|
77
49
|
prerelease: false
|
78
50
|
version_requirements: !ruby/object:Gem::Requirement
|
79
51
|
requirements:
|
80
52
|
- - "~>"
|
81
53
|
- !ruby/object:Gem::Version
|
82
|
-
version: '2.
|
54
|
+
version: '2.13'
|
83
55
|
- !ruby/object:Gem::Dependency
|
84
56
|
name: guard-minitest
|
85
57
|
requirement: !ruby/object:Gem::Requirement
|
86
58
|
requirements:
|
87
59
|
- - "~>"
|
88
60
|
- !ruby/object:Gem::Version
|
89
|
-
version: '2.
|
61
|
+
version: '2.4'
|
90
62
|
type: :development
|
91
63
|
prerelease: false
|
92
64
|
version_requirements: !ruby/object:Gem::Requirement
|
93
65
|
requirements:
|
94
66
|
- - "~>"
|
95
67
|
- !ruby/object:Gem::Version
|
96
|
-
version: '2.
|
68
|
+
version: '2.4'
|
97
69
|
description: Applies ERB template processing to a Latex file and compiles it to a
|
98
70
|
PDF. Supports layouts, partials, and string escaping. Also supplies a Guard task
|
99
71
|
to watch for modifications and auto-building files.
|
@@ -129,7 +101,7 @@ files:
|
|
129
101
|
- test/helper.rb
|
130
102
|
- yard_ext/templates/default/method_details/html/github_link.erb
|
131
103
|
- yard_ext/templates/default/method_details/setup.rb
|
132
|
-
homepage:
|
104
|
+
homepage: https://github.com/nathanstitt/erb_latex
|
133
105
|
licenses:
|
134
106
|
- MIT
|
135
107
|
metadata: {}
|
@@ -149,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
121
|
version: '0'
|
150
122
|
requirements: []
|
151
123
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.4.5.1
|
153
125
|
signing_key:
|
154
126
|
specification_version: 4
|
155
127
|
summary: Applies ERB template processing to a Latex file and compiles it to a PDF
|