Module: Padrino::Generators::Runner

Included in:
Plugin, Project
Defined in:
padrino-gen/lib/padrino-gen/generators/runner.rb

Overview

Responsible for executing plugin and template instructions including common actions for modifying a project or application.

Instance Method Summary collapse

Instance Method Details

#app(name) ⇒ Object

Executes App generator. Accepts an optional block allowing generation inside subapp.

Examples:

app :name
app :name do
 generate :model, "posts title:string" # generate a model inside of subapp
end

Parameters:

  • name (Symbol)

    Name of (sub)application to generate.

  • block (Proc)

    Commands to execute in context of (sub)appliation directory.



74
75
76
77
78
79
80
81
82
# File 'padrino-gen/lib/padrino-gen/generators/runner.rb', line 74

def app(name)
  say "=> Executing: padrino-gen app #{name} -r=#{destination_root}", :magenta
  Padrino.bin_gen(:app, name.to_s, "-r=#{destination_root}")
  if block_given?
    @_app_name = name
    yield
    @_app_name = nil
  end
end

#generate(type, arguments = "") ⇒ Object

Executes generator command for specified type with given arguments.

Examples:

generate :model, "post title:string body:text"
generate :controller, "posts get:index get:new post:new"
generate :migration, "AddEmailToUser email:string"

Parameters:

  • type (Symbol)

    Type of component module.

  • arguments (String) (defaults to: "")

    Arguments to send to component generator.



40
41
42
43
44
45
# File 'padrino-gen/lib/padrino-gen/generators/runner.rb', line 40

def generate(type, arguments="")
  params = arguments.split(" ").push("-r=#{destination_root}")
  params.push("--app=#{@_app_name}") if @_app_name
  say "=> Executing: padrino-gen #{type} #{params.join(" ")}", :magenta
  Padrino.bin_gen(*params.unshift(type))
end

#git(*args) ⇒ Object

Executes git commmands in project.

Examples:

git :init
git :add, "."
git :commit, "hello world"

Parameters:

  • action (Symbol)

    Git command to execute.

  • arguments (String)

    Arguments to invoke on git command.



97
98
99
100
101
102
103
# File 'padrino-gen/lib/padrino-gen/generators/runner.rb', line 97

def git(*args)
  FileUtils.cd(destination_root) do
    cmd = "git %s" % args.join(' ')
    say cmd, :green
    system cmd
  end
end

#project(options = {}) ⇒ Object

Generates project scaffold based on a given template file.

Examples:

project :test => :shoulda, :orm => :activerecord, :renderer => "haml"

Parameters:

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

    Options to use to generate the project.



20
21
22
23
24
25
# File 'padrino-gen/lib/padrino-gen/generators/runner.rb', line 20

def project(options={})
  components = options.sort_by { |k, v| k.to_s }.map { |component, value| "--#{component}=#{value}" }
  params = [name, *components].push("-r=#{destination_root("../")}")
  say "=> Executing: padrino-gen project #{params.join(" ")}", :magenta
  Padrino.bin_gen(*params.unshift("project"))
end

#rake(command) ⇒ Object

Executes rake command with given arguments.

Examples:

rake "custom task1 task2"

Parameters:

  • command (String)

    Rake tasks to execute.



56
57
58
# File 'padrino-gen/lib/padrino-gen/generators/runner.rb', line 56

def rake(command)
  Padrino.bin("rake", command, "-c=#{destination_root}")
end