Sha256: 7b9c55c54fa6b87dc7ae11d2b8c7e878e44efe23d4adf7adde0fe82da72d11fd

Contents?: true

Size: 1.45 KB

Versions: 27

Compression:

Stored size: 1.45 KB

Contents

require 'find'

module Octopress
  class Isolate
    attr_accessor :site

    def initialize(options)
      @options = options
      @site = Octopress.site(@options)
    end

    def integrate
      dir = File.join(site.source, '_posts')
      exile_dir = File.join(dir, '_exile')
      if Dir.exist?(exile_dir)
        posts = CommandHelpers.find_exiled_posts
        if posts.size > 0
          FileUtils.mv(posts, dir)
          FileUtils.rmdir(File.join(dir, '_exile'))

          puts "Reintegrated #{posts.size} post#{'s' if posts.size != 1} from _posts/_exile"
        else
          abort "There aren't any posts in _posts/_exile."
        end
      else
        abort "There aren't any posts in _posts/_exile."
      end
    end

    def isolate
      post = File.expand_path(@options['path']) if @options['path']
      others = (post ? find_other_posts(post) : CommandHelpers.find_posts)
      exile_dir = File.join(site.source, '_posts/_exile')

      FileUtils.mkdir_p(exile_dir)
      FileUtils.mv(others, exile_dir)

      count = (post ? others.size : "all #{others.size}")

      puts "Moved #{count} post#{'s' if others.size != 1} into _posts/_exile"
      puts "Isolated: " << "#{post.sub(Octopress.site.source + '/_posts/', '')}".yellow if post
    end

    def find_other_posts(path)
      CommandHelpers.find_posts.reject { |p| p == path }
    end

    def default_array(input)
      i = input || []
      i = [i] unless i.is_a?(Array)
      i
    end

  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
octopress-3.0.12.pre.1 lib/octopress/isolate.rb
octopress-3.0.11 lib/octopress/isolate.rb
octopress-3.0.10 lib/octopress/isolate.rb
octopress-3.0.9 lib/octopress/isolate.rb
octopress-3.0.8 lib/octopress/isolate.rb
octopress-3.0.7 lib/octopress/isolate.rb
octopress-3.0.6 lib/octopress/isolate.rb
octopress-3.0.5 lib/octopress/isolate.rb
octopress-3.0.4 lib/octopress/isolate.rb
octopress-3.0.3.alpha.2 lib/octopress/isolate.rb
octopress-3.0.3.alpha.1 lib/octopress/isolate.rb
octopress-3.0.3.alpha.0 lib/octopress/isolate.rb
octopress-3.0.2 lib/octopress/isolate.rb
octopress-3.0.1 lib/octopress/isolate.rb
octopress-3.0.0 lib/octopress/isolate.rb
octopress-3.0.0.rc.37 lib/octopress/isolate.rb
octopress-3.0.0.rc.36 lib/octopress/isolate.rb
octopress-3.0.0.rc.35 lib/octopress/isolate.rb
octopress-3.0.0.rc.34 lib/octopress/isolate.rb
octopress-3.0.0.rc.33 lib/octopress/isolate.rb