Class: Jekyll::RpLogs::RpTasks

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/jekyll/rp_logs/rp_tasks.rb

Instance Method Summary collapse

Instance Method Details

#ask(message, valid_options) ⇒ Object

Octopress



22
23
24
25
26
27
28
29
# File 'lib/jekyll/rp_logs/rp_tasks.rb', line 22

def ask(message, valid_options)
  if valid_options
    answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /, '/')} ") until valid_options.include?(answer)
  else
    answer = get_stdin(message)
  end
  answer
end

#copy_unless_exist(from, to, message = nil) ⇒ Object



8
9
10
11
12
13
# File 'lib/jekyll/rp_logs/rp_tasks.rb', line 8

def copy_unless_exist(from, to, message = nil)
  unless File.exist?(to)
    puts message if message
    cp from, to
  end
end

#get_stdin(message) ⇒ Object

Octopress



16
17
18
19
# File 'lib/jekyll/rp_logs/rp_tasks.rb', line 16

def get_stdin(message)
  print message
  STDIN.gets.chomp
end

#install_tasksObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jekyll/rp_logs/rp_tasks.rb', line 31

def install_tasks
  namespace :rp_logs do
    directory "_rps"

    desc "Create a new Jekyll site for RP logs, with the default theme"
    task :new do
      if File.directory?("_sass")
        abort("rake aborted!") if ask("A theme is already installed, proceeding will overwrite existing non-custom files. Are you sure?", ['y', 'n']) == 'n'
      end

      Rake::Task[:_rps].invoke
      # allow directory specification

      gem_root = Gem::Specification.find_by_name("jekyll-rp_logs").gem_dir
      cp_r Dir["#{gem_root}/.themes/default/source/*"], "./"
      copy_unless_exist("_config.yml.default", "_config.yml")
      touch "_sass/_custom-vars.scss"
      touch "_sass/_custom-rules.scss"
    end
  end
end