Skip to content

Commit

Permalink
Prefer single-quoted strings when interpolation not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
unixmonkey committed Aug 17, 2014
1 parent 5f2a486 commit 0f931ee
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "https://rubygems.org"
source 'https://rubygems.org'

gemspec
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ task :setup_and_run_tests do
Rake::Task[:test].invoke
end

desc "Generate dummy application for test cases"
desc 'Generate dummy application for test cases'
task :dummy_generate do
Rake::Task[:dummy_remove].invoke
puts 'Creating dummy application to run tests'
Expand Down
2 changes: 1 addition & 1 deletion generators/wicked_pdf/wicked_pdf_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class WickedPdfGenerator < Rails::Generator::Base
def manifest
record do |m|
m.file "wicked_pdf.rb", "config/initializers/wicked_pdf.rb"
m.file 'wicked_pdf.rb', 'config/initializers/wicked_pdf.rb'
end
end
end
2 changes: 1 addition & 1 deletion lib/generators/wicked_pdf_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Rails3 generator invoked with 'rails generate wicked_pdf'
class WickedPdfGenerator < Rails::Generators::Base
source_root(File.expand_path(File.dirname(__FILE__) + "/../../generators/wicked_pdf/templates"))
source_root(File.expand_path(File.dirname(__FILE__) + '/../../generators/wicked_pdf/templates'))
def copy_initializer
copy_file 'wicked_pdf.rb', 'config/initializers/wicked_pdf.rb'
end
Expand Down
38 changes: 19 additions & 19 deletions lib/wicked_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class WickedPdf
DEFAULT_BINARY_VERSION = Gem::Version.new('0.9.9')
BINARY_VERSION_WITHOUT_DASHES = Gem::Version.new('0.12.0')
EXE_NAME = "wkhtmltopdf"
EXE_NAME = 'wkhtmltopdf'
@@config = {}
cattr_accessor :config

Expand All @@ -46,7 +46,7 @@ def initialize(wkhtmltopdf_binary_path = nil)

def pdf_from_html_file(filepath, options = {})
temp_path = options.delete(:temp_path)
generated_pdf_file = WickedPdfTempfile.new("wicked_pdf_generated_file.pdf", temp_path)
generated_pdf_file = WickedPdfTempfile.new('wicked_pdf_generated_file.pdf', temp_path)
command = [@exe_path]
command << '-q' unless on_windows? # suppress errors on stdout
command += parse_options(options)
Expand Down Expand Up @@ -74,7 +74,7 @@ def pdf_from_html_file(filepath, options = {})

def pdf_from_string(string, options = {})
temp_path = options.delete(:temp_path)
string_file = WickedPdfTempfile.new("wicked_pdf.html", temp_path)
string_file = WickedPdfTempfile.new('wicked_pdf.html', temp_path)
string_file.binmode
string_file.write(string)
string_file.close
Expand Down Expand Up @@ -103,7 +103,7 @@ def on_windows?
end

def print_command(cmd)
p "*" * 15 + cmd + "*" * 15
p '*' * 15 + cmd + '*' * 15
end

def retreive_binary_version
Expand Down Expand Up @@ -144,8 +144,8 @@ def parse_extra(options)

def parse_basic_auth(options)
if options[:basic_auth]
user, passwd = Base64.decode64(options[:basic_auth]).split(":")
["--username", user, "--password", passwd]
user, passwd = Base64.decode64(options[:basic_auth]).split(':')
['--username', user, '--password', passwd]
else
[]
end
Expand Down Expand Up @@ -173,13 +173,13 @@ def valid_option(name)
end
end

def make_options(options, names, prefix = "", type = :string)
def make_options(options, names, prefix = '', type = :string)
return [] if options.nil?
names.collect do |o|
if options[o].blank?
[]
else
make_option("#{prefix.blank? ? "" : prefix + "-"}#{o.to_s}",
make_option("#{prefix.blank? ? '' : prefix + '-'}#{o.to_s}",
options[o],
type)
end
Expand Down Expand Up @@ -219,7 +219,7 @@ def parse_cover(argument)
[valid_option('cover'), arg]
else # HTML content
@hf_tempfiles ||= []
@hf_tempfiles << tf = WickedPdfTempfile.new("wicked_cover_pdf.html")
@hf_tempfiles << tf = WickedPdfTempfile.new('wicked_cover_pdf.html')
tf.write arg
tf.flush
[valid_option('cover'), tf.path]
Expand All @@ -230,7 +230,7 @@ def parse_toc(options)
return [] if options.nil?
r = [valid_option('toc')]
unless options.blank?
r += make_options(options, [:font_name, :header_text], "toc")
r += make_options(options, [:font_name, :header_text], 'toc')
r += make_options(options, [:depth,
:header_fs,
:text_size_shrink,
Expand All @@ -248,10 +248,10 @@ def parse_toc(options)
:l4_indentation,
:l5_indentation,
:l6_indentation,
:l7_indentation], "toc", :numeric)
:l7_indentation], 'toc', :numeric)
r += make_options(options, [:no_dots,
:disable_links,
:disable_back_links], "toc", :boolean)
:disable_back_links], 'toc', :boolean)
r += make_options(options, [:disable_dotted_lines,
:disable_toc_links], nil, :boolean)
end
Expand All @@ -261,14 +261,14 @@ def parse_toc(options)
def parse_outline(options)
r = []
unless options.blank?
r = make_options(options, [:outline], "", :boolean)
r += make_options(options, [:outline_depth], "", :numeric)
r = make_options(options, [:outline], '', :boolean)
r += make_options(options, [:outline_depth], '', :numeric)
end
r
end

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

def parse_others(options)
Expand All @@ -286,12 +286,12 @@ def parse_others(options)
:user_style_sheet,
:viewport_size])
r += make_options(options, [:cookie,
:post], "", :name_value)
:post], '', :name_value)
r += make_options(options, [:redirect_delay,
:zoom,
:page_offset,
:javascript_delay,
:image_quality], "", :numeric)
:image_quality], '', :numeric)
r += make_options(options, [:book,
:default_header,
:disable_javascript,
Expand All @@ -303,8 +303,8 @@ def parse_others(options)
:print_media_type,
:disable_smart_shrinking,
:use_xserver,
:no_background], "", :boolean)
r += make_options(options, [:no_stop_slow_scripts], "", nil)
:no_background], '', :boolean)
r += make_options(options, [:no_stop_slow_scripts], '', nil)
end
r
end
Expand Down
10 changes: 5 additions & 5 deletions lib/wicked_pdf/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def call(env)
headers.delete('ETag')
headers.delete('Cache-Control')

headers["Content-Length"] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
headers["Content-Type"] = "application/pdf"
headers['Content-Length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
headers['Content-Type'] = 'application/pdf'
if @options.fetch(:disposition, '') == 'attachment'
headers["Content-Disposition"] = 'attachment'
headers["Content-Transfer-Encoding"] = 'binary'
headers['Content-Disposition'] = 'attachment'
headers['Content-Transfer-Encoding'] = 'binary'
end
end

Expand Down Expand Up @@ -83,7 +83,7 @@ def set_request_to_render_as_pdf(env)
@render_pdf = true
%w(PATH_INFO REQUEST_URI).each { |e| env[e] = env[e].sub(%r{\.pdf\b}, '') }
env['HTTP_ACCEPT'] = concat(env['HTTP_ACCEPT'], Rack::Mime.mime_type('.html'))
env["Rack-Middleware-WickedPdf"] = "true"
env['Rack-Middleware-WickedPdf'] = 'true'
end

def concat(accepts, type)
Expand Down
8 changes: 4 additions & 4 deletions lib/wicked_pdf/pdf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def log_pdf_creation

def set_basic_auth(options = {})
options[:basic_auth] ||= WickedPdf.config.fetch(:basic_auth) { false }
if options[:basic_auth] && request.env["HTTP_AUTHORIZATION"]
request.env["HTTP_AUTHORIZATION"].split(" ").last
if options[:basic_auth] && request.env['HTTP_AUTHORIZATION']
request.env['HTTP_AUTHORIZATION'].split(' ').last
end
end

Expand All @@ -68,9 +68,9 @@ def make_and_send_pdf(pdf_name, options = {})
options[:wkhtmltopdf] ||= nil
options[:layout] ||= false
options[:template] ||= File.join(controller_path, action_name)
options[:disposition] ||= "inline"
options[:disposition] ||= 'inline'
if options[:show_as_html]
render_opts = { :template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers], :content_type => "text/html" }
render_opts = { :template => options[:template], :layout => options[:layout], :formats => options[:formats], :handlers => options[:handlers], :content_type => 'text/html' }
render_opts.merge!(:locals => options[:locals]) if options[:locals]
render_opts.merge!(:file => options[:file]) if options[:file]
render(render_opts)
Expand Down
8 changes: 4 additions & 4 deletions lib/wicked_pdf/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
if Rails::VERSION::MAJOR == 4

class WickedRailtie < Rails::Railtie
initializer "wicked_pdf.register" do |app|
initializer 'wicked_pdf.register' do |app|
ActionController::Base.send :include, PdfHelper
ActionView::Base.send :include, WickedPdfHelper::Assets
end
end

elsif Rails::VERSION::MAJOR == 2

unless ActionController::Base.instance_methods.include? "render_with_wicked_pdf"
unless ActionController::Base.instance_methods.include? 'render_with_wicked_pdf'
ActionController::Base.send :include, PdfHelper
end
unless ActionView::Base.instance_methods.include? "wicked_pdf_stylesheet_link_tag"
unless ActionView::Base.instance_methods.include? 'wicked_pdf_stylesheet_link_tag'
ActionView::Base.send :include, WickedPdfHelper
end

else

class WickedRailtie < Rails::Railtie
initializer "wicked_pdf.register" do |app|
initializer 'wicked_pdf.register' do |app|
ActionController::Base.send :include, PdfHelper
if Rails::VERSION::MINOR > 0 && Rails.configuration.assets.enabled
ActionView::Base.send :include, WickedPdfHelper::Assets
Expand Down
6 changes: 3 additions & 3 deletions lib/wicked_pdf/wicked_pdf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def wicked_pdf_image_tag(img, options = {})
def wicked_pdf_javascript_src_tag(jsfile, options = {})
jsfile = WickedPdfHelper.add_extension(jsfile, 'js')
src = "file:///#{WickedPdfHelper.root_path.join('public', 'javascripts', jsfile)}"
content_tag("script", "", { "type" => Mime::JS, "src" => path_to_javascript(src) }.merge(options))
content_tag('script', '', { 'type' => Mime::JS, 'src' => path_to_javascript(src) }.merge(options))
end

def wicked_pdf_javascript_include_tag(*sources)
Expand Down Expand Up @@ -85,8 +85,8 @@ def asset_pathname(source)

# will prepend a http or default_protocol to a protocol realtive URL
def set_protocol(source)
protocol = WickedPdf.config[:default_protocol] || "http"
source = [protocol, ":", source].join if source[0, 2] == "//"
protocol = WickedPdf.config[:default_protocol] || 'http'
source = [protocol, ':', source].join if source[0, 2] == '//'
source
end

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 @@ -18,7 +18,7 @@ def teardown
end

if Rails::VERSION::MAJOR == 2
test "should prerender header and footer :template options" do
test 'should prerender header and footer :template options' do
options = @ac.send(:prerender_header_and_footer,
:header => { :html => { :template => 'hf.html.erb' } })
assert_match /^file:\/\/\/.*wicked_header_pdf.*\.html/, options[:header][:html][:url]
Expand Down
8 changes: 4 additions & 4 deletions test/functional/wicked_pdf_helper_assets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class WickedPdfHelperAssetsTest < ActionView::TestCase

test 'wicked_pdf_asset_path should return an url with a protocol when assets are served by an asset server with relative urls' do
expects(:asset_path => '//assets.domain.com/dummy.png')
expects("precompiled_asset?" => true)
expects('precompiled_asset?' => true)
assert_equal 'http://assets.domain.com/dummy.png', wicked_pdf_asset_path('dummy.png')
end

test 'wicked_pdf_asset_path should return a path when assets are precompiled' do
expects("precompiled_asset?" => false)
expects('precompiled_asset?' => false)
path = wicked_pdf_asset_path('application.css')

assert path.include?("/assets/stylesheets/application.css")
assert path.include?("file:///")
assert path.include?('/assets/stylesheets/application.css')
assert path.include?('file:///')
end
end

Expand Down
10 changes: 5 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"
ENV['RAILS_ENV'] = 'test'

require File.expand_path("../dummy/config/environment.rb", __FILE__)
require File.expand_path('../dummy/config/environment.rb', __FILE__)
if Rails::VERSION::MAJOR == 2
require "test_help"
require 'test_help'
else
require "rails/test_help"
require 'rails/test_help'
end

require "wicked_pdf"
require 'wicked_pdf'

Rails.backtrace_cleaner.remove_silencers!
Loading

0 comments on commit 0f931ee

Please sign in to comment.