qwer 0.1.3 → 0.1.4
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 +4 -4
- data/.idea/qwer.iml +1 -0
- data/.rspec +2 -0
- data/README.md +43 -5
- data/lib/qwer/translater.rb +47 -20
- data/lib/qwer/version.rb +1 -1
- data/lib/temp/test.png +0 -0
- data/qwer.gemspec +2 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a049889a8c127dd590b21203a34431749253774
|
4
|
+
data.tar.gz: fc0d9ee35aeed5287c9d2224562d25c83fa02738
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eab2bb0b69143658380a3ccf3863a49e3939826d0d42e0164667eaad9da8cf092c1fad10c0cc9c246784cb2bdf940b22011814ed8512ba81c861703e24342707
|
7
|
+
data.tar.gz: 2c905049ad978b2b8b32db7a691d1e1295a31a0e58ea209ca65b7ed384616e98d952ac1324e2d0a535da3aa4b18ba0ba2fee264a7367e5ecf583b2bf9808fa22
|
data/.idea/qwer.iml
CHANGED
@@ -138,6 +138,7 @@
|
|
138
138
|
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.13.6, rbenv: 2.3.1) [gem]" level="application" />
|
139
139
|
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.0.4, rbenv: 2.3.1) [gem]" level="application" />
|
140
140
|
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, rbenv: 2.3.1) [gem]" level="application" />
|
141
|
+
<orderEntry type="library" scope="PROVIDED" name="enum_help (v0.0.16, rbenv: 2.3.1) [gem]" level="application" />
|
141
142
|
<orderEntry type="library" scope="PROVIDED" name="erubis (v2.7.0, rbenv: 2.3.1) [gem]" level="application" />
|
142
143
|
<orderEntry type="library" scope="PROVIDED" name="i18n (v0.7.0, rbenv: 2.3.1) [gem]" level="application" />
|
143
144
|
<orderEntry type="library" scope="PROVIDED" name="kaminari (v1.0.0, rbenv: 2.3.1) [gem]" level="application" />
|
data/.rspec
ADDED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Qwer
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
qwer一招带走你的index
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,47 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
- 在`index.html`适当的位置添加代码
|
24
|
+
|
25
|
+
```
|
26
|
+
model = Qwer::Tmodel.new('users', 10, 1)
|
27
|
+
|
28
|
+
|
29
|
+
第一个参数: 当前业务
|
30
|
+
第二个参数: 每页显示数量
|
31
|
+
第三个参数: 当前页数
|
32
|
+
```
|
33
|
+
|
34
|
+
- 调用方法table_seach,创建查询项
|
35
|
+
```
|
36
|
+
model.table_seach({
|
37
|
+
action: '/users', ## 提交地址(默认为当前业务)
|
38
|
+
method: 'get', ## 请求方式(默认为get)
|
39
|
+
form_class: 'form-inline text-right', ## 表单样式: 默认(pjax-form)
|
40
|
+
'charset': 'UTF-8', ## 编码(默认字符集UTF-8)
|
41
|
+
new: '/companies/new' ## 新建按钮指向地址(可选,不传则没有新建按钮)
|
42
|
+
}, {
|
43
|
+
'q[name_cont]': '名称', ## 查询项name及其显示名称
|
44
|
+
})
|
45
|
+
```
|
46
|
+
|
47
|
+
- 调用方法table_data,创建数据表
|
48
|
+
```
|
49
|
+
model.table_data({ car_no: '车牌号',
|
50
|
+
'driver.name': '司机',
|
51
|
+
status_i18n: '状态',
|
52
|
+
}, {
|
53
|
+
edit: {name: '编辑', css: 'label label-success'},
|
54
|
+
del: {name: '删除', css: 'label label-danger'},
|
55
|
+
business: '<a class="label label-success" data-confirm="我的id是??" href="/companies/??/edit">其他</a>'
|
56
|
+
}, @cars )
|
57
|
+
|
58
|
+
第一个参数: Hash | 数据表字段 | 格式: {字段或方法名: ‘显示表头’, ...}
|
59
|
+
第二个参数: Hash | 数据操作项 | 格式: {'预设操作按钮编辑(edit)和删除(del)': {name和css属性}}
|
60
|
+
第三个参数: 数据表数据
|
61
|
+
```
|
62
|
+
|
63
|
+
|
26
64
|
|
27
65
|
## Development
|
28
66
|
|
@@ -32,7 +70,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
70
|
|
33
71
|
## Contributing
|
34
72
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
73
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Canmel/qwer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
74
|
|
37
75
|
|
38
76
|
## License
|
data/lib/qwer/translater.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
module Qwer
|
2
2
|
class Translater
|
3
|
-
def self.table_search(form_params, data_params)
|
4
|
-
html_str = "<form class='pjax-form' id='' action='#{form_params[:action]}' accept-charset='#{form_params[:charset] ||= 'UTF-8' }' method='#{form_params[:method]}'>
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
html_str
|
10
|
-
html_str += "<button type='submit' class='btn btn-info' data-toggle='modal' data-target='#search_model'>查询</button> </form>"
|
3
|
+
def self.table_search(form_params, data_params, model)
|
4
|
+
html_str = "<form class='#{form_params[:form_class] ||= 'pjax-form'}' id='' action='#{form_params[:action] ||= model}' accept-charset='#{form_params[:charset] ||= 'UTF-8' }' method='#{form_params[:method] ||= 'get'}'>"
|
5
|
+
html_str << "<input name='utf8' type='hidden' value='✓'>"
|
6
|
+
data_params.reject { |key, value| html_str << "<div class='form-group'><label class='control-label'>#{value}:</label><input class='form-control' type='search' name='#{key}' id='q_#{key}'></div>" }
|
7
|
+
html_str << "<a class='btn btn-success green' href='#{form_params[:new]}'>新增</a>" if form_params[:new]
|
8
|
+
html_str << "<button type='submit' class='btn btn-info' data-toggle='modal' data-target='#search_model'>查询</button>"
|
9
|
+
html_str << "</form>"
|
11
10
|
end
|
12
11
|
|
13
|
-
def self.table_data(table_head, dname, datas, *args)
|
12
|
+
def self.table_data(table_head, dname, opt, datas, *args)
|
14
13
|
html_str = "<table class='table table-striped table-hover' id='editable-sample'><thead><tr><th>#</th>"
|
15
|
-
table_head.reject { |key, value| html_str
|
16
|
-
html_str
|
14
|
+
table_head.reject { |key, value| html_str << "<th>#{value}</th>" }
|
15
|
+
html_str << "<th>操作</th></tr></thead><tbody>"
|
17
16
|
datas.each_with_index do |data, index|
|
18
17
|
tr_html = "<tr>"
|
19
|
-
tr_html
|
20
|
-
|
21
|
-
tr_html
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
tr_html
|
26
|
-
|
18
|
+
tr_html << "<td>#{sequence index}</td>"
|
19
|
+
# 数据内容
|
20
|
+
table_head.reject { |key, value| tr_html << "<td>#{send_keys data, key}</td>" }
|
21
|
+
# 操作
|
22
|
+
tr_html << "<td>"
|
23
|
+
opt.reject { |key, value| tr_html << opt_btns(key, value, dname, data) }
|
24
|
+
tr_html << "</td>"
|
25
|
+
tr_html << "</tr>"
|
26
|
+
html_str << tr_html
|
27
27
|
end
|
28
|
-
html_str
|
28
|
+
html_str << "</tbody></table>"
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
@@ -33,5 +33,32 @@ module Qwer
|
|
33
33
|
def self.sequence(index)
|
34
34
|
(@page.to_i - 1) * @page_size.to_i + index + 1
|
35
35
|
end
|
36
|
+
|
37
|
+
def self.edit?(opt)
|
38
|
+
opt == "edit"
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.delete?(opt)
|
43
|
+
opt == "del"
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.send_keys data, key
|
47
|
+
keys = key.to_s.split '.'
|
48
|
+
keys.each do |item|
|
49
|
+
data = data.send item if data.present?
|
50
|
+
end
|
51
|
+
data
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.opt_btns key, value, dname, data
|
55
|
+
if edit? key.to_s
|
56
|
+
return "<a class='#{value[:css] ||= 'label label-success'}' href='/#{dname}/#{data.id.to_s}/edit'>#{value[:name] ||= '编辑'}</a>"
|
57
|
+
elsif delete? key.to_s
|
58
|
+
return "<a data-confirm='确认要删除这条数据吗?' class='#{value[:css] ||= 'label label-danger'}' rel='nofollow' data-method='delete' href='/#{dname}/#{data.id.to_s}'>#{ value[:name] ||= '删除'}</a>"
|
59
|
+
else
|
60
|
+
return value.gsub('??', '??'=>data.id) if value["??"].present?
|
61
|
+
end
|
62
|
+
end
|
36
63
|
end
|
37
64
|
end
|
data/lib/qwer/version.rb
CHANGED
data/lib/temp/test.png
ADDED
Binary file
|
data/qwer.gemspec
CHANGED
@@ -34,5 +34,6 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
35
|
spec.add_development_dependency "rspec", "~> 3.5.0"
|
36
36
|
spec.add_development_dependency "kaminari", "~> 1.0.0"
|
37
|
+
spec.add_development_dependency "enum_help", "~> 0.0.16"
|
37
38
|
|
38
|
-
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qwer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lidejian@skio.cn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: enum_help
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.0.16
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.0.16
|
69
83
|
description: "'this is my first gem'"
|
70
84
|
email:
|
71
85
|
- lidejian
|
@@ -79,6 +93,7 @@ files:
|
|
79
93
|
- ".idea/modules.xml"
|
80
94
|
- ".idea/qwer.iml"
|
81
95
|
- ".idea/vcs.xml"
|
96
|
+
- ".rspec"
|
82
97
|
- CODE_OF_CONDUCT.md
|
83
98
|
- Gemfile
|
84
99
|
- LICENSE.txt
|
@@ -90,6 +105,7 @@ files:
|
|
90
105
|
- lib/qwer/layout_helper.rb
|
91
106
|
- lib/qwer/translater.rb
|
92
107
|
- lib/qwer/version.rb
|
108
|
+
- lib/temp/test.png
|
93
109
|
- qwer-0.1.1.gem
|
94
110
|
- qwer.gemspec
|
95
111
|
homepage: https://www.baidu.com
|