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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c7265a5e0bc784320a9469265f3bef9eff3689487a3c86429c3ad756c5ea7f0
4
- data.tar.gz: 6d2a7097ccc116fd0603d56a9314eb8636a1a6331677854298fa4ee91076b63f
3
+ metadata.gz: 7be793d68e9e35d5c07d0b74e0632b45a69eab112ddb766f83549dd88deb0167
4
+ data.tar.gz: 894444ed831d2750d7169d07f160bf667ea58f7b8f1f435e3e41d59458726678
5
5
  SHA512:
6
- metadata.gz: c72b316023ff2dadaa80907ccbc96f7942f3be8519cc31d26f3955b99c541c6c0eb17278d485aec04b8688d1c3790cb505d22fb191e98a272160d307e487d359
7
- data.tar.gz: 73a1089d4ac63bed31b7e9fd3918f61765b3d78114227c881f98fe38617887bd90406977c876c31ae43ab7add17d90a73eb384413ebb423d90475170494367f1
6
+ metadata.gz: c4ba918e143a7025875bb7672013513362bddaba71c36b57399cf35621e006aefb06e694f7994b30b4dae71e14ade59fe6da7c25e5f0855846848ce7e91b104a
7
+ data.tar.gz: 425ea95a24a11e4239987ae1bbb1823f2f1e16aa1216387cd21dbdeeb5d338f699db6734f8163074766ac2212944827c95289cce7c3a5a057e742a5a9527c40b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.3
2
+ * Added configuration feature.
3
+
4
+ ## 0.1.2
5
+ * Added actions method for resource table.
6
+
1
7
  ## 0.1.1
2
8
  * Bug fix.
3
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_model_view (0.1.2)
4
+ simple_model_view (0.1.3)
5
5
  actionview (>= 5.0)
6
6
 
7
7
  GEM
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
@@ -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, class: :table do
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, class: :table do
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 :template, :collection
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
@@ -39,9 +39,8 @@ module SimpleModelView
39
39
  end
40
40
  end
41
41
 
42
- # TODO: gem configuration to be used
43
42
  def default_header_html
44
- {}
43
+ SimpleModelView.collection_header_html
45
44
  end
46
45
  end
47
46
  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::ValueFormatter)
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::ValueFormatter)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleModelView
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  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.2
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-04 00:00:00.000000000 Z
11
+ date: 2019-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview