Sha256: 166609e7b75edeb31137290fa9744a150c6a7e5585d9411dac184b2de82833da

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

require 'jsduck/logger'
require 'fileutils'

module JsDuck

  # Copies over the template directory.
  #
  # Or links when --template-links option specified.
  class TemplateDir
    def initialize(opts)
      @opts = opts
      @files = [
        "app",
        "app.js",
        "favicon.ico",
        "extjs",
        "resources",
      ]
    end

    def write
      FileUtils.mkdir(@opts.output_dir)
      if @opts.template_links
        Logger.log("Linking template files to", @opts.output_dir)
        move_files(:symlink)
      else
        Logger.log("Copying template files to", @opts.output_dir)
        move_files(:cp_r)
      end

      # always copy the eg-iframe file.
      eg_iframe = @opts.eg_iframe || @opts.template_dir+"/eg-iframe.html"
      FileUtils.cp(eg_iframe, @opts.output_dir+"/eg-iframe.html")
    end

    private

    # moves files from one dir to another using a method of FileUtils module.
    def move_files(method)
      @files.each do |file|
        source = File.expand_path(@opts.template_dir+"/"+file)
        target = File.expand_path(@opts.output_dir+"/"+file)
        if File.exists?(source)
          FileUtils.send(method, source, target)
        end
      end
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jsduck-4.4.0 lib/jsduck/template_dir.rb
jsduck-4.3.2 lib/jsduck/template_dir.rb
jsduck-4.3.1 lib/jsduck/template_dir.rb
jsduck-4.3.0 lib/jsduck/template_dir.rb
jsduck-4.2.1 lib/jsduck/template_dir.rb
jsduck-4.2.0 lib/jsduck/template_dir.rb
jsduck-4.1.1 lib/jsduck/template_dir.rb