Class: Octopress::Isolate

Inherits:
Object
  • Object
show all
Defined in:
lib/octopress/isolate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Isolate

Returns a new instance of Isolate.



7
8
9
10
# File 'lib/octopress/isolate.rb', line 7

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

Instance Attribute Details

#siteObject

Returns the value of attribute site.



5
6
7
# File 'lib/octopress/isolate.rb', line 5

def site
  @site
end

Instance Method Details

#default_array(input) ⇒ Object



48
49
50
51
52
# File 'lib/octopress/isolate.rb', line 48

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


44
45
46
# File 'lib/octopress/isolate.rb', line 44

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

#integrateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/octopress/isolate.rb', line 12

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

#isolateObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/octopress/isolate.rb', line 30

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