saruman 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -45,7 +45,7 @@ NOTE: I couldn't remember whether Magento even allows anything but 0.0.1 (3 digi
45
45
 
46
46
  ### saruman observer
47
47
 
48
- saruman observer
48
+ saruman observer
49
49
 
50
50
  Will create a new observer file with an unlimited amount of events you wish to observe. I also parsed a document containing most of the observer events in magento version 1.5ish I believe, so there are about 300 events to choose from, no guarantees that they all work or are up to date. Just type the number of the observer event youd like to observer, rinse and repeat until you are finished (note that it will create all the observer events into one observer.php file so it will overwrite if you have an observer already.)
51
51
 
@@ -1,9 +1,11 @@
1
1
  require "saruman/version"
2
2
  require "highline"
3
3
  require "virtus"
4
+ require "saruman/virtus/attributes"
4
5
  require "saruman"
5
6
  require "nokogiri"
6
7
  require 'active_support'
8
+
7
9
  module Saruman
8
10
 
9
11
  module Base
@@ -28,7 +30,6 @@ module Saruman
28
30
  name.downcase
29
31
  end
30
32
 
31
- #alias for name
32
33
  def extension_name_lower
33
34
  name.downcase
34
35
  end
@@ -53,6 +54,10 @@ module Saruman
53
54
  "#{extension_base_path}Model/"
54
55
  end
55
56
 
57
+ def controller_path
58
+ "#{extension_base_path}controllers/"
59
+ end
60
+
56
61
  def helper_path
57
62
  "#{extension_base_path}Helper/"
58
63
  end
@@ -65,6 +70,10 @@ module Saruman
65
70
  "#{extension_base_path}sql/#{name_lower}_setup/"
66
71
  end
67
72
 
73
+ def block_klass_name
74
+ "#{combined_namespace}_Block"
75
+ end
76
+
68
77
  def model_klass_name
69
78
  "#{combined_namespace}_Model"
70
79
  end
@@ -81,6 +90,40 @@ module Saruman
81
90
  "#{global_config_basepath}#{combined_namespace}.xml"
82
91
  end
83
92
 
93
+ def controller_block_path
94
+ "#{extension_base_path}Block/"
95
+ end
96
+
97
+ def controller_block_file_path(controller_name)
98
+ "#{controller_block_path}#{controller_name.capitalize}.php"
99
+ end
100
+
101
+ def app_design_frontend_base_path
102
+ newer_magento_base_path = "#{Dir.pwd}/app/design/frontend/base/default/"
103
+ older_magento_base_path = "#{Dir.pwd}/app/design/frontend/default/default/"
104
+ if File.directory?(newer_magento_base_path)
105
+ return newer_magento_base_path
106
+ else
107
+ return older_magento_base_path
108
+ end
109
+ end
110
+
111
+ def app_design_frontend_base_layout_path
112
+ "#{app_design_frontend_base_path}layout/"
113
+ end
114
+
115
+ def app_design_frontend_base_layout_local_xml_path
116
+ "#{app_design_frontend_base_path}layout/#{name_lower}.xml"
117
+ end
118
+
119
+ def app_design_frontend_base_template_path
120
+ "#{app_design_frontend_base_path}template/"
121
+ end
122
+
123
+ def app_design_frontend_base_template_namespace_path
124
+ "#{app_design_frontend_base_template_path}#{name_lower}/"
125
+ end
126
+
84
127
  def model?
85
128
  if arguments[:model] == true
86
129
  return true
@@ -117,6 +160,22 @@ module Saruman
117
160
  arguments[:observer_events]
118
161
  end
119
162
 
163
+ def controller?
164
+ if arguments[:controller] == true
165
+ return true
166
+ else
167
+ return false
168
+ end
169
+ end
170
+
171
+ def controllers
172
+ arguments[:controllers]
173
+ end
174
+
175
+ def controller_front_name
176
+ arguments[:controller_front_name]
177
+ end
178
+
120
179
  def helper?
121
180
  if arguments[:helper] == true
122
181
  return true
@@ -140,7 +199,7 @@ module Saruman
140
199
  file = File.open(extension_config_file_path,'w')
141
200
  file.puts @config.to_xml
142
201
  file.close
143
- end
202
+ end
144
203
 
145
204
  def extension_current_version
146
205
  @extension_current_version = @config.css("version").first.content
@@ -163,7 +222,6 @@ module Saruman
163
222
 
164
223
  def insert_tag_at_node(tag, tag_lookup)
165
224
  target_tag = @config.css(tag_lookup).first
166
- puts "inserting #{tag} from looku #{tag_lookup}"
167
225
  unless target_tag.nil?
168
226
  new_tag = "<#{tag}></#{tag}>"
169
227
  target_tag.add_child(new_tag)
@@ -177,26 +235,30 @@ module Saruman
177
235
  end
178
236
  end
179
237
 
180
- end
181
-
238
+ end
182
239
 
183
- module MenuBuilder
184
- include Virtus
185
- attribute :decisions, Array, :default => []
186
-
187
- # def decisions
188
- # return decisions_made
189
- # end
240
+ module BuilderInstanceBase
190
241
 
191
- end
242
+ def initialize(options)
243
+ @options = options
244
+ end
245
+
246
+ def method_missing(meth, *args, &block)
247
+ if(@options.has_key?(meth.to_sym))
248
+ @options[meth.to_sym]
249
+ else
250
+ super
251
+ end
252
+ end
253
+ end
192
254
 
193
255
  class ObserverMenuBuilder
194
256
 
195
- # include Virtus
196
- include MenuBuilder
197
- # attribute :chosen_events, Array
257
+ include Virtus
258
+
198
259
  attribute :observer_events, Array, :default => []
199
- # attribute :decisions, Array, :default => []
260
+ attribute :decisions, Array, :default => []
261
+
200
262
  BASE_DIR = File.dirname(__FILE__)
201
263
  OBSERVER_EVENTS_FILE_PATH = BASE_DIR+"/saruman/generators/observer/observer_events.csv"
202
264
 
@@ -230,17 +292,27 @@ module Saruman
230
292
 
231
293
  end
232
294
 
233
- class ModelBuilder
234
- def initialize
295
+ class ControllerBuilder
296
+
297
+ def initialize(options)
298
+ @options = options
235
299
  ask_question
236
300
  end
237
301
 
238
302
  def ask_question
239
- model_name = ask("Enter Name of model") { |q| q.default = "Post" }
240
- model_table_name = ask("Enter Table Name of model") { |q| q.default = "blog_post" }
241
- model_fields_input = ask("Enter Model Fields") { |q| q.default = "title:string active:boolean blog_id:integer:index" }
242
- model_sql = parse_model_fields(model_fields_input, model_table_name)
243
- @question_answer = {:model_name => model_name, :model_name_lower => model_name.downcase, :model_table_name => model_table_name, :sql => model_sql}
303
+ controller = Saruman::Controller.new(@options)
304
+ controller.name = ask("Enter Controller Name (will match www.yourmagentoinstall.com/frontname/controllername)") { |q| q.default = "index" }
305
+ controller_actions_input = ask("Enter list of actions for this controller, I.E., index show add") { |q| q.default = "index show add"}
306
+ controller.actions = parse_controller_actions(controller_actions_input)
307
+
308
+ say("Would you like to create controller action views?")
309
+ choose do |menu|
310
+ menu.choice(:yes) { controller.create_views = true }
311
+ menu.choice(:no) { controller.create_views = false }
312
+ end
313
+
314
+ # @question_answer = {:controller_name => controller_name.capitalize, :controller_actions => controller_actions}
315
+ @question_answer = controller
244
316
  @question_answer
245
317
  end
246
318
 
@@ -248,6 +320,103 @@ module Saruman
248
320
  return @question_answer
249
321
  end
250
322
 
323
+ def parse_controller_actions(controller_actions_input)
324
+ actions = []
325
+ controller_actions_input.split(" ").each do |action|
326
+ actions << Saruman::ControllerBuilderAction.new(action)
327
+ end
328
+ actions
329
+ end
330
+
331
+ end
332
+
333
+ class Controller
334
+ include Virtus
335
+ include BuilderInstanceBase
336
+ attribute :actions, Array
337
+ attribute :name, Capitalize
338
+ attribute :create_views, Boolean
339
+ attribute :name_lower, String, :default => lambda { |model,attribute| model.name.downcase }
340
+
341
+ def klass_name
342
+ "#{combined_namespace}_#{name}Controller"
343
+ end
344
+
345
+ end
346
+
347
+
348
+ class ControllerBuilderAction
349
+ include Virtus
350
+
351
+ #designed for future stuff, mostly pointless/overkill for now
352
+
353
+ attribute :visibility, String
354
+ attribute :respond_to, String
355
+ attribute :name, Downcase
356
+ attribute :method_name, String
357
+ attribute :segs, Array
358
+
359
+ def initialize(action)
360
+ @segs = action.split(":")
361
+ case segs.length
362
+ when 1
363
+ @visibility = "public"
364
+ @respond_to = "html"
365
+ @name = segs.first
366
+ @method_name = "#{name}Action"
367
+ end
368
+ end
369
+
370
+ def layout_handle(extension_name, controller_name)
371
+ @extension_name = extension_name
372
+ @controller_name = controller_name
373
+ "#{@extension_name}_#{@controller_name}_#{name}"
374
+ end
375
+
376
+ def block_name
377
+ "#{@extension_name}#{@controller_name}#{name}"
378
+ end
379
+
380
+ def block_as
381
+ "#{@extension_name}#{@controller_name}#{name}"
382
+ end
383
+
384
+ def block_template
385
+ "#{@extension_name}/#{@controller_name}/#{name}.phtml"
386
+ end
387
+
388
+ end
389
+
390
+ class ModelBuilder
391
+
392
+ def initialize(options)
393
+ @options = options
394
+ ask_questions
395
+ end
396
+
397
+ def ask_questions
398
+ model = Saruman::Model.new(@options)
399
+
400
+ model.name = ask("Enter Name of model") { |q| q.default = "Post" }
401
+ model.table_name = ask("Enter Table Name of model") { |q| q.default = "blog_post" }
402
+ model_fields_input = ask("Enter Model Fields") { |q| q.default = "title:string active:boolean blog_id:integer:index" }
403
+
404
+ model.sql = parse_model_fields(model_fields_input, model.table_name)
405
+ # @question_answer = {:model_name => model_name, :model_name_lower => model_name.downcase, :model_table_name => model_table_name, :sql => model_sql}
406
+
407
+ say("Would you like to create a collection model?")
408
+ choose do |menu|
409
+ menu.choice(:yes) { model.collection = true }
410
+ menu.choice(:no) { model.collection = false }
411
+ end
412
+
413
+ @question_answer = model
414
+ end
415
+
416
+ def output
417
+ return @question_answer
418
+ end
419
+
251
420
  def parse_model_fields(model_fields, model_table_name)
252
421
  sql = ""
253
422
  index_sql = ""
@@ -263,6 +432,29 @@ module Saruman
263
432
 
264
433
  end
265
434
 
435
+ class Model
436
+ include Virtus
437
+ include BuilderInstanceBase
438
+ attribute :name, Capitalize
439
+ attribute :name_lower, String, :default => lambda { |model,attribute| model.name.downcase }
440
+ attribute :table_name, Downcase
441
+ attribute :sql, String
442
+ attribute :collection, Boolean
443
+
444
+ def klass_name
445
+ "#{combined_namespace}_Model_#{name}"
446
+ end
447
+
448
+ def resource_model_klass_name
449
+ "#{combined_namespace}_Model_Mysql4_#{name}"
450
+ end
451
+
452
+ def collection_model_klass_name
453
+ "#{combined_namespace}_Model_Mysql4_#{name}_Collection"
454
+ end
455
+
456
+ end
457
+
266
458
  class ModelBuilderField
267
459
 
268
460
  SQL_TYPE_MAPPINGS = {:string => "varchar(255)", :text => "text NOT NULL", :boolean => "tinyint(1) NOT NULL default 0", :date => "DATETIME default NULL", :int => "int(10)", :integer => "int(10)" }
@@ -305,8 +497,8 @@ module Saruman
305
497
  else
306
498
  super
307
499
  end
308
- end
309
- end
500
+ end
501
+ end
310
502
 
311
503
  class ModelXmlConfigBuilder
312
504
  include Virtus
@@ -329,7 +521,7 @@ module Saruman
329
521
  def set_config_models_resource_entities_xml
330
522
  xml = ""
331
523
  models.each do |model|
332
- xml << "<#{model[:model_name_lower]}><table>#{model[:model_table_name]}</table></#{model[:model_name_lower]}>\n"
524
+ xml << "<#{model.name_lower}><table>#{model.table_name}</table></#{model.name_lower}>\n"
333
525
  end
334
526
  return xml
335
527
  end
@@ -414,6 +606,61 @@ module Saruman
414
606
  return xml
415
607
  end
416
608
 
609
+ end
610
+
611
+ class ControllerXmlConfigBuilder
612
+ include Virtus
613
+ include XmlBuilderBase
614
+ attribute :controllers, Array
615
+ attribute :config_frontend_routers_name_xml, String
616
+ attribute :config_frontend_layout_xml, String
617
+ attribute :config_global_blocks_xml, String
618
+
619
+ def initialize(controllers, generator)
620
+ @controllers = controllers
621
+ @generator = generator
622
+ @config_frontend_routers_name_xml = set_config_frontend_routers_name_xml
623
+ @config_frontend_layout_xml = set_config_frontend_layout_xml
624
+ @config_global_blocks_xml = set_config_global_blocks_xml
625
+ end
626
+
627
+ def set_config_frontend_routers_name_xml
628
+ xml="
629
+ <#{name_lower}>
630
+ <use>standard</use>
631
+ <args>
632
+ <module>#{combined_namespace}</module>
633
+ <frontName>#{controller_front_name}</frontName>
634
+ </args>
635
+ </#{name_lower}>
636
+ "
637
+ return xml
638
+ end
639
+
640
+ def set_config_frontend_layout_xml
641
+ xml="
642
+ <layout>
643
+ <updates>
644
+ <#{name_lower}>
645
+ <file>#{name_lower}.xml</file>
646
+ </#{name_lower}>
647
+ </updates>
648
+ </layout>
649
+ "
650
+ return xml
651
+ end
652
+
653
+ def set_config_global_blocks_xml
654
+ xml="
655
+ <blocks>
656
+ <#{name_lower}>
657
+ <class>#{block_klass_name}</class>
658
+ </#{name_lower}>
659
+ </blocks>
660
+ "
661
+ return xml
662
+ end
663
+
417
664
  end
418
665
 
419
666
  end
@@ -13,8 +13,30 @@ module Saruman
13
13
  options[:name] = ask("Enter extension name:") { |q| q.default = "Wizard" }
14
14
  options[:author] = ask("Author of extension:") { |q| q.default = "Jason Ayre www.bravenewwebdesign.com" }
15
15
  options[:version] = ask("Version number (Format - 0.0.1):") { |q| q.default = "0.0.1" }
16
+ options[:combined_namespace] = "#{options[:namespace]}_#{options[:name]}"
17
+
18
+ say("Would you like to create a controller?")
19
+ choose do |menu|
20
+ menu.choice(:yes) { options[:controller] = true }
21
+ menu.choice(:no) { options[:controller] = false }
22
+ end
23
+
24
+ if(options[:controller])
25
+
26
+ options[:controller_front_name] = ask("Enter Front Name of controller (will match www.yourmagentoinstall.com/frontname)") { |q| q.default = "extension_name" }
27
+
28
+ if(options[:controllers]).nil?
29
+ options[:controllers] = Array.new
30
+ end
31
+
32
+ begin
33
+ question = Saruman::ControllerBuilder.new(options)
34
+ options[:controllers] << question.output
35
+ end while agree("Create another controller?")
36
+
37
+ end
16
38
 
17
- say("Would you like me to create an observer?")
39
+ say("Would you like to create an observer?")
18
40
  choose do |menu|
19
41
  menu.choice(:yes) { options[:observer] = true }
20
42
  menu.choice(:no) { options[:observer] = false }
@@ -42,7 +64,7 @@ module Saruman
42
64
 
43
65
  end
44
66
 
45
- say("Would you like me to create a model?")
67
+ say("Would you like to create a model?")
46
68
  choose do |menu|
47
69
  menu.choice(:yes) { options[:model] = true }
48
70
  menu.choice(:no) { options[:model] = false }
@@ -55,13 +77,13 @@ module Saruman
55
77
  end
56
78
 
57
79
  begin
58
- question = Saruman::ModelBuilder.new
80
+ question = Saruman::ModelBuilder.new(options)
59
81
  options[:models] << question.output
60
82
  end while agree("Create another model?")
61
83
 
62
84
  end
63
85
 
64
- say("Would you like me to create a helper?")
86
+ say("Would you like to create a helper?")
65
87
  choose do |menu|
66
88
  menu.choice(:yes) { options[:helper] = true }
67
89
  menu.choice(:no) { options[:helper] = false }
@@ -71,7 +93,11 @@ module Saruman
71
93
 
72
94
  if options[:model]
73
95
  Saruman::Generators::Model.start([options])
74
- end
96
+ end
97
+
98
+ if options[:controller]
99
+ Saruman::Generators::Controller.start([options])
100
+ end
75
101
 
76
102
  end
77
103
 
@@ -81,13 +107,13 @@ module Saruman
81
107
  options[:command] = __method__
82
108
  options[:namespace] = ask("Enter extension namespace:") { |q| q.default = "Saruman" }
83
109
  options[:name] = ask("Enter extension name:") { |q| q.default = "Wizard" }
84
-
110
+ options[:combined_namespace] = "#{options[:namespace]}_#{options[:name]}"
85
111
  if(options[:models]).nil?
86
112
  options[:models] = Array.new
87
113
  end
88
114
 
89
115
  begin
90
- question = Saruman::ModelBuilder.new
116
+ question = Saruman::ModelBuilder.new(options)
91
117
  options[:models] << question.output
92
118
  end while agree("Create another model?")
93
119
 
@@ -124,6 +150,29 @@ module Saruman
124
150
 
125
151
  end
126
152
 
153
+ desc "controller", "Creates a new magento controller"
154
+ def controller
155
+ options = Hash.new
156
+ options[:command] = __method__
157
+ options[:namespace] = ask("Enter extension namespace:") { |q| q.default = "Saruman" }
158
+ options[:name] = ask("Enter extension name:") { |q| q.default = "Wizard" }
159
+ options[:controller_front_name] = ask("Enter Front Name of controller (will match www.yourmagentoinstall.com/frontname)") { |q| q.default = "extension_name" }
160
+
161
+ options[:combined_namespace] = "#{options[:namespace]}_#{options[:name]}"
162
+
163
+ if(options[:controllers]).nil?
164
+ options[:controllers] = Array.new
165
+ end
166
+
167
+ begin
168
+ question = Saruman::ControllerBuilder.new(options)
169
+ options[:controllers] << question.output
170
+ end while agree("Create another Controller?")
171
+
172
+ Saruman::Generators::Controller.start([options])
173
+
174
+ end
175
+
127
176
  end
128
177
 
129
178
  end
@@ -0,0 +1,103 @@
1
+ require 'thor/group'
2
+ require 'nokogiri'
3
+ module Saruman
4
+ module Generators
5
+ class Controller < Thor::Group
6
+
7
+ include Thor::Actions
8
+ include Saruman::Base
9
+
10
+ argument :arguments, :type => :hash
11
+
12
+ def self.source_root
13
+ File.dirname(__FILE__) + "/controller/templates"
14
+ end
15
+
16
+ def validate_extension
17
+ unless File.directory?("#{extension_base_path}")
18
+ @error = "error"
19
+ end
20
+
21
+ unless File.exist?("#{extension_config_path}/config.xml")
22
+ @error = "error"
23
+ end
24
+ end
25
+
26
+ def load_builders
27
+ @controller_xml_config_builder = Saruman::ControllerXmlConfigBuilder.new(controllers, self)
28
+ end
29
+
30
+ def create_controller_directory
31
+ empty_directory(controller_path) unless File.directory?(controller_path)
32
+ end
33
+
34
+ def modify_config
35
+
36
+ @config = read_extension_config
37
+
38
+ unless config_has_tag?("config frontend")
39
+ insert_tag_at_node("frontend", "config")
40
+ end
41
+
42
+ unless config_has_tag?("config frontend routers")
43
+ insert_tag_at_node("routers", "config frontend")
44
+ end
45
+
46
+ unless config_has_tag?("config frontend routers #{name_lower}")
47
+ insert_xml_at_node(@controller_xml_config_builder.config_frontend_routers_name_xml, "config frontend routers")
48
+ end
49
+
50
+ @controllers_with_views = controllers.select { |controller| controller.create_views == true }
51
+
52
+ if @controllers_with_views.length > 0
53
+ unless config_has_tag?("config frontend layout")
54
+ insert_xml_at_node(@controller_xml_config_builder.config_frontend_layout_xml, "config frontend")
55
+ end
56
+
57
+ unless config_has_tag?("config global blocks")
58
+ insert_xml_at_node(@controller_xml_config_builder.config_global_blocks_xml, "config global")
59
+ end
60
+
61
+ template("local.xml", app_design_frontend_base_layout_local_xml_path)
62
+
63
+ end
64
+
65
+ end
66
+
67
+ def create_controllers
68
+ controllers.each do |controller|
69
+ @controller = controller
70
+ template("Controller.php", "#{controller_path}#{@controller.name}Controller.php")
71
+
72
+ if controller.create_views
73
+ empty_directory(controller_view_path(@controller.name_lower)) unless File.directory?(controller_view_path(@controller.name_lower))
74
+ empty_directory(controller_block_path) unless File.directory?(controller_block_path)
75
+ @controller_block_klass_name = "#{combined_namespace}_Block_#{@controller.name.capitalize}"
76
+ template("Block.php", controller_block_file_path(@controller.name))
77
+ controller.actions.each do |action|
78
+ @action = action
79
+ @kontroller_front_name = controller_front_name
80
+ template("view.phtml", controller_view_action_path(@controller.name_lower, @action.name))
81
+ end
82
+ app_design_frontend_base_template_namespace_path
83
+ end
84
+ end
85
+ end
86
+
87
+ def write_changes
88
+ write_extension_config
89
+ end
90
+
91
+ private
92
+
93
+ def controller_view_path(controller_name)
94
+ "#{app_design_frontend_base_template_namespace_path}#{controller_name}/"
95
+ end
96
+
97
+ def controller_view_action_path(controller_name, action_name)
98
+ "#{controller_view_path(controller_name)}#{action_name}.phtml"
99
+ end
100
+
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,8 @@
1
+ <?php
2
+ class <%= @controller_block_klass_name %> extends Mage_Core_Block_Template
3
+ {
4
+ public function __construct()
5
+ {
6
+ parent::__construct();
7
+ }
8
+ }
@@ -0,0 +1,21 @@
1
+ <?php
2
+
3
+ class <%= @controller.klass_name %> extends Mage_Core_Controller_Front_Action
4
+ {
5
+ <% @controller.actions.each do |action| %>
6
+ <%= action.visibility %> function <%= action.method_name %>()
7
+ {
8
+ <% if @controller.create_views %>
9
+
10
+ $params = $this->getRequest()->getParams();
11
+ $this->loadLayout();
12
+ $this->renderLayout();
13
+
14
+ <% else %>
15
+ echo "Hello world.";
16
+ print_r($params);
17
+ <% end %>
18
+ }
19
+ <% end %>
20
+
21
+ }
@@ -0,0 +1,11 @@
1
+ <layout version="0.1.0">
2
+ <% @controllers_with_views.each do |controller| %>
3
+ <% controller.actions.each do |action| %>
4
+ <<%= action.layout_handle(name_lower, controller.name_lower) %>>
5
+ <reference name="content">
6
+ <block type="<%= name_lower %>/<%= controller.name_lower %>" name="<%= action.block_name %>" as="<%= action.block_as %>" template="<%= action.block_template %>" />
7
+ </reference>
8
+ </<%= action.layout_handle(name_lower, controller.name_lower) %>>
9
+ <% end %>
10
+ <% end %>
11
+ </layout>
@@ -0,0 +1 @@
1
+ <h1><%= @kontroller_front_name.capitalize %> <%= @controller.name %> <%= @action.name %></h1>
@@ -36,113 +36,6 @@ module Saruman
36
36
  end
37
37
  end
38
38
 
39
- private
40
-
41
- # def namespace
42
- # arguments[:namespace]
43
- # end
44
- #
45
- # def name
46
- # arguments[:name]
47
- # end
48
- #
49
- # def combined_namespace
50
- # "#{arguments[:namespace]}_#{arguments[:name]}"
51
- # end
52
- #
53
- # def namespace_lower
54
- # namespace.downcase
55
- # end
56
- #
57
- # def name_lower
58
- # name.downcase
59
- # end
60
- #
61
- # #alias for name
62
- # def extension_name_lower
63
- # name.downcase
64
- # end
65
- #
66
- # def author
67
- # arguments[:author]
68
- # end
69
- #
70
- # def version
71
- # arguments[:version]
72
- # end
73
- #
74
- # def global_config_basepath
75
- # "app/etc/modules/"
76
- # end
77
- #
78
- # def extension_base_path
79
- # "app/code/local/#{namespace}/#{name}/"
80
- # end
81
- #
82
- # def extension_config_path
83
- # "#{extension_base_path}etc/"
84
- # end
85
- #
86
- # def model_path
87
- # "#{extension_base_path}Model/"
88
- # end
89
- #
90
- # def resource_model_path
91
- # "#{model_path}Mysql4/"
92
- # end
93
- #
94
- # def helper_path
95
- # "#{extension_base_path}Helper/"
96
- # end
97
- #
98
- # def setup_base_path
99
- # "#{extension_base_path}/sql/"
100
- # end
101
- #
102
- # def model_klass_name
103
- # "#{combined_namespace}_Model"
104
- # end
105
- #
106
- # def resource_model_name_lower
107
- # "#{name_lower}_mysql4"
108
- # end
109
- #
110
- # def resource_model_klass_name
111
- # "#{combined_namespace}_Model_Mysql4"
112
- # end
113
- #
114
- # def observer?
115
- # if arguments[:observer] == true
116
- # return true
117
- # else
118
- # return false
119
- # end
120
- # end
121
- #
122
- # def observers
123
- # arguments[:observer_events]
124
- # end
125
- #
126
- # def helper?
127
- # if arguments[:helper] == true
128
- # return true
129
- # else
130
- # return false
131
- # end
132
- # end
133
- #
134
- # def model?
135
- # if arguments[:model] == true
136
- # return true
137
- # else
138
- # return false
139
- # end
140
- # end
141
- #
142
- # def models
143
- # arguments[:models]
144
- # end
145
-
146
39
  end
147
40
  end
148
41
  end
@@ -60,14 +60,13 @@ module Saruman
60
60
 
61
61
  def create_models
62
62
  models.each do |model|
63
- @model_name = model[:model_name]
64
- @model_klass_name = "#{namespace}_#{name}_Model_#{@model_name}"
65
- @model_name_lower = model[:model_name_lower]
66
-
67
- @resource_model_klass_name = "#{namespace}_#{name}_Model_Mysql4_#{@model_name}"
68
- @table_name = model[:model_table_name]
69
- template("Model.php", "#{model_path}#{@model_name}.php")
70
- template("Resource_Model.php", "#{resource_model_path}#{@model_name}.php")
63
+ @model = model
64
+ template("Model.php", "#{model_path}#{@model.name}.php")
65
+ template("Resource_Model.php", "#{resource_model_path}#{@model.name}.php")
66
+ if model.collection?
67
+ empty_directory("#{resource_model_path}#{@model.name}/")
68
+ template("Collection.php", "#{resource_model_path}#{@model.name}/Collection.php")
69
+ end
71
70
  end
72
71
  end
73
72
 
@@ -0,0 +1,10 @@
1
+ <?php
2
+
3
+ class <%= @model.collection_model_klass_name %> extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('<%= name_lower %>/<%= @model.name_lower %>');
9
+ }
10
+ }
@@ -1,10 +1,10 @@
1
1
  <?php
2
2
 
3
- class <%= @model_klass_name %> extends Mage_Core_Model_Abstract
3
+ class <%= @model.klass_name %> extends Mage_Core_Model_Abstract
4
4
  {
5
5
  public function _construct()
6
6
  {
7
7
  parent::_construct();
8
- $this->_init('<%= name_lower %>/<%= @model_name_lower %>');
8
+ $this->_init('<%= name_lower %>/<%= @model.name_lower %>');
9
9
  }
10
10
  }
@@ -1,10 +1,10 @@
1
1
  <?php
2
2
 
3
- class <%= @resource_model_klass_name %> extends Mage_Core_Model_Mysql4_Abstract
3
+ class <%= @model.resource_model_klass_name %> extends Mage_Core_Model_Mysql4_Abstract
4
4
  {
5
5
  public function _construct()
6
6
  {
7
- $this->_init('<%= name.downcase %>/<%= @model_name.downcase %>', 'id');
7
+ $this->_init('<%= name.downcase %>/<%= @model.name_lower %>', 'id');
8
8
  }
9
9
 
10
10
  }
@@ -6,10 +6,10 @@ $installer->startSetup();
6
6
 
7
7
  $installer->run("
8
8
  <% models.each do |model| %>
9
- DROP TABLE IF EXISTS {$this->getTable('<%= model[:model_table_name] %>')};
10
- CREATE TABLE {$this->getTable('<%= model[:model_table_name] %>')} (
9
+ DROP TABLE IF EXISTS {$this->getTable('<%= model.table_name %>')};
10
+ CREATE TABLE {$this->getTable('<%= model.table_name %>')} (
11
11
  `id` int(11) unsigned NOT NULL auto_increment,
12
- <%= model[:sql] %>
12
+ <%= model.sql %>
13
13
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
14
14
  <% end %>
15
15
  ");
@@ -2,7 +2,7 @@
2
2
  <class><%= resource_model_klass_name %></class>
3
3
  <entities>
4
4
  <% models.each do |model| %>
5
- <<%= model[:model_name_lower] %>><table><%= model[:model_table_name] %></table></<%= model[:model_name_lower] %>>
5
+ <<%= model.name_lower %>><table><%= model.table_name %></table></<%= model.name_lower %>>
6
6
  <% end %>
7
7
 
8
8
  </entities>
@@ -1,5 +1,5 @@
1
1
  <% models.each do |model| %>
2
- <<%= model[:model_name_lower] %>><table><%= model[:model_table_name] %></table></<%= model[:model_name_lower] %>>
2
+ <<%= model.name_lower %>><table><%= model.table_name %></table></<%= model.name_lower %>>
3
3
 
4
4
  <% end %>
5
5
 
@@ -3,4 +3,5 @@ require 'thor/group'
3
3
  require "saruman/generators/extension"
4
4
  require "saruman/generators/model"
5
5
  require "saruman/generators/observer"
6
+ require "saruman/generators/controller"
6
7
  require "saruman"
@@ -1,3 +1,3 @@
1
1
  module Saruman
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,25 @@
1
+ class Capitalize < Virtus::Attribute::Object
2
+ primitive String
3
+ coercion_method :capitalize
4
+ end
5
+
6
+ class Downcase < Virtus::Attribute::Object
7
+ primitive String
8
+ coercion_method :downcase
9
+ end
10
+
11
+ module Virtus
12
+ class Coercion
13
+ class String < Virtus::Coercion::Object
14
+
15
+ def self.capitalize(value)
16
+ value.capitalize
17
+ end
18
+
19
+ def self.downcase(value)
20
+ value.downcase
21
+ end
22
+
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saruman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-17 00:00:00.000000000 Z
12
+ date: 2012-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -156,12 +156,18 @@ files:
156
156
  - doc_assets/saruman_extension_example.jpg
157
157
  - lib/saruman.rb
158
158
  - lib/saruman/cli.rb
159
+ - lib/saruman/generators/controller.rb
160
+ - lib/saruman/generators/controller/templates/Block.php
161
+ - lib/saruman/generators/controller/templates/Controller.php
162
+ - lib/saruman/generators/controller/templates/local.xml
163
+ - lib/saruman/generators/controller/templates/view.phtml
159
164
  - lib/saruman/generators/extension.rb
160
165
  - lib/saruman/generators/extension/templates/Helper.php
161
166
  - lib/saruman/generators/extension/templates/Observer.php
162
167
  - lib/saruman/generators/extension/templates/extension_config.xml
163
168
  - lib/saruman/generators/extension/templates/module.xml
164
169
  - lib/saruman/generators/model.rb
170
+ - lib/saruman/generators/model/templates/Collection.php
165
171
  - lib/saruman/generators/model/templates/Model.php
166
172
  - lib/saruman/generators/model/templates/Resource_Model.php
167
173
  - lib/saruman/generators/model/templates/model_config_block.xml
@@ -173,6 +179,7 @@ files:
173
179
  - lib/saruman/generators/observer/templates/Observer.php
174
180
  - lib/saruman/generators/saruman.rb
175
181
  - lib/saruman/version.rb
182
+ - lib/saruman/virtus/attributes.rb
176
183
  - saruman.gemspec
177
184
  - spec/saruman_spec.rb
178
185
  homepage: https://github.com/jasonayre/saruman.git