erb_latex 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c84304bc85e90020a761203b4bdddc2586c039cc
4
- data.tar.gz: a9e53b0cf408eb643a2fcf9442e86817582cb4a8
3
+ metadata.gz: ff1d232589ee66eab16df483e4a00650123023e2
4
+ data.tar.gz: 812988816e5f7b00cc11e535feb0e898d49f8dd4
5
5
  SHA512:
6
- metadata.gz: 21ea773fdbff0b511714dc2582697dc80a027696ae31fb6379ce61c92819a7218b9dc9d455f83d6ae0c07395fe4b97efbfbe91ff0faaccf85a78fb03333f1ac2
7
- data.tar.gz: a9d6ac79090d939e2f1b8515a06d50cfbd88fcb5de36ecc1edb7c6412316a4326f63627c8f63c1c0c2c197909b10f49cfc9f16aa849faa96e54ab95239bfd66a
6
+ metadata.gz: 6914c9b7f198d049f633176ad2902f4e2a537c879303ad989842badbd7a488fa12b2b95db64e12a11b39fe2e0327766ed37153d760b5d52a444973386554518f
7
+ data.tar.gz: f7657b33f14bbc3ed55e20ec1d7f0ded2f5a83cc155ffc2123de7d58bc86685a57e491e233c4eb224543ebb62199dd117c4b920835a4e3894f1274f07259f45c
@@ -18,6 +18,7 @@ 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 "rake", "~> 10.5"
21
22
  spec.add_development_dependency "bundler", "~> 1.10"
22
23
  spec.add_development_dependency "yard", "~> 0.8"
23
24
  spec.add_development_dependency "guard", "~> 2.13"
@@ -1,17 +1,12 @@
1
1
  require "erb_latex/version"
2
+ require "erb_latex/configuration"
2
3
  require "erb_latex/errors"
3
4
  require "erb_latex/context"
4
5
  require "erb_latex/stringio"
5
6
  require "erb_latex/template"
6
- module ErbLatex
7
-
7
+ require "erb_latex/file_access"
8
8
 
9
+ module ErbLatex
9
10
 
10
- def self.xelatex_binary
11
- defined?(@@xelatex_binary) ? @@xelatex_binary : "xelatex"
12
- end
13
11
 
14
- def self.xelatex_binary=(bin)
15
- @@xelatex_binary = bin
16
- end
17
12
  end
@@ -0,0 +1,25 @@
1
+ module ErbLatex
2
+ class << self
3
+ attr_reader :config
4
+ end
5
+
6
+
7
+ def self.configure
8
+ yield(@config)
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :file_extension
13
+ attr_accessor :xelatex_path
14
+ attr_accessor :verbose_logs
15
+
16
+ def initialize
17
+ @verbose_logs = false
18
+ @file_extension = '.tex.erb'
19
+ @xelatex_path = 'xelatex'
20
+ end
21
+ end
22
+
23
+ # Initialize configuration with defaults
24
+ @config = Configuration.new
25
+ end
@@ -30,13 +30,8 @@ module ErbLatex
30
30
 
31
31
  # include another latex file into the current template
32
32
  def partial( template, data={} )
33
- view_file = @directory.join( template )
34
- if view_file.exist?
35
- context = Context.new( @directory, data )
36
- ERB.new( view_file.read, 0, '-' ).result( context.getBinding )
37
- else
38
- "missing partial: #{template}"
39
- end
33
+ context = Context.new( @directory, data )
34
+ ErbLatex::File.evaluate(Pathname.new(template), context.getBinding, @directory)
40
35
  end
41
36
 
42
37
  # convert newline characters into latex '\\newline'
@@ -7,7 +7,7 @@ module ErbLatex
7
7
  # @return the log from the xelatex run
8
8
  attr_reader :log
9
9
 
10
- def initialize( msg, log )
10
+ def initialize( msg, log = '')
11
11
  super(msg)
12
12
  @log = log
13
13
  end
@@ -0,0 +1,28 @@
1
+ module ErbLatex
2
+
3
+ module File
4
+
5
+ # simualar to File.read, except:
6
+ # * Will search in_directory for file if given, otherwise expects file to be an absolute path
7
+ # * appends ErbLatex.config.file_extension to the file if it's not found as-is.
8
+ def self.read(file, in_directory = nil)
9
+ if in_directory
10
+ file = Pathname.new(in_directory.to_s).join(file)
11
+ end
12
+ unless file.exist?
13
+ file = Pathname.new(file.to_s + ErbLatex.config.file_extension) unless file.exist?
14
+ end
15
+ unless file.exist?
16
+ msg = "Unable to read from #{@view.to_s}. Also tried extension #{ErbLatex.config.file_extension}"
17
+ raise LatexError.new(msg)
18
+ end
19
+ file.read
20
+ end
21
+
22
+ def self.evaluate(file, context_binding, directory = nil)
23
+ ::ERB.new( self.read(file, directory), 0, '-' ).result( context_binding )
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -97,7 +97,7 @@ module ErbLatex
97
97
  yield pdf_file
98
98
  else
99
99
  errors = @log.scan(/\*\!\s(.*?)\n\s*\n/m).map{|e| e.first.gsub(/\n/,'') }.join("; ")
100
- STDERR.puts @log
100
+ STDERR.puts @log, errors if ErbLatex.config.verbose_logs
101
101
  raise LatexError.new( errors.empty? ? "xelatex compile error" : errors, @log )
102
102
  end
103
103
  end
@@ -114,11 +114,9 @@ module ErbLatex
114
114
  def compile_latex
115
115
  begin
116
116
  context = ErbLatex::Context.new( @partials_path || @view.dirname, @data )
117
- content = ERB.new( @view.read, 0, '-' ).result( context.getBinding )
117
+ content = ErbLatex::File.evaluate(@view, context.getBinding)
118
118
  if layout
119
- ERB.new( layout_file.read, nil, '-' ).result( context.getBinding{
120
- content
121
- })
119
+ ErbLatex::File.evaluate(layout_file, context.getBinding{ content })
122
120
  else
123
121
  content
124
122
  end
@@ -144,7 +142,7 @@ module ErbLatex
144
142
  if @packages_path
145
143
  ENV['TEXINPUTS'] = "#{@packages_path}:"
146
144
  end
147
- Open3.popen2e( ErbLatex.xelatex_binary,
145
+ Open3.popen2e( ErbLatex.config.xelatex_path,
148
146
  "--no-shell-escape", "-shell-restricted",
149
147
  "-jobname=output", "-output-directory=#{dir}",
150
148
  ) do |stdin, output, wait_thr|
@@ -1,5 +1,5 @@
1
1
  module ErbLatex
2
2
 
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
 
5
5
  end
@@ -42,4 +42,11 @@ class ErbLatexTest < MiniTest::Test
42
42
  assert_match "a test ’ of a partial", text_output
43
43
  end
44
44
 
45
+ def test_path_with_extension
46
+ tmpl = ErbLatex::Template.new( document('with_partial.tex.erb') )
47
+ tmpl.to_file tmp_output_file
48
+ assert_match "a test ’ of a partial", text_output
49
+ end
50
+
51
+
45
52
  end
@@ -1,14 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
3
+ require 'minitest'
4
+
10
5
 
11
- #require 'test/unit'
6
+ require 'minitest/autorun'
12
7
 
13
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -17,7 +12,7 @@ require 'erb_latex'
17
12
  class MiniTest::Test
18
13
 
19
14
  def document( name )
20
- File.expand_path(File.join(File.dirname(__FILE__), "fixtures/#{name}.tex.erb"))
15
+ File.expand_path(File.join(File.dirname(__FILE__), "fixtures/#{name}"))
21
16
  end
22
17
 
23
18
  def tmp_output_file
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb_latex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.5'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -83,8 +97,10 @@ files:
83
97
  - Rakefile
84
98
  - erb_latex.gemspec
85
99
  - lib/erb_latex.rb
100
+ - lib/erb_latex/configuration.rb
86
101
  - lib/erb_latex/context.rb
87
102
  - lib/erb_latex/errors.rb
103
+ - lib/erb_latex/file_access.rb
88
104
  - lib/erb_latex/guard.rb
89
105
  - lib/erb_latex/guard_runner.rb
90
106
  - lib/erb_latex/stringio.rb