Skip to content

Commit

Permalink
[fix] syntax compatibility to Ruby 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
gabteles committed Oct 7, 2017
1 parent eb895d1 commit 9022e8c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 87 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 1.9
Exclude:
- 'test/dummy/**/*'

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'rails/version'
require 'bundler/gem_tasks'

desc 'Default: run unit tests.'
task :default => %i[setup_and_run_tests rubocop]
task :default => [:setup_and_run_tests, :rubocop]

desc 'Test the wicked_pdf plugin.'
Rake::TestTask.new(:test) do |t|
Expand Down
130 changes: 65 additions & 65 deletions lib/wicked_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ def make_options(options, names, prefix = '', type = :string)
def parse_header_footer(options)
r = []
unless options.blank?
%i[header footer].collect do |hf|
[:header, :footer].collect do |hf|
next if options[hf].blank?
opt_hf = options[hf]
r += make_options(opt_hf, %i[center font_name left right], hf.to_s)
r += make_options(opt_hf, %i[font_size spacing], hf.to_s, :numeric)
r += make_options(opt_hf, [:center, :font_name, :left, :right], hf.to_s)
r += make_options(opt_hf, [:font_size, :spacing], hf.to_s, :numeric)
r += make_options(opt_hf, [:line], hf.to_s, :boolean)
if options[hf] && options[hf][:content]
@hf_tempfiles = [] unless defined?(@hf_tempfiles)
Expand Down Expand Up @@ -237,31 +237,31 @@ def parse_toc(options)
return [] if options.nil?
r = [valid_option('toc')]
unless options.blank?
r += make_options(options, %i[font_name header_text], 'toc')
r += make_options(options, [:font_name, :header_text], 'toc')
r += make_options(options, [:xsl_style_sheet])
r += make_options(options, %i[depth
header_fs
text_size_shrink
l1_font_size
l2_font_size
l3_font_size
l4_font_size
l5_font_size
l6_font_size
l7_font_size
level_indentation
l1_indentation
l2_indentation
l3_indentation
l4_indentation
l5_indentation
l6_indentation
l7_indentation], 'toc', :numeric)
r += make_options(options, %i[no_dots
disable_links
disable_back_links], 'toc', :boolean)
r += make_options(options, %i[disable_dotted_lines
disable_toc_links], nil, :boolean)
r += make_options(options, [:depth,
:header_fs,
:text_size_shrink,
:l1_font_size,
:l2_font_size,
:l3_font_size,
:l4_font_size,
:l5_font_size,
:l6_font_size,
:l7_font_size,
:level_indentation,
:l1_indentation,
:l2_indentation,
:l3_indentation,
:l4_indentation,
:l5_indentation,
:l6_indentation,
:l7_indentation], 'toc', :numeric)
r += make_options(options, [:no_dots,
:disable_links,
:disable_back_links], 'toc', :boolean)
r += make_options(options, [:disable_dotted_lines,
:disable_toc_links], nil, :boolean)
end
r
end
Expand All @@ -276,23 +276,23 @@ def parse_outline(options)
end

def parse_margins(options)
make_options(options, %i[top bottom left right], 'margin', :numeric)
make_options(options, [:top, :bottom, :left, :right], 'margin', :numeric)
end

def parse_global(options)
r = []
unless options.blank?
r += make_options(options, %i[orientation
dpi
page_size
page_width
title])
r += make_options(options, %i[lowquality
grayscale
no_pdf_compression], '', :boolean)
r += make_options(options, %i[image_dpi
image_quality
page_height], '', :numeric)
r += make_options(options, [:orientation,
:dpi,
:page_size,
:page_width,
:title])
r += make_options(options, [:lowquality,
:grayscale,
:no_pdf_compression], '', :boolean)
r += make_options(options, [:image_dpi,
:image_quality,
:page_height], '', :numeric)
r += parse_margins(options.delete(:margin))
end
r
Expand All @@ -301,32 +301,32 @@ def parse_global(options)
def parse_others(options)
r = []
unless options.blank?
r += make_options(options, %i[proxy
username
password
encoding
user_style_sheet
viewport_size
window_status])
r += make_options(options, %i[cookie
post], '', :name_value)
r += make_options(options, %i[redirect_delay
zoom
page_offset
javascript_delay], '', :numeric)
r += make_options(options, %i[book
default_header
disable_javascript
enable_plugins
disable_internal_links
disable_external_links
print_media_type
disable_smart_shrinking
use_xserver
no_background
images
no_images
no_stop_slow_scripts], '', :boolean)
r += make_options(options, [:proxy,
:username,
:password,
:encoding,
:user_style_sheet,
:viewport_size,
:window_status])
r += make_options(options, [:cookie,
:post], '', :name_value)
r += make_options(options, [:redirect_delay,
:zoom,
:page_offset,
:javascript_delay], '', :numeric)
r += make_options(options, [:book,
:default_header,
:disable_javascript,
:enable_plugins,
:disable_internal_links,
:disable_external_links,
:print_media_type,
:disable_smart_shrinking,
:use_xserver,
:no_background,
:images,
:no_images,
:no_stop_slow_scripts], '', :boolean)
end
r
end
Expand Down
2 changes: 1 addition & 1 deletion lib/wicked_pdf/pdf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def make_and_send_pdf(pdf_name, options = {})
# Given an options hash, prerenders content for the header and footer sections
# to temp files and return a new options hash including the URLs to these files.
def prerender_header_and_footer(options)
%i[header footer].each do |hf|
[:header, :footer].each do |hf|
next unless options[hf] && options[hf][:html] && options[hf][:html][:template]
@hf_tempfiles = [] unless defined?(@hf_tempfiles)
@hf_tempfiles.push(tf = WickedPdfTempfile.new("wicked_#{hf}_pdf.html"))
Expand Down
2 changes: 1 addition & 1 deletion test/functional/pdf_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def teardown

# test that calling render does not trigger infinite loop
ac = ActionController::Base.new
assert_equal %i[base patched], ac.render(:cats)
assert_equal [:base, :patched], ac.render(:cats)
rescue SystemStackError
assert_equal true, false # force spec failure
ensure
Expand Down
38 changes: 19 additions & 19 deletions test/unit/wicked_pdf_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ def setup
end

test 'should parse header and footer options' do
%i[header footer].each do |hf|
%i[center font_name left right].each do |o|
[:header, :footer].each do |hf|
[:center, :font_name, :left, :right].each do |o|
assert_equal "--#{hf}-#{o.to_s.tr('_', '-')} header_footer",
@wp.get_parsed_options(hf => { o => 'header_footer' }).strip
end

%i[font_size spacing].each do |o|
[:font_size, :spacing].each do |o|
assert_equal "--#{hf}-#{o.to_s.tr('_', '-')} 12",
@wp.get_parsed_options(hf => { o => '12' }).strip
end
Expand All @@ -109,21 +109,21 @@ def setup
test 'should parse toc options' do
toc_option = @wp.get_valid_option('toc')

%i[font_name header_text].each do |o|
[:font_name, :header_text].each do |o|
assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')} toc",
@wp.get_parsed_options(:toc => { o => 'toc' }).strip
end

%i[
depth header_fs l1_font_size l2_font_size l3_font_size l4_font_size
l5_font_size l6_font_size l7_font_size l1_indentation l2_indentation
l3_indentation l4_indentation l5_indentation l6_indentation l7_indentation
[
:depth, :header_fs, :l1_font_size, :l2_font_size, :l3_font_size, :l4_font_size,
:l5_font_size, :l6_font_size, :l7_font_size, :l1_indentation, :l2_indentation,
:l3_indentation, :l4_indentation, :l5_indentation, :l6_indentation, :l7_indentation
].each do |o|
assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')} 5",
@wp.get_parsed_options(:toc => { o => 5 }).strip
end

%i[no_dots disable_links disable_back_links].each do |o|
[:no_dots, :disable_links, :disable_back_links].each do |o|
assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')}",
@wp.get_parsed_options(:toc => { o => true }).strip
end
Expand All @@ -140,7 +140,7 @@ def setup
end

test 'should parse margins options' do
%i[top bottom left right].each do |o|
[:top, :bottom, :left, :right].each do |o|
assert_equal "--margin-#{o} 12", @wp.get_parsed_options(:margin => { o => '12' }).strip
end
end
Expand All @@ -155,28 +155,28 @@ def setup
end

test 'should parse other options' do
%i[
orientation page_size proxy username password dpi
encoding user_style_sheet
[
:orientation, :page_size, :proxy, :username, :password, :dpi,
:encoding, :user_style_sheet
].each do |o|
assert_equal "--#{o.to_s.tr('_', '-')} opts", @wp.get_parsed_options(o => 'opts').strip
end

%i[cookie post].each do |o|
[:cookie, :post].each do |o|
assert_equal "--#{o.to_s.tr('_', '-')} name value", @wp.get_parsed_options(o => 'name value').strip

nv_formatter = proc { |number| "--#{o.to_s.tr('_', '-')} par#{number} val#{number}" }
assert_equal "#{nv_formatter.call(1)} #{nv_formatter.call(2)}", @wp.get_parsed_options(o => ['par1 val1', 'par2 val2']).strip
end

%i[redirect_delay zoom page_offset].each do |o|
[:redirect_delay, :zoom, :page_offset].each do |o|
assert_equal "--#{o.to_s.tr('_', '-')} 5", @wp.get_parsed_options(o => 5).strip
end

%i[
book default_header disable_javascript grayscale lowquality
enable_plugins disable_internal_links disable_external_links
print_media_type disable_smart_shrinking use_xserver no_background
[
:book, :default_header, :disable_javascript, :grayscale, :lowquality,
:enable_plugins, :disable_internal_links, :disable_external_links,
:print_media_type, :disable_smart_shrinking, :use_xserver, :no_background
].each do |o|
assert_equal "--#{o.to_s.tr('_', '-')}", @wp.get_parsed_options(o => true).strip
end
Expand Down

0 comments on commit 9022e8c

Please sign in to comment.