ok this kind of works

This commit is contained in:
John Bintz 2012-11-21 16:31:45 -05:00
parent 05125fd7ea
commit 58b42a7392
3 changed files with 47 additions and 0 deletions

View File

@ -1,3 +1,5 @@
require 'delegate'
module SemanticRailsViewHelpers module SemanticRailsViewHelpers
class AttributesBuilder < SimpleDelegator class AttributesBuilder < SimpleDelegator
attr_reader :object attr_reader :object
@ -21,6 +23,8 @@ module SemanticRailsViewHelpers
value = @object.send(field) value = @object.send(field)
end end
value = value.to_label if value.respond_to?(:to_label)
value = @context.content_tag(:data, value, 'data-field' => field) value = @context.content_tag(:data, value, 'data-field' => field)
if options[:as] if options[:as]

View File

@ -0,0 +1,4 @@
def find_attribute(name)
find("[data-field='#{name}']")
end

View File

@ -1,8 +1,47 @@
require 'semantic_rails_view_helpers/attributes_builder'
module SemanticRailsViewHelpers module SemanticRailsViewHelpers
module ViewHelpers module ViewHelpers
def attributes_for(object, &block) def attributes_for(object, &block)
AttributesBuilder.new(object, self, block) AttributesBuilder.new(object, self, block)
end end
def link_to_route(route, *args)
link_to t(".#{route}"), send("#{route}_path", *args), 'data-link' => route
end
def link_to_collection(route)
collection = route.last
link_to t(".#{collection}"), polymorphic_url(route), 'data-link' => collection
end
def link_to_model(model)
route = model
route = route.to_route if route.respond_to?(:to_route)
link_to model.to_label, polymorphic_url(route), 'data-action' => 'show'
end
def link_to_model_action(model, action = :show, options = {})
target_action = action
if action == :destroy
options = options.merge(:method => :delete, 'data-skip-pjax' => 'true')
action = nil
end
options = Hash[options.collect { |k, v| [ k, CGI.escapeHTML(v.to_s) ] }]
route = model
route = route.to_route if route.respond_to?(:to_route)
link_to t(".#{action}"), polymorphic_url(route, :action => action), options.merge("data-action" => target_action)
end
def li_for(object, &block)
content_tag(:li, capture(&block), 'data-id' => object.id)
end
end end
end end