ptero 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d4792a46c456252b457597f5c0a6ff05d3937d1
4
- data.tar.gz: 922fcf8074aa76113104c1d07d4140bcef12a43c
3
+ metadata.gz: a27fb5289bea6827e5b3b7cb7145a06d482cb17f
4
+ data.tar.gz: 8fd22cae5ea40774e96784ad43c428a8f68a6e39
5
5
  SHA512:
6
- metadata.gz: 50fabbb8af36688eab64319d0ce8bbdb4b1d3188e14be69539b33ddbc1a56eafb917a5f3f00e8560a6aab70735cd5566f32515db07c0ca36fb2fb47a15f53a71
7
- data.tar.gz: b453ce63d1b3e6b2a456cbc23b7fbff9b1d8a7ed5eb99045d4dd28099022b427d9a99c705df9e74b3748e4a3a8d25289e3d0bff61770f32d9400445717cdc871
6
+ metadata.gz: 919135e5a2ca537f012aa988275e43024901ef35a004d1adca05f168cd4b733442e5bbd8f86ec4b4ca4349dc85e977a0eeb747296f6b12c6997bbd0ba1a1ad49
7
+ data.tar.gz: 6f63fa5383ce9263dee0365f292975e3fb4b64475a6baf1995cbb2255ccfc7a384f5a21245bb5cb5765e0014b000dd0446eeff04e6535ad178a0693ed598a406
@@ -8,7 +8,4 @@ require 'pathname'
8
8
  # The namespace for all Ptero classes and constants
9
9
  module Ptero
10
10
 
11
- # The directory location of all Ptero templates for code generation
12
- TEMPLATE_PATH = Pathname.new("#{__dir__}/ptero/templates")
13
-
14
11
  end
@@ -18,14 +18,36 @@ module Ptero
18
18
  # Input a directory String or Pathname to make a new Application from that path. (Defaults to Dir.pwd)
19
19
  # @param dir [Pathname,String] the Application directory
20
20
  def initialize(dir=Dir.pwd)
21
- @name = dir.to_s.split('/').last.capitalize
22
21
  @dir = Pathname.new(dir)
23
22
 
23
+ @name = ''
24
+
25
+ composer_path = @dir.join('composer.json')
26
+ if File.exist? composer_path
27
+
28
+ hash = JSON.parse File.read(composer_path)
29
+
30
+ if hash['dinosaur'] && hash['dinosaur']['root'].eql?(true) && hash['dinosaur']['name']
31
+ @name = hash['dinosaur']['name']
32
+ end
33
+
34
+
35
+ end
24
36
 
25
37
  end
26
38
 
27
39
  attr_reader :name,:dir
28
40
 
41
+ # Find out if this folder really contains a Ptero application using metadat
42
+ # @return [Boolean] whether or not this application was verified successfully
43
+ def verify
44
+ composer_path = dir.join('composer.json')
45
+ return false unless File.exist? composer_path
46
+ hash = JSON.parse File.read(composer_path)
47
+ return false unless hash['dinosaur'] && hash['dinosaur']['root']
48
+ true
49
+ end
50
+
29
51
  # Find out whether or not the user has the PHP command-line tool installed so that they can use Composer.
30
52
  # @return [Boolean] whether or not the user's PHP command works.
31
53
  def test_php
@@ -39,7 +61,7 @@ module Ptero
39
61
  #
40
62
  # @return [Application,Boolean] self
41
63
  def get_composer
42
- raise Ptero::Exception::ApplicationException, "Application #{self} already has composer.phar file" if has_composer?
64
+ raise Ptero::Exception::ApplicationException, "Application \"#{self.name}\" already has composer.phar file" if has_composer?
43
65
  Dir.chdir @dir do
44
66
  # Download code from the composer website
45
67
  # https://getcomposer.org
@@ -56,7 +78,7 @@ module Ptero
56
78
  puts
57
79
 
58
80
  unless exit_status.success?
59
- raise Ptero::Exception::ApplicationException, "Could not install Composer in Application #{self.dir} with command `#{command}`. Output was: \"#{output.chomp}\""
81
+ raise Ptero::Exception::ApplicationException, "Could not install Composer in Application \"#{self.name}\" with command `#{command}`. Output was: \"#{output.chomp}\""
60
82
  end
61
83
 
62
84
  puts 'Done!'
@@ -68,7 +90,7 @@ module Ptero
68
90
  # Remove the composer.phar file
69
91
  # @return [Application,Boolean] self if composer was removed, flse if composer is not downloaded
70
92
  def remove_composer
71
- raise Ptero::Exception::ApplicationException, "Application #{self} does not have a composer.phar file" unless has_composer?
93
+ raise Ptero::Exception::ApplicationException, "Application \"#{self.name}\" does not have a composer.phar file" unless has_composer?
72
94
  File.unlink(dir.join('composer.phar'))
73
95
  self
74
96
  end
@@ -87,7 +109,7 @@ module Ptero
87
109
  def install_dependencies
88
110
  raise Ptero::Exception::ApplicationException, "Not a dinosaur root: #{Dir.pwd}" unless verify
89
111
  raise Ptero::Exception::ApplicationException, "PHP command-line tool failed, update your version of PHP" unless test_php
90
- # get_composer unless has_composer?
112
+ get_composer unless has_composer?
91
113
  Dir.chdir @dir do
92
114
  # Install dependencies using Composer
93
115
  # https://getcomposer.org
@@ -105,7 +127,7 @@ module Ptero
105
127
  puts
106
128
 
107
129
  unless exit_status.success?
108
- raise Ptero::Exception::ApplicationException, "Could not install dependencies in Application #{self.dir} with command `#{command}`. Output was: \"#{output.chomp}\""
130
+ raise Ptero::Exception::ApplicationException, "Could not install dependencies in Application \"#{self.name}\" with command `#{command}`. Output was: \"#{output.chomp}\""
109
131
  end
110
132
  puts 'Done!'
111
133
  end
@@ -135,7 +157,7 @@ module Ptero
135
157
  puts
136
158
 
137
159
  unless exit_status.success?
138
- raise Ptero::Exception::ApplicationException, "Could not update dependencies in Application #{self.dir} with command `#{command}`. Output was: \"#{output.chomp}\""
160
+ raise Ptero::Exception::ApplicationException, "Could not update dependencies in Application \"#{self.name}\" with command `#{command}`. Output was: \"#{output.chomp}\""
139
161
  end
140
162
 
141
163
  puts 'Done!'
@@ -152,16 +174,6 @@ module Ptero
152
174
  @dir.join('vendor').directory?
153
175
  end
154
176
 
155
- # Find out if this folder really contains a Ptero application using metadata in composer.json
156
- # @return [Boolean] whether or not this application was verified successfully.
157
- def verify
158
- composer_path = dir.join('composer.json')
159
- return false unless File.exist? composer_path
160
- hash = JSON.parse File.read(composer_path)
161
- return false unless hash['dinosaur'] && hash['dinosaur']['root']
162
- self
163
- end
164
-
165
177
  # Generate a file using the given arguments
166
178
  # @param klass [String,Class] what type of file to generate
167
179
  # @param *params all other parameters to pass to the generator
@@ -262,12 +274,14 @@ module Ptero
262
274
  # @return [Application] the new Application object
263
275
  def create(name,dir=Pathname.new(Dir.pwd))
264
276
 
277
+ name = "#{name[0].upcase}#{name[1,name.length-1]}"
278
+
265
279
  Dir.chdir dir do
266
- raise Ptero::Exception::ApplicationException, "Cannot create project #{name} because a file already exists with that name" if File.exist? name
280
+ raise Ptero::Exception::ApplicationException, "Cannot create project \"#{name}\" because a file already exists with that name" if File.exist? name.downcase
267
281
 
268
- puts "Creating directory #{name} in #{Dir.pwd}"
269
- Dir.mkdir(name)
270
- Dir.chdir(name) do
282
+ puts "Creating directory #{name.downcase} in #{Dir.pwd}"
283
+ Dir.mkdir(name.downcase)
284
+ Dir.chdir(name.downcase) do
271
285
 
272
286
  puts "Loading default composer.json"
273
287
  composer = JSON.parse( File.read("#{__dir__}/composer_default.json") )
@@ -298,14 +312,16 @@ module Ptero
298
312
  # @return [Application] the verified Application object
299
313
  def app_for(dir=Dir.pwd)
300
314
  path = Pathname.new dir
301
- path.realpath.ascend do |level|
302
- app = self.new(level)
315
+ path.ascend do |level|
316
+ app = new(level)
303
317
  return app if app.verify
304
318
  end
305
319
 
306
320
  raise Ptero::Exception::ApplicationException, "Couldn't find composer.json with dinosaur information in #{dir} or parent directories"
307
321
  end
308
322
 
323
+
324
+
309
325
  # Return the verified Application object corresponding to Dir.pwd or its parent directories
310
326
  # @return [Application] the Application object that represents the found verified application
311
327
  def current_app
@@ -25,7 +25,9 @@ module Ptero
25
25
  def const_missing(const_name)
26
26
  # Load the cli
27
27
  require "#{__dir__}/cli/#{const_name.downcase}.rb"
28
- return const_get const_name
28
+ return const_get const_name if const_defined? const_name
29
+ super
30
+ # If we couldn't load it, throw an error
29
31
  rescue LoadError
30
32
  super
31
33
  end
@@ -47,7 +47,7 @@ class Ptero::CLI::Root < Ptero::CLI
47
47
  # PHP
48
48
  Dir.mkdir 'php'
49
49
  app.generate('PHP_Info')
50
- app.generate_setup(app.name.downcase)
50
+ app.generate_setup
51
51
  app.generate_routes
52
52
 
53
53
  Dir.mkdir 'php/controllers'
@@ -151,7 +151,7 @@ class Ptero::CLI::Root < Ptero::CLI
151
151
  # and exits.
152
152
  # @param dir [String,Pathname] the directory to destroy
153
153
  def destroy(dir = Dir.pwd)
154
- a = Ptero::Application.new(dir)
154
+ a = Ptero::Application.app_for(dir)
155
155
  if a.verify
156
156
  puts "Are you sure you want to destroy #{dir}? Type 'Yes' to authorize".yellow
157
157
  print '>> '
@@ -176,18 +176,6 @@ class Ptero::CLI::Root < Ptero::CLI
176
176
  end
177
177
  end
178
178
 
179
- desc 'update', 'Update dependencies'
180
- long_desc <<-LONGDESC
181
- Use the composer.json file to update dependencies. Install Composer if it is not already downloaded.
182
- LONGDESC
183
- # Call the appropriate Application methods to update Composer dependencies.
184
- # If verify returns false, install quits with the ptero_dir_message text
185
- def update
186
- verify do
187
- app.update_dependencies
188
- end
189
- end
190
-
191
179
  desc 'composer', 'Download composer.phar'
192
180
  long_desc <<-LONGDESC
193
181
  Download the compser.phar file in order to facilitate future downloads
@@ -14,7 +14,8 @@ class Ptero::Exception < StandardError
14
14
  def const_missing(const_name)
15
15
  # Require the exception
16
16
  require "#{__dir__}/exceptions/#{const_name.downcase}.rb"
17
- return const_get const_name
17
+ return const_get const_name if const_defined? const_name
18
+ super
18
19
  # If we couldn't load the file, throw an error
19
20
  rescue LoadError
20
21
  super
@@ -65,7 +65,7 @@ module Ptero
65
65
  # The path to the directory where Ptero templates are stored
66
66
  # @return [String] the aforementioned path
67
67
  def template_path
68
- Pathname.new("#{Ptero::TEMPLATE_PATH}/#{self.class.name.split('::').last.downcase}.#{extension}.erb")
68
+ Pathname.new("#{TEMPLATE_PATH}/#{self.class.name.split('::').last.downcase}.#{extension}.erb")
69
69
  end
70
70
 
71
71
  # Generate a file and print the location of the generated file
@@ -127,6 +127,10 @@ module Ptero
127
127
  self
128
128
  end
129
129
 
130
+
131
+ # The directory location of all Ptero templates for code generation
132
+ TEMPLATE_PATH = Pathname.new("#{__dir__}/templates")
133
+
130
134
 
131
135
 
132
136
  class << self
@@ -134,7 +138,8 @@ module Ptero
134
138
  def const_missing(const_name)
135
139
  # Require the generator
136
140
  require "#{__dir__}/generators/#{const_name.downcase}.rb"
137
- return const_get const_name
141
+ return const_get const_name if const_defined? const_name
142
+ super
138
143
  # If we couldn't load the file, throw an error
139
144
  rescue LoadError
140
145
  super
@@ -13,7 +13,7 @@ class Ptero::Generator::JavascriptGenerator < Ptero::Generator
13
13
  # @param name [String] the name of the Javascript
14
14
  # @param desc [String] a String to describe this script
15
15
  def initialize(name,desc = 'This script does...')
16
- super name
16
+ super name.downcase
17
17
  @desc = desc
18
18
  end
19
19
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  # Generate application layout template
13
13
  class Ptero::Generator::LayoutGenerator < Ptero::Generator::TwigGenerator
14
- # @param name [String] the name of the application
14
+ # @param name [String] the name of the layout
15
15
  def initialize(name='application')
16
16
  super(name)
17
17
  end
@@ -10,4 +10,9 @@
10
10
  # A generator for "setup" files that load dependencies and initialize the application
11
11
  class Ptero::Generator::SetupGenerator < Ptero::Generator::PHPGenerator
12
12
 
13
+ # The name of the setup is always the same as the name of the Application
14
+ def initialize
15
+ super Ptero::Application.app_for(Dir.pwd).name.downcase
16
+ end
17
+
13
18
  end
@@ -13,7 +13,7 @@ class Ptero::Generator::StylesheetGenerator < Ptero::Generator
13
13
  # @param name [String] the name of the stylesheet
14
14
  # @param desc [String] a String to describe this stylesheet
15
15
  def initialize(name,desc = 'The purpose of this stylesheet is...')
16
- super name
16
+ super name.downcase
17
17
  @desc = desc
18
18
  end
19
19
 
@@ -10,6 +10,10 @@
10
10
  # Generator for Twig templates
11
11
  class Ptero::Generator::TwigGenerator < Ptero::Generator
12
12
 
13
+ def initialize(name)
14
+ super name.downcase
15
+ end
16
+
13
17
  # @return [String] "html.twig"
14
18
  def extension
15
19
  'html.twig'
@@ -12,13 +12,13 @@
12
12
  # Generator for a view that extends a layout
13
13
  class Ptero::Generator::ViewGenerator < Ptero::Generator::TwigGenerator
14
14
 
15
- # @param name [String] the name of the view
16
- # @param parent [String] the name of the layout to extend
15
+ # @param name [String] the name of the view
16
+ # @param parent [String] the name of the layout to extend
17
17
  def initialize(name,parent='application')
18
18
  super(name)
19
19
  @parent = parent
20
20
  end
21
21
 
22
- attr_reader :parent
22
+ attr_reader :parent
23
23
 
24
24
  end
@@ -8,7 +8,7 @@
8
8
  *
9
9
  */
10
10
 
11
- namespace <%= app.name.capitalize %>\Controllers;
11
+ namespace <%= app.name %>\Controllers;
12
12
 
13
13
 
14
14
  class <%= name %> extends <%= parent %> {
@@ -1,3 +1,3 @@
1
1
  <?php
2
- require_once __DIR__ . '/../php/<%= app.name %>.php';
2
+ require_once __DIR__ . '/../php/<%= app.name.downcase %>.php';
3
3
  ?>
@@ -12,7 +12,7 @@
12
12
  */
13
13
 
14
14
 
15
- namespace <%= app.name.capitalize %>\Models;
15
+ namespace <%= app.name %>\Models;
16
16
 
17
17
  class <%= name %> extends \ActiveRecord\Model {
18
18
 
@@ -11,10 +11,10 @@
11
11
 
12
12
 
13
13
 
14
- namespace <%= app.name.capitalize %>;
14
+ namespace <%= app.name %>;
15
15
 
16
16
 
17
- class <%= name %> <%= !parent.nil? && "extends #{parent}" %> {
17
+ class <%= name %> <%= parent.nil? ? '' : "extends #{parent} " %>{
18
18
 
19
19
 
20
20
 
@@ -4,7 +4,7 @@
4
4
  $application->route(array(
5
5
 
6
6
  <% routes.each_pair do |key,value| %>
7
- '<%= key %>' => '<%= app.name.capitalize %>\Controllers\<%= value %>Controller',
7
+ '<%= key %>' => '<%= app.name %>\Controllers\<%= value %>Controller',
8
8
  <% end %>
9
9
  ));
10
10
 
@@ -1,4 +1,4 @@
1
1
  module Ptero
2
2
  # Do you I need to explain this?
3
- VERSION = "1.0.4"
3
+ VERSION = "1.0.5"
4
4
  end
@@ -65,10 +65,9 @@ generators:
65
65
  - global_template
66
66
  phpinfogenerator:
67
67
  params:
68
+ setupgenerator:
69
+ params:
68
70
  routesgenerator:
69
71
  params:
70
72
  - routes:
71
- asdf: Asdf
72
- setupgenerator:
73
- params:
74
- - nm
73
+ asdf: Asdf
@@ -71,14 +71,24 @@ class TestApplication < MiniTest::Test
71
71
 
72
72
  def test_verify_application
73
73
  assert @app.verify
74
- a = Ptero::Application.new(__dir__)
75
- refute a.verify
74
+ Mute::IO.capture_stdout do
75
+ a = Ptero::Application.create('throwaway')
76
+ assert a.verify
77
+ a.destroy
78
+ refute a.verify
79
+ end
80
+
81
+ Mute::IO.capture_stdout do
82
+ assert_raises Ptero::Exception::ApplicationException do
83
+ app = Ptero::Application.app_for('throwaway')
84
+ end
85
+ end
76
86
  end
77
87
 
78
88
  def test_application_generate
79
89
  Mute::IO.capture_stdout do
80
- ['controller','setup','javascript'].each do |str|
81
- g = Ptero::Generator.const_get("#{str.capitalize}Generator".intern).new('review')
90
+ ['controller','model','javascript'].each do |str|
91
+ g = Ptero::Generator.const_get("#{str[0].upcase}#{str[1,str.length-1]}Generator".intern).new('review')
82
92
  @app.generate(str,'review')
83
93
  assert g.generated?
84
94
 
@@ -92,9 +102,9 @@ class TestApplication < MiniTest::Test
92
102
  end
93
103
 
94
104
  def test_generated
95
- ['controller','setup','javascript'].each do |str|
105
+ ['controller','model','javascript'].each do |str|
96
106
  name = 'exams'
97
- gen = Ptero::Generator.const_get("#{str.capitalize}Generator".intern).new(name)
107
+ gen = Ptero::Generator.const_get("#{str[0].upcase}#{str[1,str.length-1]}Generator".intern).new(name)
98
108
  Mute::IO.capture_stdout do
99
109
  refute gen.generated?
100
110
  refute @app.generated? gen.class, name
@@ -8,7 +8,7 @@ require 'ptero'
8
8
 
9
9
  class TestExceptions < MiniTest::Test
10
10
 
11
- def exceptions_should_be_exceptions
11
+ def test_exceptions_should_be_exceptions
12
12
  @exceptions.each do |klass|
13
13
  exception = klass.new('Something bad happened!')
14
14
 
@@ -20,7 +20,7 @@ class TestExceptions < MiniTest::Test
20
20
  end
21
21
  end
22
22
 
23
- def exceptions_should_raise
23
+ def test_exceptions_should_raise
24
24
  @exceptions.each do |klass|
25
25
  exception = klass.new('Something bad happened!')
26
26
 
@@ -39,7 +39,7 @@ class TestExceptions < MiniTest::Test
39
39
  require location
40
40
  end
41
41
 
42
- @exceptions = Ptero::Exception.constants.map { |sym| Ptero::Generator.const_get(sym) }
42
+ @exceptions = Ptero::Exception.constants.map { |sym| Ptero::Exception.const_get(sym) }
43
43
  end
44
44
 
45
45
 
@@ -59,8 +59,10 @@ class TestGenerators < MiniTest::Test
59
59
  def test_generators_should_complain
60
60
  @generators.each do |gen|
61
61
  type = gen.to_s.split('::').last.downcase
62
+
62
63
  params = @fixture['generators'][type]['params']
63
64
  g = gen.new(*params)
65
+
64
66
  assert_raises(Ptero::Exception::GeneratorException) do
65
67
  g.remove
66
68
  end
@@ -80,7 +82,7 @@ class TestGenerators < MiniTest::Test
80
82
  app
81
83
  generators
82
84
  fixture
83
- end
85
+ end
84
86
 
85
87
  def app
86
88
  Dir.chdir __dir__
@@ -95,7 +97,7 @@ class TestGenerators < MiniTest::Test
95
97
  require location
96
98
  end
97
99
 
98
- @generators = Ptero::Generator.constants.map { |sym| Ptero::Generator.const_get(sym) }
100
+ @generators = Ptero::Generator.constants.select { |sym| sym.match /(\w+)Generator/ }.map { |sym| Ptero::Generator.const_get(sym) }
99
101
  end
100
102
 
101
103
  def fixture
@@ -15,12 +15,8 @@ class TestRoot < MiniTest::Test
15
15
  def setup
16
16
  @klass = Ptero::CLI::Root
17
17
  Dir.chdir __dir__
18
- if FileTest.directory? 'root'
19
- @app = Ptero::Application.new('root')
20
- else
21
- Mute::IO.capture_stdout do
22
- @app = Ptero::Application.create('root')
23
- end
18
+ Mute::IO.capture_stdout do
19
+ @app = Ptero::Application.create('example')
24
20
  end
25
21
  Dir.chdir @app.dir
26
22
  end
@@ -51,7 +47,7 @@ class TestRoot < MiniTest::Test
51
47
  end
52
48
 
53
49
 
54
- Mute::IO.capture_stdout do
50
+ Mute::IO.capture_stdout do
55
51
  @app.generate('routes')
56
52
  @klass.start(['route', '/app/path/:number.jpg', 'Photo'])
57
53
  end
@@ -69,9 +65,7 @@ class TestRoot < MiniTest::Test
69
65
  def test_verify
70
66
  Mute::IO.capture_stdout do
71
67
  Dir.mkdir('notapp')
72
- notapp = Ptero::Application.new('notapp')
73
68
  refute @klass.start(['verify','notapp'])
74
- refute notapp.verify
75
69
  Dir.chdir 'notapp' do
76
70
  refute @klass.start(['verify'])
77
71
  end
@@ -127,7 +121,7 @@ class TestRoot < MiniTest::Test
127
121
  end
128
122
  assert @app.has_composer?
129
123
  end
130
-
124
+
131
125
  def test_install
132
126
  Mute::IO.capture_stdout do
133
127
  @app.get_composer
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ptero
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - LuminousRubyist