rmvc 1.0.0 → 2.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rmvc.rb +98 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d34e514f34ac5e720c39efdfce7f0dda351dcdba
4
- data.tar.gz: 6ddb59eff0fec7bdbc6359d589ad7e8ca851221c
3
+ metadata.gz: ff6b9d591547b9836f3826d80206c24997082aee
4
+ data.tar.gz: 153ea70524ee43fad17368dbdf5be1e2ae379068
5
5
  SHA512:
6
- metadata.gz: a10eaed7d6731a064115508138b79545f5567e431ce08b024905987764014ef02b875c2b5d6d7ef39a8955fbad529326ceb6eb34c785e787596858f84067288a
7
- data.tar.gz: 191e961c922a6e121bcd42facb81ffb5930fc7b31b2e388f655f32ddcbcc1617f509a550a83f5bd549eb349cf0c08c4610c1e4f309173e3ef1da11890d6b5fee
6
+ metadata.gz: 9c0b06f833c8bc2b0c44e71f13a98af85a4d2dff069c3660e7d8f380661df5e838a8d219e2cdc5a031e0346174a236302ee6caea6e2c13f0c3a100e48d7f7585
7
+ data.tar.gz: 7319566d1bdc3efc52be2c2341ca7153abdd598652d3cf1151e05b53011a999212d65ceec2b44fcb0761fe3808fcb49da9ef494eeaa5c43f56d2a8ca20463684
data/lib/rmvc.rb CHANGED
@@ -27,7 +27,15 @@ module RMVC
27
27
  end
28
28
  elsif args[0] == "generate"
29
29
  # Generate code
30
- RMVC::Core.generate(args)
30
+ if (args.length < 3) then
31
+ puts "Wrong syntax for 'generate'!"
32
+ RMVC::Interface.showHelp
33
+ elsif (args[1] == "view" && args.length < 4)
34
+ puts "Wrong syntax for 'generate view'!"
35
+ RMVC::Interface.showHelp
36
+ else
37
+ RMVC::Core.generate(args)
38
+ end
31
39
  else
32
40
  # Unknown command
33
41
  RMVC::Interface.showHelp
@@ -44,17 +52,63 @@ module RMVC
44
52
  puts " where [ProjectName] is the name of your new project"
45
53
  puts " Creates a new project using the RMVC architecture."
46
54
  puts ""
47
- puts " generate [model|controller|view] [name]"
55
+ puts " generate [model|controller|view] [name] [controllerName]"
48
56
  puts " where [name] is the name of the model/controller/view"
49
57
  puts " Creates a new model/controller/view with the desired name."
58
+ puts " If a controller is created, it will automatically be linked (through require) to a model "
59
+ puts " and a view of the same name than the controller."
60
+ puts " If a model is created, it will be linked (through require) to a controller of the same name."
61
+ puts " If a view is created, you must specify [controllerName]. It will be linked (through require) to it."
50
62
  puts ""
51
63
  end
52
64
  end
53
65
 
54
66
  # Core (commands)
55
67
  class Core
56
- def self.generate(whatever)
57
- puts "Placeholder"
68
+ def self.generate(args)
69
+ # Check if we're in a RMVC project
70
+ if (!File.directory? ".rmvc") then
71
+ puts "error".red + " Not a RMVC project! (missing directory .rmvc)"
72
+ exit
73
+ end
74
+ if (args[1] == "model") then
75
+ puts "Generating model #{args[2]}..."
76
+ # Create file /app/models/args[2].rb
77
+ if (File.exists? "app/models/#{args[2]}.rb") then
78
+ puts "error".red + " File /app/models/#{args[2]}.rb already exists."
79
+ exit
80
+ end
81
+ File.open("app/models/#{args[2]}.rb", "w") do |f|
82
+ f.write(RMVC::Helpers.createModel(args[2]))
83
+ end
84
+ puts "create".green + " File /app/models/#{args[2]}.rb"
85
+ elsif (args[1] == "controller")
86
+ puts "Generating controller #{args[2]}..."
87
+ # Create file /app/controllers/args[2]_controller.rb
88
+ if (File.exists? "app/controllers/#{args[2]}_controller.rb") then
89
+ puts "error".red + " File /app/controller/#{args[2]}_controller.rb already exists."
90
+ exit
91
+ end
92
+ File.open("app/controllers/#{args[2]}_controller.rb", "w") do |f|
93
+ f.write(RMVC::Helpers.createController(args[2]))
94
+ end
95
+ puts "create".green + " File /app/controllers/#{args[2]}_controller.rb"
96
+ puts "notice".yellow + " Remember to add a require statement to the main file of the project, to include app/controllers/#{args[2]}_controller."
97
+ elsif (args[1] == "view")
98
+ puts "Generating view #{args[2]}..."
99
+ # Create file /app/controllers/args[2]_controller.rb
100
+ if (File.exists? "app/views/#{args[2]}.rb") then
101
+ puts "error".red + " File /app/views/#{args[2]}.rb already exists."
102
+ exit
103
+ end
104
+ File.open("app/views/#{args[2]}.rb", "w") do |f|
105
+ f.write(RMVC::Helpers.createView(args[2], args[3]))
106
+ end
107
+ puts "create".green + " File /app/views/#{args[2]}.rb"
108
+ else
109
+ puts "Wrong argument for generate: #{args[1]}"
110
+ RMVC::Interface.showHelp
111
+ end
58
112
  end
59
113
  # CMD: new [ProjectName]
60
114
  def self.create(projectname)
@@ -72,6 +126,9 @@ module RMVC
72
126
  else
73
127
  puts "create".green + " Directory #{projectname}"
74
128
  end
129
+ # Create directory .rmvc
130
+ Dir.mkdir(projectname + "/.rmvc")
131
+ puts "create".green + " Directory #{projectname}/.rmvc"
75
132
  # Create file projectname.rb
76
133
  File.open(projectname + "/" + projectname + ".rb", "w") do |f|
77
134
  f.write("require './app/controllers/default_controller'\n")
@@ -127,4 +184,41 @@ module RMVC
127
184
  puts "create".green + " File /app/models/default.rb"
128
185
  end
129
186
  end
187
+
188
+ # Helpers
189
+ class Helpers
190
+ # Helper for creating a controller
191
+ def self.createController(controllerName)
192
+ controllerCap = controllerName.capitalize
193
+ "require './app/models/#{controllerName}'\n
194
+ require './app/views/#{controllerName}'\n
195
+ class #{controllerCap}Controller\n
196
+ class << self
197
+ #Add your variables here!\n
198
+ attr_accessor :name\n
199
+ end\n
200
+ @name = \"James!\"\n
201
+ def self.main\n
202
+ #{controllerCap}View.load\n
203
+ end\n
204
+ end\n"
205
+ end
206
+ # Helper for creating a view
207
+ def self.createView(viewName, controllerName)
208
+ viewCap = viewName.capitalize
209
+ "require './app/controllers/#{controllerName}_controller'\n
210
+ class #{viewCap}View\n
211
+ def self.load\n
212
+ puts \"Hello, hello!\"\n
213
+ end\n
214
+ end\n"
215
+ end
216
+
217
+ # Helper for creating a model
218
+ def self.createModel(modelName)
219
+ "require './app/controllers/#{modelName}_controller'\n
220
+ class #{modelName.capitalize}Model\n
221
+ end\n"
222
+ end
223
+ end
130
224
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmvc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Catbuntu