nanoc-latexmk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31432aeef559015397ad00d6f276e265896c3b80
4
+ data.tar.gz: 8f1ac7dc2a96aed15ef0a528dd6b9b65c9ebc9d0
5
+ SHA512:
6
+ metadata.gz: '049a200efb3b01b6b5256956f3360b95a6eaf822a62c5323cabd18a6939eaf3e0360eb67d902a36ecc92598675bff4b3b1f55707777a849850868d006b20228c'
7
+ data.tar.gz: 62057f6a30b0a4cfa78c3f6e724bf0506b294e24d3cbac508f3fb9118303ba9b22249dec6713934f7479bfe636ccf4e4460fb8224fb442a4c6f91a84e36624fc
data/.gitignore ADDED
@@ -0,0 +1,57 @@
1
+ # Created by https://www.gitignore.io/api/ruby
2
+
3
+ .byebug_history
4
+
5
+ ### Ruby ###
6
+ *.gem
7
+ *.rbc
8
+ /.config
9
+ /coverage/
10
+ /InstalledFiles
11
+ /pkg/
12
+ /spec/reports/
13
+ /spec/examples.txt
14
+ /test/tmp/
15
+ /test/version_tmp/
16
+ /tmp/
17
+
18
+ # Used by dotenv library to load environment variables.
19
+ # .env
20
+
21
+ ## Specific to RubyMotion:
22
+ .dat*
23
+ .repl_history
24
+ build/
25
+ *.bridgesupport
26
+ build-iPhoneOS/
27
+ build-iPhoneSimulator/
28
+
29
+ ## Specific to RubyMotion (use of CocoaPods):
30
+ #
31
+ # We recommend against adding the Pods directory to your .gitignore. However
32
+ # you should judge for yourself, the pros and cons are mentioned at:
33
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
34
+ #
35
+ # vendor/Pods/
36
+
37
+ ## Documentation cache and generated files:
38
+ /.yardoc/
39
+ /_yardoc/
40
+ /doc/
41
+ /rdoc/
42
+
43
+ ## Environment normalization:
44
+ /.bundle/
45
+ /vendor/bundle
46
+ /lib/bundler/man/
47
+
48
+ # for a library or gem, you might want to ignore these files since the code is
49
+ # intended to run in multiple environments; otherwise, check them in:
50
+ # Gemfile.lock
51
+ # .ruby-version
52
+ # .ruby-gemset
53
+
54
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
55
+ .rvmrc
56
+
57
+ # End of https://www.gitignore.io/api/ruby
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## Release 0.1.0
4
+
5
+ - First release
6
+
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'coveralls'
5
+ gem 'rspec'
6
+ gem 'byebug'
7
+ end
8
+
9
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nanoc-latexmk (0.pre.1.pre.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (9.1.0)
10
+ coveralls (0.8.21)
11
+ json (>= 1.8, < 3)
12
+ simplecov (~> 0.14.1)
13
+ term-ansicolor (~> 1.3)
14
+ thor (~> 0.19.4)
15
+ tins (~> 1.6)
16
+ diff-lcs (1.3)
17
+ docile (1.1.5)
18
+ json (2.1.0)
19
+ rspec (3.7.0)
20
+ rspec-core (~> 3.7.0)
21
+ rspec-expectations (~> 3.7.0)
22
+ rspec-mocks (~> 3.7.0)
23
+ rspec-core (3.7.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-expectations (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-mocks (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-support (3.7.0)
32
+ simplecov (0.14.1)
33
+ docile (~> 1.1.0)
34
+ json (>= 1.8, < 3)
35
+ simplecov-html (~> 0.10.0)
36
+ simplecov-html (0.10.2)
37
+ term-ansicolor (1.6.0)
38
+ tins (~> 1.0)
39
+ thor (0.19.4)
40
+ tins (1.16.3)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ byebug
47
+ coveralls
48
+ nanoc-latexmk!
49
+ rspec
50
+
51
+ BUNDLED WITH
52
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Nanoc-latexmk
2
+
3
+ [Nanoc](https://nanoc.ws/) filter to compile `.tex` files to pdf using the `latexmk` command. Supports both `pdflatex` and `xelatex`.
4
+
5
+ ## System requirements
6
+
7
+ You need everything to build your LaTeX file manually, so `latexmk`, `pdflatex` and `xelatex` need to be installed on your system.
8
+
9
+ ## Installation
10
+
11
+ To use this filter, add nanoc-latexmk to your `Gemfile`.
12
+ ```
13
+ gem 'nanoc-latexmk'
14
+ ```
15
+ Then require this project in your `Rules`:
16
+ ```
17
+ require 'nanoc/latexmk'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ First, be sure to add `tex` to the `text_extensions` in your `nanoc.yaml`.
23
+
24
+ With a basic file in `content/file.tex`:
25
+
26
+ ```
27
+ ---
28
+ title: Hello
29
+ ---
30
+ \section{World}
31
+ ```
32
+ And a layout in `layouts/default.tex.erb`
33
+ ```
34
+ \documentclass{article}
35
+ \title{<%= item[:title] %>}
36
+ \begin{document}
37
+ \maketitle
38
+ <%= yield %>
39
+ \end{document}
40
+ ```
41
+ You can add this to your `Rules`
42
+ ```
43
+ compile '/**/*.tex', rep: :pdf do
44
+ layout '/default.tex.erb'
45
+ filter :latexmk
46
+ write ext: 'pdf'
47
+ end
48
+ ```
49
+
50
+ Results in:
51
+ ![Hello World PDF](https://user-images.githubusercontent.com/3226995/34323260-3995578a-e841-11e7-9aeb-b1e2ae6e84a6.png)
52
+
53
+ ## Licence
54
+
55
+ See the [UNLICENSE](https://github.com/rien/nanoc-latexmk/blob/master/LICENSE) for details.
56
+
57
+ ## Author
58
+ Rien Maertens [maertensrien@gmail.com](mailto:maertensrien@gmail.com)
59
+
60
+ ## Changelog
61
+
62
+ See the [CHANGELOG](https://github.com/rien/nanoc-latexmk/blob/master/CHANGELOG.md) for details.
63
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ require 'rubygems'
3
+ require 'rspec/core/rake_task'
4
+ require 'rake'
5
+
6
+ Bundler::GemHelper.install_tasks
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = './spec/**/*_spec.rb'
10
+ end
11
+
12
+ task default: :spec
@@ -0,0 +1,9 @@
1
+ require 'nanoc'
2
+
3
+ module Nanoc
4
+ module Latexmk
5
+ end
6
+ end
7
+
8
+ require_relative 'latexmk/filters'
9
+ require_relative 'latexmk/version'
@@ -0,0 +1,4 @@
1
+ module Nanoc::Latexmk::Filters
2
+ end
3
+
4
+ require_relative 'filters/latexmk'
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tmpdir'
4
+
5
+ module Nanoc::Latexmk::Filters
6
+ class LatexmkFilter < Nanoc::Filter
7
+ identifier :latexmk
8
+
9
+ type :text => :binary
10
+
11
+ TMPFILE_NAME = 'nanoc-latexmk.tex'
12
+
13
+ ENGINES = {
14
+ pdflatex: { cmd: %w[pdflatex], param: '-pdf' },
15
+ xelatex: { cmd: %w[xelatex], param: '-xelatex' }
16
+ }.freeze
17
+
18
+ LATEX_PARAMS = %w[-interaction=nonstopmode -halt-on-error].freeze
19
+
20
+ DEFAULT_PARAMS = {
21
+ engine: :pdflatex,
22
+ command_params: LATEX_PARAMS,
23
+ shell_escape: false
24
+ }.freeze
25
+
26
+ def run(content, params = {})
27
+ params = DEFAULT_PARAMS.merge(params)
28
+
29
+ raise 'Unknown Engine' unless ENGINES.key? params[:engine].to_sym
30
+ engine = ENGINES[params[:engine].to_sym]
31
+
32
+ latex_command = engine[:cmd]
33
+
34
+ latex_command += params[:command_params]
35
+
36
+ latex_command << if params[:shell_escape]
37
+ '-shell-escape'
38
+ else
39
+ '-no-shell-escape'
40
+ end
41
+
42
+ Dir.mktmpdir do |dir|
43
+ File.open(File.join(dir, TMPFILE_NAME), 'w') do |f|
44
+ f.write(content)
45
+ f.flush
46
+
47
+ latexmk_command = ['latexmk',
48
+ engine[:param],
49
+ "-latex=\"#{latex_command.join(' ')}\"",
50
+ "-output-directory=#{dir}",
51
+ f.path]
52
+
53
+ raise 'Build Error' unless system(*latexmk_command)
54
+ system('mv', f.path.sub('.tex', '.pdf'), output_filename)
55
+
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,14 @@
1
+ module Nanoc
2
+ module Latexmk
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ PATCH = 0
7
+ BUILD = nil
8
+
9
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
10
+ end
11
+
12
+ VERSION = Version::STRING
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../lib/nanoc/latexmk/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'nanoc-latexmk'
5
+ s.version = Nanoc::Latexmk::VERSION
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ['Rien Maertens']
8
+ s.email = ['maertensrien@gmail.com']
9
+ s.homepage = 'https://github.com/rien/nanoc-latexmk'
10
+ s.summary = 'Latexmk filter for nanoc.'
11
+ s.description = 'Nanoc filter to convert latex files to pdf using latexmk'
12
+ s.files = `git ls-files`.split("\n")
13
+ s.require_path = 'lib'
14
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'byebug'
3
+
4
+ describe Nanoc::Latexmk::Filters::LatexmkFilter do
5
+ before(:each) do
6
+ @filter = described_class.new
7
+ @input = <<~HEREDOC
8
+ \\documentclass[12pt]{article}
9
+ \\begin{document}
10
+ Hello world!
11
+ \\end{document}
12
+ HEREDOC
13
+ @pdf_magic_bytes = '%PDF'
14
+ end
15
+
16
+ describe '.run' do
17
+ it 'compile to pdf' do
18
+ expect(@filter.run(@input)).to be_truthy
19
+
20
+ result = File.read @filter.output_filename
21
+ expect(result.slice(0, @pdf_magic_bytes.length)).to eql(@pdf_magic_bytes)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'rspec/core'
5
+ require 'nanoc/latexmk'
6
+ require 'nanoc'
7
+
8
+ unless defined?(SPEC_ROOT)
9
+ SPEC_ROOT = File.expand_path('../', __FILE__)
10
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-latexmk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rien Maertens
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Nanoc filter to convert latex files to pdf using latexmk
14
+ email:
15
+ - maertensrien@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".ruby-version"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - lib/nanoc/latexmk.rb
29
+ - lib/nanoc/latexmk/filters.rb
30
+ - lib/nanoc/latexmk/filters/latexmk.rb
31
+ - lib/nanoc/latexmk/version.rb
32
+ - nanoc-latexmk.gemspec
33
+ - spec/filters/latexmk_spec.rb
34
+ - spec/spec_helper.rb
35
+ homepage: https://github.com/rien/nanoc-latexmk
36
+ licenses: []
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.6.13
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Latexmk filter for nanoc.
58
+ test_files: []