Sha256: 9b428649d63b45313c74e86dd116e1ea49fc5db1f51ff18f51a42ed8d2af416e

Contents?: true

Size: 1.54 KB

Versions: 13

Compression:

Stored size: 1.54 KB

Contents

require 'find'

module Octopress
  class Scaffold
    attr_reader :path, :force

    def initialize(args, options)
      @path  = init_path(args)
      @force = !!options['force']
      @blank = !!options['blank']
    end

    def init_path(args)
      path = File.expand_path(args.join(" "), Dir.pwd)
      config_file = File.join(path, '_config.yml') 

      # If there is a Jekyll configuration file present
      # Add template to source directory
      if File.exist?(config_file)
        config = SafeYAML.load_file(config_file)
        if config['source']
          path = File.join(path, config['source'])
        end
      end
      path
    end
    
    def write
      if !@force && File.exist?(File.join(path, '_templates'))
        abort "Some files already exist.  Use --force to overwrite."
      end

      FileUtils.cp_r(File.join(scaffold_path, '.'), path)
      puts "Added Octopress scaffold:"
      puts scaffold_file_list.green
    end

    def local_path
      pwd = File.join(Dir.pwd, '')
      path.sub(pwd, '')
    end

    def scaffold_path
      Octopress.gem_dir('scaffold')
    end

    # Returns a list of 
    def scaffold_files
      Find.find(scaffold_path).to_a.reject do |file| 
        file == scaffold_path
      end
    end

    def scaffold_file_list
      scaffold_files.map do |file| 
        name = file.sub(File.join(scaffold_path, ''), '')
        name = name.gsub(/[^\/]+\//, '  ')

        if File.directory?(file)
          name = File.join(name, '')
        end

        " + " + name
      end.join("\n")
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
octopress-3.0.12.pre.1 lib/octopress/scaffold.rb
octopress-3.0.11 lib/octopress/scaffold.rb
octopress-3.0.10 lib/octopress/scaffold.rb
octopress-3.0.9 lib/octopress/scaffold.rb
octopress-3.0.8 lib/octopress/scaffold.rb
octopress-3.0.7 lib/octopress/scaffold.rb
octopress-3.0.6 lib/octopress/scaffold.rb
octopress-3.0.5 lib/octopress/scaffold.rb
octopress-3.0.4 lib/octopress/scaffold.rb
octopress-3.0.3.alpha.2 lib/octopress/scaffold.rb
octopress-3.0.3.alpha.1 lib/octopress/scaffold.rb
octopress-3.0.3.alpha.0 lib/octopress/scaffold.rb
octopress-3.0.2 lib/octopress/scaffold.rb