Module: ReVIEW::MakerHelper

Included in:
EPUBMaker, IDGXMLMaker, TEXTMaker, WEBMaker
Defined in:
lib/review/makerhelper.rb

Class Method Summary collapse

Class Method Details

.copy_images_to_dir(from_dir, to_dir, options = {}) ⇒ Object

Copy image files under from_dir to to_dir recursively

Args

from_dir

path to the directory which has image files to be copied

to_dir

path to the directory to which the image files are copied

options

used to specify optional operations during copy

Returns

list of image files

Options

:convert

Conversion rule

Examples

copy_images_to_dir("/path/to/foo", "/path/to/bar", :convert => {:eps => :png})

Image files are copied recursively, and each ‘.eps’ file is converted into ‘.eps.png’



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/review/makerhelper.rb', line 41

def copy_images_to_dir(from_dir, to_dir, options = {})
  image_files = []

  Dir.open(from_dir) do |dir|
    dir.each do |fname|
      next if /^\./.match?(fname)

      if FileTest.directory?("#{from_dir}/#{fname}")
        image_files += copy_images_to_dir("#{from_dir}/#{fname}", "#{to_dir}/#{fname}", options)
      else
        FileUtils.mkdir_p(to_dir)

        is_converted = false
        (options[:convert] || {}).each do |orig_type, conv_type|
          next unless /\.#{orig_type}$/.match?(fname)

          is_converted = system("convert #{from_dir}/#{fname} #{to_dir}/#{fname}.#{conv_type}")
          image_files << "#{from_dir}/#{fname}.#{conv_type}"
        end

        exts = options[:exts] || %w[png gif jpg jpeg svg pdf eps ai tif psd]
        exts_str = exts.join('|')
        if !is_converted && fname =~ /\.(#{exts_str})$/i
          if options[:use_symlink]
            FileUtils.ln_s(File.realpath("#{from_dir}/#{fname}"), to_dir)
          else
            FileUtils.cp("#{from_dir}/#{fname}", to_dir)
          end
          image_files << "#{from_dir}/#{fname}"
        end
      end
    end
  end

  image_files
end

.h(str) ⇒ Object



20
21
22
# File 'lib/review/makerhelper.rb', line 20

def h(str)
  CGI.escapeHTML(str)
end