ok this kind of works
This commit is contained in:
parent
05125fd7ea
commit
58b42a7392
|
@ -1,3 +1,5 @@
|
|||
require 'delegate'
|
||||
|
||||
module SemanticRailsViewHelpers
|
||||
class AttributesBuilder < SimpleDelegator
|
||||
attr_reader :object
|
||||
|
@ -21,6 +23,8 @@ module SemanticRailsViewHelpers
|
|||
value = @object.send(field)
|
||||
end
|
||||
|
||||
value = value.to_label if value.respond_to?(:to_label)
|
||||
|
||||
value = @context.content_tag(:data, value, 'data-field' => field)
|
||||
|
||||
if options[:as]
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
def find_attribute(name)
|
||||
find("[data-field='#{name}']")
|
||||
end
|
||||
|
|
@ -1,8 +1,47 @@
|
|||
require 'semantic_rails_view_helpers/attributes_builder'
|
||||
|
||||
module SemanticRailsViewHelpers
|
||||
module ViewHelpers
|
||||
def attributes_for(object, &block)
|
||||
AttributesBuilder.new(object, self, block)
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue