display_for 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Rakefile CHANGED
@@ -32,16 +32,6 @@ Rake::TestTask.new(:test) do |test|
32
32
  test.verbose = true
33
33
  end
34
34
 
35
- =begin
36
- require 'rcov/rcovtask'
37
- Rcov::RcovTask.new do |test|
38
- test.libs << 'test'
39
- test.pattern = 'test/**/test_*.rb'
40
- test.verbose = true
41
- test.rcov_opts << '--exclude "gems/*"'
42
- end
43
- =end
44
-
45
35
  task :default => :test
46
36
 
47
37
  require 'rdoc/task'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
data/display_for.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "display_for"
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mateo Murphy"]
12
- s.date = "2012-10-13"
12
+ s.date = "2012-10-19"
13
13
  s.description = "A Rails library for display data, in tabular and other formats"
14
14
  s.email = "mateo.murphy@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".rspec",
21
22
  "Gemfile",
22
23
  "Gemfile.lock",
23
24
  "LICENSE.txt",
@@ -39,8 +40,10 @@ Gem::Specification.new do |s|
39
40
  "lib/display_for/element/base.rb",
40
41
  "lib/display_for/element/html.rb",
41
42
  "lib/display_for/helper.rb",
42
- "test/helper.rb",
43
- "test/test_display_for.rb"
43
+ "spec/lib/builder/table_spec.rb",
44
+ "spec/spec_helper.rb",
45
+ "spec/support/test_model.rb",
46
+ "spec/support/test_template.rb"
44
47
  ]
45
48
  s.homepage = "http://github.com/mateomurphy/display_for"
46
49
  s.licenses = ["MIT"]
@@ -10,10 +10,8 @@ module DisplayFor
10
10
  @attributes = []
11
11
  @actions = []
12
12
  @html_options = html_options
13
-
14
- raise "invalid resource class #{resource_class}" unless resource_class.respond_to?(:human_attribute_name)
15
13
 
16
- block.call(self)
14
+ block.call(self) if block_given?
17
15
  end
18
16
 
19
17
  def attribute(name, options = {}, &block)
@@ -14,11 +14,13 @@ module DisplayFor
14
14
  def build_row(resource)
15
15
  result = ''
16
16
  @attributes.each do |attribute|
17
- result << content_tag(:td, attribute.content(resource))
17
+ result << content_tag(:td, attribute.content(resource), attribute.html_options)
18
18
  end
19
19
  result << content_tag(:td, build_actions(resource)) if @actions.any?
20
20
 
21
- content_tag(:tr, result.html_safe, :id => "#{@resource_class}_#{resource.id}".underscore) << "\n"
21
+ options = {}
22
+ options[:id] = "#{@resource_class}_#{resource.id}".underscore if resource
23
+ content_tag(:tr, result.html_safe, options) << "\n"
22
24
  end
23
25
 
24
26
  def build_actions(resource)
@@ -40,9 +42,19 @@ module DisplayFor
40
42
 
41
43
  result = build_header + content_tag(:tbody, result)
42
44
 
45
+ if @footer
46
+ result << content_tag(:tfoot, @footer.build_row(nil))
47
+ end
48
+
43
49
  html_options[:class] ||= "table table-bordered table-striped #{@resource_class.to_s.underscore}-table"
44
50
  content_tag(:table, result, html_options).html_safe
45
51
  end
52
+
53
+ def footer
54
+ @footer = Table.new(resource_class, [], html_options, template)
55
+ yield @footer
56
+ end
57
+
46
58
  end
47
59
  end
48
60
  end
@@ -2,6 +2,8 @@ module DisplayFor
2
2
  module Element
3
3
  class Attribute < Base
4
4
  def default_label(resource_class)
5
+ raise "#{resource_class} does not respond to human_attribute_name" unless resource_class.respond_to?(:human_attribute_name)
6
+
5
7
  resource_class.human_attribute_name(@name.to_s)
6
8
  end
7
9
 
@@ -7,6 +7,10 @@ module DisplayFor
7
7
  @builder, @name, @options, @block = builder, name, options, block
8
8
  end
9
9
 
10
+ def html_options
11
+ @options[:html] || {}
12
+ end
13
+
10
14
  def label(resource_class = nil)
11
15
  return nil if @options[:label] === false
12
16
 
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ OUTPUT = %q|<table class="table table-bordered table-striped test_model-table"><thead><tr><th class="test_model_id">id</th><th class="test_model_first_name">first_name</th><th class="test_model_last_name">last_name</th></tr></thead>
4
+ <tbody><tr id="test_model_1"><td>1</td><td>foo</td><td>bar</td></tr>
5
+ </tbody><tfoot><tr><td colspan="3">&nbsp;</td></tr>
6
+ </tfoot></table>|
7
+
8
+ module DisplayFor
9
+ module Builder
10
+ describe Table, :focus => true do
11
+ context 'when given a footer' do
12
+ subject :table do
13
+ Table.new(TestModel, [TestModel.new(1, 'foo', 'bar')], {}, TestTemplate.new) do |t|
14
+ t.attribute :id
15
+ t.attribute :first_name
16
+ t.attribute :last_name
17
+ t.footer do |f|
18
+ f.html :form, :html => { :colspan => 3 } do
19
+ '&nbsp;'.html_safe
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '#to_s' do
26
+ it 'renders the table' do
27
+ table.to_s.should eq(OUTPUT)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'action_view'
5
+ require 'display_for'
6
+
7
+ Dir['./spec/support/**/*.rb'].each {|f| require f }
8
+
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+ config.order = 'random'
14
+ end
@@ -0,0 +1,5 @@
1
+ class TestModel < Struct.new(:id, :first_name, :last_name)
2
+ def self.human_attribute_name(string)
3
+ string
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class TestTemplate
2
+ include ActionView::Helpers::TagHelper
3
+
4
+ attr_accessor :output_buffer
5
+
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: display_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-13 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -116,6 +116,7 @@ extra_rdoc_files:
116
116
  - README.rdoc
117
117
  files:
118
118
  - .document
119
+ - .rspec
119
120
  - Gemfile
120
121
  - Gemfile.lock
121
122
  - LICENSE.txt
@@ -137,8 +138,10 @@ files:
137
138
  - lib/display_for/element/base.rb
138
139
  - lib/display_for/element/html.rb
139
140
  - lib/display_for/helper.rb
140
- - test/helper.rb
141
- - test/test_display_for.rb
141
+ - spec/lib/builder/table_spec.rb
142
+ - spec/spec_helper.rb
143
+ - spec/support/test_model.rb
144
+ - spec/support/test_template.rb
142
145
  homepage: http://github.com/mateomurphy/display_for
143
146
  licenses:
144
147
  - MIT
@@ -154,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
157
  version: '0'
155
158
  segments:
156
159
  - 0
157
- hash: 3084550570020739390
160
+ hash: -3711101849509490407
158
161
  required_rubygems_version: !ruby/object:Gem::Requirement
159
162
  none: false
160
163
  requirements:
data/test/helper.rb DELETED
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- $LOAD_PATH.unshift(File.dirname(__FILE__))
15
- require 'display_for'
16
-
17
- class Test::Unit::TestCase
18
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestDisplayFor < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end