Sha256: f546b5ceacbe6578f05c01ff265a95c147a3ab4c072090635df5ec8efcaddb86

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

#                                                                          
# File 'pathhelper.rb' created on 15 feb 2008 at 16:33:15.                    
#
# See 'dokkit.rb' or +LICENSE+ for licence information.                      
#                                                                          
# (C) 2006, 2007 Andrea Fazzi <andrea.fazzi@alca.le.it> (and contributors). 
#                                                                          

module Dokkit
  module PathHelper
    def strip_ext(fn)
      ext = File.extname(fn)
      fn.sub(/#{ext}/, '')
    end
    # Get a new filename from a given filename substituting the
    # sub_dir portion of the given file with new_dir and the file
    # extension with new_ext. 
    #
    # Example:
    #
    # filename_helper('output/subdir/document.output', 'output', 'doc/pages', '.in')
    #
    # should return:
    #
    # => 'doc/pages/subdir/document.in'
    #
    def filename_helper(fn, sub_dir, new_dir, new_ext = '')
      ext = File.extname(fn).sub(/^\./,'') # strip leading dot
      new_fn = fn.sub(/#{sub_dir}/, new_dir)
      new_fn = new_fn << new_ext unless new_ext.empty?
      new_fn
    end    
    def output_fn_helper(fn, output_ext, config)
      filename_helper(fn, config.document_dir, config.output_dir, output_ext)      
    end
    def layout_fn_helper(fn, layout_ext, config)
      filename_helper(fn, config.document_dir, config.layout_dir, layout_ext)
    end        
    def config_fn_helper(fn, config)
      filename_helper(fn, config.document_dir, config.config_dir, '.yaml')
    end
    def data_fn_helper(fn, config)
      filename_helper(fn, config.data_dir, config.output_dir)      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dokkit-0.3.0 lib/dokkit/pathhelper.rb