action_table 0.3.0 → 0.4.0

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
- SHA256:
3
- metadata.gz: 764eb83721f4fdcb2d2ba4d83b4e475193dfd942ba092ba66fa51d9b99500792
4
- data.tar.gz: 28cf0551ac9a6db16b109c45e9fd480876112989480dc87d3b7a5e77604e8ccc
2
+ SHA1:
3
+ metadata.gz: 78aecafe799ebdad113b9a962e1e4e92bca747d9
4
+ data.tar.gz: f4e741f5003ec2434df34891ba9f5fb394edbddf
5
5
  SHA512:
6
- metadata.gz: 2c54233fa2ff645ba5068bad3dec99e22f77459f400fc559e828c48c998a6d40529847cebcf110df09fbaae6055f20461edd4685ce6290ed6708528e5a8bfec2
7
- data.tar.gz: 0b4595270ccfb5cbff0e08d51614eabc82658e0a949d02d174f2c785b1c6cc511bce64c9ec47f837993855abe8cd610782d09e62541ceef56784b3186546f7b5
6
+ metadata.gz: e02d126244c84e84129c5740c1253ea9fed1e900ae8007d9fe4735ea3cf460d2394b5bc60b21195a54fdeda7eafa6a36cb49e4ebb4d696cd7c0760a862d4520a
7
+ data.tar.gz: 34e256d1887e30cfbac9617148375e3b9ebd1cc2c5b8eb07b2d1188dd8fad074e8a177aa9423369f2b50abfac147a707be8008717348d90f75ac2e470c99b814
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## HEAD
4
4
 
5
+ ### v0.4.0
6
+
7
+ - Decrease public API of View
8
+ - Minimal support for rendering non-ActiveRecord tables
5
9
 
6
10
  ## v0.3.0
7
11
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'erb'
3
+ require 'action_table/bootstrap_styles'
4
4
  require 'action_table/view'
5
5
 
6
6
  module ActionTable
@@ -33,10 +33,10 @@ module ActionTable
33
33
  paginate: paginate,
34
34
  links: links,
35
35
  actions: actions,
36
- styles: styles,
37
36
  )
38
37
 
39
- render('action_table/table', table: action_table)
38
+ styles = BootstrapStyles.new(styles)
39
+ render('action_table/table', table: action_table, styles: styles)
40
40
  end
41
41
  end
42
42
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionTable
4
- VERSION = '0.3.0'.freeze
4
+ VERSION = '0.4.0'.freeze
5
5
  end
@@ -1,31 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'set'
4
- require 'action_table/bootstrap_styles'
5
4
 
6
5
  module ActionTable
7
6
  class View
8
7
  include ActionView::Helpers::UrlHelper
9
8
  include ActionTable.config.rails_host_app.routes.url_helpers
10
9
 
11
- attr_reader :model_name, :rows, :styles
10
+ attr_reader :rows
12
11
 
13
12
  def initialize(
14
13
  columns:,
15
14
  records:,
16
15
  paginate: false,
17
16
  links: ActionTable.config.links,
18
- actions: ActionTable.config.actions,
19
- styles: ActionTable.config.styles
17
+ actions: ActionTable.config.actions
20
18
  )
21
- @columns = columns.map(&:to_s)
19
+ @columns = Array(columns).map(&:to_s)
22
20
  @rows = records
23
- @table_name = records.table_name
24
- @model_name = @table_name.singularize
25
21
  @paginate = paginate
26
22
  @links = Set.new(Array(links).map(&:to_s)).reject(&:empty?)
27
23
  @actions = Array(actions).map(&:to_s)
28
- @styles = BootstrapStyles.new(styles)
29
24
  end
30
25
 
31
26
  def headers
@@ -65,7 +60,7 @@ module ActionTable
65
60
 
66
61
  # This must be defined for record_path to work
67
62
  def controller
68
- @table_name
63
+ table_name
69
64
  end
70
65
 
71
66
  # Contstruct path to record, i.e programs_path(record)
@@ -75,6 +70,8 @@ module ActionTable
75
70
  public_send(path, record)
76
71
  end
77
72
 
73
+ private
74
+
78
75
  def t_actions
79
76
  @actions.map { |name| t_action(name) }
80
77
  end
@@ -85,8 +82,25 @@ module ActionTable
85
82
  end
86
83
 
87
84
  def t_col(col_name)
88
- t_key = "activerecord.attributes.#{@model_name}.#{col_name}"
89
- I18n.t(t_key, default: col_name.titleize)
85
+ if model_name?
86
+ t_key = "activerecord.attributes.#{model_name}.#{col_name}"
87
+ return I18n.t(t_key, default: col_name.titleize)
88
+ end
89
+
90
+ col_name.humanize.titleize
91
+ end
92
+
93
+ def table_name
94
+ rows.table_name
95
+ end
96
+
97
+ def model_name
98
+ table_name.singularize
99
+ end
100
+
101
+ def table_name?
102
+ rows.respond_to?(:table_name)
90
103
  end
104
+ alias_method :model_name?, :table_name?
91
105
  end
92
106
  end
@@ -1,10 +1,10 @@
1
- <% wrapper_class = table.styles.responsive_wrapper_class %>
1
+ <% wrapper_class = styles.responsive_wrapper_class %>
2
2
 
3
3
  <% if wrapper_class %>
4
4
  <div class="<%= wrapper_class %>">
5
5
  <% end %>
6
6
 
7
- <table class="<%= table.styles.table_classes %>">
7
+ <table class="<%= styles.table_classes %>">
8
8
  <thead>
9
9
  <% table.headers.each do |header| %>
10
10
  <th><%= header %></th>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Burenstam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-03 00:00:00.000000000 Z
11
+ date: 2018-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,8 +114,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.7.6
117
+ rubygems_version: 2.5.2.3
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Render ActiveRecord objects as HTML tables with one line of Ruby.
121
121
  test_files: []
122
+ has_rdoc: