martile 0.6.5 → 0.6.6

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: 73846c6282cf20b59b4afcb0f5b7864f775f8f96
4
- data.tar.gz: 7baf57d9425254be7cbf203483205b6ae012b604
3
+ metadata.gz: c63c50dfb33d820a5e691a8c4c891a0b08f2d9e2
4
+ data.tar.gz: e6e6fc61f78cc63352ecbb34c017694323c6b8c1
5
5
  SHA512:
6
- metadata.gz: 7922dee94cfcb4704f9cf086a1c838ce6742200d5e863d2184e2133dd63d62bfabdc7be9e520765e64a77fb3dfea73139c0f8ce04be7967888c7342ea81746ff
7
- data.tar.gz: bd0ba146beee259b300abd3eee65eb7f57292bf2d783518aac95ea08b51c53f3d764ccf99dca8edbaa77bd7eed8a39b1700b7c3e621ac709e5ef899e1b64c111
6
+ metadata.gz: 93d2b0e234640fc100eaff52bc194ba6f0129a314d90e1744fc1bbbe46db792a91afd57c86430592a670dd1948a7af007d3515daabbd7dcc4df519c7cd0f8dd7
7
+ data.tar.gz: de26b7b0f4b764be08bab71fdbb7410e43cd00ec9d1ec6e34eb6f016e8c803a1e8d179535fac24abc1ce16ad678852961c2f42151001df8361d20402856a91c5
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/martile.rb CHANGED
@@ -8,8 +8,9 @@ require 'dynarex'
8
8
  require 'rdiscount'
9
9
 
10
10
 
11
- # feature: 06-Jul-2015 dynarex_to_table(): A URL within a
12
- # col is now hyperlinked
11
+ # feature: 06-Jul-2015 dynarex_to_table():
12
+ # 1. A URL within a col is now hyperlinked
13
+ # 2. Select fields can now be displayd
13
14
  # feature: 02-Jul-2015 Apply_filter() now filters out pre and code tags
14
15
  # The shorthand !i[]() can now render an iframe tag
15
16
  # e.g. !i[](http://somefile.url/sometext.txt)
@@ -198,24 +199,36 @@ class Martile
198
199
 
199
200
  def dynarex_to_table(s)
200
201
 
201
- s.gsub(/-\[((https?:\/\/)?[\w\/\.\-]+)\]/) do |match|
202
-
202
+ s.gsub(/-\[((https?:\/\/)?[\w\/\.\-]+)\](\{[^\}]+\})?/) do |match|
203
+
204
+ source = ($1)
205
+ raw_select = ($3)
206
+
207
+ if raw_select then
208
+ raw_fields = raw_select[/select:\s*["']([^"']+)/,1]
209
+ fields = raw_fields.split(/\s*,\s*/)
210
+ end
211
+
203
212
  print_row = -> (row, widths) do
204
- '| ' + row.map.with_index {|y,i| y.to_s.ljust(widths[i])}.join(' | ') + " |\n"
213
+ '| ' + row.map\
214
+ .with_index {|y,i| y.to_s.ljust(widths[i])}.join(' | ') + " |\n"
205
215
  end
206
216
 
207
217
  print_thline = -> (row, widths) do
208
- '|:' + row.map.with_index {|y,i| y.to_s.ljust(widths[i])}.join('|:') + "|\n"
218
+ '|:' + row.map\
219
+ .with_index {|y,i| y.to_s.ljust(widths[i])}.join('|:') + "|\n"
209
220
  end
210
221
 
211
222
  print_rows = -> (rows, widths) do
212
223
  rows.map {|x| print_row.call(x,widths)}.join
213
224
  end
214
225
 
215
- dx = Dynarex.new($1)
216
- keys = dx.to_h.map(&:keys).first
226
+ dx = Dynarex.new(source)
217
227
 
218
- raw_vals = dx.to_h.map(&:values)
228
+ flat_records = raw_select ? dx.to_a(select: fields) : dx.to_a
229
+
230
+ keys = flat_records.map(&:keys).first
231
+ raw_vals = flat_records.map(&:values)
219
232
 
220
233
  # create Markdown hyperlinks for any URLs
221
234
 
@@ -276,7 +289,9 @@ class Martile
276
289
 
277
290
  s.split(/(?=\[#{symbol}|^#{symbol*2})/).map do |x|
278
291
 
279
- s2, remainder = [x[/\[#{symbol}.*#{symbol}[^\]]+\]/m], ($').to_s] if x.strip.length > 0
292
+ if x.strip.length > 0 then
293
+ s2, remainder = [x[/\[#{symbol}.*#{symbol}[^\]]+\]/m], ($').to_s]
294
+ end
280
295
 
281
296
  if s2 then
282
297
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: martile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file