Sha256: 71de6b483f51654ad06a31c5deb9c0495a2106ebe64037188d13df5c1d844d06
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
Contents
require 'cgi' module LedgerWeb::Decorators class NumberDecorator def initialize(precision=2) @precision = precision end def decorate(cell, row) if cell.value.is_a?(Numeric) cell.align = 'right' cell.text = sprintf("%0.#{@precision}f", cell.value) end cell end end class LinkDecorator def initialize(href_pattern) @href_pattern = href_pattern end def decorate(cell, row) url = String.new(@href_pattern) row.each_with_index do |c,i| url.gsub!(":#{i}", CGI.escape(c.value.to_s)) end url.gsub!(':title', CGI.escape(cell.title.to_s)) url.gsub!(':now', CGI.escape(DateTime.now.strftime('%Y-%m-%d'))) url.gsub!(':this', CGI.escape(cell.value.to_s)) prev_text = cell.text cell.text = "<a href=\"#{url}\">#{cell.text}</a>" cell end end class IconDecorator def initialize(icon) @icon = icon end def decorate(cell, row) cell.text = "<i class=\"icon-#{@icon}\"></i>" cell end end class HighlightDecorator def initialize(color) @color = color end def decorate(cell, row) cell.style['background-color'] = @color cell end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ledger_web-1.5.2 | lib/ledger_web/decorators.rb |
ledger_web-1.5.1 | lib/ledger_web/decorators.rb |
ledger_web-1.5.0 | lib/ledger_web/decorators.rb |