extra_doilies 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +24 -0
- data/Rakefile +1 -0
- data/extra_doilies.gemspec +28 -0
- data/lib/extra_doilies.rb +14 -0
- data/lib/extra_doilies/counter_column.rb +10 -0
- data/lib/extra_doilies/linked_association_column.rb +12 -0
- data/lib/extra_doilies/linked_column.rb +5 -0
- data/lib/extra_doilies/version.rb +3 -0
- data/spec/counter_column_spec.rb +10 -0
- data/spec/fixtures.rb +42 -0
- data/spec/linked_association_column_spec.rb +22 -0
- data/spec/linked_column_spec.rb +11 -0
- data/spec/spec_helper.rb +16 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c150a90ea3e1ef4dde160d6bbcf3f4394e17e898
|
4
|
+
data.tar.gz: e60da0e086c945ba9c33d2bb21aa2dbe65a4c476
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 03b089521c361c0df667ca25ba4f5def1e80b87de5a8236e55d1f9a01e659534059da229295f4b97d573a066eadcc7eed368f0919dba3b9cfe40e6b1ef824ba2
|
7
|
+
data.tar.gz: 9d6213b9030146680e8e5d6f64b28901b0b5507eb6329a89b9e37dded8935affc12b8e3f5b19ddd0967f51d4c30023957048fb9999320c4144d3b2f1bbb218a4
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sam Schenkman-Moore
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# ExtraDoilies
|
2
|
+
|
3
|
+
I really like [table cloth](https://github.com/bobbytables/table_cloth).
|
4
|
+
|
5
|
+
This project is some extra stuff for table_cloth.
|
6
|
+
|
7
|
+
`gem 'extra_doilies'` gets you:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class BookTable < TableCloth::Base
|
11
|
+
column :"#", using: ExtraDoilies::CounterColumn
|
12
|
+
column :title, using: ExtraDoilies::LinkedColumn
|
13
|
+
column :author, using: ExtraDoilies::LinkedAssociationColumn
|
14
|
+
```
|
15
|
+
|
16
|
+
This will get you a numbered column, a title column (linked to the ActiveModel object), and a column for author, with links to that author. Woo!
|
17
|
+
|
18
|
+
## Contributing
|
19
|
+
|
20
|
+
1. Fork it
|
21
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
22
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
23
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
24
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'extra_doilies/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "extra_doilies"
|
8
|
+
spec.version = ExtraDoilies::VERSION
|
9
|
+
spec.authors = ["Sam Schenkman-Moore"]
|
10
|
+
spec.email = ["samsm@samsm.com"]
|
11
|
+
spec.description = %q{Extra columns for use with the gem table_cloth.}
|
12
|
+
spec.summary = %q{Extras for table_cloth}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "table_cloth"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "actionpack"
|
27
|
+
spec.add_development_dependency "activemodel"
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "extra_doilies/version"
|
2
|
+
require "table_cloth"
|
3
|
+
module ExtraDoilies
|
4
|
+
# autoload all the .rb in filters under this namespace
|
5
|
+
def self.library_files
|
6
|
+
Dir.glob("#{File.dirname(__FILE__)}/extra_doilies/*.rb")
|
7
|
+
end
|
8
|
+
def self.file_name_to_class_name(filename)
|
9
|
+
File.basename(filename, '.*').split('_').collect(&:capitalize).join.to_sym
|
10
|
+
end
|
11
|
+
library_files.each do |filename|
|
12
|
+
autoload file_name_to_class_name(filename), filename
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class ExtraDoilies::LinkedAssociationColumn < TableCloth::Column
|
2
|
+
def initialize(name, options ={})
|
3
|
+
@association_accessor = options[:association_accessor] || :name
|
4
|
+
super(name,options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def value(object, view, table=nil)
|
8
|
+
view.link_to object.send(name).send(association_accessor), object.send(name)
|
9
|
+
end
|
10
|
+
private
|
11
|
+
attr_reader :association_accessor
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe ExtraDoilies::CounterColumn do
|
4
|
+
let(:counter) { ExtraDoilies::CounterColumn.new(name, options) }
|
5
|
+
|
6
|
+
it "counts up" do
|
7
|
+
expect(counter.value(object,view)).to eq(1)
|
8
|
+
expect(counter.value(object,view)).to eq(2)
|
9
|
+
end
|
10
|
+
end
|
data/spec/fixtures.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "pry-debugger"
|
2
|
+
require "active_model"
|
3
|
+
module Fixtures
|
4
|
+
def name
|
5
|
+
:name
|
6
|
+
end
|
7
|
+
|
8
|
+
def options
|
9
|
+
{}
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_object_class(accessor = :name)
|
13
|
+
@test_object_class ||= Struct.new(accessor) do
|
14
|
+
extend ActiveModel::Naming
|
15
|
+
def self.name
|
16
|
+
"TestObject"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def object
|
22
|
+
@object ||= test_object_class.new "test name"
|
23
|
+
end
|
24
|
+
|
25
|
+
def view
|
26
|
+
require 'action_dispatch/routing/polymorphic_routes'
|
27
|
+
@view_model ||= Class.new do
|
28
|
+
include ActionView::Helpers::UrlHelper
|
29
|
+
include ActionView::RoutingUrlFor
|
30
|
+
include ActionDispatch::Routing::PolymorphicRoutes
|
31
|
+
def test_object_path(*args)
|
32
|
+
obj = args.first
|
33
|
+
"/#{obj.send(obj.members.first)}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
@view ||= @view_model.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def table
|
40
|
+
Object.new
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe ExtraDoilies::LinkedAssociationColumn do
|
4
|
+
let(:linked) { ExtraDoilies::LinkedAssociationColumn.new(:association, options) }
|
5
|
+
let(:with_association) { Struct.new(:association).new(object) }
|
6
|
+
|
7
|
+
it "links object" do
|
8
|
+
link = linked.value(with_association,view)
|
9
|
+
expect(link).to match(%{<a href="/#{object.name}"})
|
10
|
+
expect(link).to match(%r{>#{object.name}<})
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with a non-default accessor" do
|
14
|
+
let(:options) { { association_accessor: :custom } }
|
15
|
+
let(:object) { test_object_class(:custom).new("custom accessor") }
|
16
|
+
it "links object" do
|
17
|
+
link = linked.value(with_association,view)
|
18
|
+
expect(link).to match(%{<a href="/#{object.custom}"})
|
19
|
+
expect(link).to match(%r{>#{object.custom}<})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe ExtraDoilies::LinkedColumn do
|
4
|
+
let(:linked) { ExtraDoilies::LinkedColumn.new(name, options) }
|
5
|
+
|
6
|
+
it "links object" do
|
7
|
+
link = linked.value(object,view)
|
8
|
+
expect(link).to match(%{<a href="/#{object.name}"})
|
9
|
+
expect(link).to match(%r{>#{object.name}<})
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "fixtures"
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
5
|
+
config.run_all_when_everything_filtered = true
|
6
|
+
config.filter_run :focus
|
7
|
+
config.include Fixtures
|
8
|
+
|
9
|
+
# Run specs in random order to surface order dependencies. If you find an
|
10
|
+
# order dependency and want to debug it, you can fix the order by providing
|
11
|
+
# the seed, which is printed after each run.
|
12
|
+
# --seed 1234
|
13
|
+
config.order = 'random'
|
14
|
+
end
|
15
|
+
|
16
|
+
require_relative "../lib/extra_doilies"
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: extra_doilies
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Schenkman-Moore
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: table_cloth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: actionpack
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activemodel
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Extra columns for use with the gem table_cloth.
|
98
|
+
email:
|
99
|
+
- samsm@samsm.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- extra_doilies.gemspec
|
111
|
+
- lib/extra_doilies.rb
|
112
|
+
- lib/extra_doilies/counter_column.rb
|
113
|
+
- lib/extra_doilies/linked_association_column.rb
|
114
|
+
- lib/extra_doilies/linked_column.rb
|
115
|
+
- lib/extra_doilies/version.rb
|
116
|
+
- spec/counter_column_spec.rb
|
117
|
+
- spec/fixtures.rb
|
118
|
+
- spec/linked_association_column_spec.rb
|
119
|
+
- spec/linked_column_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
homepage: ''
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.0.6
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Extras for table_cloth
|
145
|
+
test_files:
|
146
|
+
- spec/counter_column_spec.rb
|
147
|
+
- spec/fixtures.rb
|
148
|
+
- spec/linked_association_column_spec.rb
|
149
|
+
- spec/linked_column_spec.rb
|
150
|
+
- spec/spec_helper.rb
|