jekyll-latex-pdf 0.3.1 → 0.4.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: c206e73833eec7f40f7d9478b400f2b7b04d375a
4
- data.tar.gz: 6bc6c41424c049589a90d65ee8d482730738568d
3
+ metadata.gz: 5696d522098b6d7102e6a018725a5bdbd66fac63
4
+ data.tar.gz: 2140c6d7fa8468fb02c1fa16c405ac89c7584298
5
5
  SHA512:
6
- metadata.gz: 903a0808e458235e79ff210dd7206fc04609a5202b2bfc4a175c875cbf9739723084d4b299e9ee3b55c00df77dea04f5685c70c8c4f04eacbe04428d062a4036
7
- data.tar.gz: cf4f8283d2bfc800b76f08b43c2a9eda039476cd345ab1b19627af8c5385edc29ce91dc86d8083c6fdb0b74c136f18cd95202347cf60dcd294444ff4292bc9fe
6
+ metadata.gz: abf1490bb38c2f34cda5679dd76309a313dd0636226dcee8a435f81e4d69745df0c10e4bcb648b67605ab24b193a9c4b82e5027818f739fb2d3493a9ae5a7498
7
+ data.tar.gz: 21ed7ba16de27881ef3bc2a9db5de399f69faf35d3a34bf10577dd703a4bc13c59b67d28f5cfa02087eb640bfa900e7978c280d84c6fd6136015c4d7dab54714
data/.rubocop.yml ADDED
@@ -0,0 +1,162 @@
1
+ ---
2
+
3
+ require:
4
+ - ./rubocop/jekyll
5
+
6
+ Jekyll/NoPutsAllowed:
7
+ Exclude:
8
+ - rake/*.rake
9
+
10
+ AllCops:
11
+ TargetRubyVersion: 2.3
12
+ Include:
13
+ - lib/**/*.rb
14
+ - test/**/*.rb
15
+ Exclude:
16
+ - bin/**/*
17
+ - exe/**/*
18
+ - benchmark/**/*
19
+ - script/**/*
20
+ - vendor/**/*
21
+ - tmp/**/*
22
+ Layout/AlignHash:
23
+ EnforcedHashRocketStyle: table
24
+ Layout/IndentationWidth:
25
+ Severity: error
26
+ Layout/IndentArray:
27
+ EnforcedStyle: consistent
28
+ Layout/IndentHash:
29
+ EnforcedStyle: consistent
30
+ Layout/MultilineMethodCallIndentation:
31
+ EnforcedStyle: indented
32
+ Layout/MultilineOperationIndentation:
33
+ EnforcedStyle: indented
34
+ Lint/NestedPercentLiteral:
35
+ Exclude:
36
+ - test/test_site.rb
37
+ Layout/EmptyComment:
38
+ Enabled: false
39
+ Layout/EndAlignment:
40
+ Severity: error
41
+ Lint/UnreachableCode:
42
+ Severity: error
43
+ Lint/Void:
44
+ Exclude:
45
+ - lib/jekyll/site.rb
46
+ Metrics/AbcSize:
47
+ Max: 21
48
+ Metrics/BlockLength:
49
+ Exclude:
50
+ - test/**/*.rb
51
+ - lib/jekyll/configuration.rb
52
+ - rake/*.rake
53
+ Metrics/ClassLength:
54
+ Exclude:
55
+ - !ruby/regexp /features\/.*.rb$/
56
+ - !ruby/regexp /test\/.*.rb$/
57
+ - lib/jekyll/document.rb
58
+ - lib/jekyll/site.rb
59
+ - lib/jekyll/commands/serve.rb
60
+ - lib/jekyll/configuration.rb
61
+ Max: 240
62
+ Metrics/CyclomaticComplexity:
63
+ Exclude:
64
+ - lib/jekyll/utils.rb
65
+ - lib/jekyll/commands/serve.rb
66
+ Metrics/LineLength:
67
+ Exclude:
68
+ - !ruby/regexp /features\/.*.rb/
69
+ - Rakefile
70
+ - rake/*.rake
71
+ - Gemfile
72
+ Max: 120
73
+ Severity: warning
74
+ Metrics/MethodLength:
75
+ CountComments: false
76
+ Max: 20
77
+ Severity: error
78
+ Metrics/ModuleLength:
79
+ Max: 240
80
+ Metrics/ParameterLists:
81
+ Max: 4
82
+ Metrics/PerceivedComplexity:
83
+ Max: 8
84
+ Naming/FileName:
85
+ Enabled: false
86
+ Naming/HeredocDelimiterNaming:
87
+ Exclude:
88
+ - test/**/*.rb
89
+ Naming/MemoizedInstanceVariableName:
90
+ Exclude:
91
+ - lib/jekyll/convertible.rb
92
+ - lib/jekyll/drops/site_drop.rb
93
+ - lib/jekyll/drops/unified_payload_drop.rb
94
+ - lib/jekyll/page_without_a_file.rb
95
+ Security/MarshalLoad:
96
+ Exclude:
97
+ - !ruby/regexp /test\/.*.rb$/
98
+ - lib/jekyll/regenerator.rb
99
+ Security/YAMLLoad:
100
+ Exclude:
101
+ - !ruby/regexp /features\/.*.rb/
102
+ - !ruby/regexp /test\/.*.rb$/
103
+ Style/AccessModifierDeclarations:
104
+ Enabled: false
105
+ Style/Alias:
106
+ EnforcedStyle: prefer_alias_method
107
+ Style/AndOr:
108
+ Severity: error
109
+ Style/ClassAndModuleChildren:
110
+ Exclude:
111
+ - test/**/*.rb
112
+ Style/ClassVars:
113
+ Enabled: false
114
+ Style/FrozenStringLiteralComment:
115
+ EnforcedStyle: always
116
+ Style/Documentation:
117
+ Enabled: false
118
+ Style/DoubleNegation:
119
+ Enabled: false
120
+ Style/FormatStringToken:
121
+ Exclude:
122
+ - lib/jekyll/utils/ansi.rb
123
+ Style/GuardClause:
124
+ Enabled: false
125
+ Style/HashSyntax:
126
+ EnforcedStyle: hash_rockets
127
+ Severity: error
128
+ Style/MixinUsage:
129
+ Exclude:
130
+ - test/helper.rb
131
+ Style/ModuleFunction:
132
+ Enabled: false
133
+ Style/MultilineTernaryOperator:
134
+ Severity: error
135
+ Style/PercentLiteralDelimiters:
136
+ PreferredDelimiters:
137
+ "%q": "{}"
138
+ "%Q": "{}"
139
+ "%r": "!!"
140
+ "%s": "()"
141
+ "%w": "()"
142
+ "%W": "()"
143
+ "%x": "()"
144
+ Style/RegexpLiteral:
145
+ EnforcedStyle: percent_r
146
+ Style/RescueModifier:
147
+ Enabled: false
148
+ Style/SafeNavigation:
149
+ Exclude:
150
+ - lib/jekyll/document.rb
151
+ Style/SignalException:
152
+ EnforcedStyle: only_raise
153
+ Style/StringLiterals:
154
+ EnforcedStyle: double_quotes
155
+ Style/StringLiteralsInInterpolation:
156
+ EnforcedStyle: double_quotes
157
+ Style/SymbolArray:
158
+ EnforcedStyle: brackets
159
+ Style/TrailingCommaInArrayLiteral:
160
+ EnforcedStyleForMultiline: consistent_comma
161
+ Style/TrailingCommaInHashLiteral:
162
+ EnforcedStyleForMultiline: consistent_comma
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in jekyll-latex-pdf.gemspec
6
8
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-latex-pdf (0.3.1)
4
+ jekyll-latex-pdf (0.4.0)
5
5
  jekyll (~> 3.8.5)
6
6
  kramdown (~> 1.17)
7
7
 
@@ -10,6 +10,8 @@ GEM
10
10
  specs:
11
11
  addressable (2.6.0)
12
12
  public_suffix (>= 2.0.2, < 4.0)
13
+ ast (2.4.0)
14
+ coderay (1.1.2)
13
15
  colorator (1.1.0)
14
16
  concurrent-ruby (1.1.5)
15
17
  em-websocket (0.5.1)
@@ -21,6 +23,7 @@ GEM
21
23
  http_parser.rb (0.6.0)
22
24
  i18n (0.9.5)
23
25
  concurrent-ruby (~> 1.0)
26
+ jaro_winkler (1.5.2)
24
27
  jekyll (3.8.5)
25
28
  addressable (~> 2.4)
26
29
  colorator (~> 1.0)
@@ -45,14 +48,35 @@ GEM
45
48
  rb-inotify (~> 0.9, >= 0.9.7)
46
49
  ruby_dep (~> 1.2)
47
50
  mercenary (0.3.6)
51
+ method_source (0.8.2)
52
+ parallel (1.17.0)
53
+ parser (2.6.2.1)
54
+ ast (~> 2.4.0)
48
55
  pathutil (0.16.2)
49
56
  forwardable-extended (~> 2.6)
57
+ pry (0.11.0)
58
+ coderay (~> 1.1.0)
59
+ method_source (~> 0.8.1)
60
+ pry-doc (0.6.0)
61
+ pry (~> 0.9)
62
+ yard (~> 0.8)
63
+ psych (3.1.0)
50
64
  public_suffix (3.0.3)
65
+ rainbow (3.0.0)
51
66
  rake (10.5.0)
52
67
  rb-fsevent (0.10.3)
53
68
  rb-inotify (0.10.0)
54
69
  ffi (~> 1.0)
55
70
  rouge (3.3.0)
71
+ rubocop (0.67.2)
72
+ jaro_winkler (~> 1.5.1)
73
+ parallel (~> 1.10)
74
+ parser (>= 2.5, != 2.5.1.1)
75
+ psych (>= 3.1.0)
76
+ rainbow (>= 2.2.2, < 4.0)
77
+ ruby-progressbar (~> 1.7)
78
+ unicode-display_width (>= 1.4.0, < 1.6)
79
+ ruby-progressbar (1.10.0)
56
80
  ruby_dep (1.5.0)
57
81
  safe_yaml (1.0.5)
58
82
  sass (3.7.3)
@@ -60,6 +84,8 @@ GEM
60
84
  sass-listen (4.0.0)
61
85
  rb-fsevent (~> 0.9, >= 0.9.4)
62
86
  rb-inotify (~> 0.9, >= 0.9.7)
87
+ unicode-display_width (1.5.0)
88
+ yard (0.9.19)
63
89
 
64
90
  PLATFORMS
65
91
  ruby
@@ -67,7 +93,11 @@ PLATFORMS
67
93
  DEPENDENCIES
68
94
  bundler (~> 1.16)
69
95
  jekyll-latex-pdf!
96
+ method_source (~> 0.8.2)
97
+ pry
98
+ pry-doc (~> 0.6.0)
70
99
  rake (~> 10.0)
100
+ rubocop (~> 0.67)
71
101
 
72
102
  BUNDLED WITH
73
103
  1.16.1
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
data/bin/console CHANGED
@@ -1,14 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "jekyll/latex/pdf"
3
+ require 'bundler/setup'
4
+ require 'jekyll'
5
+ require 'jekyll/latex/pdf'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
8
9
 
9
10
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
11
+ require "pry"
12
+ Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,3 +1,4 @@
1
+ <% data = @converter.options[:data] %>
1
2
  <%
2
3
  encmap = {
3
4
  'UTF-8' => 'utf8x',
@@ -19,6 +20,12 @@ encmap = {
19
20
  'CP1257' => 'cp1257'
20
21
  }
21
22
  %>
23
+ <%
24
+ enclang = {
25
+ 'de' => 'ngerman',
26
+ 'sv' => 'swedish'
27
+ }
28
+ %>
22
29
  \documentclass{scrartcl}
23
30
  <% if RUBY_VERSION >= '1.9' %>
24
31
  \usepackage[<%= encmap[@body.encoding.name] %>]{inputenc}
@@ -32,6 +39,18 @@ encmap = {
32
39
  <% } %>
33
40
  \usepackage{hyperref}
34
41
 
42
+ <% if data[:lang] %>
43
+ \usepackage[<%= enclang[data[:lang]] %>]{babel}
44
+ \usepackage[<%= enclang[data[:lang]] %>]{isodate}
45
+ <% end %>
46
+
47
+ <% if data[:bibtex_files] %>
48
+ \usepackage{biblatex}
49
+ <% data[:bibtex_files].each { |bibfile| %>\addbibresource{<%= bibfile %>}
50
+ <% } %>
51
+ <% end %>
52
+
53
+
35
54
  <% if @converter.data[:packages].include?('fancyvrb') %>
36
55
  \VerbatimFootnotes
37
56
  <% end %>
@@ -45,14 +64,22 @@ encmap = {
45
64
 
46
65
  \hypersetup{colorlinks=true,urlcolor=blue}
47
66
 
48
- <% if @converter.options[:title] %>
49
- \title{<%= @converter.options[:title] %>}
50
- \author{<%= @converter.options[:author] %>}
51
- \date{<%= @converter.options[:date] %>}
67
+ <% if data[:title] %>
68
+ \title{<%= data[:title] %>}
69
+ <% end %>
70
+ <% if data[:author] %>
71
+ \author{<%= data[:author] %>}
72
+ <% end %>
73
+ <% if data[:date] %>
74
+ <% if data[:lang] %>
75
+ \date{\printdate{<%= data[:date] %>}}
76
+ <% else %>
77
+ \date{<%= data[:date] %>}
78
+ <% end %>
52
79
  <% end %>
53
80
 
54
81
  \begin{document}
55
- <% if @converter.options[:title] %>
82
+ <% if data[:title] %>
56
83
  \maketitle
57
84
  <% end %>
58
85
  <%= @body %>
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require "jekyll/latex/pdf/version"
5
6
 
@@ -15,14 +16,18 @@ Gem::Specification.new do |spec|
15
16
  spec.license = "MIT"
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
19
+ f.match(%r!^(test|spec|features)/!)
19
20
  end
20
21
  spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.executables = spec.files.grep(%r!^exe/!) { |f| File.basename(f) }
22
23
  spec.require_paths = ["lib"]
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "method_source", "~> 0.8.2"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "pry-doc", "~> 0.6.0"
25
29
  spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rubocop", "~> 0.67"
26
31
 
27
32
  spec.add_runtime_dependency "jekyll", "~> 3.8.5"
28
33
  spec.add_runtime_dependency "kramdown", "~> 1.17"
@@ -1,68 +1,44 @@
1
- #require "paru/pandoc"
1
+ # frozen_string_literal: true
2
+
2
3
  require "kramdown"
3
- require 'tmpdir'
4
- require "open3"
5
- require 'fileutils'
4
+ require "fileutils"
6
5
 
7
6
  module Jekyll
8
7
  module Latex
9
8
  module Pdf
9
+ # The document adds the file.
10
10
  class Document < Jekyll::Page
11
+ attr_accessor :source
12
+
13
+ def initialize_data(page)
14
+ self.data = page.data.clone
15
+ self.content = page.content.clone
16
+ self.source = page.content.dup
17
+ page.data["pdf_url"] = url
18
+ data["html_url"] = page.url
19
+ data["date"] = data["date"].strftime("%Y-%m-%d")
20
+ Options.add_data data
21
+ end
22
+
11
23
  def initialize(site, page)
12
24
  @site = site
13
25
  @base = site.source
14
26
  @dir = File.dirname(page.url)
15
- @name = File.basename(page.url, File.extname(page.url)) + '.pdf'
16
- @texname = File.basename(page.url, File.extname(page.url)) + '.tex'
17
- @settings = site.config.key?('pdf') ? site.config['pdf'].clone : {}
18
-
19
- self.process(@name)
20
- self.data = page.data.clone
21
- self.content = page.content.clone
22
- page.data['pdf_url'] = self.url
23
- self.data['html_url'] = page.url
24
-
25
- self.data['date'] = self.data['date'].strftime("%Y-%m-%d")
26
-
27
- template = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'data', 'kramdown', 'jekyll-latex-pdf.latex'))
28
-
29
- defaults = {
30
- 'template' => template,
31
- 'pdf_engine' => 'lualatex'
32
- }
27
+ @name = File.basename(page.url, File.extname(page.url)) + ".pdf"
28
+ @texname = File.basename(page.url, File.extname(page.url)) + ".tex"
29
+ @settings = site.config.key?("pdf") ? site.config["pdf"].clone : {}
33
30
 
34
- if @settings['template']
35
- @settings['template'] = File.expand_path(File.join("_latex", @settings['template']))
36
- unless @settings['template'].end_with?(".latex")
37
- @settings['template'].concat(".latex")
38
- end
39
- end
31
+ process(@name)
32
+ Options.add_options @settings
40
33
 
41
- @options = defaults.merge( @settings.merge(self.data) )
42
- puts @options
34
+ initialize_data(page)
43
35
  end
44
-
45
- def write(dest)
46
- path = File.join(dest, CGI.unescape(self.url))
47
- tempdir = Dir.mktmpdir('jekyll-latex-pdf')
48
- latexfile = File.join(tempdir, "texput.tex")
49
-
50
- latex_string = Kramdown::Document.new(self.content, @options).to_latex
51
- File.open(latexfile, "w:UTF-8") do |f|
52
- f.write(latex_string)
53
- end
54
-
55
- stdout_str, status = Open3.capture2(@options['pdf_engine'], "--output-directory=#{tempdir}", "--output-format=pdf",
56
- "--interaction=batchmode", latexfile)
57
- #puts stdout_str
58
36
 
59
-
60
- if (status == 0)
61
- FileUtils.mv(File.join(tempdir, "texput.pdf"), path)
62
- else
63
- puts "Error when trying to run #{@options['pdf_engine']}. See #{tempdir}/texput.log"
64
- end
37
+ def write(dest)
38
+ path = File.join(dest, CGI.unescape(url))
65
39
 
40
+ latex = Latex.new(source, @site)
41
+ FileUtils.cp(latex.pdf_file, path) if latex.compile == 0
66
42
  end
67
43
  end
68
44
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Latex
3
5
  module Pdf
4
6
  class Generator < Jekyll::Generator
5
7
  def generate(site)
6
8
  site.posts.docs.each do |post|
7
- site.pages << Document.new(site, post) if post.data['pdf']
9
+ site.pages << Document.new(site, post) if post.data["pdf"]
8
10
  end
9
11
  end
10
12
  end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tmpdir"
4
+ require "open3"
5
+ # require 'fileutils'
6
+
7
+ module Jekyll
8
+ module Latex
9
+ module Pdf
10
+ # The Latex Class will create the tex file and compile it to the pdf file.
11
+ class Latex
12
+ attr_accessor :source, :latex
13
+ attr_reader :pdf_file
14
+ def initialize(source, site)
15
+ @engine = Options.options[:pdf_engine]
16
+ @bibengine = Options.options[:bib_engine]
17
+ @site = site
18
+
19
+ self.source = source
20
+ end
21
+
22
+ def prepare_latex
23
+ TempLiquid.run do
24
+ liquid_parsed = Liquid::Template.parse(source, :error_mode => :strict)
25
+ unless liquid_parsed.errors.empty?
26
+ Jekyll.logger.warn("Liquid parse errors", liquid_parsed.errors.join(", "))
27
+ end
28
+ prep_latex = liquid_parsed.render(:strict_filters => true,
29
+ :strict_variables => true)
30
+ unless liquid_parsed.errors.empty?
31
+ Jekyll.logger.warn("Liquid render errors", liquid_parsed.errors.join(", "))
32
+ end
33
+ @latex = Kramdown::Document
34
+ .new(prep_latex, Options.options)
35
+ .to_latex
36
+ end
37
+ end
38
+
39
+ def prepare
40
+ prepare_latex
41
+
42
+ @tempdir = Dir.mktmpdir("jekyll-latex-pdf")
43
+ @latexfile = "texput.tex" # File.join(@tempdir, "texput.tex")
44
+
45
+ # puts "writing to #{@latexfile}:", latex
46
+ File.open(File.join(@tempdir, @latexfile), "w:UTF-8") do |f|
47
+ f.write(latex)
48
+ end
49
+
50
+ add_bibliography
51
+ end
52
+
53
+ def add_bibliography
54
+ if Options.data.key? :bibtex_files
55
+ Options.data[:bibtex_files].each do |bibfile|
56
+ bibpath = File.join(@tempdir, File.dirname(bibfile))
57
+ FileUtils.mkdir_p bibpath unless File.directory? bibpath
58
+ FileUtils.cp(bibfile, bibpath)
59
+ end
60
+ end
61
+ end
62
+
63
+ def prepare_cmds
64
+ cmds = [[Options.options[:pdf_engine],
65
+ # "--output-directory=#{@tempdir}",
66
+ "--output-format=pdf",
67
+ "--interaction=batchmode",
68
+ @latexfile,]]
69
+ # biber if bibfiles given
70
+ if Options.data.key? :bibtex_files
71
+ cmds << [Options.options[:bib_engine],
72
+ File.basename(@latexfile, File.extname(@latexfile)),]
73
+ cmds << cmds[0]
74
+ end
75
+ end
76
+
77
+ def compile
78
+ prepare
79
+ cmds = prepare_cmds
80
+
81
+ Jekyll.logger.info "jekyll-latex-pdf", "compiling in tempdir: #{@tempdir}"
82
+
83
+ status = 0
84
+ out = ""
85
+ cmds.each do |cmd|
86
+ Open3.popen2(*cmd, :chdir => @tempdir) do |_i, oe, t|
87
+ oe.each { |l| out += l }
88
+ status = t.value
89
+ end
90
+ end
91
+
92
+ # puts stdout_str
93
+ if status == 0
94
+ @pdf_file = File.join(@tempdir, "texput.pdf")
95
+ else
96
+ # puts stdout_str
97
+ Jekyll.logger.debug "jekyll-latex-pdf", "status: #{status}"
98
+ Jekyll.logger.debug "jekyll-latex-pdf", "output: #{out}"
99
+ Jekyll.logger.debug "jekyll-latex-pdf", "Error when trying to run #{Options.options[:pdf_engine]}."
100
+ Jekyll.logger.debug "jekyll-latex-pdf", "See #{@tempdir}/texput.log"
101
+ end
102
+ status
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Latex
5
+ module Pdf
6
+ # Generates an environment where we temporarily can add new tags to the templet,
7
+ # without changing the registered tags.
8
+ class TempLiquid
9
+ def save_liquid_tags
10
+ @saved_liquid_tags = Liquid::Template.tags.dup
11
+ end
12
+
13
+ def register_tag(tag_key, tag_value)
14
+ Liquid::Template.register_tag(tag_key, tag_value)
15
+ @tmp_keys ||= []
16
+ @tmp_keys << tag_key
17
+ end
18
+
19
+ def register_tags
20
+ Options.tags.each do |tag_key, tag_value|
21
+ register_tag(tag_key, tag_value)
22
+ Jekyll.logger.debug "Register tag:", tag_key.to_s
23
+ end
24
+ end
25
+
26
+ def restore_liquid_tags
27
+ @tmp_keys.each do |k|
28
+ if @saved_liquid_tags[k]
29
+ Liquid::Template.register_tag(k, @saved_liquid_tags[k])
30
+ else
31
+ Liquit::Template.tags.delete(k)
32
+ end
33
+ end
34
+ end
35
+
36
+ def self.run
37
+ s = TempLiquid.new
38
+ s.save_liquid_tags
39
+ s.register_tags
40
+ yield s
41
+ s.restore_liquid_tags
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Latex
5
+ module Pdf
6
+ class Options
7
+ # setting default
8
+
9
+ @@liquid_tags = {}
10
+ @@options = { :pdf_engine => "lualatex",
11
+ :bib_engine => "biber",
12
+ :template => File.expand_path(
13
+ File.join(File.dirname(__FILE__), "..", "..", "..", "..",
14
+ "data", "kramdown", "jekyll-latex-pdf.latex")
15
+ ), }
16
+
17
+ @@data = {}
18
+ @@allowed_keys = @@options.keys
19
+
20
+ class << self
21
+ def hash_args(*args)
22
+ hashed_args = args.detect { |f| f.class == Hash }
23
+ hashed_args.each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v; }
24
+ end
25
+
26
+ def add_options(*args)
27
+ hashed_args = hash_args(*args)
28
+ if hashed_args[:template]
29
+ hashed_args[:template] = File.expand_path(File.join("_latex", hashed_args[:template]))
30
+ hashed_args[:template].concat(".latex") unless hashed_args[:template].end_with?(".latex")
31
+ end
32
+
33
+ allowed_args = hashed_args.select { |key, _| @@allowed_keys.include? key }
34
+ @@options.merge! allowed_args
35
+ add_data(hashed_args.reject { |key, _| @@allowed_keys.include? key })
36
+ end
37
+
38
+ def options
39
+ @@options[:data] = @@data
40
+ @@options
41
+ end
42
+
43
+ def add_data(*args)
44
+ @@data.merge! hash_args(*args)
45
+ puts "@@data is now:", @@data
46
+ end
47
+
48
+ def data
49
+ @@data
50
+ end
51
+
52
+ def tags
53
+ @@liquid_tags
54
+ end
55
+
56
+ def register_tag(name, klass)
57
+ @@liquid_tags[name.to_s] = klass
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Latex
5
+ module Pdf
6
+ ## here we add support for jekyll-scholar, a great module for scientific writing.
7
+ module Scholar
8
+ class Bibliography < Liquid::Tag
9
+ include Utilities
10
+ include Jekyll::Scholar::Utilities
11
+ def initialize(tag_name, arguments, tokens)
12
+ super
13
+
14
+ # getting bibtex files
15
+ @config = Jekyll::Scholar.defaults.dup
16
+ puts "bibtex files", bibtex_files.class
17
+ Options.add_data(:bibtex_files => bibtex_files.map { |bibfile| File.join(@config["source"], bibfile) })
18
+
19
+ @keys = arguments
20
+ end
21
+
22
+ def render(_context)
23
+ nomarkdown "\\printbibliography"
24
+ end
25
+ end
26
+ end
27
+
28
+ Options.register_tag("bibliography", Scholar::Bibliography)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Latex
5
+ module Pdf
6
+ ## here we add support for jekyll-scholar, a great module for scientific writing.
7
+ module Scholar
8
+ class Cite < Liquid::Tag
9
+ include Utilities
10
+ def initialize(tag_name, arguments, tokens)
11
+ super
12
+
13
+ @keys = arguments
14
+ end
15
+
16
+ def render(_context)
17
+ # set_context_to context+
18
+ if @keys.is_a? String
19
+ nomarkdown "\\parencite\{#{@keys.strip}\}"
20
+ else
21
+ nomarkdown "\\parencite\{" + @keys.collect { |x| x.strip || x }.join(",") + "\}"
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ Options.register_tag("cite", Scholar::Cite)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll/latex/pdf/scholar/cite"
4
+ require "jekyll/latex/pdf/scholar/bibliography"
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Latex
5
+ module Pdf
6
+ module Utilities
7
+ def nomarkdown(string_to_wrap)
8
+ "{::nomarkdown type=\"latex\"}" + string_to_wrap + "{:/}"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Latex
3
5
  module Pdf
4
- VERSION = "0.3.1"
6
+ VERSION = "0.4.0"
5
7
  end
6
8
  end
7
9
  end
@@ -1,3 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll/latex/pdf/options"
4
+ require "jekyll/latex/pdf/utilities"
5
+ require "jekyll/latex/pdf/liquid"
6
+
7
+ # having jekyll-scholar installed?
8
+ require "jekyll/latex/pdf/scholar" if Jekyll.configuration({})["plugins"].include? "jekyll-scholar"
9
+
10
+ require "jekyll/latex/pdf/latex"
1
11
  require "jekyll/latex/pdf/document"
2
12
  require "jekyll/latex/pdf/generator"
3
13
  require "jekyll/latex/pdf/version"
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "jekyll/latex/pdf"
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Jekyll
6
+ # Checks for `assert_equal(exp, act, msg = nil)` calls containing literal values as
7
+ # second argument. The second argument should ideally be a method called on the tested
8
+ # instance.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # assert_equal @foo.bar, "foobar"
13
+ # assert_equal @alpha.beta, { "foo" => "bar", "lorem" => "ipsum" }
14
+ # assert_equal @alpha.omega, ["foobar", "lipsum"]
15
+ #
16
+ # # good
17
+ # assert_equal "foobar", @foo.bar
18
+ #
19
+ # assert_equal(
20
+ # { "foo" => "bar", "lorem" => "ipsum" },
21
+ # @alpha.beta
22
+ # )
23
+ #
24
+ # assert_equal(
25
+ # ["foobar", "lipsum"],
26
+ # @alpha.omega
27
+ # )
28
+ #
29
+ class AssertEqualLiteralActual < Cop
30
+ MSG = "Provide the 'expected value' as the first argument to `assert_equal`.".freeze
31
+
32
+ SIMPLE_LITERALS = %i(
33
+ true
34
+ false
35
+ nil
36
+ int
37
+ float
38
+ str
39
+ sym
40
+ complex
41
+ rational
42
+ regopt
43
+ ).freeze
44
+
45
+ COMPLEX_LITERALS = %i(
46
+ array
47
+ hash
48
+ pair
49
+ irange
50
+ erange
51
+ regexp
52
+ ).freeze
53
+
54
+ def_node_matcher :literal_actual?, <<-PATTERN
55
+ (send nil? :assert_equal $(send ...) $#literal?)
56
+ PATTERN
57
+
58
+ def_node_matcher :literal_actual_with_msg?, <<-PATTERN
59
+ (send nil? :assert_equal $(send ...) $#literal? $#opt_msg?)
60
+ PATTERN
61
+
62
+ def on_send(node)
63
+ return unless literal_actual?(node) || literal_actual_with_msg?(node)
64
+ add_offense(node, location: :expression)
65
+ end
66
+
67
+ def autocorrect(node)
68
+ lambda do |corrector|
69
+ corrector.replace(node.loc.expression, replacement(node))
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def opt_msg?(node)
76
+ node&.source
77
+ end
78
+
79
+ # This is not implement using a NodePattern because it seems
80
+ # to not be able to match against an explicit (nil) sexp
81
+ def literal?(node)
82
+ node && (simple_literal?(node) || complex_literal?(node))
83
+ end
84
+
85
+ def simple_literal?(node)
86
+ SIMPLE_LITERALS.include?(node.type)
87
+ end
88
+
89
+ def complex_literal?(node)
90
+ COMPLEX_LITERALS.include?(node.type) &&
91
+ node.each_child_node.all?(&method(:literal?))
92
+ end
93
+
94
+ def replacement(node)
95
+ _, _, first_param, second_param, optional_param = *node
96
+
97
+ replaced_text = \
98
+ if second_param.type == :hash
99
+ replace_hash_with_variable(first_param.source, second_param.source)
100
+ elsif second_param.type == :array && second_param.source != "[]"
101
+ replace_array_with_variable(first_param.source, second_param.source)
102
+ else
103
+ replace_based_on_line_length(first_param.source, second_param.source)
104
+ end
105
+
106
+ return "#{replaced_text}, #{optional_param.source}" if optional_param
107
+ replaced_text
108
+ end
109
+
110
+ def replace_based_on_line_length(first_expression, second_expression)
111
+ result = "assert_equal #{second_expression}, #{first_expression}"
112
+ return result if result.length < 80
113
+
114
+ # fold long lines independent of Rubocop configuration for better readability
115
+ <<~TEXT
116
+ assert_equal(
117
+ #{second_expression},
118
+ #{first_expression}
119
+ )
120
+ TEXT
121
+ end
122
+
123
+ def replace_hash_with_variable(first_expression, second_expression)
124
+ expect_expression = if second_expression.start_with?("{")
125
+ second_expression
126
+ else
127
+ "{#{second_expression}}"
128
+ end
129
+ <<~TEXT
130
+ expected = #{expect_expression}
131
+ assert_equal expected, #{first_expression}
132
+ TEXT
133
+ end
134
+
135
+ def replace_array_with_variable(first_expression, second_expression)
136
+ expect_expression = if second_expression.start_with?("%")
137
+ second_expression
138
+ else
139
+ Array(second_expression)
140
+ end
141
+ <<~TEXT
142
+ expected = #{expect_expression}
143
+ assert_equal expected, #{first_expression}
144
+ TEXT
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Jekyll
8
+ class NoPAllowed < Cop
9
+ MSG = "Avoid using `p` to print things. Use `Jekyll.logger` instead.".freeze
10
+
11
+ def_node_search :p_called?, <<-PATTERN
12
+ (send _ :p _)
13
+ PATTERN
14
+
15
+ def on_send(node)
16
+ if p_called?(node)
17
+ add_offense(node, :location => :selector)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Jekyll
8
+ class NoPutsAllowed < Cop
9
+ MSG = "Avoid using `puts` to print things. Use `Jekyll.logger` instead.".freeze
10
+
11
+ def_node_search :puts_called?, <<-PATTERN
12
+ (send nil? :puts _)
13
+ PATTERN
14
+
15
+ def on_send(node)
16
+ if puts_called?(node)
17
+ add_offense(node, :location => :selector)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
data/rubocop/jekyll.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir[File.join(File.expand_path("jekyll", __dir__), "*.rb")].each do |ruby_file|
4
+ require ruby_file
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-latex-pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Kaffanke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-03 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: method_source
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-doc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.0
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rake
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +80,20 @@ dependencies:
38
80
  - - "~>"
39
81
  - !ruby/object:Gem::Version
40
82
  version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.67'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.67'
41
97
  - !ruby/object:Gem::Dependency
42
98
  name: jekyll
43
99
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +131,7 @@ extensions: []
75
131
  extra_rdoc_files: []
76
132
  files:
77
133
  - ".gitignore"
134
+ - ".rubocop.yml"
78
135
  - CODE_OF_CONDUCT.md
79
136
  - Gemfile
80
137
  - Gemfile.lock
@@ -89,7 +146,18 @@ files:
89
146
  - lib/jekyll/latex/pdf.rb
90
147
  - lib/jekyll/latex/pdf/document.rb
91
148
  - lib/jekyll/latex/pdf/generator.rb
149
+ - lib/jekyll/latex/pdf/latex.rb
150
+ - lib/jekyll/latex/pdf/liquid.rb
151
+ - lib/jekyll/latex/pdf/options.rb
152
+ - lib/jekyll/latex/pdf/scholar.rb
153
+ - lib/jekyll/latex/pdf/scholar/bibliography.rb
154
+ - lib/jekyll/latex/pdf/scholar/cite.rb
155
+ - lib/jekyll/latex/pdf/utilities.rb
92
156
  - lib/jekyll/latex/pdf/version.rb
157
+ - rubocop/jekyll.rb
158
+ - rubocop/jekyll/assert_equal_literal_actual.rb
159
+ - rubocop/jekyll/no_p_allowed.rb
160
+ - rubocop/jekyll/no_puts_allowed.rb
93
161
  homepage: https://gitlab.com/grauschnabel/jekyll-latex-pdf
94
162
  licenses:
95
163
  - MIT