Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%span.badge= attribute.value ? 'Yes' : 'No'
1 change: 1 addition & 0 deletions app/views/upmin/partials/attribute_values/_enum.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%span.badge= attribute.value
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= attribute.value
2 changes: 1 addition & 1 deletion app/views/upmin/partials/attributes/_datetime.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
- else
%p.well
-# TODO(jon): Make this show an uneditable date and time field.
= iso8601
= up_render(attribute.display_value)
2 changes: 1 addition & 1 deletion app/views/upmin/partials/search_results/_results.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
%dt
= attribute.label_name
%dd
= attribute.value
= up_render(attribute.display_value)
1 change: 1 addition & 0 deletions lib/upmin/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

require "upmin/model"
require "upmin/attribute"
require "upmin/attribute_value"
require "upmin/association"
require "upmin/action"
require "upmin/parameter"
Expand Down
6 changes: 6 additions & 0 deletions lib/upmin/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def value
return model.model.send(name)
end

def display_value
return @display_value if defined?(@display_value)
@display_value = Upmin::AttributeValue.new(self)
return @display_value
end

def type
# TODO(jon): Add a way to override with widgets?
return @type if defined?(@type)
Expand Down
10 changes: 10 additions & 0 deletions lib/upmin/attribute_value.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Upmin
class AttributeValue
attr_reader :attribute

def initialize(attribute, options = {})
@attribute = attribute
end

end
end
4 changes: 4 additions & 0 deletions lib/upmin/railties/render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def up_render(data, options = {})
options = RenderHelpers.attribute_options(data, options)
partials = RenderHelpers.attribute_partials(data, options)

elsif data.is_a?(Upmin::AttributeValue)
options = RenderHelpers.attribute_value_options(data, options)
partials = RenderHelpers.attribute_value_partials(data, options)

elsif data.is_a?(Upmin::Association)
options = RenderHelpers.association_options(data, options)
partials = RenderHelpers.association_partials(data, options)
Expand Down
35 changes: 35 additions & 0 deletions lib/upmin/railties/render_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,41 @@ def RenderHelpers.build_attribute_path(partial)



def RenderHelpers.attribute_value_partials(attribute_value, options = {})
attribute = attribute_value.attribute
partials = []
# <options[:as]>
# <model_name>_<attr_name>, eg: user_name
# <model_name>_<attr_type>, eg: user_string
# <attr_type>, eg: string
# unknown

model_name = attribute.model.underscore_name
attr_type = attribute.type

partials << build_attribute_value_path(options[:as]) if options[:as]
partials << build_attribute_value_path("#{model_name}_#{attribute.name}")
partials << build_attribute_value_path("#{model_name}_#{attr_type}")
partials << build_attribute_value_path(attribute.name)
partials << build_attribute_value_path(attr_type)
partials << build_attribute_value_path(:unknown)
return partials
end

def RenderHelpers.attribute_value_options(attribute_value, options = {})
attribute = attribute_value.attribute
options[:locals] ||= {}
options[:locals][:model] ||= attribute.model
options[:locals][:attribute] = attribute
return options
end

def RenderHelpers.build_attribute_value_path(partial)
return build_path("attribute_values", partial)
end



# NOTE: assoc_type is sketchy at best. It tries to determine it, but in some cases it has to be guessed at, so if you have polymorphic associations it will choose the data type of the first association it finds - eg if user.things returns [Order, Product, Review] it will use the type of "order"
def RenderHelpers.association_partials(association, options = {})
partials = []
Expand Down