Class: Edgar::ListDrawer::Base
- Inherits:
-
Object
- Object
- Edgar::ListDrawer::Base
- Includes:
- ERB::Util
- Defined in:
- app/helpers/edgar/list_drawer.rb
Overview
Base for popup-list and normal-list column drawer
Direct Known Subclasses
Instance Method Summary (collapse)
- - (Object) draw_column(rec, col)
-
- (Object) draw_normal_column(rec, col)
private
draw rec.col other than 'belongs_to' 1.
-
- (Object) draw_trimmed_str(str)
private
trim string when too long.
-
- (Base) initialize(template)
constructor
A new instance of Base.
-
- (Object) td_options(rec, col)
private
<td> options.
Constructor Details
- (Base) initialize(template)
A new instance of Base
9 10 11 12 13 14 15 |
# File 'app/helpers/edgar/list_drawer.rb', line 9 def initialize(template) @t = template @enum_cache = {} @bitset_cache = {} @parent_column = nil @belongs_to_link = false # doesn't make link on belongs_to end |
Instance Method Details
- (Object) draw_column(rec, col)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/edgar/list_drawer.rb', line 17 def draw_column(rec, col) @parent_column = rec.belongs_to_AR(col) @t.content_tag(:td, (rec, col)) do # edgar_address column is prior to draw_belongs_to() because of # avoiding link_to process on the 'belongs_to' column. if rec.class.edgar_address?(col) col_name = rec.class.get_column_name(col) adrs = Edgar::Address.find_by_id(rec.send(col_name)) adrs ? draw_trimmed_str(adrs.name) : '' elsif @parent_column then @t.draw_belongs_to(@parent_column, @belongs_to_link) else draw_normal_column(rec, col) end end end |
- (Object) draw_normal_column(rec, col) (private)
draw rec.col other than 'belongs_to'
-
DateTime format is YYYY-MM-DD hh:mm:ss.
-
if col.name == 'flags', it is assumed bitset.
-
if col is edgar_file, it is assumed file.
INPUTS
- rec
-
AR instance
- col
-
ActiveRecord::ConnectionAdapters::Column type which rec.class.columns returns
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/helpers/edgar/list_drawer.rb', line 84 def draw_normal_column(rec, col) if rec.class.edgar_file?(col) file_info = FileInfo.safe_find(rec.send(col.name)) file_info ? file_info.filename : '' elsif (enum = @enum_cache[col.name]) @t.draw_column_enum(rec, col, enum) elsif (bitset = @bitset_cache[col.name]) @t.draw_column_bitset(rec, col, bitset) else if (enum = @t.get_enum(rec.class, col)) @enum_cache[col.name] = enum @t.draw_column_enum(rec, col, enum) elsif (bitset = @t.get_bitset(rec.class, col)) @bitset_cache[col.name] = bitset @t.draw_column_bitset(rec, col, bitset) else case col.type when :datetime @t.datetime_fmt(rec.send(col.name)) when :date @t.date_fmt(rec.send(col.name)) when :integer h(rec.send(col.name)) when :boolean rec.send(col.name) ? '√' : '' else # NOTE: rec.send(col.name) is not used since sssn.send(:data) # becomes hash rather than actual string-data so that following # split() fails for Hash. if str = rec.attributes[col.name] draw_trimmed_str(str) else '' end end end end end |
- (Object) draw_trimmed_str(str) (private)
trim string when too long
68 69 70 71 72 73 74 |
# File 'app/helpers/edgar/list_drawer.rb', line 68 def draw_trimmed_str(str) s = str.split(//) if s.size > Edgar::LIST_TEXT_MAX_LEN s = s[0..Edgar::LIST_TEXT_MAX_LEN] << '...' end h(s.join('')) end |
- (Object) td_options(rec, col) (private)
<td> options
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/edgar/list_drawer.rb', line 36 def (rec, col) if rec.class.edgar_file?(col) {} elsif @enum_cache[col.name] {} elsif @bitset_cache[col.name] {} elsif @parent_column {} else if @t.get_enum(rec.class, col) {} elsif @t.get_bitset(rec.class, col) {} else case col.type when :datetime {} when :date {} when :integer {align: 'right'} when :boolean {align: 'center'} else {} end end end end |