ez_table 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/Gemfile +27 -0
- data/MIT-LICENSE +20 -0
- data/README.md +69 -0
- data/Rakefile +15 -0
- data/easy_table.gemspec +28 -0
- data/lib/easy_table.rb +21 -0
- data/lib/easy_table/action_column.rb +17 -0
- data/lib/easy_table/action_view_extension.rb +18 -0
- data/lib/easy_table/base.rb +48 -0
- data/lib/easy_table/builder.rb +10 -0
- data/lib/easy_table/column.rb +34 -0
- data/lib/easy_table/config.rb +9 -0
- data/lib/easy_table/engine.rb +10 -0
- data/lib/easy_table/presenter.rb +47 -0
- data/lib/easy_table/version.rb +3 -0
- data/lib/ez_table.rb +1 -0
- data/lib/generators/easy_table/install_generator.rb +16 -0
- data/lib/generators/templates/easy_table.rb +5 -0
- data/lib/generators/templates/scaffold/index.html.slim +14 -0
- data/lib/tasks/easy_table_tasks.rake +4 -0
- data/spec/generators/install_generator_spec.rb +17 -0
- data/spec/lib/action_view_extension_spec.rb +14 -0
- data/spec/lib/base_spec.rb +22 -0
- data/spec/lib/builder_spec.rb +74 -0
- data/spec/lib/column_spec.rb +27 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/support/dummy_models.rb +7 -0
- data/spec/support/matchers.rb +17 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7de5ef863145742e5635667d51d6108f5537570a
|
4
|
+
data.tar.gz: 03f1a79c60610b2fb767d93c534252cd81db53c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e3943057438cd38b12bea839980fcc814a2f9431fadf521b93d05cf9d3b97898cfa5dcf5debff9bdc47f51481875d9115e461a95380deac984e135ed919e42f
|
7
|
+
data.tar.gz: 94f4d065a51995dcb5d1f0116af5ca0edeed8898b86b91979bc0f246031880519eb14f6712bf526117aa6f6126e5cdc05217b617abafea0299f956fe443f8451
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
source "http://ruby.taobao.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in easy_table.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'debugger'
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem 'nokogiri'
|
18
|
+
gem 'pry'
|
19
|
+
gem 'pry-debugger'
|
20
|
+
gem 'ammeter'
|
21
|
+
|
22
|
+
#gem 'rspec-rails'
|
23
|
+
gem 'rspec'
|
24
|
+
gem 'slim-rails'
|
25
|
+
gem 'capybara'
|
26
|
+
gem 'hashie'
|
27
|
+
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
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.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
EasyTable
|
2
|
+
===============
|
3
|
+
|
4
|
+
This project rocks and uses MIT-LICENSE.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
===============
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'nie_easy_table', require: 'easy_table'
|
11
|
+
```
|
12
|
+
|
13
|
+
Usage
|
14
|
+
===============
|
15
|
+
|
16
|
+
Run the generator:
|
17
|
+
|
18
|
+
```console
|
19
|
+
rails g easy_table:install
|
20
|
+
```
|
21
|
+
|
22
|
+
this will create a initializer file named `easy_table.rb`, which you can
|
23
|
+
config some html option for your table
|
24
|
+
also `lib/templates/slim/scaffold/index.html.slim` will be created, you
|
25
|
+
can modify it to adapt your app
|
26
|
+
|
27
|
+
To Start using `easy_table`, you just have to use the easy_table_for helper
|
28
|
+
|
29
|
+
```slim
|
30
|
+
= easy_table_for(@users) do |t|
|
31
|
+
- t.td :id
|
32
|
+
- t.td :name, header: 'user name'
|
33
|
+
- t.action do |user|
|
34
|
+
= link_to "View User", user_path(user)
|
35
|
+
```
|
36
|
+
|
37
|
+
You can custom the td(column) output with a block,
|
38
|
+
|
39
|
+
```slim
|
40
|
+
- t.td(:name) { |user| "Hello #{user.name}"}
|
41
|
+
```
|
42
|
+
|
43
|
+
You can provide a model_class option for `easy_table_for` helper,
|
44
|
+
|
45
|
+
```
|
46
|
+
= easy_table_for(@users , model_class: User)
|
47
|
+
```
|
48
|
+
|
49
|
+
then the table header will using User.human_attribute_name(attr) for
|
50
|
+
output
|
51
|
+
|
52
|
+
if the current controller is UsersController, the model_class can be
|
53
|
+
omitted.
|
54
|
+
|
55
|
+
|
56
|
+
TODO
|
57
|
+
===============
|
58
|
+
|
59
|
+
- [x] I18n header
|
60
|
+
- [x] custom header using options
|
61
|
+
- [x] guess model_class from current controller
|
62
|
+
- [x] guess model_class from current controller, with namespace
|
63
|
+
- [x] custom column using block
|
64
|
+
- [ ] custom column using class
|
65
|
+
- [x] add action column
|
66
|
+
- [x] specify multiple columns using :tds
|
67
|
+
- [x] config for action_column
|
68
|
+
- [ ] config options for single column
|
69
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
6
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
10
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
11
|
+
spec.rcov = true
|
12
|
+
end
|
13
|
+
|
14
|
+
task :spec
|
15
|
+
task :default => :spec
|
data/easy_table.gemspec
ADDED
@@ -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
|
+
|
5
|
+
# Maintain your gem's version:
|
6
|
+
require "easy_table/version"
|
7
|
+
|
8
|
+
# Describe your gem and declare its dependencies:
|
9
|
+
Gem::Specification.new do |s|
|
10
|
+
s.name = "ez_table"
|
11
|
+
s.version = EasyTable::VERSION
|
12
|
+
s.authors = ["Dianhui Nie"]
|
13
|
+
s.email = ["niedhui@gmail.com"]
|
14
|
+
s.homepage = "http://github.com/niedhui/ez_table"
|
15
|
+
s.summary = "Create Table easily"
|
16
|
+
s.description = "Create Table easily for Rails app"
|
17
|
+
s.license = "MIT"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split($/)
|
20
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
|
24
|
+
|
25
|
+
s.add_dependency "rails", "> 3.0.0"
|
26
|
+
|
27
|
+
s.add_development_dependency "sqlite3"
|
28
|
+
end
|
data/lib/easy_table.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
require 'rails/generators'
|
4
|
+
module EasyTable
|
5
|
+
autoload :Config, 'easy_table/config'
|
6
|
+
autoload :ActionViewExtension, 'easy_table/action_view_extension'
|
7
|
+
autoload :Builder, 'easy_table/builder'
|
8
|
+
autoload :Base, 'easy_table/base'
|
9
|
+
autoload :Column, 'easy_table/column'
|
10
|
+
autoload :ActionColumn , 'easy_table/action_column'
|
11
|
+
|
12
|
+
autoload :Presenter, 'easy_table/presenter'
|
13
|
+
|
14
|
+
def self.config
|
15
|
+
EasyTable::Config
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
EZTable = EasyTable
|
20
|
+
|
21
|
+
require 'easy_table/engine'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module EasyTable
|
2
|
+
module ActionViewExtension
|
3
|
+
def easy_table_for(objects, options = {})
|
4
|
+
options[:model_class] ||= guess_model_class
|
5
|
+
|
6
|
+
EasyTable::Builder.build(objects, self, options) do |table|
|
7
|
+
yield table if block_given?
|
8
|
+
end.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
# TODO: support namespace
|
12
|
+
def guess_model_class
|
13
|
+
controller_name.classify.constantize
|
14
|
+
rescue
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module EasyTable
|
2
|
+
class Base
|
3
|
+
attr_reader :columns, :items, :options, :model_class, :action_columns
|
4
|
+
attr_accessor :presenter
|
5
|
+
|
6
|
+
delegate :render, to: :presenter
|
7
|
+
|
8
|
+
# options:
|
9
|
+
# model_class: the class of the model, used for i18n, using with the human_attribute_name
|
10
|
+
def initialize(items, options = {})
|
11
|
+
@items = items
|
12
|
+
@options = options
|
13
|
+
@columns = []
|
14
|
+
@action_columns = []
|
15
|
+
process_options
|
16
|
+
end
|
17
|
+
|
18
|
+
def tds(*names)
|
19
|
+
names.each { |name| td(name) }
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO: spec & doc for using option
|
23
|
+
def td(name, options = {}, &block)
|
24
|
+
column_class = options.delete(:using) || Column
|
25
|
+
@columns << column_class.new(name, options, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def action(&block)
|
29
|
+
@action_columns << ActionColumn.new("", {}, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def all_columns
|
33
|
+
@all_columns ||= (columns + action_columns)
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_options
|
37
|
+
@model_class = options[:model_class] || NilModelClass.instance
|
38
|
+
end
|
39
|
+
|
40
|
+
class NilModelClass
|
41
|
+
include Singleton
|
42
|
+
def human_attribute_name(attribute)
|
43
|
+
attribute.to_s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module EasyTable
|
2
|
+
class Column
|
3
|
+
attr_reader :name, :options, :value_block
|
4
|
+
|
5
|
+
def initialize(name, options = {}, &block)
|
6
|
+
@name, @options, @value_block = name, options, block
|
7
|
+
end
|
8
|
+
|
9
|
+
def header(table, view)
|
10
|
+
if options[:header].present?
|
11
|
+
options[:header]
|
12
|
+
elsif table.model_class
|
13
|
+
table.model_class.human_attribute_name(name)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def th_html
|
18
|
+
options[:th_html] || Config.th_html
|
19
|
+
end
|
20
|
+
|
21
|
+
def td_html
|
22
|
+
options[:td_html] || Config.td_html
|
23
|
+
end
|
24
|
+
|
25
|
+
def value(item, view)
|
26
|
+
if value_block
|
27
|
+
view.capture(item, &value_block)
|
28
|
+
else
|
29
|
+
item.send(name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module EasyTable
|
2
|
+
class Presenter
|
3
|
+
attr_reader :view, :table
|
4
|
+
delegate :content_tag, to: :view
|
5
|
+
|
6
|
+
def initialize(table, view)
|
7
|
+
@table, @view = table, view
|
8
|
+
end
|
9
|
+
|
10
|
+
def render
|
11
|
+
content_tag("table", Config.table_html) do
|
12
|
+
trs = "".html_safe
|
13
|
+
trs += render_header
|
14
|
+
trs += render_body
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def render_header
|
19
|
+
content_tag("thead") do
|
20
|
+
content_tag("tr") do
|
21
|
+
ths = "".html_safe
|
22
|
+
table.all_columns.each do |column|
|
23
|
+
ths += content_tag("th", column.header(table, view), column.th_html)
|
24
|
+
end
|
25
|
+
ths
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def render_body
|
31
|
+
content_tag("tbody") do
|
32
|
+
tbodys = "".html_safe
|
33
|
+
table.items.each do |item|
|
34
|
+
tbodys += content_tag("tr") do
|
35
|
+
tds = "".html_safe
|
36
|
+
table.all_columns.each do |column|
|
37
|
+
tds += content_tag("td", column.value(item, view), column.td_html)
|
38
|
+
end
|
39
|
+
tds
|
40
|
+
end
|
41
|
+
end
|
42
|
+
tbodys
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/ez_table.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'easy_table'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module EasyTable
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < ::Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
desc "Create a easy_table initializer"
|
6
|
+
|
7
|
+
def copy_initializer
|
8
|
+
template "easy_table.rb", "config/initializers/easy_table.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_scaffold_template
|
12
|
+
copy_file "scaffold/index.html.slim", "lib/templates/slim/scaffold/index.html.slim"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
h1 Listing <%= plural_table_name %>
|
2
|
+
|
3
|
+
= easy_table_for <%= plural_table_name %> do |t|
|
4
|
+
<% attributes.each do |attribute| -%>
|
5
|
+
- t.td :<%= attribute.name %>
|
6
|
+
<% end -%>
|
7
|
+
- t.action do |<%= singular_table_name %>|
|
8
|
+
= link_to 'Show', <%= singular_table_name %>
|
9
|
+
= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>)
|
10
|
+
= link_to 'Destroy', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete
|
11
|
+
|
12
|
+
br
|
13
|
+
|
14
|
+
= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rails/version'
|
3
|
+
require 'generators/easy_table/install_generator'
|
4
|
+
require 'ammeter/init'
|
5
|
+
describe EasyTable::Generators::InstallGenerator do
|
6
|
+
|
7
|
+
before { run_generator }
|
8
|
+
|
9
|
+
it "generate config/initializers/easy_table.rb" do
|
10
|
+
File.read(file('config/initializers/easy_table.rb')).should =~ /EasyTable::Config.configure/
|
11
|
+
end
|
12
|
+
|
13
|
+
it "create index.html.slim on lib" do
|
14
|
+
File.read(file('lib/templates/slim/scaffold/index.html.slim')).should =~ /easy_table_for/
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module EasyTable
|
4
|
+
describe ActionViewExtension do
|
5
|
+
subject { ActionView::Base.new}
|
6
|
+
|
7
|
+
it { should respond_to :easy_table_for }
|
8
|
+
|
9
|
+
it " can render a table" do
|
10
|
+
subject.easy_table_for([]).should have_tag('table')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module EasyTable
|
3
|
+
describe Base do
|
4
|
+
subject { Base.new([]) }
|
5
|
+
|
6
|
+
context "tds" do
|
7
|
+
before { subject.tds :id, :name, :age}
|
8
|
+
|
9
|
+
it { should have(3).columns}
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
context "td" do
|
14
|
+
it "using custom Column class" do
|
15
|
+
IdColumn = Class.new(Column)
|
16
|
+
subject.td :id, using:IdColumn
|
17
|
+
subject.columns.first.should be_kind_of(IdColumn)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module EasyTable
|
3
|
+
describe Builder do
|
4
|
+
let(:view) { ActionView::Base.new }
|
5
|
+
let(:users) { [DummyUser.new(1,'jack')]}
|
6
|
+
|
7
|
+
subject do
|
8
|
+
view.easy_table_for(users) do |table|
|
9
|
+
table.td :id
|
10
|
+
table.td :name
|
11
|
+
table.action { |model| view.link_to("View #{model.name}", "")}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "table header" do
|
16
|
+
it { should have_xpath("//table/thead/tr/th[text()='id']")}
|
17
|
+
it { should have_xpath("//table/thead/tr/th[text()='name']")}
|
18
|
+
end
|
19
|
+
|
20
|
+
context "table body" do
|
21
|
+
it { should have(2).trs}
|
22
|
+
it { should have_xpath("//table/tbody/tr/td[text()='1']")}
|
23
|
+
it { should have_xpath("//table/tbody/tr/td[text()='jack']")}
|
24
|
+
end
|
25
|
+
|
26
|
+
context "table config" do
|
27
|
+
it { should have_tag("table.easy-table")}
|
28
|
+
it { should have_tag("th.action")}
|
29
|
+
end
|
30
|
+
|
31
|
+
context "no config for table" do
|
32
|
+
it "should have no class" do
|
33
|
+
Config.table_html = nil
|
34
|
+
Nokogiri::HTML(subject).at_css('table').attr(:class).should be_blank
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "i18n" do
|
39
|
+
|
40
|
+
|
41
|
+
context "table header" do
|
42
|
+
subject do
|
43
|
+
view.easy_table_for(users, model_class: DummyUser) do |table|
|
44
|
+
table.td :id
|
45
|
+
table.td :name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
it { should have_xpath("//table/thead/tr/th[text()='ID']")}
|
49
|
+
it { should have_xpath("//table/thead/tr/th[text()='名称']")}
|
50
|
+
end
|
51
|
+
|
52
|
+
context " guess model class using controller_name" do
|
53
|
+
before { view.stub(:controller_name).and_return('dummy_users') }
|
54
|
+
|
55
|
+
it { should have_xpath("//table/thead/tr/th[text()='ID']")}
|
56
|
+
it { should have_xpath("//table/thead/tr/th[text()='名称']")}
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context " custom column using block" do
|
62
|
+
subject do
|
63
|
+
view.easy_table_for(users) do |table|
|
64
|
+
table.td(:name) {|model| "Hi #{model.name}" }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
it { should have_xpath("//table/tbody/tr/td[text()='Hi jack']")}
|
68
|
+
end
|
69
|
+
|
70
|
+
context " action column" do
|
71
|
+
it { should have_xpath("//table/tbody/tr/td/a[text()='View jack']")}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
module EasyTable
|
4
|
+
describe Column do
|
5
|
+
let(:table) { Base.new([]) }
|
6
|
+
context "header" do
|
7
|
+
it "should ok if model_class is not exist" do
|
8
|
+
table = Base.new([])
|
9
|
+
column = Column.new(:name)
|
10
|
+
column.header(table, nil).should == 'name'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should using human attribute name" do
|
14
|
+
table = Base.new([], model_class: DummyUser)
|
15
|
+
column = Column.new(:name)
|
16
|
+
column.header(table, nil).should == '名称'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should using options header first" do
|
20
|
+
column = Column.new(:name, header: 'Name')
|
21
|
+
column.header(table, nil).should == 'Name'
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'easy_table'
|
2
|
+
require 'hashie'
|
3
|
+
#ENV["RAILS_ENV"] = "test"
|
4
|
+
|
5
|
+
#require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
6
|
+
#require 'rspec/rails'
|
7
|
+
#require 'capybara/rspec'
|
8
|
+
Dir['./spec/support/**/*.rb'].each {|f| require f }
|
9
|
+
#Rails.backtrace_cleaner.remove_silencers!
|
10
|
+
#Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
11
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
12
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
13
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
14
|
+
# loaded once.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
19
|
+
config.run_all_when_everything_filtered = true
|
20
|
+
config.filter_run :focus
|
21
|
+
|
22
|
+
config.before :each do
|
23
|
+
EasyTable::Engine.initializers.each(&:run)
|
24
|
+
EasyTable::Config.configure do |t_config|
|
25
|
+
t_config.table_html = { class: 'easy-table table table-bordered' }
|
26
|
+
t_config.action_th_html = { class: 'action' }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Run specs in random order to surface order dependencies. If you find an
|
31
|
+
# order dependency and want to debug it, you can fix the order by providing
|
32
|
+
# the seed, which is printed after each run.
|
33
|
+
# --seed 1234
|
34
|
+
config.order = 'random'
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
|
3
|
+
|
4
|
+
RSpec::Matchers.define :have_xpath do |xpath|
|
5
|
+
match { |string| !!Nokogiri::HTML(string.to_s).at_xpath(xpath) }
|
6
|
+
end
|
7
|
+
|
8
|
+
RSpec::Matchers.define :have_tag do |tag|
|
9
|
+
match { |string| !!Nokogiri::HTML(string.to_s).at_css(tag) }
|
10
|
+
end
|
11
|
+
|
12
|
+
class String
|
13
|
+
def trs
|
14
|
+
Nokogiri::HTML(self).css('tr')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ez_table
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dianhui Nie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>'
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>'
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Create Table easily for Rails app
|
42
|
+
email:
|
43
|
+
- niedhui@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .rspec
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- MIT-LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- easy_table.gemspec
|
56
|
+
- lib/easy_table.rb
|
57
|
+
- lib/easy_table/action_column.rb
|
58
|
+
- lib/easy_table/action_view_extension.rb
|
59
|
+
- lib/easy_table/base.rb
|
60
|
+
- lib/easy_table/builder.rb
|
61
|
+
- lib/easy_table/column.rb
|
62
|
+
- lib/easy_table/config.rb
|
63
|
+
- lib/easy_table/engine.rb
|
64
|
+
- lib/easy_table/presenter.rb
|
65
|
+
- lib/easy_table/version.rb
|
66
|
+
- lib/ez_table.rb
|
67
|
+
- lib/generators/easy_table/install_generator.rb
|
68
|
+
- lib/generators/templates/easy_table.rb
|
69
|
+
- lib/generators/templates/scaffold/index.html.slim
|
70
|
+
- lib/tasks/easy_table_tasks.rake
|
71
|
+
- spec/generators/install_generator_spec.rb
|
72
|
+
- spec/lib/action_view_extension_spec.rb
|
73
|
+
- spec/lib/base_spec.rb
|
74
|
+
- spec/lib/builder_spec.rb
|
75
|
+
- spec/lib/column_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/support/dummy_models.rb
|
78
|
+
- spec/support/matchers.rb
|
79
|
+
homepage: http://github.com/niedhui/ez_table
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.0.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Create Table easily
|
103
|
+
test_files:
|
104
|
+
- spec/generators/install_generator_spec.rb
|
105
|
+
- spec/lib/action_view_extension_spec.rb
|
106
|
+
- spec/lib/base_spec.rb
|
107
|
+
- spec/lib/builder_spec.rb
|
108
|
+
- spec/lib/column_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/support/dummy_models.rb
|
111
|
+
- spec/support/matchers.rb
|