Module: Cog::Controllers::TemplateController

Defined in:
lib/cog/controllers/template_controller.rb

Overview

Manage a project’s templates

Class Method Summary collapse

Class Method Details

.create(name, opt = {}) ⇒ nil

Create a new project template

Parameters:

  • name (String)

    name of the template, relative to the project’s templates directory

  • opt (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opt):

  • :force_override (Boolean) — default: false

    if a built-in or plugin template with the same name already exists, should a project override be created?

Returns:

  • (nil)


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cog/controllers/template_controller.rb', line 11

def self.create(name, opt={})
  prefix = Cog.project_template_path
  raise Errors::ActionRequiresProjectTemplatePath.new('create template') unless prefix
  name = name.without_extension :erb
  dest = File.join prefix, "#{name}.erb"
  original = Generator.get_template name, :as_path => true
  Generator.copy_file_if_missing original, dest
  nil
rescue Errors::NoSuchTemplate
  # No original, ok to create an empty template
  Generator.touch_file dest
  nil
end

.listArray<String>

List the available templates

Returns:



27
28
29
# File 'lib/cog/controllers/template_controller.rb', line 27

def self.list
  Helpers::CascadingSet.process_paths Cog.template_path, :ext => 'erb'
end