Sha256: f6ff7290fbaf2e7856d8af73d90c5773e38d7843ffce233467b1403e50afe7e1
Contents?: true
Size: 1.45 KB
Versions: 5
Compression:
Stored size: 1.45 KB
Contents
module ExpressAdmin class DefinitionList < ExpressTemplates::Components::Configurable include ExpressTemplates::Components::Capabilities::Resourceful tag :dl list_types = {} list_types[:array] = {description: "List of fields on the current resource", options: -> {resource.columns.map(&:name)}} list_types[:hash] = {description: "List of terms and definitions."} has_argument :list, "A list of things to define, presented as <label>: <definition>.", as: :list, type: list_types contains -> { definitions.each do |label, content| dt { label } dd { content } end } def definitions if config[:list].kind_of?(Array) definitions_from_array(@args.first) elsif config[:list].kind_of?(Hash) definitions_from_hash(@args.first) end end def definitions_from_hash(hash) processed = hash.map do |k,v| if v.kind_of? Symbol [promptify(k), resource.send(v)] else [promptify(k), helpers.instance_eval("(#{v.source}).call(resource).to_s").html_safe] end end Hash[processed] end def definitions_from_array(fields) Hash[fields.map {|field| ["#{field.to_s.titleize}:", "{{resource.#{field}}}"]}] end private def promptify(k) if k.kind_of?(Symbol) k.to_s.promptify else k.to_s end end end end
Version data entries
5 entries across 5 versions & 1 rubygems