Module: Tooler::Template

Included in:
CLI
Defined in:
lib/tooler/template.rb,
lib/tooler/cuba_template.rb,
lib/tooler/sinatra_template.rb

Instance Method Summary collapse

Instance Method Details

#config_ruObject



17
18
19
20
21
# File 'lib/tooler/cuba_template.rb', line 17

def config_ru
  contents = file_read @options[:template_path]+'cuba/config.ru'
  contents = contents % {name: @options[:name]}
  file_write @options[:pwd]+"/config.ru", contents
end

#copy_template_cubaObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/tooler/cuba_template.rb', line 4

def copy_template_cuba
  gitignore
  license
  readme
  create_dir "lib"
  create_dir "spec"
  create_dir "log"
  template
  config_ru
  gemfile
  procfile
end

#copy_template_sinatraObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/tooler/sinatra_template.rb', line 4

def copy_template_sinatra
  gitignore
  license
  readme
  create_dir "lib"
  create_dir "spec"
  create_dir "log"
  template
  gemfile
  procfile
  config_ru
end

#create_dir(name) ⇒ Object



28
29
30
# File 'lib/tooler/template.rb', line 28

def create_dir name
  ::FileUtils.mkdir @options[:pwd]+"/"+name
end

#file_read(file_path) ⇒ Object



32
33
34
# File 'lib/tooler/template.rb', line 32

def file_read file_path
  File.read(file_path)
end

#file_write(file_path, contents) ⇒ Object



36
37
38
39
40
# File 'lib/tooler/template.rb', line 36

def file_write file_path, contents
  File.open(file_path, 'w+') do |f2|
    f2.puts contents
  end
end

#gemfileObject



4
5
6
# File 'lib/tooler/template.rb', line 4

def gemfile
  ::FileUtils.cp @options[:template_path]+"#{@options[:template]}/Gemfile", @options[:pwd]+"/Gemfile"
end

#gitignoreObject



12
13
14
# File 'lib/tooler/template.rb', line 12

def gitignore
  ::FileUtils.cp @options[:template_path]+"gitignore", @options[:pwd]+"/.gitignore"
end

#license(name = nil) ⇒ Object



16
17
18
19
20
# File 'lib/tooler/template.rb', line 16

def license name=nil
  contents = file_read @options[:template_path]+"license/#{name||'mit'}.txt"
  contents = contents % {username: @options[:username] || "[Replace your fullname]", year: Time.new.strftime("%Y")}
  file_write @options[:pwd]+"/License", contents
end

#procfileObject



8
9
10
# File 'lib/tooler/template.rb', line 8

def procfile
  ::FileUtils.cp @options[:template_path]+"#{@options[:template]}/Procfile", @options[:pwd]+"/Procfile"
end

#readmeObject



22
23
24
25
26
# File 'lib/tooler/template.rb', line 22

def readme
  contents = file_read @options[:template_path]+"README.md"
  contents = contents % {name: @options[:name], description: ""}
  file_write @options[:pwd]+"/README.md", contents
end

#templateObject



23
24
25
26
27
# File 'lib/tooler/cuba_template.rb', line 23

def template
  contents = file_read @options[:template_path]+'cuba/cuba_template.rb'
  contents = contents % {name: @options[:name]}
  file_write @options[:pwd]+"/lib/#{@options[:name]}.rb", contents
end