Module: Capistrano::Ops::Wkhtmltopdf::Helpers

Defined in:
lib/capistrano/ops/wkhtmltopdf/helpers.rb

Instance Method Summary collapse

Instance Method Details

#binary_pathObject



7
8
9
10
# File 'lib/capistrano/ops/wkhtmltopdf/helpers.rb', line 7

def binary_path
  gem_path = capture(:bundle, 'show', 'wkhtmltopdf-binary').strip
  "#{gem_path}/bin"
end

#binary_path_and_versionObject



16
17
18
# File 'lib/capistrano/ops/wkhtmltopdf/helpers.rb', line 16

def binary_path_and_version
  [binary_path, gem_version]
end

#check_file_and_permissions(binary_path, version) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/capistrano/ops/wkhtmltopdf/helpers.rb', line 28

def check_file_and_permissions(binary_path, version)
  binary_file = "#{binary_path}/wkhtmltopdf_ubuntu_#{version}_amd64"

  if file_existing?(binary_file)
    info('wkhtmltopdf binary already extracted')

    if right_permissions?(binary_file)
      info('wkhtmltopdf binary has already the right permissions')
    else
      info('adding right permissions to wkhtmltopdf binary')
      execute("chmod 777 #{binary_file}")
    end
  else
    info('extracting wkhtmltopdf binary')
    # extract the binary but keep the gzip file
    execute("cd #{binary_path} && gzip -dk  wkhtmltopdf_ubuntu_#{version}_amd64.gz")
    # add execute permission to the binary
    execute("chmod 777 #{binary_file}")
  end
  info('wkhtmltopdf setup finished')
end

#file_existing?(file) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/capistrano/ops/wkhtmltopdf/helpers.rb', line 20

def file_existing?(file)
  test("[ -f #{file} ]")
end

#gem_versionObject



12
13
14
# File 'lib/capistrano/ops/wkhtmltopdf/helpers.rb', line 12

def gem_version
  capture(:cat, 'config/initializers/wicked_pdf.rb').scan(/wkhtmltopdf_ubuntu_(\d+\.\d+)_amd64/).flatten.first
end

#right_permissions?(file) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/capistrano/ops/wkhtmltopdf/helpers.rb', line 24

def right_permissions?(file)
  test("[ $(stat -c '%a' #{file}) = '777' ]")
end