Sha256: f5e4732dccd5230829ff58a121673235b460c4d1e9be32eccc8499118e65d735
Contents?: true
Size: 1.6 KB
Versions: 4
Compression:
Stored size: 1.6 KB
Contents
module Symbolink class Configuration attr_reader :symbols attr_reader :actions def initialize @symbols, @actions = {}, {} @symbols.default_proc = ->(hash, key) { raise ArgumentError, "Unregistered symbolink #{key}" } init_defaults end def add_icons(map = {}) map.each { |symbol, icon| @symbols[symbol] = icon.html_safe } end alias :add_icon :add_icons alias :icon :add_icons # Define action for symbol # Options: # # - icon: symbol for defined icon or string. # defies new icon with action name as a key if string given as icon # uses action sysmbol as icon symbol if not provided # # - title: string to be used as link title # humanized action sysmbol will be used as a title if not provided # # - confirm: string to be used as action confirmation text # data-confirm attribute will be added into the generated link if defined. def action(sym, ops = {}) ops[:icon] ||= sym ops[:title] ||= sym.to_s.humanize if ops[:icon].is_a?(String) add_icon sym => ops[:icon] ops[:icon] = sym end @actions[sym] = ops end private def init_defaults add_icons( delete: '✖', add: '✚', print: '⌸', half: '½', left_arrow: '≪', double_left_arrow: '⋘', right_arrow: '≫', double_right_arrow: '⋙', edit: '⌨', refresh: '⟲', ) end end end
Version data entries
4 entries across 4 versions & 1 rubygems