markbates / mack-more
- Source
- Commits
- Network (2)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
27c345d
commit 27c345da851775cf2443b5813890c4ae0bf64809
tree 287b5127c560fbdb91bd13e4a0f15641af149faa
parent b4a3fe55fa83a1c70c93e591063fe9569b4e48b7
tree 287b5127c560fbdb91bd13e4a0f15641af149faa
parent b4a3fe55fa83a1c70c93e591063fe9569b4e48b7
| bc0e4be5 » | markbates | 2008-06-18 | 1 | module Mack | |
| 5f4a5d32 » | markbates | 2008-07-30 | 2 | module Genosaurus # :nodoc: | |
| ed02d231 » | markbates | 2008-08-12 | 3 | module Orm # :nodoc: | |
| 2d01c354 » | markbates | 2008-07-15 | 4 | # Used to represent a 'column' from the param cols or columns for generators. | |
| 5f4a5d32 » | markbates | 2008-07-30 | 5 | class ModelColumn # :nodoc: | |
| bc0e4be5 » | markbates | 2008-06-18 | 6 | ||
| 2d01c354 » | markbates | 2008-07-15 | 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 | 13 | ||
| 2d01c354 » | markbates | 2008-07-15 | 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 | 21 | ||
| 2d01c354 » | markbates | 2008-07-15 | 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 | 26 | # => "<%= :user.text_field :username %>" | |
| 2d01c354 » | markbates | 2008-07-15 | 27 | # Mack::Generator::ColumnObject.new("Post", "body:text").form_field | |
| 27c345da » | markbates | 2008-08-15 | 28 | # => "<%= :post.text_area :body %>" | |
| 2d01c354 » | markbates | 2008-07-15 | 29 | def form_field | |
| 30 | case self.column_type | ||||
| 31 | when "text" | ||||
| 27c345da » | markbates | 2008-08-15 | 32 | %{<%= :#{self.model_name}.text_area :#{self.column_name} %>} | |
| 2d01c354 » | markbates | 2008-07-15 | 33 | else | |
| 27c345da » | markbates | 2008-08-15 | 34 | %{<%= :#{self.model_name}.text_field :#{self.column_name} %>} | |
| 2d01c354 » | markbates | 2008-07-15 | 35 | end | |
| bc0e4be5 » | markbates | 2008-06-18 | 36 | end | |
| 37 | |||||
| 2d01c354 » | markbates | 2008-07-15 | 38 | end # ModelColumn | |
| ed02d231 » | markbates | 2008-08-12 | 39 | end # Orm | |
| bc0e4be5 » | markbates | 2008-06-18 | 40 | end # Generator | |
| 41 | end # Mack | ||||
