jekyll-database-tables 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b6ef16fd80c0260fe03a2d55fe293a39c7ddfc0350e1ace10199052b034bf0e
4
- data.tar.gz: d6e6b26601c76f96bc19bb40ce06fda25bb6cb2de40578579219e93b9870f6d5
3
+ metadata.gz: c1cef8889f7925d214a208eb901e489637ce8f63be1346707a09999db1ab0e0b
4
+ data.tar.gz: 998be79150f29b3f21ec55941a09a85e0aa02e400ca356bb17520c0c3aba4395
5
5
  SHA512:
6
- metadata.gz: '08d3dcf78d286c9e7c1d522bd8ec38686e5aca1c64614b9a38b44556770a75fa87c76046dc8cb2891c0cbf771e2c2c47069db90c6fb85105b3c9fbd98528a0f6'
7
- data.tar.gz: 718f97cbe8be09c7e721137d6a77a9c3559a6cf67a94116393ee9f0c94c2336240c96eee714ef9c8ae7cd452f1ca9103e16e421cbddf549308d8dd4ad42651bf
6
+ metadata.gz: 0f423a612a85b39803b79f4377b70a24be7eabb4bb2efd483fda04c1b64580e772bd987e98633d49c5b605ff1ca834a6d115c2d55233f28b7e30485c9f214734
7
+ data.tar.gz: 6c544d7525320f94a06ee988e0810409a05335f1e63f329f4d8315e3ac92d9eb835d28b85de28bf19320b800f698a6fb5505f7305731cd6c6ba45d3e8b49b6cd
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
4
+
3
5
  module Jekyll
4
6
  module DatabaseTables
5
7
  # Abstract base class for table formatters.
@@ -80,43 +82,49 @@ module Jekyll
80
82
  def render(table, title: nil)
81
83
  widths = column_widths(table)
82
84
 
83
- lines = +''
84
- lines << "#{title.center(total_width(widths)).rstrip}\n" if title
85
-
86
- lines << format_row(table.headers, widths)
87
- lines << "\n"
88
- lines << separator(widths)
89
- lines << "\n"
90
-
91
- table.rows.each do |row|
92
- lines << format_row(row.cells, widths)
93
- lines << "\n"
94
- end
95
-
96
- "<pre class=\"psql-table\">\n#{lines}</pre>\n"
85
+ <<~HTML
86
+ <pre class="psql-table">
87
+ #{table_rows(table, widths, title).join("\n")}
88
+ </pre>
89
+ HTML
97
90
  end
98
91
 
99
- # Formats a row as space-padded cells joined by +|+.
92
+ # formats a row as space-padded cells joined by +|+.
100
93
  #
101
- # @param cells [Array<#to_s>] the cell values to render
102
- # @param widths [Array<Integer>] the column widths to left-justify against
103
- # @return [String] the formatted row, with trailing whitespace stripped
94
+ # @param cells [array<#to_s>] the cell values to render
95
+ # @param widths [array<integer>] the column widths to left-justify against
96
+ # @return [string] the formatted row, with trailing whitespace stripped
104
97
  def format_row(cells, widths)
105
98
  cells.each_with_index.map do |cell, i|
106
- cell.to_s.ljust(widths[i])
99
+ CGI.escapeHTML(cell.to_s.ljust(widths[i]))
107
100
  end.join(' | ').rstrip
108
101
  end
109
102
 
110
- # Renders a +-+-+ separator sized to the given column widths.
103
+ # renders a +-+-+ separator sized to the given column widths.
111
104
  #
112
- # @param widths [Array<Integer>] the column widths
113
- # @return [String] the separator line
105
+ # @param widths [array<integer>] the column widths
106
+ # @return [string] the separator line
114
107
  def separator(widths)
115
108
  widths.map { |w| '-' * w }.join('-+-')
116
109
  end
117
110
 
118
111
  private
119
112
 
113
+ def table_rows(table, widths, title)
114
+ [
115
+ title_row(title, widths),
116
+ format_row(table.headers, widths),
117
+ separator(widths),
118
+ *table.rows.map { |row| format_row(row.cells, widths) }
119
+ ].compact
120
+ end
121
+
122
+ def title_row(title, widths)
123
+ return unless title
124
+
125
+ CGI.escapeHTML(title).center(total_width(widths)).rstrip
126
+ end
127
+
120
128
  def total_width(widths)
121
129
  widths.sum + ((widths.length - 1) * 3)
122
130
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module DatabaseTables
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-database-tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Aguiar