simple_model_view 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +20 -0
- data/lib/simple_model_view.rb +26 -0
- data/lib/simple_model_view/action_view_helper_builder.rb +2 -2
- data/lib/simple_model_view/collection_table_builder.rb +8 -3
- data/lib/simple_model_view/collection_table_header_builder.rb +1 -2
- data/lib/simple_model_view/collection_table_row_builder.rb +2 -3
- data/lib/simple_model_view/resource_table_builder.rb +4 -5
- data/lib/simple_model_view/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7be793d68e9e35d5c07d0b74e0632b45a69eab112ddb766f83549dd88deb0167
|
4
|
+
data.tar.gz: 894444ed831d2750d7169d07f160bf667ea58f7b8f1f435e3e41d59458726678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4ba918e143a7025875bb7672013513362bddaba71c36b57399cf35621e006aefb06e694f7994b30b4dae71e14ade59fe6da7c25e5f0855846848ce7e91b104a
|
7
|
+
data.tar.gz: 425ea95a24a11e4239987ae1bbb1823f2f1e16aa1216387cd21dbdeeb5d338f699db6734f8163074766ac2212944827c95289cce7c3a5a057e742a5a9527c40b
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -16,6 +16,26 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install simple_model_view
|
18
18
|
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
In `config/initializers/simple_model_view.rb` file following options are available
|
22
|
+
|
23
|
+
SimpleModelView.setup do |config|
|
24
|
+
# set initial html attributes for collection table
|
25
|
+
config.collection_table_html = {}
|
26
|
+
config.collection_header_html = {}
|
27
|
+
config.collection_wrapper_html = {}
|
28
|
+
|
29
|
+
# set initial html attributes for resource table
|
30
|
+
config.resource_table_html = {}
|
31
|
+
config.resource_wrapper_html = {}
|
32
|
+
config.resource_label_html = {}
|
33
|
+
config.resource_value_html = {}
|
34
|
+
|
35
|
+
# set formatter class
|
36
|
+
config.formatter = SimpleModelView::ValueFormatter
|
37
|
+
end
|
38
|
+
|
19
39
|
## Usage
|
20
40
|
|
21
41
|
SimpleModelView provides you two main helpers
|
data/lib/simple_model_view.rb
CHANGED
@@ -17,6 +17,32 @@ module SimpleModelView
|
|
17
17
|
autoload :CollectionTableRowBuilder
|
18
18
|
autoload :CollectionTableBuilder
|
19
19
|
end
|
20
|
+
|
21
|
+
@collection_table_html = {}
|
22
|
+
@collection_header_html = {}
|
23
|
+
@collection_wrapper_html = {}
|
24
|
+
@resource_table_html = {}
|
25
|
+
@resource_wrapper_html = {}
|
26
|
+
@resource_label_html = {}
|
27
|
+
@resource_value_html = {}
|
28
|
+
|
29
|
+
@formatter = SimpleModelView::ValueFormatter
|
30
|
+
|
31
|
+
class << self
|
32
|
+
attr_accessor :collection_table_html
|
33
|
+
attr_accessor :collection_header_html
|
34
|
+
attr_accessor :collection_wrapper_html
|
35
|
+
attr_accessor :resource_table_html
|
36
|
+
attr_accessor :resource_wrapper_html
|
37
|
+
attr_accessor :resource_label_html
|
38
|
+
attr_accessor :resource_value_html
|
39
|
+
|
40
|
+
attr_accessor :formatter
|
41
|
+
|
42
|
+
def setup
|
43
|
+
yield self
|
44
|
+
end
|
45
|
+
end
|
20
46
|
end
|
21
47
|
|
22
48
|
require 'simple_model_view/railtie' if defined?(Rails)
|
@@ -13,7 +13,7 @@ module SimpleModelView
|
|
13
13
|
def resource_table(model, *args)
|
14
14
|
builder = SimpleModelView::ResourceTableBuilder.new template, model, *args
|
15
15
|
|
16
|
-
template.content_tag :table,
|
16
|
+
template.content_tag :table, nil, SimpleModelView.collection_table_html do
|
17
17
|
template.content_tag :tbody do
|
18
18
|
yield builder
|
19
19
|
end
|
@@ -23,7 +23,7 @@ module SimpleModelView
|
|
23
23
|
def collection_table(collection, *args)
|
24
24
|
builder = SimpleModelView::CollectionTableBuilder.new template, collection, *args
|
25
25
|
|
26
|
-
template.content_tag :table,
|
26
|
+
template.content_tag :table, nil, SimpleModelView.collection_table_html do
|
27
27
|
block_concat do
|
28
28
|
template.content_tag :thead do
|
29
29
|
template.content_tag :tr do
|
@@ -5,19 +5,24 @@ module SimpleModelView
|
|
5
5
|
include SimpleModelView::TemplateHelpers
|
6
6
|
include SimpleModelView::BuilderHelpers
|
7
7
|
|
8
|
-
def initialize(template, collection, *_args)
|
8
|
+
def initialize(template, collection, *_args, formatter: SimpleModelView.formatter)
|
9
9
|
@template = template
|
10
10
|
@collection = collection
|
11
|
+
@formatter = formatter
|
11
12
|
end
|
12
13
|
|
13
|
-
attr_reader :
|
14
|
+
attr_reader :collection, :formatter
|
14
15
|
|
15
16
|
def columns_builder
|
16
17
|
CollectionTableHeaderBuilder.new template, collection
|
17
18
|
end
|
18
19
|
|
19
20
|
def row_builder_for(resource)
|
20
|
-
CollectionTableRowBuilder.new template, resource
|
21
|
+
CollectionTableRowBuilder.new template, resource, formatter: formatter
|
21
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :template
|
22
27
|
end
|
23
28
|
end
|
@@ -5,7 +5,7 @@ module SimpleModelView
|
|
5
5
|
include SimpleModelView::TemplateHelpers
|
6
6
|
include SimpleModelView::BuilderHelpers
|
7
7
|
|
8
|
-
def initialize(template, object, *_args, formatter: SimpleModelView
|
8
|
+
def initialize(template, object, *_args, formatter: SimpleModelView.formatter)
|
9
9
|
@template = template
|
10
10
|
@object = object
|
11
11
|
@formatter = formatter
|
@@ -35,9 +35,8 @@ module SimpleModelView
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
# TODO: gem configuration to be used
|
39
38
|
def default_wrapper_html
|
40
|
-
|
39
|
+
SimpleModelView.collection_wrapper_html
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
@@ -5,7 +5,7 @@ module SimpleModelView
|
|
5
5
|
include SimpleModelView::TemplateHelpers
|
6
6
|
include SimpleModelView::BuilderHelpers
|
7
7
|
|
8
|
-
def initialize(template, object, *_args, formatter: SimpleModelView
|
8
|
+
def initialize(template, object, *_args, formatter: SimpleModelView.formatter)
|
9
9
|
@template = template
|
10
10
|
@object = object
|
11
11
|
@formatter = formatter
|
@@ -85,17 +85,16 @@ module SimpleModelView
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
# TODO: gem configuration to be used
|
89
88
|
def default_wrapper_html
|
90
|
-
|
89
|
+
SimpleModelView.resource_wrapper_html
|
91
90
|
end
|
92
91
|
|
93
92
|
def default_label_html
|
94
|
-
|
93
|
+
SimpleModelView.resource_label_html
|
95
94
|
end
|
96
95
|
|
97
96
|
def default_value_html
|
98
|
-
|
97
|
+
SimpleModelView.resource_value_html
|
99
98
|
end
|
100
99
|
end
|
101
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_model_view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuriy Esaulov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|