Remove ActiveSupport dependency and minor fixes
This commit is contained in:
parent
b135372c30
commit
b14ef9be32
@ -99,7 +99,7 @@ For asset URLs in CSS files we recommend creating a separate CSS file overriding
|
||||
|
||||
## To Do
|
||||
|
||||
- Remove dependencies for ActiveSupport & PDFKit
|
||||
- Remove PDFKit Dependency
|
||||
- Write tests (rspec)
|
||||
- Package default PDF layout file in Gem
|
||||
- Support layouts in partials
|
||||
@ -1,5 +1,5 @@
|
||||
Gem::Specification.new do |spec|
|
||||
spec.version = "0.1.0"
|
||||
spec.version = "0.1.2"
|
||||
spec.homepage = "http://github.com/abemedia/jekyll-pdf/"
|
||||
spec.authors = ["Adam Bouqdib"]
|
||||
spec.email = ["adam@abemedia.co.uk"]
|
||||
@ -16,7 +16,6 @@ Gem::Specification.new do |spec|
|
||||
spec.add_runtime_dependency("wkhtmltopdf-installer", "~> 0.12")
|
||||
spec.add_runtime_dependency("pdfkit", "~> 0.8")
|
||||
spec.add_runtime_dependency("digest", "~> 0")
|
||||
spec.add_runtime_dependency("activesupport", "~> 4.2")
|
||||
spec.add_runtime_dependency("jekyll", ">= 2.0", "~> 3.1")
|
||||
|
||||
spec.add_development_dependency "bundler", "~> 1.6"
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
require 'pdfkit'
|
||||
require 'active_support/core_ext/hash/deep_merge'
|
||||
|
||||
module Jekyll
|
||||
module PDF
|
||||
@ -11,7 +10,7 @@ module Jekyll
|
||||
@base = base
|
||||
@dir = File.dirname(page.url)
|
||||
@name = File.basename(page.url, File.extname(page.url)) + ".pdf"
|
||||
@settings = site.config['pdf'] || {}
|
||||
@settings = site.config['pdf'].clone || {}
|
||||
@partials = ['cover','header_html','footer_html']
|
||||
|
||||
self.process(@name)
|
||||
@ -22,7 +21,7 @@ module Jekyll
|
||||
self.data['layout'] = layout
|
||||
|
||||
# Get PDF settings from the layouts
|
||||
@settings = (site.config['pdf'] || {}).deep_merge(self.getConfig(self.data))
|
||||
Jekyll::Utils.deep_merge_hashes!(@settings, self.getConfig(self.data))
|
||||
|
||||
PDFKit.configure do |config|
|
||||
config.verbose = site.config['verbose']
|
||||
@ -50,7 +49,8 @@ module Jekyll
|
||||
return settings if layout == nil
|
||||
|
||||
# Merge settings with parent layout settings
|
||||
layout['pdf'] = (layout['pdf'] || {}).deep_merge(settings)
|
||||
layout['pdf'] ||= {}
|
||||
Jekyll::Utils.deep_merge_hashes!(layout['pdf'], settings)
|
||||
|
||||
return self.getConfig(layout)
|
||||
end
|
||||
|
||||
@ -2,8 +2,7 @@ module Jekyll
|
||||
module PDF
|
||||
module Helper
|
||||
def fix_relative_paths
|
||||
prefix = "file://#{site.dest}/"
|
||||
output = output.gsub(/(href|src)=(['"])\/([^\/"']([^\"']*|[^"']*))?['"]/, "\\1=\\2#{prefix}\\3\\2")
|
||||
output.gsub!(/(href|src)=(['"])\/([^\/"']([^\"']*|[^"']*))?['"]/, "\\1=\\2file://#{site.dest}/\\3\\2") if output != nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
Jekyll::Hooks.register :site, :post_write do |jekyll, payload|
|
||||
if jekyll.data[:jekyll_pdf_partials]
|
||||
jekyll.data[:jekyll_pdf_partials].each do |partial|
|
||||
partial.clean
|
||||
File.delete(partial) if File.exist?(partial)
|
||||
end
|
||||
jekyll.data.delete(:jekyll_pdf_partials)
|
||||
end
|
||||
|
||||
@ -42,8 +42,7 @@ module Jekyll
|
||||
File.join(doc.path, partial)
|
||||
end
|
||||
|
||||
# Returns the file name for the temporary file
|
||||
def filename
|
||||
def id
|
||||
File.basename(path, File.extname(path)) + "-" + Digest::MD5.hexdigest(to_s) + File.extname(path)
|
||||
end
|
||||
|
||||
@ -74,19 +73,16 @@ module Jekyll
|
||||
|
||||
# generate temp file & set output to it's path
|
||||
def write
|
||||
tempfile = File.join(dir, filename)
|
||||
tempfile = File.absolute_path(File.join(dir, id))
|
||||
unless File.exist?(tempfile)
|
||||
FileUtils.mkdir_p(File.dirname(tempfile)) unless File.exist?(File.dirname(tempfile))
|
||||
File.open(tempfile, 'w') {|f| f.write(to_s) }
|
||||
end
|
||||
site.data[:jekyll_pdf_partials] ||= []
|
||||
site.data[:jekyll_pdf_partials] << self
|
||||
@output = tempfile
|
||||
end
|
||||
|
||||
# delete temp file
|
||||
def clean
|
||||
File.delete(@output)
|
||||
# store path for cleanup
|
||||
site.data[:jekyll_pdf_partials] ||= []
|
||||
site.data[:jekyll_pdf_partials] << "#{self}"
|
||||
end
|
||||
|
||||
def place_in_layout?
|
||||
|
||||
Loading…
Reference in New Issue
Block a user