add basic activeadmin support
This commit is contained in:
parent
d6c5879bea
commit
ed66c74344
|
@ -76,6 +76,11 @@ You can even make simple tables, a la Active Admin:
|
||||||
= f.field :description
|
= 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
|
## Not Finding Things
|
||||||
|
|
||||||
Sometimes the absence of a thing is just as important as the presence of a thing. Make it easy on yourself:
|
Sometimes the absence of a thing is just as important as the presence of a thing. Make it easy on yourself:
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
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 do
|
||||||
|
content_for(attr, block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
def content_for(attr, block)
|
||||||
|
value = begin
|
||||||
|
if block
|
||||||
|
block.call(@record)
|
||||||
|
else
|
||||||
|
content_for_attribute(attr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
value = pretty_format(value)
|
||||||
|
value == "" || value.nil? ? empty_value : value
|
||||||
|
|
||||||
|
%{<data data-field="#{attr}">#{value}</data>}.html_safe
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@ module SemanticRailsViewHelpers
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
@options[:class] ||= ''
|
@options[:class] ||= ''
|
||||||
@options[:class] << 'attributes table'
|
@options[:class] << ' attributes table'
|
||||||
|
|
||||||
@context.content_tag(:table, @options) do
|
@context.content_tag(:table, @options) do
|
||||||
@context.capture(self, &@block)
|
@context.capture(self, &@block)
|
||||||
|
|
|
@ -7,10 +7,14 @@ module SemanticRailsViewHelpers
|
||||||
AttributesBuilder.new(object, self, block)
|
AttributesBuilder.new(object, self, block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias :semantic_attributes_for :attributes_for
|
||||||
|
|
||||||
def attributes_table_for(object, options = {}, &block)
|
def attributes_table_for(object, options = {}, &block)
|
||||||
AttributesTableBuilder.new(object, options, self, block)
|
AttributesTableBuilder.new(object, options, self, block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias :semantic_attributes_table_for :attributes_table_for
|
||||||
|
|
||||||
def link_to_route(route, *args)
|
def link_to_route(route, *args)
|
||||||
options = {}
|
options = {}
|
||||||
if args.last.kind_of?(::Hash)
|
if args.last.kind_of?(::Hash)
|
||||||
|
|
Loading…
Reference in New Issue