table_help 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 07701ffc15d5313d31e28e2ad3d4d4842beacc11
4
- data.tar.gz: 8af86e6dba4c5a7cd8c74aac54563fe0f4f80ec2
3
+ metadata.gz: 61af2d6d87068a5556baa4a426dc135a1cba79be
4
+ data.tar.gz: 3a4f7bedddaeaa25c1c47a58a4b9cdcaf77fbd0a
5
5
  SHA512:
6
- metadata.gz: 275cf7c643275c52f792fb7f7156b5f89ca9bb712ee0d6cd420e10670cbf68f764881ac38089d6cc08a67a10bc8e9639310d04cf01a75c9b3dcdaadade3bc5df
7
- data.tar.gz: d58e16c9f74e5c71be3ed5f621fe12059b11fea5bb049b929cb7da6e813a6ffc0632dd6d51c28eaf1aa073fcf5d919b83b484d344c93f87f988c97db1ff8cb3c
6
+ metadata.gz: d56e09307140ed8348fc963c30f05f478cf1b4081914bab7a77572b3ba14042d8285e953758901aebae16c88320a80eb0d1f0590fb34bc1563d82f2c0caa933e
7
+ data.tar.gz: d707d87fca1584a922a50273513317351e96f7efb89f6b0235dc038793997bc2fb3938d56e4019d2dc00555e378faaecfb6f6165f3ecc24dca86d95fa6b6bb1d
@@ -1,16 +1,39 @@
1
1
  module TableHelp
2
2
  class Config
3
- attr_accessor :default_options
3
+ DEFAULT_OPTIONS = {
4
+ table_for: {
5
+ class: "table table-striped table-hover table_for",
6
+ },
7
+ attributes_table_for: {
8
+ class: "table table-striped table-hover attributes_table_for",
9
+ },
10
+ }.freeze
11
+
12
+ DEFAULT_FORMATTER = {
13
+ attribute_name: ->(name, collection_or_resource) do
14
+ if collection_or_resource.respond_to?(:model)
15
+ collection_or_resource.model.human_attribute_name(name)
16
+ else
17
+ collection_or_resource.class.human_attribute_name(name)
18
+ end
19
+ end,
20
+ value: ->(name, value) do
21
+ case value
22
+ when DateTime, Time
23
+ I18n.l(value)
24
+ when Numeric
25
+ (name.to_sym == :id) ? value : value.to_s(:delimited)
26
+ else
27
+ value
28
+ end
29
+ end,
30
+ }.freeze
31
+
32
+ attr_accessor :default_options, :formatter
4
33
 
5
34
  def initialize
6
- @default_options = {
7
- table_for: {
8
- class: "table table-striped table-hover table_for",
9
- },
10
- attributes_table_for: {
11
- class: "table table-striped table-hover attributes_table_for",
12
- },
13
- }
35
+ @default_options = DEFAULT_OPTIONS
36
+ @formatter = DEFAULT_FORMATTER
14
37
  end
15
38
  end
16
39
  end
@@ -4,27 +4,11 @@ module TableHelp
4
4
 
5
5
  def format_attribute_name(name, collection_or_resource)
6
6
  return if name.blank?
7
-
8
- if collection_or_resource.respond_to?(:model)
9
- collection_or_resource.model.human_attribute_name(name)
10
- else
11
- collection_or_resource.class.human_attribute_name(name)
12
- end
7
+ TableHelp.config.formatter[:attribute_name].call(name, collection_or_resource)
13
8
  end
14
9
 
15
10
  def format_value(name, value)
16
- case value
17
- when DateTime, Time
18
- I18n.l(value)
19
- when Numeric
20
- (name.to_sym == :id) ? value : value.to_s(:delimited)
21
- when TrueClass, FalseClass
22
- value.to_s
23
- when NilClass
24
- name ? tag.em(:empty) : nil
25
- else
26
- value
27
- end
11
+ TableHelp.config.formatter[:value].call(name, value)
28
12
  end
29
13
  end
30
14
  end
@@ -1,3 +1,3 @@
1
1
  module TableHelp
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.1".freeze
3
3
  end
@@ -770,3 +770,35 @@ Processing by ArticlesController#show as HTML
770
770
  Completed 200 OK in 10ms (Views: 7.2ms)
771
771
 
772
772
 
773
+ DEPRECATION WARNING: You didn't set `secret_key_base`. Read the upgrade documentation to learn more about this new config option. (called from block (3 levels) in <top (required)> at /Users/yhirano/dev/src/github.com/yhirano55/table_help/spec/table_help_spec.rb:14)
774
+ Started GET "/articles" for 127.0.0.1 at 2017-10-09 02:46:10 +0900
775
+ Processing by ArticlesController#index as HTML
776
+ Rendering articles/index.html.erb
777
+ Rendered articles/index.html.erb (15.8ms)
778
+ Completed 200 OK in 25ms (Views: 23.4ms)
779
+
780
+
781
+ Started GET "/articles/2" for 127.0.0.1 at 2017-10-09 02:46:10 +0900
782
+ Processing by ArticlesController#show as HTML
783
+ Parameters: {"id"=>"2"}
784
+ Rendering articles/show.html.erb
785
+ Rendered articles/show.html.erb (2.1ms)
786
+ Completed 200 OK in 14ms (Views: 9.6ms)
787
+
788
+
789
+ DEPRECATION WARNING: You didn't set `secret_key_base`. Read the upgrade documentation to learn more about this new config option. (called from block (3 levels) in <top (required)> at /Users/yhirano/dev/src/github.com/yhirano55/table_help/spec/table_help_spec.rb:14)
790
+ Started GET "/articles" for 127.0.0.1 at 2017-10-09 02:53:26 +0900
791
+ Processing by ArticlesController#index as HTML
792
+ Rendering articles/index.html.erb
793
+ Rendered articles/index.html.erb (7.4ms)
794
+ Completed 200 OK in 16ms (Views: 14.2ms)
795
+
796
+
797
+ Started GET "/articles/6" for 127.0.0.1 at 2017-10-09 02:53:26 +0900
798
+ Processing by ArticlesController#show as HTML
799
+ Parameters: {"id"=>"6"}
800
+ Rendering articles/show.html.erb
801
+ Rendered articles/show.html.erb (1.6ms)
802
+ Completed 200 OK in 10ms (Views: 7.2ms)
803
+
804
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_help
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiyuki Hirano