Sha256: ef5e01d3fe537eee8372f0e24134507789b96f01ecd67198536a6dda3edef30e

Contents?: true

Size: 1.21 KB

Versions: 31

Compression:

Stored size: 1.21 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.instance.log("Linking template files to", @opts.output_dir)
        move_files(:symlink)
      else
        Logger.instance.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

31 entries across 31 versions & 1 rubygems

Version Path
jsduck-4.0.1 lib/jsduck/template_dir.rb
jsduck-4.0.0 lib/jsduck/template_dir.rb
jsduck-3.11.2 lib/jsduck/template_dir.rb
jsduck-4.0.beta2 lib/jsduck/template_dir.rb
jsduck-3.11.1 lib/jsduck/template_dir.rb
jsduck-4.0.beta lib/jsduck/template_dir.rb
jsduck-3.11.0 lib/jsduck/template_dir.rb
jsduck-3.10.5 lib/jsduck/template_dir.rb
jsduck-3.10.4 lib/jsduck/template_dir.rb
jsduck-3.10.3 lib/jsduck/template_dir.rb
jsduck-3.10.2 lib/jsduck/template_dir.rb
jsduck-3.10.1 lib/jsduck/template_dir.rb
jsduck-3.10.0 lib/jsduck/template_dir.rb
jsduck-3.9.1 lib/jsduck/template_dir.rb
jsduck-3.9.0 lib/jsduck/template_dir.rb
jsduck-3.9.0.pre lib/jsduck/template_dir.rb
jsduck-3.8.4 lib/jsduck/template_dir.rb
jsduck-3.8.3 lib/jsduck/template_dir.rb
jsduck-3.8.2 lib/jsduck/template_dir.rb
jsduck-3.8.1 lib/jsduck/template_dir.rb