hirb 0.2.10 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +0,0 @@
1
- ---
2
- :minor: 2
3
- :patch: 10
4
- :build:
5
- :major: 0
@@ -1,17 +0,0 @@
1
- require 'ostruct'
2
-
3
- class Hirb::HashStruct < OpenStruct #:nodoc:
4
- def self.block_to_hash(block=nil)
5
- config = self.new
6
- if block
7
- block.call(config)
8
- config.to_hash
9
- else
10
- {}
11
- end
12
- end
13
-
14
- def to_hash
15
- @table
16
- end
17
- end
@@ -1,26 +0,0 @@
1
- class Hirb::Helpers::ActiveRecordTable < Hirb::Helpers::ObjectTable
2
- # Rows are Rails' ActiveRecord::Base objects. These objects should all be from one class.
3
- # Takes same options as Hirb::Helpers::Table.render except as noted below.
4
- #
5
- # Options:
6
- # :fields- Can be any attribute, column or not. If not given, this defaults to the database table's columns.
7
- def self.render(rows, options={})
8
- rows = Array(rows)
9
- options[:fields] ||=
10
- begin
11
- fields = rows.first.class.column_names
12
- fields.map {|e| e.to_sym }
13
- end
14
- if query_used_select?(rows)
15
- selected_columns = rows.first.attributes.keys
16
- sorted_columns = rows.first.class.column_names.dup.delete_if {|e| !selected_columns.include?(e) }
17
- sorted_columns += (selected_columns - sorted_columns)
18
- options[:fields] = sorted_columns.map {|e| e.to_sym}
19
- end
20
- super(rows, options)
21
- end
22
-
23
- def self.query_used_select?(rows) #:nodoc:
24
- rows.first.attributes.keys.sort != rows.first.class.column_names.sort
25
- end
26
- end
@@ -1,9 +0,0 @@
1
- class Hirb::Views::ActiveRecord_Base #:nodoc:
2
- def self.default_options
3
- {:ancestor=>true}
4
- end
5
-
6
- def self.render(*args)
7
- Hirb::Helpers::ActiveRecordTable.render(*args)
8
- end
9
- end
@@ -1,35 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
2
-
3
- class Hirb::Helpers::ActiveRecordTableTest < Test::Unit::TestCase
4
- context "activerecord table" do
5
- test "with no select renders" do
6
- expected_table = <<-TABLE.unindent
7
- +-----+-------+
8
- | age | name |
9
- +-----+-------+
10
- | 7 | rufus |
11
- | 101 | alf |
12
- +-----+-------+
13
- 2 rows in set
14
- TABLE
15
- @pets = [stub(:name=>'rufus', :age=>7, :attributes=>{"name"=>'rufus', 'age'=>7}, :class=>stub(:column_names=>%w{age name})),
16
- stub(:name=>'alf', :age=>101)]
17
- Hirb::Helpers::ActiveRecordTable.render(@pets).should == expected_table
18
- end
19
-
20
- test "with select renders" do
21
- expected_table = <<-TABLE.unindent
22
- +-------+
23
- | name |
24
- +-------+
25
- | rufus |
26
- | alf |
27
- +-------+
28
- 2 rows in set
29
- TABLE
30
- @pets = [stub(:name=>'rufus', :age=>7, :attributes=>{'name'=>'rufus'}, :class=>stub(:column_names=>%w{age name})),
31
- stub(:name=>'alf', :age=>101)]
32
- Hirb::Helpers::ActiveRecordTable.render(@pets).should == expected_table
33
- end
34
- end
35
- end