table_help 0.1.0 → 0.1.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 +4 -4
- data/lib/table_help/config.rb +32 -9
- data/lib/table_help/formatter.rb +2 -18
- data/lib/table_help/version.rb +1 -1
- data/spec/fake_app/log/development.log +32 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61af2d6d87068a5556baa4a426dc135a1cba79be
|
4
|
+
data.tar.gz: 3a4f7bedddaeaa25c1c47a58a4b9cdcaf77fbd0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d56e09307140ed8348fc963c30f05f478cf1b4081914bab7a77572b3ba14042d8285e953758901aebae16c88320a80eb0d1f0590fb34bc1563d82f2c0caa933e
|
7
|
+
data.tar.gz: d707d87fca1584a922a50273513317351e96f7efb89f6b0235dc038793997bc2fb3938d56e4019d2dc00555e378faaecfb6f6165f3ecc24dca86d95fa6b6bb1d
|
data/lib/table_help/config.rb
CHANGED
@@ -1,16 +1,39 @@
|
|
1
1
|
module TableHelp
|
2
2
|
class Config
|
3
|
-
|
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
|
-
|
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
|
data/lib/table_help/formatter.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/table_help/version.rb
CHANGED
@@ -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
|
+
|