Sha256: 2bcb08d33d7ab47c055eaacb5e384b97024fdc978e943270d4896709aa55e571

Contents?: true

Size: 1.17 KB

Versions: 16

Compression:

Stored size: 1.17 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|
        target = File.expand_path(@opts.output_dir)
        Dir.glob(File.expand_path(@opts.template_dir+"/"+file)).each do |source|
          FileUtils.send(method, source, target)
        end
      end
    end

  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
jsduck-4.10.4 lib/jsduck/template_dir.rb
jsduck-4.10.3 lib/jsduck/template_dir.rb
jsduck-4.10.2 lib/jsduck/template_dir.rb
jsduck-4.10.1 lib/jsduck/template_dir.rb
jsduck-4.10.0 lib/jsduck/template_dir.rb
jsduck-4.9.0 lib/jsduck/template_dir.rb
jsduck-4.8.0 lib/jsduck/template_dir.rb
jsduck-4.7.1 lib/jsduck/template_dir.rb
jsduck-4.7.0 lib/jsduck/template_dir.rb
jsduck-5.0.0.beta01 lib/jsduck/template_dir.rb
jsduck-4.6.2 lib/jsduck/template_dir.rb
jsduck-4.6.1 lib/jsduck/template_dir.rb
jsduck-4.6.0 lib/jsduck/template_dir.rb
jsduck-4.5.1 lib/jsduck/template_dir.rb
jsduck-4.5.0 lib/jsduck/template_dir.rb
jsduck-4.4.1 lib/jsduck/template_dir.rb