Class: Ptero::CLI::Root

Inherits:
Ptero::CLI show all
Defined in:
lib/ptero/cli/root.rb

Overview

The principal Ptero CLI, the one that is called with the ‘ptero’ command

Instance Method Summary collapse

Methods inherited from Ptero::CLI

const_missing

Instance Method Details

#composerObject

Call the appropriate Application methods on the current Application to download composer.phar. If verify returns false, composer quits with the ptero_dir_message text



185
186
187
188
189
# File 'lib/ptero/cli/root.rb', line 185

def composer
  verify do
    app.get_composer
  end
end

#destroy(dir = Dir.pwd) ⇒ Object

Destroy dir if dir is a dinosaur directory This method will ask for confirmation by prompting to the user to type “Yes” (case sensitive) before destroying the directory. If the user types this exactly, destroy will recursively delete dir and print “Removed dir”.green. If the user types anything else, the method will exit without output. If the call to verify fails and the application is not a dinosaur directory, destroy prints “Cannot destroy dir because it is not a dinosaur directory”.red and exits.

Parameters:

  • dir (String, Pathname) (defaults to: Dir.pwd)

    the directory to destroy



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/ptero/cli/root.rb', line 153

def destroy(dir = Dir.pwd)
  a = Ptero::Application.new(dir)
  if a.verify
    puts "Are you sure you want to destroy #{dir}? Type 'Yes' to authorize".yellow
    print '>> '
    return unless $stdin.gets.chomp == 'Yes'
    a.destroy
    puts "Removed #{dir}".green
    
  else
    puts "Cannot destroy #{dir} because it is not a dinosaur directory.".red
  end
end

#generate(type, *args) ⇒ Object

Use the appropriate Application methods to generate new files and components. As with other methods, this one runs a check with the verify method before undertaking any action

Parameters:

  • type (String)

    the type of file to generate

  • *args

    other parameters for the generator



203
204
205
206
207
# File 'lib/ptero/cli/root.rb', line 203

def generate(type,*args)
  verify do
    app.generate(type,*args)
  end
end

#installObject

Call the appropriate Application methods on the current Application to install Composer dependencies. If verify returns false, install quits with the ptero_dir_message text



173
174
175
176
177
# File 'lib/ptero/cli/root.rb', line 173

def install
  verify do
    app.install_dependencies
  end
end

#new(name) ⇒ Object

Seed a new Application, then download composer.phar and all dependencies

Parameters:

  • name (String)

    the name of the new application



27
28
29
30
31
32
33
34
# File 'lib/ptero/cli/root.rb', line 27

def new(name)
  seed(name)
  Dir.chdir name do
    composer()
    install()
  end
  puts "Change your working directory to '#{Dir.pwd}/#{name}' and starting generating files with 'ptero generate' to start your application"
end

#reload(type, *args) ⇒ Object

Use the Application object to remove and regenerate a file or component As with other methods, this one runs a check with the verify method before undertaking any action

Parameters:

  • type (String)

    the type of file to reload

  • *args

    other parameters



219
220
221
222
223
# File 'lib/ptero/cli/root.rb', line 219

def reload(type,*args)
  verify do
    app.reload(type,*args)
  end
end

#remove(type, *args) ⇒ Object

Reload is the inverse of generate. Use the Application object to remove a file. It runs verify on the Application before taking any action.

Parameters:

  • type (String)

    the type of file to remove

  • *args

    other arguments to remove the file



234
235
236
237
238
# File 'lib/ptero/cli/root.rb', line 234

def remove(type,*args)
  verify do
    app.remove(type,*args)
  end
end

#route(path, controller) ⇒ Object

Add a new route to the Application routes file

Parameters:

  • path (String)

    the path to route

  • controller (String)

    the name of the controller to route



99
100
101
102
103
# File 'lib/ptero/cli/root.rb', line 99

def route(path,controller)
  verify do
    app.route(path,controller)
  end
end

#routesObject

If verify succeeds, display all routes of the current application



246
247
248
249
250
251
252
# File 'lib/ptero/cli/root.rb', line 246

def routes
  verify do
    app.routes.each_pair do |key,value|
      puts "#{key} => #{value}Controller"
    end
  end
end

#seed(name) ⇒ Object

Seed a new Application by generating a new application directory and generating all necessary files, without accessing the internet or getting dependencies

Parameters:

  • name (String)

    the name of the new application



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ptero/cli/root.rb', line 44

def seed(name)
  Ptero::Application.create(name) do |app|
    
    # PHP
    Dir.mkdir 'php'
    app.generate('PHP_Info')
    app.generate_setup(app.name.downcase)
    app.generate_routes
    
    Dir.mkdir 'php/controllers'
    app.generate_controller('Application','\Dinosaur\\')
    app.generate_load_all('php/controllers','ApplicationController')
    
    Dir.mkdir 'php/models'
    app.generate_load_all('php/models')
    
    # Configuration
    Dir.mkdir 'config'
    app.generate_config
    
    # Templates
    Dir.mkdir 'views'
    app.generate_layout
    app.generate_page_not_found
    
    # Document Root
    Dir.mkdir 'www'
    app.generate('HTAccess')
    app.generate_landing

    # CSS, Javascripts, Images
    Dir.mkdir 'www/assets'
    
    # CSS
    Dir.mkdir 'www/assets/css'
    app.generate_application_stylesheet('application','This is the main CSS stylesheet for application-wide styles. It is included in all pages by default.')
    
    # JS
    Dir.mkdir 'www/assets/js'
    app.generate_application_javascript('application','This is the main file that is loaded along with every page. Put application-wide behavior here.')
    
    # Images
    Dir.mkdir 'www/assets/images'
    
  end
end

#unroute(path) ⇒ Object

Remove a route from the Application routes file

Parameters:

  • path (String)

    the path to unroute



112
113
114
115
116
# File 'lib/ptero/cli/root.rb', line 112

def unroute(path)
  verify do
    app.unroute(path)
  end
end

#verify(dir = Dir.pwd) ⇒ Object

Tell the user whether or not the specified directory is a Ptero directory. Print “#dir is a dinosaur directory” if so or call ptero_dir_message if not If a block is given and dir is a dinosaur directory, yield control to the block (without arguments) rather than displaying output

Parameters:

  • dir (String, Pathname) (defaults to: Dir.pwd)

    the directory to check



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/ptero/cli/root.rb', line 127

def verify(dir=Dir.pwd)
  a = Ptero::Application.new(dir)
  if a.verify
    if block_given?
      yield
    else
      puts "#{dir} is a dinosaur project root.".green
    end
    true
  else
    ptero_dir_message
    false
  end
end

#versionObject

Print the Ptero version number



259
260
261
# File 'lib/ptero/cli/root.rb', line 259

def version
  puts Ptero::VERSION
end