Sha256: 49216448576cb0c4477343fb906477fee17dfc3692fb46ad52c7563963421de8

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

require 'fileutils'
require 'pathname'

require 'magic_reveal/version'
require 'magic_reveal/reveal_js_fetcher'
require 'magic_reveal/project_config'

module MagicReveal
  class Creator
    attr_reader :directory
    attr_writer :reveal_js_fetcher, :template_slides, :template_config_ru

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

    def reveal_js_fetcher
      @reveal_js_fetcher ||= RevealJsFetcher.new
    end

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

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

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

      reveal_js_fetcher.save_important_parts_to(top_dir)
    end

    def create_project(project)
      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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
magic_reveal-2.6.1.2 lib/magic_reveal/creator.rb
magic_reveal-2.6.1.1 lib/magic_reveal/creator.rb