Class: Munger::Render::Html
- Inherits:
-
Object
- Object
- Munger::Render::Html
- Defined in:
- lib/munger/render/html.rb
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Instance Method Summary collapse
- #cycle(one, two) ⇒ Object
-
#initialize(report, options = {}) ⇒ Html
constructor
A new instance of Html.
- #render ⇒ Object
- #set_classes(options = nil) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(report, options = {}) ⇒ Html
Returns a new instance of Html.
14 15 16 17 |
# File 'lib/munger/render/html.rb', line 14 def initialize(report, = {}) @report = report set_classes([:classes]) end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
12 13 14 |
# File 'lib/munger/render/html.rb', line 12 def classes @classes end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
12 13 14 |
# File 'lib/munger/render/html.rb', line 12 def report @report end |
Instance Method Details
#cycle(one, two) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/munger/render/html.rb', line 76 def cycle(one, two) if @current == one @current = two else @current = one end end |
#render ⇒ Object
25 26 27 28 29 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 67 68 69 70 71 72 73 74 |
# File 'lib/munger/render/html.rb', line 25 def render x = Builder::XmlMarkup.new x.table(:class => @classes[:table], :id=>'report-table') do x.thead do x.tr do @report.columns.each do |column| x.th(:class => 'columnTitle') { x << @report.column_title(column) } end end end x.tbody do @report.process_data.each do |row| classes = [] classes << row[:meta][:row_styles] classes << 'group' + row[:meta][:group].to_s if row[:meta][:group] classes << cycle('even', 'odd') classes.compact! if row[:meta][:group_header] classes << 'groupHeader' + row[:meta][:group_header].to_s end row_attrib = {} row_attrib = {:class => classes.join(' ')} if classes.size > 0 x.tr(row_attrib) do if row[:meta][:group_header] header = row[:meta][:group_value].to_s x.th(:colspan => @report.columns.size) { x << header } else @report.columns.each do |column| cell_attrib = {} if cst = row[:meta][:cell_styles] cst = Item.ensure(cst) if cell_styles = cst[column] cell_attrib = {:class => cell_styles.join(' ')} end end x.td(cell_attrib) { x << row[:data][column].to_s } end end end end end end end |
#set_classes(options = nil) ⇒ Object
19 20 21 22 23 |
# File 'lib/munger/render/html.rb', line 19 def set_classes( = nil) = {} if ! default = {:table => 'report-table'} @classes = default.merge() end |
#valid? ⇒ Boolean
84 85 86 |
# File 'lib/munger/render/html.rb', line 84 def valid? @report.is_a? Munger::Report end |