Skip to content

Commit

Permalink
Added attributes = to hash model, change type to string before
Browse files Browse the repository at this point in the history
splitting. Return fields that don't have any relations.
  • Loading branch information
Doug Youch committed Mar 26, 2010
1 parent c729269 commit 52731ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
21 changes: 13 additions & 8 deletions app/models/content_model.rb
Expand Up @@ -93,13 +93,13 @@ def content_type_name
end

# Return a list of content fields with their modules added in
def self.content_fields
returning fields = [] do
get_handler_info(:content,:fields).each do |info|
fields.concat(info[:class].fields)
end
def self.content_fields(opts={})
fields = []
get_handler_info(:content,:fields).each do |info|
fields.concat(info[:class].fields)
end

fields = fields.reject { |info| info[:relation] } if opts[:simple]
fields
end

# Return a hash of content fields with their modules added in
Expand All @@ -112,8 +112,13 @@ def self.content_fields_hash
end

# Returns a select-friendly list of available content field types
def self.content_field_options
self.content_fields.collect { |fld| [ fld[:description].t, "#{fld[:module]}::#{fld[:name]}" ] }
def self.content_field_options(opts={})
self.content_fields(opts).collect { |fld| [ fld[:description].t, "#{fld[:module]}::#{fld[:name]}" ] }
end

# Returns a select-friendly list of available content field types without relation's
def self.simple_content_field_options
self.content_field_options(:simple => true)
end

# Returns all the ContentModelField's of this content model (including a field for the id)
Expand Down
4 changes: 2 additions & 2 deletions app/models/content_model_field.rb
Expand Up @@ -28,13 +28,13 @@ def validate
def field_type=(type)
return unless type

vals = type.split('::')
vals = type.to_s.split('::')
if vals.length == 2
self.field_module = vals[0]
write_attribute :field_type, vals[1]
else
self.field_module ||= 'content/core_field'
write_attribute :field_type, type
write_attribute :field_type, type.to_s
end
end

Expand Down
12 changes: 11 additions & 1 deletion lib/hash_model.rb
Expand Up @@ -217,7 +217,17 @@ def initialize(hsh)

@additional_vars = []
end


def attributes
to_h
end

def attributes=(hsh)
hsh.each do |key,value|
self.send("#{key.to_s}=",value) if defaults.has_key?(key.to_sym) || self.respond_to?("#{key.to_s}=")
end
end

def additional_vars(vars)
@additional_vars += vars

Expand Down

0 comments on commit 52731ae

Please sign in to comment.