Class: Hackademic

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/hackademic.rb

Constant Summary collapse

HACKADEMIC_DIRECTORY =
File.open("#{ENV['HOME']}/.hackademic", "r").read.chomp

Instance Method Summary collapse

Instance Method Details

#install_templates(args) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/hackademic.rb', line 44

def install_templates(args)
  if !Dir.exists?(ENV["HOME"]+"/.pandoc/templates")
    empty_directory ENV["HOME"]+"/.pandoc"
    empty_directory ENV["HOME"]+"/.pandoc/templates"
  end
  template "../templates/default.asciidoc", ENV["HOME"] + "/.pandoc/templates/default.asciidoc"
  template "../templates/default.html5", ENV["HOME"] + "/.pandoc/templates/default.html5"
  template "../templates/default.latex", ENV["HOME"] + "/.pandoc/templates/default.latex"
end

#listObject



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

def list
  say ""
  say "  ❡ hackademic ➤➤➤", :magenta
  say ""
  say "    Listing projects found in #{HACKADEMIC_DIRECTORY}/Projects/", :cyan
  say ""
  say "    " + %x[ls -1 #{HACKADEMIC_DIRECTORY}/Projects].gsub!("\n","\n    "), :blue
end

#setup(root_directory) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/hackademic.rb', line 55

def setup(root_directory)

  say "--------------------------------------------------------------", :cyan
  say "Hackademic Setup:", :green
  say "⫸⫸⫸ Setting up main Hackademic folder structure:", :yellow

  directory = "#{root_directory}/Hackademic"
  empty_directory(directory)
  File.open("#{ENV['HOME']}/.hackademic", "w+"){|config| config << directory }

  empty_directory "#{directory}/Libraries"
  empty_directory "#{directory}/Libraries/My-Library"
  create_file "#{directory}/Libraries/My-Library/References.bib"

  empty_directory "#{directory}/Meta"

  if system("which brew")
    run "brew update"
  else
    run 'ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'
  end

  invoke :update_pandoc
  invoke :install_templates

  say "⫸⫸⫸ Initializing version control (git) for Notes database:", :yellow
  empty_directory "#{directory}/Notes"
  create_file "#{directory}/Notes/SampleNote.md"
  unless File.exists? "#{directory}/Notes/.git"
    inside "#{directory}/Notes" do
      run "git init ."
      run "git add ."
      run "git commit -m 'Initial commit of Notes Database'"
    end
  end

  empty_directory "#{directory}/Projects"

  say "»»»»» Done!", :green
  say "--------------------------------------------------------------", :cyan

end

#update_pandoc(args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/hackademic.rb', line 32

def update_pandoc(args)
  if !pandoc_is_current
    run "brew unlink pandoc"
    run "brew install pandoc"
    run "brew link pandoc"
    run "brew unlink pandoc-citeproc"
    run "brew install pandoc-citeproc"
    run "brew link pandoc-citeproc"
  end
end