ptero 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +350 -0
  6. data/Rakefile +10 -0
  7. data/bin/ptero +13 -0
  8. data/lib/ptero.rb +14 -0
  9. data/lib/ptero/application.rb +281 -0
  10. data/lib/ptero/cli.rb +35 -0
  11. data/lib/ptero/cli/root.rb +282 -0
  12. data/lib/ptero/composer_default.json +8 -0
  13. data/lib/ptero/exception.rb +26 -0
  14. data/lib/ptero/exceptions/applicationexception.rb +9 -0
  15. data/lib/ptero/exceptions/generatorexception.rb +9 -0
  16. data/lib/ptero/generator.rb +146 -0
  17. data/lib/ptero/generators/applicationjavascriptgenerator.rb +19 -0
  18. data/lib/ptero/generators/applicationstylesheetgenerator.rb +18 -0
  19. data/lib/ptero/generators/configgenerator.rb +34 -0
  20. data/lib/ptero/generators/controllergenerator.rb +23 -0
  21. data/lib/ptero/generators/htaccessgenerator.rb +27 -0
  22. data/lib/ptero/generators/javascriptgenerator.rb +34 -0
  23. data/lib/ptero/generators/landinggenerator.rb +23 -0
  24. data/lib/ptero/generators/layoutgenerator.rb +19 -0
  25. data/lib/ptero/generators/loadallgenerator.rb +26 -0
  26. data/lib/ptero/generators/modelgenerator.rb +22 -0
  27. data/lib/ptero/generators/pagegenerator.rb +56 -0
  28. data/lib/ptero/generators/pagenotfoundgenerator.rb +16 -0
  29. data/lib/ptero/generators/phpclassgenerator.rb +27 -0
  30. data/lib/ptero/generators/phpgenerator.rb +18 -0
  31. data/lib/ptero/generators/phpinfogenerator.rb +16 -0
  32. data/lib/ptero/generators/routesgenerator.rb +68 -0
  33. data/lib/ptero/generators/setupgenerator.rb +13 -0
  34. data/lib/ptero/generators/stylesheetgenerator.rb +33 -0
  35. data/lib/ptero/generators/twiggenerator.rb +24 -0
  36. data/lib/ptero/generators/viewgenerator.rb +24 -0
  37. data/lib/ptero/templates/applicationjavascriptgenerator.js.erb +11 -0
  38. data/lib/ptero/templates/applicationstylesheetgenerator.css.erb +40 -0
  39. data/lib/ptero/templates/configgenerator.php.erb +26 -0
  40. data/lib/ptero/templates/controllergenerator.php.erb +25 -0
  41. data/lib/ptero/templates/generator.txt.erb +1 -0
  42. data/lib/ptero/templates/htaccessgenerator.htaccess.erb +9 -0
  43. data/lib/ptero/templates/javascriptgenerator.js.erb +11 -0
  44. data/lib/ptero/templates/landinggenerator.php.erb +3 -0
  45. data/lib/ptero/templates/layoutgenerator.html.twig.erb +37 -0
  46. data/lib/ptero/templates/loadallgenerator.php.erb +12 -0
  47. data/lib/ptero/templates/modelgenerator.php.erb +21 -0
  48. data/lib/ptero/templates/pagegenerator.html.twig.erb +13 -0
  49. data/lib/ptero/templates/pagenotfoundgenerator.html.twig.erb +13 -0
  50. data/lib/ptero/templates/phpclassgenerator.php.erb +24 -0
  51. data/lib/ptero/templates/phpgenerator.php.erb +3 -0
  52. data/lib/ptero/templates/phpinfogenerator.php.erb +3 -0
  53. data/lib/ptero/templates/routesgenerator.php.erb +13 -0
  54. data/lib/ptero/templates/setupgenerator.php.erb +19 -0
  55. data/lib/ptero/templates/stylesheetgenerator.css.erb +8 -0
  56. data/lib/ptero/templates/twiggenerator.html.twig.erb +5 -0
  57. data/lib/ptero/templates/viewgenerator.html.twig.erb +13 -0
  58. data/lib/ptero/version.rb +4 -0
  59. data/ptero.gemspec +28 -0
  60. data/test/fixtures/test_generators_fixtures.yaml +74 -0
  61. data/test/test_application.rb +123 -0
  62. data/test/test_exceptions.rb +52 -0
  63. data/test/test_generators.rb +110 -0
  64. data/test/test_root.rb +212 -0
  65. metadata +212 -0
@@ -0,0 +1,19 @@
1
+ #
2
+ #
3
+ # applicationjavascriptgenerator.rb
4
+ # =================================
5
+ # Generate application-wide Javascripts
6
+ #
7
+
8
+ # Generate Javascript for the default page layout
9
+ class Ptero::Generator::ApplicationJavascriptGenerator < Ptero::Generator::JavascriptGenerator
10
+
11
+ # @param name [String] The name of the Javscript, defaults to "application"
12
+ # @param desc [String] The description of the Javascript, defaults to "The application-wide Javascript file"
13
+ def initialize(name='application',desc = 'The application-wide Javascript file')
14
+ super name,desc
15
+ end
16
+
17
+
18
+
19
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # applicationstylesheetgenerator.rb
3
+ # =================================
4
+ # Generate application-wide CSS stylesheets
5
+ #
6
+ #
7
+
8
+ # Generate stylesheets to be used by application layouts
9
+ class Ptero::Generator::ApplicationStylesheetGenerator < Ptero::Generator::StylesheetGenerator
10
+ # Initialize with name and description
11
+ # @param name [String] the stylesheet's name
12
+ # @param desc [String] the stylesheet's description
13
+ def initialize(name='application',desc='The main application stylesheet')
14
+ super(name,desc)
15
+ end
16
+
17
+
18
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # configgenerator.rb
3
+ # ==================
4
+ # Generate the config.php file for each application
5
+
6
+
7
+
8
+ # Generator for the config.php file
9
+ class Ptero::Generator::ConfigGenerator < Ptero::Generator::PHPGenerator
10
+ # Automatically with name "config". Pass a hash of mappings to be included in the config file
11
+ # @param options [Hash] a mapping of keys and values to be included in the config.php file
12
+ def initialize(options={})
13
+ super 'config'
14
+ @options = options
15
+
16
+ # Defaults
17
+ @options[:templates_path] ||= 'views'
18
+ @options[:controllers_path] ||= 'php/controllers'
19
+ @options[:models_path] ||= 'php/models'
20
+
21
+ @options[:database] ||= {
22
+ name: 'database-name',
23
+ user: 'username',
24
+ password: 'password',
25
+ server: 'localhost'
26
+ }
27
+ end
28
+
29
+ attr_reader :options
30
+ # @return [String] "config"
31
+ def path
32
+ "config"
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # controllergenerator.rb
3
+ # ======================
4
+ # generate Dinosaur controller objects
5
+ #
6
+ #
7
+ #
8
+
9
+ class Ptero::Generator::ControllerGenerator < Ptero::Generator::PHPClassGenerator
10
+ # @param name [String] the name of the controller
11
+ # @param parent [String] the name of the controller's parent
12
+ def initialize(name,parent='Application')
13
+ super("#{name}Controller","#{parent}Controller")
14
+ end
15
+
16
+ # @return [String] superclass_path/controllers
17
+ def path
18
+ "#{super}/controllers"
19
+ end
20
+
21
+
22
+
23
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # htaccessgenerator.rb
3
+ # ====================
4
+ # Generate the Apache .htaccess file for redirects
5
+ #
6
+ #
7
+ #
8
+
9
+ # Generate .htaccess files for apache routing
10
+ class Ptero::Generator::HTAccessGenerator < Ptero::Generator
11
+
12
+ # This is a dotfile, there are no parameters, and the name is always ""
13
+ def initialize
14
+ super ''
15
+ end
16
+
17
+ # @return [String] "htaccess"
18
+ def extension
19
+ 'htaccess'
20
+ end
21
+
22
+ # @return [String] "www"
23
+ def path
24
+ 'www'
25
+ end
26
+
27
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ #
3
+ # javascriptgenerator.rb
4
+ # ======================
5
+ # Generate javascripts
6
+ #
7
+
8
+ # Generate Javascripts
9
+ class Ptero::Generator::JavascriptGenerator < Ptero::Generator
10
+
11
+ # Initialize with name and an optional description that will be generated in a comment.
12
+ # (Defaults to "This script does...")
13
+ # @param name [String] the name of the Javascript
14
+ # @param desc [String] a String to describe this script
15
+ def initialize(name,desc = 'This script does...')
16
+ super name
17
+ @desc = desc
18
+ end
19
+
20
+ attr_reader :desc
21
+
22
+ # @return [String] "www/assets/js"
23
+ def path
24
+ 'www/assets/js'
25
+ end
26
+
27
+ # @return [String] "js"
28
+ def extension
29
+ 'js'
30
+ end
31
+
32
+
33
+
34
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ #
3
+ # landinggenerator.rb
4
+ # ===================
5
+ # The landing redirect page
6
+ #
7
+ #
8
+
9
+ # Generator for the global landing page of the application that handles all incoming requests and initiates Routing
10
+ class Ptero::Generator::LandingGenerator < Ptero::Generator::PHPGenerator
11
+
12
+ # Initialize with name "index"
13
+ def initialize
14
+ super 'index'
15
+ end
16
+
17
+ # @return "www"
18
+ def path
19
+ 'www'
20
+ end
21
+
22
+
23
+ end
@@ -0,0 +1,19 @@
1
+ #
2
+ #
3
+ #
4
+ # layoutgenerator.rb
5
+ # ==================
6
+ #
7
+ # Generate the application layout twig file
8
+ #
9
+ #
10
+ #
11
+
12
+ # Generate application layout template
13
+ class Ptero::Generator::LayoutGenerator < Ptero::Generator::TwigGenerator
14
+ # @param name [String] the name of the application
15
+ def initialize(name='application')
16
+ super(name)
17
+ end
18
+
19
+ end
@@ -0,0 +1,26 @@
1
+ #
2
+ # loadallgenerator.rb
3
+ # ===================
4
+ # Generate a PHP file to run all other PHP files in the same directory
5
+
6
+
7
+
8
+ require 'pathname'
9
+
10
+
11
+ # Generator for the loadall.php file that is tasked with running all other PHP files in its directory
12
+ class Ptero::Generator::LoadAllGenerator < Ptero::Generator::PHPGenerator
13
+ # Send the directory in which to generate as a parameter, as well as the names of files that need to be loaded first
14
+ # @param path [String] the path to the file that will be generated
15
+ # @param priorities [Array] all files that need to be required first, in order of priority
16
+ def initialize(path,*priorities)
17
+ super 'loadall'
18
+ # Stuff to load first, should be an array
19
+ @path = Pathname.new(path)
20
+ @priorities = priorities
21
+ end
22
+
23
+ attr_reader :path, :priorities
24
+
25
+
26
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ #
3
+ # modelgenerator.rb
4
+ # =================
5
+ # Generate PHPActiveRecord models
6
+ # http://www.phpactiverecord.org/
7
+ #
8
+
9
+ # A generator for PHP ActiveRecord Models
10
+ class Ptero::Generator::ModelGenerator < Ptero::Generator::PHPClassGenerator
11
+ def initialize(name)
12
+ super(name)
13
+ end
14
+
15
+ # @return [String] superclass_path/models
16
+ def path
17
+ "#{super}/models"
18
+ end
19
+
20
+
21
+
22
+ end
@@ -0,0 +1,56 @@
1
+ #
2
+ #
3
+ # pagegenerator.rb
4
+ # ================
5
+ #
6
+ # Generate necessary elements for a full-fledged template page
7
+ #
8
+ #
9
+
10
+ # Generate all elements of a page
11
+ class Ptero::Generator::PageGenerator < Ptero::Generator::ViewGenerator
12
+ # Initialize a ControllerGenerator, JavascriptGenerator, and StylesheetGenerator with parameter name
13
+ def initialize(name,parent='application')
14
+ super name,parent
15
+ @controller = Ptero::Generator::ControllerGenerator.new(name)
16
+ @js = Ptero::Generator::JavascriptGenerator.new(name.downcase)
17
+ @css = Ptero::Generator::StylesheetGenerator.new(name.downcase)
18
+ @elements = [ @controller, @js, @css ]
19
+ end
20
+
21
+ attr_reader :controller,:js,:css,:elements
22
+
23
+ # Call the #generate method on all Generator instance variables and self
24
+ # @return [Ptero::Generator::PageGenerator] self
25
+ def generate
26
+ super
27
+ @controller.generate
28
+ @js.generate
29
+ @css.generate
30
+ self
31
+ end
32
+
33
+ # Call the #remove method on all Generator instance variables and self
34
+ # @return [Ptero::Generator::PageGenerator] self
35
+ def remove
36
+ super
37
+ @controller.remove
38
+ @js.remove
39
+ @css.remove
40
+ self
41
+ end
42
+
43
+ def reload
44
+ super
45
+ @controller.reload
46
+ @js.reload
47
+ @css.reload
48
+ self
49
+ end
50
+
51
+ # @return [Boolean] whether or not every Generator instance variable is generated
52
+ def generated?
53
+ @controller.generated? and @js.generated? and @css.generated? and super
54
+ end
55
+
56
+ end
@@ -0,0 +1,16 @@
1
+ #
2
+ #
3
+ # pagenotfoundgenerator.rb
4
+ # ========================
5
+ # Generate the HTTP 404 template
6
+ #
7
+ #
8
+ class Ptero::Generator::PageNotFoundGenerator < Ptero::Generator::ViewGenerator
9
+
10
+ # @param parent [String] the layout to extend
11
+ def initialize(parent = 'application')
12
+ super '404',parent
13
+ end
14
+
15
+
16
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ #
3
+ # phpclassgenerator.rb
4
+ # ====================
5
+ #
6
+ # Generate a PHP class file
7
+ #
8
+ #
9
+ #
10
+
11
+ # A generator for PHP classes
12
+ class Ptero::Generator::PHPClassGenerator < Ptero::Generator::PHPGenerator
13
+ # @param name [String] the name of the class, it will be capitalized
14
+ # @param parent [String] the name of the class's superclass
15
+ def initialize(name,parent=nil)
16
+ # Capitalize class names
17
+ super("#{name[0].upcase}#{name[1,name.length-1]}")
18
+ @parent = "#{parent[0].upcase}#{parent[1,parent.length-1]}"if parent
19
+ end
20
+
21
+ attr_reader :parent
22
+
23
+
24
+
25
+
26
+
27
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ #
3
+ # phpgenerator.rb
4
+ # ===============
5
+ # Generate PHP files
6
+
7
+ # Generator for PHP files
8
+ class Ptero::Generator::PHPGenerator < Ptero::Generator
9
+
10
+ # @return [String] "php"
11
+ def extension
12
+ 'php'
13
+ end
14
+ # @return [String] "php"
15
+ def path
16
+ 'php'
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ #
2
+ # phpinfogenerator.rb
3
+ # ===================
4
+ # Generate phpinfo files
5
+
6
+ # A generator for files that call phpinfo(); to show PHP configuration
7
+ class Ptero::Generator::PHPInfoGenerator < Ptero::Generator::PHPGenerator
8
+
9
+ # Name is always "phpinfo"
10
+ def initialize
11
+ super 'phpinfo'
12
+
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,68 @@
1
+ #
2
+ #
3
+ #
4
+ # routesgenerator.rb
5
+ # ==================
6
+ #
7
+ # Generate the application's routing file
8
+ #
9
+ #
10
+
11
+ # A generator for the application routes file
12
+ class Ptero::Generator::RoutesGenerator < Ptero::Generator::PHPGenerator
13
+
14
+ # Initialize as a generator, name is always "routes"
15
+ # @param routes [Hash] a list of route mappings from path to controller-name
16
+ def initialize(routes = {})
17
+ super('routes')
18
+ @routes = routes
19
+
20
+ end
21
+
22
+ attr_reader :routes
23
+
24
+ # Add a new route to routes.php
25
+ # @param path [String] the path of the new route
26
+ # @param controller [String] the name of the route's controller
27
+ def route(path,controller)
28
+ get_current_routes
29
+ raise Ptero::Exception::GeneratorException, "Route #{path} already exists" if @routes.has_key? path
30
+ controller = "#{controller[0].upcase}#{controller[1,controller.length-1]}"
31
+ @routes[path] = controller
32
+ Mute::IO.capture_stdout do
33
+ reload
34
+ end
35
+ puts "ROUTE - #{path} => #{controller}Controller".blue
36
+ self
37
+ end
38
+
39
+ # Remove a route from routes.php
40
+ # @param path [String] the path of the route to be deleted
41
+ def unroute(path)
42
+ get_current_routes
43
+ raise Ptero::Exception::GeneratorException, "No such route #{path}" unless @routes.has_key? path
44
+ @routes.delete path
45
+ Mute::IO.capture_stdout do
46
+ reload
47
+ end
48
+ puts "UNROUTE - #{path}".red
49
+ self
50
+ end
51
+
52
+ # Open the routes.rb file and parse out any existing routes into this object
53
+ # @return [Ptero::Generator::RoutesGenerator] self
54
+ def get_current_routes
55
+ raise Ptero::Exception::GeneratorException, "Routes file: #{location} not found" unless File.exist? location
56
+ File.open(location,'r') do |file|
57
+ file.each_line do |line|
58
+ line.match( /^\s*(['"])([\/\w:\.]+)\1\s*=>\s*(['"])#{app.name}\\Controllers\\(\w+)Controller\3,?\s*$/ ) do |match|
59
+ key = match[2]
60
+ value = match[4]
61
+ @routes[key] = value
62
+ end
63
+ end
64
+ end
65
+ self
66
+ end
67
+
68
+ end