Class: MagicReveal::Creator

Inherits:
Object
  • Object
show all
Defined in:
lib/magic_reveal/creator.rb

Overview

Creates the world!

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ Creator

Returns a new instance of Creator.



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

def initialize(directory)
  @directory = Pathname.new directory
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



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

def directory
  @directory
end

#reveal_js_fetcherObject



18
19
20
# File 'lib/magic_reveal/creator.rb', line 18

def reveal_js_fetcher
  @reveal_js_fetcher ||= RevealJsFetcher.new
end

#template_config_ruObject



26
27
28
# File 'lib/magic_reveal/creator.rb', line 26

def template_config_ru
  @template_config_ru ||= Pathname.new(__FILE__).dirname + 'template-config.ru'
end

#template_slidesObject



22
23
24
# File 'lib/magic_reveal/creator.rb', line 22

def template_slides
  @template_slides ||= Pathname.new(__FILE__).dirname.dirname.dirname + 'README.md'
end

Instance Method Details

#create_project(project) ⇒ Object

rubocop:disable MethodLength



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/magic_reveal/creator.rb', line 36

def create_project(project) # rubocop:disable MethodLength
  top_dir = directory + project
  gemfile = top_dir + 'Gemfile'

  top_dir.mkdir

  reveal_js_fetcher.save_important_parts_to(top_dir)

  FileUtils.copy_file template_slides.to_s, (top_dir + 'slides.md').to_s
  FileUtils.copy_file template_config_ru.to_s, (top_dir + 'config.ru').to_s
  FileUtils.copy_file ProjectConfig::DEFAULT_TEMPLATE.to_s, (top_dir + 'config.json').to_s
  gemfile.open('w') do |f|
    f.puts "source 'https://rubygems.org'"
    f.puts
    f.puts "gem 'magic_reveal', '~> #{VERSION}'"
  end

  Dir.chdir(top_dir.to_s) do
    system 'bundle install'
  end
end

#update_project(directory) ⇒ Object



30
31
32
33
34
# File 'lib/magic_reveal/creator.rb', line 30

def update_project(directory)
  top_dir = Pathname.new(directory)

  reveal_js_fetcher.save_important_parts_to(top_dir)
end