File tree Expand file tree Collapse file tree 4 files changed +16
-7
lines changed
Expand file tree Collapse file tree 4 files changed +16
-7
lines changed Original file line number Diff line number Diff line change 33module TinyAdmin
44 class Support
55 class << self
6+ def call ( value , options : [ ] )
7+ value && options &.any? ? options . inject ( value ) { |result , message | result &.send ( message ) } : value
8+ end
9+
610 def downcase ( value , options : [ ] )
711 value &.downcase
812 end
Original file line number Diff line number Diff line change @@ -47,7 +47,9 @@ def table_header
4747 thead {
4848 tr {
4949 fields . each_value do |field |
50- td ( class : "field-header-#{ field . name } field-header-type-#{ field . type } " ) { field . title }
50+ td ( class : "field-header-#{ field . name } field-header-type-#{ field . type } " ) {
51+ field . options [ :header ] || field . title
52+ }
5153 end
5254 td { whitespace }
5355 }
@@ -63,8 +65,9 @@ def table_body
6365 field = fields [ key ]
6466 td ( class : "field-value-#{ field . name } field-value-type-#{ field . type } " ) {
6567 if field . options && field . options [ :link_to ]
66- reference = record . send ( field . options [ :field ] )
67- a ( href : route_for ( field . options [ :link_to ] , reference : reference ) ) { value }
68+ messages = ( field . options [ :call ] || '' ) . split ( ',' ) . map ( &:strip )
69+ label = messages . any? ? messages . inject ( record ) { |result , msg | result &.send ( msg ) } : value
70+ a ( href : route_for ( field . options [ :link_to ] , reference : value ) ) { label }
6871 else
6972 value
7073 end
Original file line number Diff line number Diff line change @@ -22,12 +22,13 @@ def template
2222 field = fields [ key ]
2323 div ( class : "field-#{ field . name } row lh-lg" ) {
2424 if field
25- div ( class : 'field-header col-2' ) { field . title }
25+ div ( class : 'field-header col-2' ) { field . options [ :header ] || field . title }
2626 end
2727 div ( class : 'field-value col-10' ) {
2828 if field . options && field . options [ :link_to ]
29- reference = record . send ( field . options [ :field ] )
30- a ( href : route_for ( field . options [ :link_to ] , reference : reference ) ) { value }
29+ messages = ( field . options [ :call ] || '' ) . split ( ',' ) . map ( &:strip )
30+ label = messages . any? ? messages . inject ( record ) { |result , msg | result &.send ( msg ) } : value
31+ a ( href : route_for ( field . options [ :link_to ] , reference : value ) ) { label }
3132 else
3233 value
3334 end
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ sections:
3535 pagination : 5
3636 attributes :
3737 - id
38- - title
38+ - title : call, downcase, capitalize
3939 - field : author_id
4040 link_to : authors
4141 - category : upcase
@@ -66,6 +66,7 @@ sections:
6666 - description
6767 - field : author_id
6868 link_to : authors
69+ call : author, name
6970 - category
7071 - published
7172 - position : format, %f
You can’t perform that action at this time.
0 commit comments