Sha256: b2e6527d034a3c854947573cd6784468def192bd9ac9dca39f9f94dad99d4f0a

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

#!/usr/bin/env ruby
require "rubygems"
require 'thor'
require 'date'

module LatexDocument
  class New < Thor::Group
    include Thor::Actions

    argument :name, :desc => 'Name of the new project.'

    def self.source_root
      File.expand_path('../../', __FILE__)
    end

    def gen_root
      empty_directory name
    end

    def fill_root
      empty_directory file_path('src')
      empty_directory file_path('include')
      empty_directory file_path('diagrams')
      create_file_from_template "Makefile"
    end

    def src
      template("templates/document.tex.tt", file_path("src/#{name}.tex"))
      template("templates/references.bib.tt", file_path("src/references.bib"))
    end

    def include
      template("templates/mydefault.sty.tt", file_path("include/mydefault.sty"))
    end

    private

    def title
      title_string = name.dup
      title_string[0] = name[0].upcase
      title_string.gsub(/(\w)([A-Z])/) { "#{$1} #{$2}" } # Camel case
      title_string.gsub(/[_\.\s](.)/) { " #{$1.upcase}" } # Snake case
    end

    def date
      Date.today.to_s
    end

    def file_path(file_name)
      File.join name, file_name
    end

    def create_file_from_template(file_name)
      template(
        "templates/#{file_name}.tt",
        file_path(file_name)
      )
    end
  end

  class LatexDocument < Thor
    map 'n' => :new

    register(
      New,
      'new',
      'new NAME',
      "Creates a new latex document NAME"
    )
    tasks["new"].options = New.class_options
  end
end

LatexDocument::LatexDocument.start(ARGV)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
latex_document-0.0.1 bin/latex_document