markbates / mack-more

All the extra stuff you could want for the Mack Framework.

This URL has Read+Write access

mack-more / mack-orm / lib / mack-orm / model_column.rb
bc0e4be5 » markbates 2008-06-18 Working on getting mack-dat... 1 module Mack
5f4a5d32 » markbates 2008-07-30 Added README for mack-data_... 2 module Genosaurus # :nodoc:
ed02d231 » markbates 2008-08-12 more refactoring of the orm... 3 module Orm # :nodoc:
2d01c354 » markbates 2008-07-15 More RDoc work prepping for... 4 # Used to represent a 'column' from the param cols or columns for generators.
5f4a5d32 » markbates 2008-07-30 Added README for mack-data_... 5 class ModelColumn # :nodoc:
bc0e4be5 » markbates 2008-06-18 Working on getting mack-dat... 6
2d01c354 » markbates 2008-07-15 More RDoc work prepping for... 7 # The name of the column.
8 attr_accessor :column_name
9 # The type of the column. Ie. string, integer, datetime, etc...
10 attr_accessor :column_type
11 # The name of the model associated with the column. Ie. user, post, etc...
12 attr_accessor :model_name
bc0e4be5 » markbates 2008-06-18 Working on getting mack-dat... 13
2d01c354 » markbates 2008-07-15 More RDoc work prepping for... 14 # Takes in the model_name (user, post, etc...) and the column (username:string, body:text, etc...)
15 def initialize(model_name, column_unsplit)
16 self.model_name = model_name.singular.underscore
17 cols = column_unsplit.split(":")
18 self.column_name = cols.first#.underscore
19 self.column_type = cols.last#.underscore
20 end
bc0e4be5 » markbates 2008-06-18 Working on getting mack-dat... 21
2d01c354 » markbates 2008-07-15 More RDoc work prepping for... 22 # Generates the appropriate HTML form field for the type of column represented.
23 #
24 # Examples:
25 # Mack::Generator::ColumnObject.new("user", "username:string").form_field
27c345da » markbates 2008-08-15 Deprecated the model_text_f... 26 # => "<%= :user.text_field :username %>"
2d01c354 » markbates 2008-07-15 More RDoc work prepping for... 27 # Mack::Generator::ColumnObject.new("Post", "body:text").form_field
27c345da » markbates 2008-08-15 Deprecated the model_text_f... 28 # => "<%= :post.text_area :body %>"
2d01c354 » markbates 2008-07-15 More RDoc work prepping for... 29 def form_field
30 case self.column_type
31 when "text"
27c345da » markbates 2008-08-15 Deprecated the model_text_f... 32 %{<%= :#{self.model_name}.text_area :#{self.column_name} %>}
2d01c354 » markbates 2008-07-15 More RDoc work prepping for... 33 else
27c345da » markbates 2008-08-15 Deprecated the model_text_f... 34 %{<%= :#{self.model_name}.text_field :#{self.column_name} %>}
2d01c354 » markbates 2008-07-15 More RDoc work prepping for... 35 end
bc0e4be5 » markbates 2008-06-18 Working on getting mack-dat... 36 end
37
2d01c354 » markbates 2008-07-15 More RDoc work prepping for... 38 end # ModelColumn
ed02d231 » markbates 2008-08-12 more refactoring of the orm... 39 end # Orm
bc0e4be5 » markbates 2008-06-18 Working on getting mack-dat... 40 end # Generator
41 end # Mack