Sha256: 79bc0180d1555a4d57b4710d5138253c77dc1237feb140bb371a6b98a82f1816

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require 'thor'

module Author
  module Commands
    class Generator < Thor::Group
      include Thor::Actions
      
      argument :name
      
      def set_destination_root
        self.destination_root = File.join(self.destination_root, name)
      end
      
      def create_project_structure
        say "Creating directories for your new book, #{name}"
        empty_directory "chapters"
        empty_directory "export"
        empty_directory "templates"
      end
      
      def copy_files
        say "Copying files"
        template    'config.yml', 'config.yml'
        copy_file   'Gemfile', 'Gemfile'
        create_file 'outline.txt'
        template    'sample.md', 'chapters/sample.md'
        template    'layout.xhtml', 'templates/layout.xhtml'
        
        gsub_file   'templates/layout.xhtml', '<!-- insert @body -->', '<%= @body %>'
        
        copy_file   'book.css', 'export/book.css'
      end
      
      def bundle_gems
        inside destination_root do
          say "Bundling gems"
          run "bundle install", capture: true
        end
      end
      
      private
      
      def self.source_root
        File.join(File.dirname(__FILE__), '..', 'templates')
      end
      
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
author-1.1.4.alpha lib/author/commands/generator.rb
author-1.1.3.alpha lib/author/commands/generator.rb
author-1.1.2.alpha lib/author/commands/generator.rb
author-1.1.1.alpha lib/author/commands/generator.rb