Class: Haskell

Inherits:
Thor
  • Object
show all
Includes:
GitConfig, Thor::Actions
Defined in:
lib/haskell.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GitConfig

#author, #email, #github_token, #github_user, #jenkins_password, #jenkins_server, #jenkins_user

Instance Attribute Details

#modObject (readonly)

Returns the value of attribute mod.



11
12
13
# File 'lib/haskell.rb', line 11

def mod
  @mod
end

Class Method Details

.source_rootObject



14
15
16
# File 'lib/haskell.rb', line 14

def self.source_root
  File.join(File.dirname(__FILE__), '..', 'templates')
end

Instance Method Details

#cabal_devObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/haskell.rb', line 68

def cabal_dev
  ["cabal-dev", "happy"].each do |prereq|
    guarded "[ -x `which #{prereq}` ]" do
      warn "#{prereq} not installed, attempting..."
      guarded "cabal install #{prereq}" do |err|
        abort "#{prereq} not installable: #{ap err}"
      end
    end
  end

  # system "cabal-dev install-deps"
  guarded "cabal install -v"
end

#mkdirObject



40
41
42
43
44
# File 'lib/haskell.rb', line 40

def mkdir
  puts "creating #{Dir.getwd}/#{name}"
  Dir.mkdir name
  Dir.mkdir "#{name}/Tests"
end

#preflightObject



19
20
21
22
23
24
25
26
# File 'lib/haskell.rb', line 19

def preflight
  author
  email
  abort "#{name} already taken on hackage" unless
    HTTParty.get("http://hackage.haskell.org/package/#{name}").code == 404
  %x{cabal list --simple-output #{name}} == ""
  abort "#{name} directory already exists!" if Dir.exists? name
end

#setupObject



29
30
31
32
33
34
35
36
# File 'lib/haskell.rb', line 29

def setup
  invoke :mkdir
  Dir.chdir name do
    invoke :skeleton
    invoke :cabal_dev
  end
  announce "new haskell project set up"
end

#skeletonObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/haskell.rb', line 51

def skeleton
  @mod = name.camelize
  guarded "cabal init -m -n #{name} -l BSD3 -a Mark Wotton -e [email protected] -c #{options.category} -q"
  guarded "rm #{name}.cabal" do end
  # overwrite the cabal file
  template 'cabal.tt',  "#{name}/#{name}.cabal"
  template 'test.tt',   "#{name}/Tests/Test#{@mod}.hs"
  template 'module.tt', "#{name}/src/#{@mod}.hs"
  template 'main.tt',   "#{name}/src/Main.hs" if options.app?
  template 'watchr.tt', "#{name}/watchr.rb"
  template 'README.tt', "#{name}/README.md"
  File.open("runtests.sh", "w") do |f|
    f.write "tbc -v Tests"
  end
end