lib/orange/resources/model_resource.rb in orange-0.0.4 vs lib/orange/resources/model_resource.rb in orange-0.0.5
- old
+ new
@@ -1,10 +1,9 @@
require 'orange/resources/routable_resource'
module Orange
class ModelResource < RoutableResource
- extend ClassInheritableAttributes
# Defines a model class as an inheritable class attribute and also an instance
# attribute
cattr_inheritable :model_class
attr_accessor :model_class
@@ -27,16 +26,15 @@
# Decision between show or list is determined by whether an id has been chosen.
# An id is set in opts[:id], or extracted from the packet['route.resource_id'].
# Calling view is equivalent to calling a viewable method directly, view just
# sets up safe defaults so method missing errors are less likely.
# @param [Orange::Packet] packet the packet calling view on this resource
- def view(packet, *args)
- opts = args.last || {}
+ def view(packet, opts = {})
resource_id = opts[:id] || packet['route.resource_id', false]
mode = opts[:mode] || packet['route.resource_action'] ||
(resource_id ? :show : :index)
- self.__send__(mode, packet, *args)
+ self.__send__(mode, packet, opts)
end
# Renders a view, with all options set for haml to access.
# Calls #view_opts to generate the haml options.
# @param [Orange::Packet] packet the packet we are returning a view for
@@ -213,28 +211,31 @@
end
# Returns a scaffolded attribute
def view_attribute(prop, model_name, *args)
args = args.extract_options!
- val = args[:value] || ''
+ val = (args[:value] || '')
label = args[:label] || false
show = args[:show] || false
name = prop[:name]
human_readable_name = name.to_s.split('_').each{|w| w.capitalize!}.join(' ')
unless show
case prop[:type]
when :title
- ret = "<input class='title' type='text' value='#{val}' name='#{model_name}[#{name}]' />"
+ val.gsub!('"', '"')
+ ret = "<input class=\"title\" type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
when :text
- ret = "<input type='text' value='#{val}' name='#{model_name}[#{name}]' />"
+ val.gsub!('"', '"')
+ ret = "<input type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
when :fulltext
ret = "<textarea name='#{model_name}[#{name}]'>#{val}</textarea>"
when :boolean
human_readable_name = human_readable_name + '?'
ret = "<input type='hidden' name='#{model_name}[#{name}]' value='0' /><input type='checkbox' name='#{model_name}[#{name}]' value='1' #{'checked="checked"' if (val && val != '')}/>"
else
- ret = "<input type='text' value='#{val}' name='#{model_name}[#{name}]' />"
+ val.gsub!('"', '"')
+ ret = "<input type=\"text\" value=\"#{val}\" name=\"#{model_name}[#{name}]\" />"
end
display_name = prop[:display_name] || human_readable_name
ret = "<label for=''>#{display_name}</label><br />" + ret if label
else
case prop[:type]
@@ -246,9 +247,9 @@
ret = "<div class='#{model_name}-#{name}'>#{val}</div>"
else
ret = "<div class='#{model_name}-#{name}'>#{val}</div>"
end
end
- ret
+ return ret
end
end
end
\ No newline at end of file