Merge branch 'master' of github.com:johnbintz/semantic_rails_view_helpers

This commit is contained in:
John Bintz 2013-01-02 17:59:49 -05:00
commit ce7d15b676
3 changed files with 33 additions and 5 deletions

View File

@ -30,6 +30,10 @@ module SemanticRailsViewHelpers
value = raw_value
value = value.to_label if value.respond_to?(:to_label)
if options[:raw]
value = value.html_safe
end
if SemanticRailsViewHelpers.semantic_data?
value = @context.content_tag(:data, value, 'data-field' => field)
end
@ -41,6 +45,10 @@ module SemanticRailsViewHelpers
(value or '').html_safe
end
def field!(field, options = {}, &block)
self.field(field, options.merge(:raw => true), &block)
end
class TagBuilder
def initialize(attributes_builder)
@attributes_builder = attributes_builder

View File

@ -58,6 +58,10 @@ def find_action(action)
find("[data-action='#{action}']")
end
def find_object_action(object, action)
find("[data-type='#{object}'][data-action='#{action}']")
end
module Capybara
class ElementFound < StandardError
def initialize(search)
@ -115,11 +119,15 @@ def within_any(search, &block)
search = "[data-type='#{search}']"
end
all(search).each_with_index do |node, index|
nodes = all(search)
raise Capybara::ElementNotFound if nodes.empty?
nodes.each_with_index do |node, index|
begin
within("#{search}:eq(#{index + 1})", &block)
return true
rescue RSpec::Expectations::ExpectationNotMetError
rescue RSpec::Expectations::ExpectationNotMetError, Capybara::ElementNotFound
end
end
@ -129,3 +137,7 @@ end
def refind_object(object)
object.class.find(object.id)
end
def find_semantic_link(link)
find("[data-link='#{link}']")
end

View File

@ -36,7 +36,7 @@ module SemanticRailsViewHelpers
def link_to_model_action(model, action = :show, options = {})
target_action = action
label = options.delete(:label) || t(".#{action}")
label = options.delete(:label) || t(".#{model.class.name.underscore}.#{action}")
if action == :destroy
options = options.merge(:method => :delete, 'data-skip-pjax' => 'true')
@ -52,7 +52,9 @@ module SemanticRailsViewHelpers
route = model
route = route.to_route if route.respond_to?(:to_route)
link_to label, polymorphic_url(route, :action => action), options.merge(semantic_action_data(target_action))
data = semantic_action_data(target_action).merge(semantic_model_data(model))
link_to label, polymorphic_url(route, :action => action), options.merge(data)
end
def li_for(object, options = {}, &block)
@ -70,7 +72,13 @@ module SemanticRailsViewHelpers
end
end
{ 'data-type' => type, 'data-id' => object.id }
output = { 'data-type' => type }
if object.respond_to?(:id)
output['data-id'] = object.id
end
output
end
end