Merge branch 'master' of github.com:johnbintz/semantic_rails_view_helpers
This commit is contained in:
commit
820c7cf5d2
|
@ -76,6 +76,11 @@ You can even make simple tables, a la Active Admin:
|
|||
= f.field :description
|
||||
```
|
||||
|
||||
### Active Admin
|
||||
|
||||
You can add semantic data to Active Admin's `attributes_table`s in `show` views. Just `require 'semantic_rails_view_helpers/active_admin'`
|
||||
in an initializer and you can then target attributes in `show` views.
|
||||
|
||||
## Not Finding Things
|
||||
|
||||
Sometimes the absence of a thing is just as important as the presence of a thing. Make it easy on yourself:
|
||||
|
@ -84,5 +89,9 @@ Sometimes the absence of a thing is just as important as the presence of a thing
|
|||
# selector's not there
|
||||
|
||||
dont_find('#user')
|
||||
|
||||
# ...after you've already found something...
|
||||
|
||||
find('.node').dont_find('.something_inside')
|
||||
```
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
require 'active_admin/views/components/attributes_table'
|
||||
|
||||
class ActiveAdmin::Views::AttributesTable
|
||||
def row(attr, &block)
|
||||
@table << tr do
|
||||
th do
|
||||
header_content_for(attr)
|
||||
end
|
||||
td 'data-field' => attr do
|
||||
content_for(block || attr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@ module SemanticRailsViewHelpers
|
|||
|
||||
def to_s
|
||||
@options[:class] ||= ''
|
||||
@options[:class] << 'attributes table'
|
||||
@options[:class] << ' attributes table'
|
||||
|
||||
@context.content_tag(:table, @options) do
|
||||
@context.capture(self, &@block)
|
||||
|
|
|
@ -62,6 +62,26 @@ def find_object_action(object, action)
|
|||
find("[data-type='#{object}'][data-action='#{action}']")
|
||||
end
|
||||
|
||||
module DontFindable
|
||||
def dont_find_wrap(search)
|
||||
yield
|
||||
|
||||
sleep Capybara.default_wait_time
|
||||
|
||||
yield
|
||||
|
||||
raise Capybara::ElementFound.new(search)
|
||||
rescue Capybara::ElementNotFound
|
||||
true
|
||||
end
|
||||
|
||||
def dont_find(search)
|
||||
dont_find_wrap(search) do
|
||||
find(search)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Capybara
|
||||
class ElementFound < StandardError
|
||||
def initialize(search)
|
||||
|
@ -72,26 +92,14 @@ module Capybara
|
|||
@search
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def dont_find_wrap(search)
|
||||
yield
|
||||
|
||||
sleep Capybara.default_wait_time
|
||||
|
||||
yield
|
||||
|
||||
raise Capybara::ElementFound.new(search)
|
||||
rescue Capybara::ElementNotFound
|
||||
true
|
||||
end
|
||||
|
||||
def dont_find(search)
|
||||
dont_find_wrap(search) do
|
||||
find(search)
|
||||
class Node::Element
|
||||
include DontFindable
|
||||
end
|
||||
end
|
||||
|
||||
include DontFindable
|
||||
|
||||
def dont_find_object(object)
|
||||
case object
|
||||
when Class
|
||||
|
|
|
@ -7,10 +7,14 @@ module SemanticRailsViewHelpers
|
|||
AttributesBuilder.new(object, self, block)
|
||||
end
|
||||
|
||||
alias :semantic_attributes_for :attributes_for
|
||||
|
||||
def attributes_table_for(object, options = {}, &block)
|
||||
AttributesTableBuilder.new(object, options, self, block)
|
||||
end
|
||||
|
||||
alias :semantic_attributes_table_for :attributes_table_for
|
||||
|
||||
def link_to_route(route, *args)
|
||||
options = {}
|
||||
if args.last.kind_of?(::Hash)
|
||||
|
@ -65,8 +69,8 @@ module SemanticRailsViewHelpers
|
|||
def semantic_model_data(object)
|
||||
SemanticRailsViewHelpers.with_semantic_data do
|
||||
type = begin
|
||||
if object.respond_to?(:model)
|
||||
object.model.class
|
||||
if object.respond_to?(:source) and object.respond_to?(:to_source)
|
||||
object.source.class
|
||||
else
|
||||
object.class
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue