Merge branch 'master' of github.com:johnbintz/semantic_rails_view_helpers
This commit is contained in:
commit
ce7d15b676
|
@ -30,6 +30,10 @@ module SemanticRailsViewHelpers
|
||||||
value = raw_value
|
value = raw_value
|
||||||
value = value.to_label if value.respond_to?(:to_label)
|
value = value.to_label if value.respond_to?(:to_label)
|
||||||
|
|
||||||
|
if options[:raw]
|
||||||
|
value = value.html_safe
|
||||||
|
end
|
||||||
|
|
||||||
if SemanticRailsViewHelpers.semantic_data?
|
if SemanticRailsViewHelpers.semantic_data?
|
||||||
value = @context.content_tag(:data, value, 'data-field' => field)
|
value = @context.content_tag(:data, value, 'data-field' => field)
|
||||||
end
|
end
|
||||||
|
@ -41,6 +45,10 @@ module SemanticRailsViewHelpers
|
||||||
(value or '').html_safe
|
(value or '').html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def field!(field, options = {}, &block)
|
||||||
|
self.field(field, options.merge(:raw => true), &block)
|
||||||
|
end
|
||||||
|
|
||||||
class TagBuilder
|
class TagBuilder
|
||||||
def initialize(attributes_builder)
|
def initialize(attributes_builder)
|
||||||
@attributes_builder = attributes_builder
|
@attributes_builder = attributes_builder
|
||||||
|
|
|
@ -58,6 +58,10 @@ def find_action(action)
|
||||||
find("[data-action='#{action}']")
|
find("[data-action='#{action}']")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_object_action(object, action)
|
||||||
|
find("[data-type='#{object}'][data-action='#{action}']")
|
||||||
|
end
|
||||||
|
|
||||||
module Capybara
|
module Capybara
|
||||||
class ElementFound < StandardError
|
class ElementFound < StandardError
|
||||||
def initialize(search)
|
def initialize(search)
|
||||||
|
@ -115,11 +119,15 @@ def within_any(search, &block)
|
||||||
search = "[data-type='#{search}']"
|
search = "[data-type='#{search}']"
|
||||||
end
|
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
|
begin
|
||||||
within("#{search}:eq(#{index + 1})", &block)
|
within("#{search}:eq(#{index + 1})", &block)
|
||||||
return true
|
return true
|
||||||
rescue RSpec::Expectations::ExpectationNotMetError
|
rescue RSpec::Expectations::ExpectationNotMetError, Capybara::ElementNotFound
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -129,3 +137,7 @@ end
|
||||||
def refind_object(object)
|
def refind_object(object)
|
||||||
object.class.find(object.id)
|
object.class.find(object.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_semantic_link(link)
|
||||||
|
find("[data-link='#{link}']")
|
||||||
|
end
|
||||||
|
|
|
@ -36,7 +36,7 @@ module SemanticRailsViewHelpers
|
||||||
def link_to_model_action(model, action = :show, options = {})
|
def link_to_model_action(model, action = :show, options = {})
|
||||||
target_action = action
|
target_action = action
|
||||||
|
|
||||||
label = options.delete(:label) || t(".#{action}")
|
label = options.delete(:label) || t(".#{model.class.name.underscore}.#{action}")
|
||||||
|
|
||||||
if action == :destroy
|
if action == :destroy
|
||||||
options = options.merge(:method => :delete, 'data-skip-pjax' => 'true')
|
options = options.merge(:method => :delete, 'data-skip-pjax' => 'true')
|
||||||
|
@ -52,7 +52,9 @@ module SemanticRailsViewHelpers
|
||||||
route = model
|
route = model
|
||||||
route = route.to_route if route.respond_to?(:to_route)
|
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
|
end
|
||||||
|
|
||||||
def li_for(object, options = {}, &block)
|
def li_for(object, options = {}, &block)
|
||||||
|
@ -70,7 +72,13 @@ module SemanticRailsViewHelpers
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue