lib/pdfkit/pdfkit.rb in pdfkit-0.7.0 vs lib/pdfkit/pdfkit.rb in pdfkit-0.8.0

- old
+ new

@@ -80,10 +80,11 @@ protected # Pulled from: # https://github.com/wkhtmltopdf/wkhtmltopdf/blob/ebf9b6cfc4c58a31349fb94c568b254fac37b3d3/README_WKHTMLTOIMAGE#L27 REPEATABLE_OPTIONS = %w[--allow --cookie --custom-header --post --post-file --run-script] + SPECIAL_OPTIONS = %w[cover toc] def find_options_in_meta(content) # Read file if content is a File content = content.read if content.is_a?(File) @@ -127,16 +128,17 @@ options.each do |key, value| next if !value # The actual option for wkhtmltopdf - normalized_key = "--#{normalize_arg key}" + normalized_key = normalize_arg key + normalized_key = "--#{normalized_key}" unless SPECIAL_OPTIONS.include?(normalized_key) # If the option is repeatable, attempt to normalize all values if REPEATABLE_OPTIONS.include? normalized_key - normalize_repeatable_value(value) do |normalized_key_piece, normalized_value| - normalized_options[[normalized_key, normalized_key_piece]] = normalized_value + normalize_repeatable_value(normalized_key, value) do |normalized_unique_key, normalized_value| + normalized_options[normalized_unique_key] = normalized_value end else # Otherwise, just normalize it like usual normalized_options[normalized_key] = normalize_value(value) end end @@ -148,10 +150,12 @@ arg.to_s.downcase.gsub(/[^a-z0-9]/,'-') end def normalize_value(value) case value + when nil + nil when TrueClass, 'true' #ie, ==true, see http://www.ruby-doc.org/core-1.9.3/TrueClass.html nil when Hash value.to_a.flatten.collect{|x| normalize_value(x)}.compact when Array @@ -159,17 +163,17 @@ else value.to_s end end - def normalize_repeatable_value(value) + def normalize_repeatable_value(option_name, value) case value when Hash, Array value.each do |(key, val)| - yield [normalize_value(key), normalize_value(val)] + yield [[option_name, normalize_value(key)], normalize_value(val)] end else - [normalize_value(value), ''] + yield [[option_name, normalize_value(value)], nil] end end def successful?(status) return true if status.success?