martile 0.6.7 → 0.6.8

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
  SHA1:
3
- metadata.gz: a6f75a6d7fc3b3c016747c5bfed719bdf08ab2d9
4
- data.tar.gz: 6e3203dc584f605d97150997d40b66d18820de0e
3
+ metadata.gz: 047df8e816c678ff60a333e8b0b1a7883781b2b6
4
+ data.tar.gz: 725d1fa7318ddcb909475a216076587505b50f38
5
5
  SHA512:
6
- metadata.gz: 47c7143e239abf3bb794480c2833160a5bf0f901b76c1c23eaed1a24780e6d4c36c526e21a5b796d01c435f3a48c6e94182bea057f9d333dd003068056a504c5
7
- data.tar.gz: 13b61c680d53ce68967be62d05ea9512077e51b9e1dc6bc4b1ac93d816653689c8147255ffbdaadaa56948d31f954aa3b5855c27ec35ce86697ed58e1f2b2b66
6
+ metadata.gz: 5785400f160e2565afc7244253c8be5d8adb37225bc8b6451936df3b982534f5d0af94af213b102527135763a8e54e5c265144e0c440af2130f0cf8d4ad224c1
7
+ data.tar.gz: 51f2a250dcba07bfe43e11ffcb98a555f005aa5ac6e75932bfe1e9464364a9d6856e5c6ec3208787b025c173bf887115cd2929b4dec1f06f311ad4b652fef86b
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -8,10 +8,13 @@ require 'dynarex'
8
8
  require 'rdiscount'
9
9
 
10
10
 
11
+ # feature: 02-Aug-2015 dynarex_to_table() is now know as dynarex_to_markdown()
12
+ # A markdown list will be rendered from a Dynarex
13
+ # document if there is only a single field column
11
14
  # improvement:
12
15
  # 16-Jul-2015 to_s is now equivalent to_html; to_s is
13
16
  # more readable when it's just text which is returned
14
- # feature: 06-Jul-2015 dynarex_to_table():
17
+ # feature: 06-Jul-2015 dynarex_to_markdown():
15
18
  # 1. A URL within a col is now hyperlinked
16
19
  # 2. Select fields can now be displayd
17
20
  # feature: 02-Jul-2015 Apply_filter() now filters out pre and code tags
@@ -79,12 +82,12 @@ require 'rdiscount'
79
82
  # feature: 12-Aug-2013: unordered_list supported
80
83
  # feature: 31-Mar-2013: markdown inside a martile ordered list
81
84
  # is now converted to HTML
82
- # bug fix: 02-Nov-2012: within dynarex_to_table URLs containing a
85
+ # bug fix: 02-Nov-2012: within dynarex_to_markdown URLs containing a
83
86
  # dash now work
84
87
  # bug fix: 20-Sep-2012: in ordered_list_to_html it now cuts off from
85
88
  # parsing headings
86
89
  # bug fix: 04-Aug-2012; replaced \s with a space in regex patterns
87
- # modified: 28-Mar-2012; Added dynarex_to_table
90
+ # modified: 28-Mar-2012; Added dynarex_to_markdown
88
91
  # modified: 28-Aug-2011; Added escaping of HTML within a code block
89
92
 
90
93
  class Martile
@@ -108,7 +111,7 @@ class Martile
108
111
  s5 = apply_filter(s4) {|x| unordered_list_to_html x }
109
112
  #puts 's5 : ' + s5.inspect
110
113
 
111
- s6 = apply_filter(s5) {|x| dynarex_to_table x }
114
+ s6 = apply_filter(s5) {|x| dynarex_to_markdown x }
112
115
  #puts 's6 :' + s6.inspect
113
116
 
114
117
  s7 = apply_filter(s6) {|x| table_to_html x }
@@ -192,7 +195,7 @@ class Martile
192
195
 
193
196
  end
194
197
 
195
- def dynarex_to_table2(s)
198
+ def dynarex_to_markdown2(s)
196
199
 
197
200
  s.gsub(/-\[((https?:\/\/)?[\w\/\.\-]+)\]/) do |match|
198
201
 
@@ -202,72 +205,19 @@ class Martile
202
205
  end
203
206
  end
204
207
 
205
- def dynarex_to_table(s)
208
+ def dynarex_to_markdown(s)
206
209
 
207
210
  s.gsub(/-\[((https?:\/\/)?[\w\/\.\-]+)\](\{[^\}]+\})?/) do |match|
208
211
 
209
212
  source = ($1)
210
213
  raw_select = ($3)
211
-
212
- if raw_select then
213
- raw_fields = raw_select[/select:\s*["']([^"']+)/,1]
214
- fields = raw_fields.split(/\s*,\s*/)
215
- end
216
-
217
- print_row = -> (row, widths) do
218
- '| ' + row.map\
219
- .with_index {|y,i| y.to_s.ljust(widths[i])}.join(' | ') + " |\n"
220
- end
221
-
222
- print_thline = -> (row, widths) do
223
- '|:' + row.map\
224
- .with_index {|y,i| y.to_s.ljust(widths[i])}.join('|:') + "|\n"
225
- end
214
+ dx = Dynarex.new(source)
226
215
 
227
- print_rows = -> (rows, widths) do
228
- rows.map {|x| print_row.call(x,widths)}.join
216
+ if dx.fields.length > 1 then
217
+ dx_render_table(source, raw_select)
218
+ else
219
+ dx.records.keys.map {|x| '* ' + x}.join("\n")
229
220
  end
230
-
231
- dx = Dynarex.new(source)
232
-
233
- flat_records = raw_select ? dx.to_a(select: fields) : dx.to_a
234
-
235
- keys = flat_records.map(&:keys).first
236
- raw_vals = flat_records.map(&:values)
237
-
238
- # create Markdown hyperlinks for any URLs
239
-
240
- vals = raw_vals.map do |row|
241
-
242
- row.map do |col|
243
-
244
- found_match = col.match(/https?:\/\/([^\/]+)(.*)/)
245
-
246
- r = if found_match then
247
-
248
- domain, path = found_match.captures
249
-
250
- a = domain.split('.')
251
- a.shift if a.length > 2
252
- url_title = (a.join('.') + path)[0..39] + '...'
253
-
254
- "[%s](%s)" % [url_title, col]
255
- else
256
- col
257
- end
258
-
259
- r
260
- end
261
- end
262
-
263
- widths = ([keys] + vals).transpose.map{|x| x.max_by(&:length).length}
264
- th = '|' + keys.join('|') + "|\n"
265
- th = print_row.call(keys, widths)
266
- th_line = print_thline.call widths.map {|x| '-' * (x+1)}, widths
267
-
268
- tb = print_rows.call(vals, widths)
269
- table = th + th_line + tb
270
-
271
221
  end
272
222
  end
273
223
 
@@ -393,6 +343,68 @@ class Martile
393
343
  list_to_html s, '#'
394
344
  end
395
345
 
346
+ def dx_render_table()
347
+
348
+ if raw_select then
349
+ raw_fields = raw_select[/select:\s*["']([^"']+)/,1]
350
+ fields = raw_fields.split(/\s*,\s*/)
351
+ end
352
+
353
+ print_row = -> (row, widths) do
354
+ '| ' + row.map\
355
+ .with_index {|y,i| y.to_s.ljust(widths[i])}.join(' | ') + " |\n"
356
+ end
357
+
358
+ print_thline = -> (row, widths) do
359
+ '|:' + row.map\
360
+ .with_index {|y,i| y.to_s.ljust(widths[i])}.join('|:') + "|\n"
361
+ end
362
+
363
+ print_rows = -> (rows, widths) do
364
+ rows.map {|x| print_row.call(x,widths)}.join
365
+ end
366
+
367
+
368
+
369
+ flat_records = raw_select ? dx.to_a(select: fields) : dx.to_a
370
+
371
+ keys = flat_records.map(&:keys).first
372
+ raw_vals = flat_records.map(&:values)
373
+
374
+ # create Markdown hyperlinks for any URLs
375
+
376
+ vals = raw_vals.map do |row|
377
+
378
+ row.map do |col|
379
+
380
+ found_match = col.match(/https?:\/\/([^\/]+)(.*)/)
381
+
382
+ r = if found_match then
383
+
384
+ domain, path = found_match.captures
385
+
386
+ a = domain.split('.')
387
+ a.shift if a.length > 2
388
+ url_title = (a.join('.') + path)[0..39] + '...'
389
+
390
+ "[%s](%s)" % [url_title, col]
391
+ else
392
+ col
393
+ end
394
+
395
+ r
396
+ end
397
+ end
398
+
399
+ widths = ([keys] + vals).transpose.map{|x| x.max_by(&:length).length}
400
+ th = '|' + keys.join('|') + "|\n"
401
+ th = print_row.call(keys, widths)
402
+ th_line = print_thline.call widths.map {|x| '-' * (x+1)}, widths
403
+
404
+ tb = print_rows.call(vals, widths)
405
+ table = th + th_line + tb
406
+ end
407
+
396
408
  def unordered_list_to_html(s)
397
409
  list_to_html s, '\*'
398
410
  end
@@ -501,4 +513,4 @@ class Martile
501
513
  end
502
514
 
503
515
  end
504
- end
516
+ end
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.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  fnr5l+RI/6f8lfxBNgDrktGB/RwPkOyWtyKk1tu9CWgHmptxL0JglikCXg5MzuZI
32
32
  tZzXOvXUoUf1VQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-07-16 00:00:00.000000000 Z
34
+ date: 2015-08-02 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdiscount
metadata.gz.sig CHANGED
Binary file