Class: Edgar::RecordDrawer
- Inherits:
-
Object
- Object
- Edgar::RecordDrawer
- Defined in:
- app/helpers/edgar/record_drawer.rb
Overview
draws table-based read-only record data.
Instance Method Summary (collapse)
-
- (Object) _draw_2_lane(&block)
flip field to left-lane or right-lane.
-
- (Object) _draw_field(col)
draw general field.
-
- (Object) _draw_head(col, label = nil, &block)
draw head(label).
- - (Object) columns
-
- (Object) draw
draw record data.
-
- (RecordDrawer) initialize(template, model)
constructor
INPUTS
- template
-
view template to call helper
- model
-
model object.
Constructor Details
- (RecordDrawer) initialize(template, model)
INPUTS
- template
-
view template to call helper
- model
-
model object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/edgar/record_drawer.rb', line 8 def initialize(template, model) @template = template @model = model # define default options for draw_X() method, where X is :flags, :kind, # and so on. @options can be redefined at derived class. @options = { :flags => {}, :kind => {}, :boolean => {}, :default => {} } end |
Instance Method Details
- (Object) _draw_2_lane(&block)
flip field to left-lane or right-lane
74 75 76 77 78 79 80 |
# File 'app/helpers/edgar/record_drawer.rb', line 74 def _draw_2_lane(&block) result = @left ? '<tr>' : '' result += yield result += '</tr>' if !@left @left = !@left # flip it result end |
- (Object) _draw_field(col)
draw general field
98 99 100 101 102 103 104 105 |
# File 'app/helpers/edgar/record_drawer.rb', line 98 def _draw_field(col) case col.type when :boolean @model.send(col.name) ? '[x]' : '[_]' else @model.send(col.name).to_s end end |
- (Object) _draw_head(col, label = nil, &block)
draw head(label).
INPUTS
- col
-
column info
- label
-
if not-nil, label is used rather than human_attribute_name of col.name for field-label
- block
-
wrapped field-drawing logic
89 90 91 92 93 94 95 |
# File 'app/helpers/edgar/record_drawer.rb', line 89 def _draw_head(col, label=nil, &block) _draw_2_lane{ sprintf("<th>%s</th><td></td><td>", label || @model.class.human_attribute_name(col.name)) + yield + '</td>' } end |
- (Object) columns
68 69 70 71 |
# File 'app/helpers/edgar/record_drawer.rb', line 68 def columns m = @model.class m.columns_for(m.view_form_columns) end |
- (Object) draw
draw record data
I18n for label is:
-
usual column uses model.human_attribute_name()
-
'belongs_to' column uses:
** I18n.t('activerecord.attributes.MODEL.EXT_ID') ** parent.human_name
30 31 32 33 34 35 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 66 |
# File 'app/helpers/edgar/record_drawer.rb', line 30 def draw() adrs_field = {} html = "<table>" @left = true for col in columns do html += if col.name =~ /^(adrs_\d_)/ adrs_prefix = $1 if !adrs_field[adrs_prefix] adrs_field[adrs_prefix] = true render :partial => 'edgar/address_show', :locals=>{:prefix=>adrs_prefix} else '' end else parent = @model.belongs_to_AR(col) if parent _draw_head(col, @model.class.human_attribute_name( col.name, :default=>parent.class.human_name)){ @template.draw_belongs_to(parent) } else _draw_head(col){ case col.name when 'flags' @template.draw_column_flags(@model) else _draw_field(col) end } end end end html += '<td colspan=3></td>' if !@left html + "</table>" end |