display_for 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :test, :development do
9
+ gem "rails", "~> 3.2.8"
10
+ gem 'rspec', '>=0'
11
+ gem "rdoc", "~> 3.12"
12
+ gem "bundler", "~> 1.1.0"
13
+ gem "jeweler", "~> 1.8.3"
14
+ gem "simplecov"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,109 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.8)
5
+ actionpack (= 3.2.8)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.8)
8
+ activemodel (= 3.2.8)
9
+ activesupport (= 3.2.8)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.3)
17
+ activemodel (3.2.8)
18
+ activesupport (= 3.2.8)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.8)
21
+ activemodel (= 3.2.8)
22
+ activesupport (= 3.2.8)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.8)
26
+ activemodel (= 3.2.8)
27
+ activesupport (= 3.2.8)
28
+ activesupport (3.2.8)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.0)
33
+ diff-lcs (1.1.3)
34
+ erubis (2.7.0)
35
+ git (1.2.5)
36
+ hike (1.2.1)
37
+ i18n (0.6.0)
38
+ jeweler (1.8.4)
39
+ bundler (~> 1.0)
40
+ git (>= 1.2.5)
41
+ rake
42
+ rdoc
43
+ journey (1.0.4)
44
+ json (1.7.4)
45
+ mail (2.4.4)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.19)
50
+ multi_json (1.3.6)
51
+ polyglot (0.3.3)
52
+ rack (1.4.1)
53
+ rack-cache (1.2)
54
+ rack (>= 0.4)
55
+ rack-ssl (1.3.2)
56
+ rack
57
+ rack-test (0.6.1)
58
+ rack (>= 1.0)
59
+ rails (3.2.8)
60
+ actionmailer (= 3.2.8)
61
+ actionpack (= 3.2.8)
62
+ activerecord (= 3.2.8)
63
+ activeresource (= 3.2.8)
64
+ activesupport (= 3.2.8)
65
+ bundler (~> 1.0)
66
+ railties (= 3.2.8)
67
+ railties (3.2.8)
68
+ actionpack (= 3.2.8)
69
+ activesupport (= 3.2.8)
70
+ rack-ssl (~> 1.3.2)
71
+ rake (>= 0.8.7)
72
+ rdoc (~> 3.4)
73
+ thor (>= 0.14.6, < 2.0)
74
+ rake (0.9.2.2)
75
+ rdoc (3.12)
76
+ json (~> 1.4)
77
+ rspec (2.11.0)
78
+ rspec-core (~> 2.11.0)
79
+ rspec-expectations (~> 2.11.0)
80
+ rspec-mocks (~> 2.11.0)
81
+ rspec-core (2.11.1)
82
+ rspec-expectations (2.11.2)
83
+ diff-lcs (~> 1.1.3)
84
+ rspec-mocks (2.11.2)
85
+ simplecov (0.6.4)
86
+ multi_json (~> 1.0)
87
+ simplecov-html (~> 0.5.3)
88
+ simplecov-html (0.5.3)
89
+ sprockets (2.1.3)
90
+ hike (~> 1.2)
91
+ rack (~> 1.0)
92
+ tilt (~> 1.1, != 1.3.0)
93
+ thor (0.15.4)
94
+ tilt (1.3.3)
95
+ treetop (1.4.10)
96
+ polyglot
97
+ polyglot (>= 0.3.1)
98
+ tzinfo (0.3.33)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ bundler (~> 1.1.0)
105
+ jeweler (~> 1.8.3)
106
+ rails (~> 3.2.8)
107
+ rdoc (~> 3.12)
108
+ rspec
109
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Mateo Murphy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = display_for
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to display_for
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Mateo Murphy. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "display_for"
18
+ gem.homepage = "http://github.com/mateomurphy/display_for"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Rails library for displaying data}
21
+ gem.description = %Q{A Rails library for display data, in tabular and other formats}
22
+ gem.email = "mateo.murphy@gmail.com"
23
+ gem.authors = ["Mateo Murphy"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
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
+ task :default => :test
46
+
47
+ require 'rdoc/task'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "display_for #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
@@ -0,0 +1,78 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "display_for"
8
+ s.version = "0.1.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mateo Murphy"]
12
+ s.date = "2012-08-12"
13
+ s.description = "A Rails library for display data, in tabular and other formats"
14
+ s.email = "mateo.murphy@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "display_for.gemspec",
28
+ "lib/display_for.rb",
29
+ "lib/display_for/builder.rb",
30
+ "lib/display_for/builder/base.rb",
31
+ "lib/display_for/builder/collection_base.rb",
32
+ "lib/display_for/builder/csv.rb",
33
+ "lib/display_for/builder/resource_base.rb",
34
+ "lib/display_for/builder/table.rb",
35
+ "lib/display_for/builder/view.rb",
36
+ "lib/display_for/element.rb",
37
+ "lib/display_for/element/action.rb",
38
+ "lib/display_for/element/attribute.rb",
39
+ "lib/display_for/element/base.rb",
40
+ "lib/display_for/element/html.rb",
41
+ "lib/display_for/helper.rb",
42
+ "test/helper.rb",
43
+ "test/test_display_for.rb"
44
+ ]
45
+ s.homepage = "http://github.com/mateomurphy/display_for"
46
+ s.licenses = ["MIT"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = "1.8.24"
49
+ s.summary = "Rails library for displaying data"
50
+
51
+ if s.respond_to? :specification_version then
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_development_dependency(%q<rails>, ["~> 3.2.8"])
56
+ s.add_development_dependency(%q<rspec>, [">= 0"])
57
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
59
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
60
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
61
+ else
62
+ s.add_dependency(%q<rails>, ["~> 3.2.8"])
63
+ s.add_dependency(%q<rspec>, [">= 0"])
64
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
67
+ s.add_dependency(%q<simplecov>, [">= 0"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<rails>, ["~> 3.2.8"])
71
+ s.add_dependency(%q<rspec>, [">= 0"])
72
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
73
+ s.add_dependency(%q<bundler>, ["~> 1.1.0"])
74
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
75
+ s.add_dependency(%q<simplecov>, [">= 0"])
76
+ end
77
+ end
78
+
@@ -0,0 +1,33 @@
1
+ module DisplayFor
2
+ module Builder
3
+ class Base
4
+ attr_reader :template, :namespace, :resource_class, :html_options
5
+
6
+ delegate :content_tag, :cycle, :to => :template
7
+
8
+ def initialize(html_options, template, &block)
9
+ @template = template
10
+ @attributes = []
11
+ @actions = []
12
+ @html_options = html_options
13
+
14
+ raise "invalid resource class #{resource_class}" unless resource_class.respond_to?(:human_attribute_name)
15
+
16
+ block.call(self)
17
+ end
18
+
19
+ def attribute(name, options = {}, &block)
20
+ @attributes << Element::Attribute.new(self, name, options, &block)
21
+ end
22
+
23
+ def action(name, options = {}, &block)
24
+ @actions << Element::Action.new(self, name, options, &block)
25
+ end
26
+
27
+ def html(name, options = {}, &block)
28
+ @attributes << Element::Html.new(self, name, options, &block)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ module DisplayFor
2
+ module Builder
3
+ class CollectionBase < Base
4
+ attr_reader :collection
5
+
6
+ def initialize(resource_class, collection, html_options, template, &block)
7
+ @collection = collection
8
+
9
+ if resource_class.is_a?(Array)
10
+ @namespace = resource_class
11
+ @resource_class = @namespace.pop
12
+ else
13
+ @namespace = []
14
+ @resource_class = resource_class
15
+ end
16
+
17
+ super(html_options, template, &block)
18
+ end
19
+
20
+ def default_actions
21
+ action :show
22
+ action :edit, :link_to => lambda { |r| [:edit] + @namespace + [r] }
23
+ action :delete, :method => :delete, :confirm => "Are you sure?"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ module DisplayFor
2
+ module Builder
3
+ class Csv < CollectionBase
4
+
5
+ def build_header
6
+ @attributes.map { |attribute| quote(attribute.label(@resource_class)) }.join(',').html_safe
7
+ end
8
+
9
+ def build_row(resource)
10
+ @attributes.map { |attribute| quote(attribute.content(resource)) }.join(',').html_safe
11
+ end
12
+
13
+ def build_actions(resource)
14
+ nil
15
+ end
16
+
17
+ def quote(string)
18
+ "\"#{string.gsub('"', '""')}\"".html_safe
19
+ end
20
+
21
+ def to_s
22
+ result = [build_header]
23
+
24
+ @collection.each do |resource|
25
+ result << build_row(resource)
26
+ end
27
+
28
+ result.join("\n").html_safe
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ module DisplayFor
2
+ module Builder
3
+ class ResourceBase < Base
4
+ attr_reader :resource
5
+
6
+ def initialize(resource, html_options, template, &block)
7
+ if resource.is_a?(Array)
8
+ @namespace = resource
9
+ @resource = @namespace.pop
10
+ else
11
+ @namespace = []
12
+ @resource = resource
13
+ end
14
+
15
+ @resource_class = @resource.class
16
+
17
+ super(html_options, template, &block)
18
+ end
19
+
20
+ def default_actions
21
+ action :list, :link_to => lambda { |r| @namespace + [@resource_class]}, :class => 'btn btn-small'
22
+ action :edit, :link_to => lambda { |r| [:edit] + @namespace + [r] }, :class => 'btn btn-small'
23
+ action :delete, :method => :delete, :confirm => "Are you sure?", :class => 'btn btn-small btn-danger'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,48 @@
1
+ module DisplayFor
2
+ module Builder
3
+ class Table < CollectionBase
4
+ def build_header
5
+ result = ''
6
+ @attributes.each do |attribute|
7
+ result << content_tag(:th, attribute.label(@resource_class), :class => "#{@resource_class}_#{attribute.name}".underscore)
8
+ end
9
+ result << content_tag(:th, "Actions", :class => 'actions') if @actions.any?
10
+
11
+ content_tag(:thead, content_tag(:tr, result.html_safe)) << "\n"
12
+ end
13
+
14
+ def build_row(resource)
15
+ result = ''
16
+ @attributes.each do |attribute|
17
+ result << content_tag(:td, attribute.content(resource))
18
+ end
19
+ result << content_tag(:td, build_actions(resource)) if @actions.any?
20
+
21
+ content_tag(:tr, result.html_safe, :id => "#{@resource_class}_#{resource.id}".underscore) << "\n"
22
+ end
23
+
24
+ def build_actions(resource)
25
+ result = []
26
+
27
+ @actions.each do |action|
28
+ result << action.content(resource)
29
+ end
30
+
31
+ result.join("&nbsp;").html_safe
32
+ end
33
+
34
+ def to_s
35
+ result = ''.html_safe
36
+
37
+ @collection.each do |resource|
38
+ result << build_row(resource)
39
+ end
40
+
41
+ result = build_header + content_tag(:tbody, result)
42
+
43
+ html_options[:class] = "table table-bordered table-striped #{@resource_class.to_s.underscore}"
44
+ content_tag(:table, result, html_options).html_safe
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,49 @@
1
+ module DisplayFor
2
+ module Builder
3
+ class View < ResourceBase
4
+ attr_reader :template
5
+
6
+ def build_header
7
+ result = ''
8
+
9
+ result << content_tag(:th, "Attribute")
10
+ result << content_tag(:th, "Value")
11
+
12
+ content_tag(:thead, content_tag(:tr, result.html_safe)) << "\n"
13
+ end
14
+
15
+ def build_row(attribute)
16
+ result = ''.html_safe
17
+ result << content_tag(:th, attribute.label(resource_class))
18
+ result << content_tag(:td, attribute.content(resource))
19
+ content_tag(:tr, result.html_safe)
20
+ end
21
+
22
+ def build_actions
23
+ result = []
24
+
25
+ @actions.each do |action|
26
+ result << action.content(resource)
27
+ end
28
+
29
+ content_tag(:tr) do
30
+ content_tag(:td, result.join("&nbsp;").html_safe, :colspan => 2)
31
+ end
32
+
33
+ end
34
+
35
+ def to_s
36
+ result = build_header
37
+
38
+ @attributes.each do |attribute|
39
+ result << build_row(attribute)
40
+ end
41
+
42
+ result << build_actions
43
+
44
+ html_options[:class] = "table table-bordered table-striped #{@resource_class.to_s.underscore}"
45
+ content_tag(:table, result, html_options).html_safe
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,10 @@
1
+ module DisplayFor
2
+ module Builder
3
+ autoload :Base, 'display_for/builder/base'
4
+ autoload :CollectionBase, 'display_for/builder/collection_base'
5
+ autoload :Csv, 'display_for/builder/csv'
6
+ autoload :ResourceBase, 'display_for/builder/resource_base'
7
+ autoload :Table, 'display_for/builder/table'
8
+ autoload :View, 'display_for/builder/view'
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module DisplayFor
2
+ module Element
3
+ class Action < Base
4
+ def content(resource)
5
+ super || link_to(label, resource)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,43 @@
1
+ module DisplayFor
2
+ module Element
3
+ class Attribute < Base
4
+ def default_label(resource_class)
5
+ resource_class.human_attribute_name(@name.to_s)
6
+ end
7
+
8
+ def content(resource)
9
+ if @block
10
+ @block.call(resource)
11
+ else
12
+ value(resource)
13
+ end
14
+ end
15
+
16
+ def value(resource)
17
+ raise "#{resource.class} does not respond to #{@name}" unless resource.respond_to?(@name)
18
+
19
+ result = resource.send(@name)
20
+
21
+ if @options[:type]
22
+ if @options[:type] == :html
23
+ result = result.html_safe
24
+ else
25
+ result = template.send(:"number_to_#{@options[:type]}", result)
26
+ end
27
+ end
28
+
29
+ if [Date, DateTime, Time].include?(result.class) && @options[:format]
30
+ result = template.l(result, :format => @options[:format])
31
+ end
32
+
33
+ result = link_to(result, resource) if @options[:link_to]
34
+ result.to_s
35
+ end
36
+
37
+ def template
38
+ @builder.template
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,52 @@
1
+ module DisplayFor
2
+ module Element
3
+ class Base
4
+ attr_reader :name
5
+
6
+ def initialize(builder, name, options = {}, &block)
7
+ @builder, @name, @options, @block = builder, name, options, block
8
+ end
9
+
10
+ def label(resource_class = nil)
11
+ return nil if @options[:label] === false
12
+
13
+ name = @options[:label] || @name.to_sym
14
+
15
+ return name unless name.is_a?(Symbol)
16
+
17
+ I18n.t(name, :scope => 'display_for.labels', :default => default_label(resource_class) )
18
+ end
19
+
20
+ def default_label(resource_classs = nil)
21
+ @name.to_s.humanize
22
+ end
23
+
24
+ def content(resource)
25
+ if @block
26
+ @block.call(resource)
27
+ else
28
+ nil
29
+ end
30
+ end
31
+
32
+ def link_to(string, resource, html_options = {})
33
+ url = if @options[:link_to].respond_to?(:call)
34
+ @options[:link_to].call(resource)
35
+ elsif @options[:link_to].is_a?(Symbol)
36
+ @builder.template.send(@options[:link_to], resource)
37
+ else
38
+ @builder.namespace + [resource]
39
+ end
40
+
41
+ return nil unless url
42
+
43
+ html_options[:method] ||= @options[:method]
44
+ html_options[:confirm] ||= @options[:confirm]
45
+ html_options[:remote] ||= @options[:remote]
46
+ html_options[:class] ||= @options[:class]
47
+
48
+ @builder.template.link_to(string, url, html_options)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,11 @@
1
+ module DisplayFor
2
+ module Element
3
+ class Html < Base
4
+
5
+ def content(resource)
6
+ @builder.template.capture(resource, &@block)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module DisplayFor
2
+ module Element
3
+ autoload :Action, 'display_for/element/action'
4
+ autoload :Attribute, 'display_for/element/attribute'
5
+ autoload :Base, 'display_for/element/base'
6
+ autoload :Html, 'display_for/element/html'
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module DisplayFor
2
+ module Helper
3
+ def table_for(resource_class, collection, html_options={}, &block)
4
+ Builder::Table.new(resource_class, collection, html_options, self, &block).to_s
5
+ end
6
+
7
+ def view_for(resource, html_options={}, &block)
8
+ Builder::View.new(resource, html_options, self, &block).to_s
9
+ end
10
+
11
+ def csv_for(resource_class, collection, html_options={}, &block)
12
+ Builder::Csv.new(resource_class, collection, html_options, self, &block).to_s
13
+ end
14
+ end
15
+ end
16
+
17
+ ActionView::Base.send :include, DisplayFor::Helper
@@ -0,0 +1,6 @@
1
+ require 'display_for/helper'
2
+
3
+ module DisplayFor
4
+ autoload :Builder, 'display_for/builder'
5
+ autoload :Element, 'display_for/element'
6
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,7 @@
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
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: display_for
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mateo Murphy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.8
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.8
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.1.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.1.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.3
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.3
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: A Rails library for display data, in tabular and other formats
111
+ email: mateo.murphy@gmail.com
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files:
115
+ - LICENSE.txt
116
+ - README.rdoc
117
+ files:
118
+ - .document
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE.txt
122
+ - README.rdoc
123
+ - Rakefile
124
+ - VERSION
125
+ - display_for.gemspec
126
+ - lib/display_for.rb
127
+ - lib/display_for/builder.rb
128
+ - lib/display_for/builder/base.rb
129
+ - lib/display_for/builder/collection_base.rb
130
+ - lib/display_for/builder/csv.rb
131
+ - lib/display_for/builder/resource_base.rb
132
+ - lib/display_for/builder/table.rb
133
+ - lib/display_for/builder/view.rb
134
+ - lib/display_for/element.rb
135
+ - lib/display_for/element/action.rb
136
+ - lib/display_for/element/attribute.rb
137
+ - lib/display_for/element/base.rb
138
+ - lib/display_for/element/html.rb
139
+ - lib/display_for/helper.rb
140
+ - test/helper.rb
141
+ - test/test_display_for.rb
142
+ homepage: http://github.com/mateomurphy/display_for
143
+ licenses:
144
+ - MIT
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ segments:
156
+ - 0
157
+ hash: -4404602922498023565
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 1.8.24
167
+ signing_key:
168
+ specification_version: 3
169
+ summary: Rails library for displaying data
170
+ test_files: []