thinreports 0.9.0 → 0.9.1

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: de107dd9a703e23d4e1f84dcb2849c481efc1ae2
4
- data.tar.gz: 2630e25d206449815b82be3cd96ac87da09f4b94
3
+ metadata.gz: c93b3357d3d5cf6c1b61a01e9426482712d918da
4
+ data.tar.gz: d6947e5e59242e15735d7bb3022dda152ed03d5d
5
5
  SHA512:
6
- metadata.gz: dd9c28499653a33484ae6a8724ce7c0c01fab0a9c26e2d37af415a5d55c33316ed626b2f6562ab3d54ccb4af88f1b96141691a703f9041fca9ab83614a8081aa
7
- data.tar.gz: 0a76ccd613319b2766118031ccdd473e7c42e7fe9e7a9103120c944bb2573dfc9e19915b546468829ac68d2361698f50a82adfa35dfe84b53d70b2562d46b2fe
6
+ metadata.gz: c05756da8074b034b0747ee7d469086c11348ec9366e2311874230961aa36d82c105453ad0d9079eb6ca0c63b3a05ded8135d8bfb3b17fa41aff330f7c2e2804
7
+ data.tar.gz: 10805e8930c437ecc4c2c48fb370c93a450d155af49d783405e0ec2289e1f263b3bd8a29111e6675eac8bf67d426df237ecc5f4831e02dbe477e1696bafac73e
@@ -1,3 +1,9 @@
1
+ ## 0.9.1
2
+
3
+ * Fixed bug that line-height of text-block is always set to 0 #68
4
+ * Fixed a referenced text-block not rendered #68
5
+ * Fixed #66 an error occurred when render list #68
6
+
1
7
  ## 0.9.0
2
8
 
3
9
  * Drop support for layout file saved with Editor v0.7 or lower #62
@@ -6,8 +6,14 @@ require 'rexml/document'
6
6
  module Thinreports
7
7
  module Layout
8
8
  class LegacySchema
9
+ include Utils
10
+
9
11
  def initialize(legacy_schema)
10
12
  @legacy_schema = legacy_schema
13
+ @legacy_svg = legacy_schema['svg'].dup
14
+ @legacy_item_schemas = extract_legacy_item_schemas(legacy_svg)
15
+
16
+ normalize_svg!(@legacy_svg)
11
17
  end
12
18
 
13
19
  def upgrade
@@ -24,20 +30,23 @@ module Thinreports
24
30
  'orientation' => page_config['orientation'],
25
31
  'margin' => page_config.values_at('margin-top', 'margin-right', 'margin-bottom', 'margin-left').map(&:to_f)
26
32
  },
27
- 'items' => build_item_schemas_from_svg(legacy_schema['svg'].dup, '/svg/g', 1)
33
+ 'items' => item_schemas
28
34
  }
29
35
  end
30
36
 
31
- attr_reader :legacy_schema
37
+ attr_reader :legacy_schema, :legacy_svg, :legacy_item_schemas
38
+
39
+ def item_schemas
40
+ svg = REXML::Document.new(legacy_svg)
41
+ build_item_schemas_from_svg(svg.elements['/svg/g'])
42
+ end
32
43
 
33
- def build_item_schemas_from_svg(svg, root_xpath, level)
34
- item_schemas = extract_item_schemas(svg, level)
44
+ def build_item_schemas_from_svg(svg_elements)
45
+ return [] unless svg_elements
35
46
 
36
- svg_doc = REXML::Document.new(normalize_svg(svg, level))
37
47
  items = []
38
48
 
39
- svg_doc.elements[root_xpath].each do |item_element|
40
- item_schema = item_schemas[item_element.attributes['x-id']] || {}
49
+ svg_elements.each do |item_element|
41
50
  item_attributes = item_element.attributes
42
51
 
43
52
  items <<
@@ -50,7 +59,7 @@ module Thinreports
50
59
  when 's-tblock' then text_block_item_schema(item_attributes)
51
60
  when 's-iblock' then image_block_item_schema(item_attributes)
52
61
  when 's-pageno' then page_number_item_schema(item_attributes)
53
- when 's-list' then list_item_schema(item_schema)
62
+ when 's-list' then list_item_schema(item_element)
54
63
  else raise 'Unknown item type'
55
64
  end
56
65
  end
@@ -224,6 +233,7 @@ module Thinreports
224
233
  'value' => attributes['x-value'],
225
234
  'multiple-line' => attributes['x-multiple'] == 'true',
226
235
  'format' => text_format,
236
+ 'reference-id' => attributes['x-ref-id'],
227
237
  'style' => {
228
238
  'font-family' => [ attributes['font-family'] ],
229
239
  'font-size' => attributes['font-size'].to_f,
@@ -234,29 +244,47 @@ module Thinreports
234
244
  'line-height' => line_height(attributes['x-line-height']),
235
245
  'letter-spacing' => letter_spacing(attributes['kerning']),
236
246
  'overflow' => attributes['x-overflow'],
237
- 'word-wrap' => attributes['x-word-wrap']
247
+ 'word-wrap' => attributes['x-word-wrap'] || ''
238
248
  }
239
249
  }
240
250
  end
241
251
 
242
- def list_item_schema(legacy_schema)
243
- {
252
+ def list_item_schema(legacy_element)
253
+ legacy_schema = legacy_item_schemas[legacy_element.attributes['x-id']]
254
+
255
+ header = list_section_schema('header', legacy_element, legacy_schema)
256
+ detail = list_section_schema('detail', legacy_element, legacy_schema)
257
+ page_footer = list_section_schema('page-footer', legacy_element, legacy_schema)
258
+ footer = list_section_schema('footer', legacy_element, legacy_schema)
259
+
260
+ schema = {
244
261
  'id' => legacy_schema['id'],
245
262
  'type' => Core::Shape::List::TYPE_NAME,
246
263
  'content-height' => legacy_schema['content-height'].to_f,
247
264
  'auto-page-break' => legacy_schema['page-break'] == 'true',
248
265
  'display' => display(legacy_schema['display']),
249
- 'header' => list_section_schema('header', legacy_schema),
250
- 'detail' => list_section_schema('detail', legacy_schema),
251
- 'page-footer' => list_section_schema('page-footer', legacy_schema),
252
- 'footer' => list_section_schema('footer', legacy_schema)
266
+ 'header' => header,
267
+ 'detail' => detail,
268
+ 'page-footer' => page_footer,
269
+ 'footer' => footer
253
270
  }
271
+
272
+ if page_footer['enabled']
273
+ page_footer['translate']['y'] += detail['height']
274
+ end
275
+
276
+ if footer['enabled']
277
+ footer['translate']['y'] += detail['height']
278
+ footer['translate']['y'] += page_footer['height'] if page_footer['enabled']
279
+ end
280
+ schema
254
281
  end
255
282
 
256
- def list_section_schema(section_name, legacy_list_schema)
283
+ def list_section_schema(section_name, legacy_list_element, legacy_list_schema)
257
284
  legacy_section_schema = legacy_list_schema[section_name]
285
+ return {} if legacy_section_schema.empty?
258
286
 
259
- section_svg = %(<svg xmlns:xlink="http://www.w3.org/1999/xlink">#{legacy_section_schema['svg']['content']}</svg>)
287
+ section_item_elements = legacy_list_element.elements["g[@class='s-list-#{section_name}']"]
260
288
 
261
289
  section_schema = {
262
290
  'height' => legacy_section_schema['height'].to_f,
@@ -264,7 +292,7 @@ module Thinreports
264
292
  'x' => legacy_section_schema['translate']['x'].to_f,
265
293
  'y' => legacy_section_schema['translate']['y'].to_f
266
294
  },
267
- 'items' => build_item_schemas_from_svg(section_svg, '/svg', 2)
295
+ 'items' => build_item_schemas_from_svg(section_item_elements)
268
296
  }
269
297
 
270
298
  unless section_name == 'detail'
@@ -310,7 +338,7 @@ module Thinreports
310
338
  end
311
339
 
312
340
  def vertical_align(legacy_vertical_align)
313
- return nil unless legacy_vertical_align
341
+ return '' unless legacy_vertical_align
314
342
 
315
343
  case legacy_vertical_align
316
344
  when 'top' then 'top'
@@ -321,7 +349,7 @@ module Thinreports
321
349
  end
322
350
 
323
351
  def line_height(legacy_line_height)
324
- legacy_line_height == '' ? '' : legacy_line_height.to_f
352
+ blank_value?(legacy_line_height) ? '' : legacy_line_height.to_f
325
353
  end
326
354
 
327
355
  def letter_spacing(legacy_letter_spacing)
@@ -331,23 +359,18 @@ module Thinreports
331
359
  end
332
360
  end
333
361
 
334
- def extract_item_schemas(svg, level)
362
+ def extract_legacy_item_schemas(svg)
335
363
  items = {}
336
- svg.scan(/<!--#{level_symbol(level)}SHAPE(.*?)SHAPE#{level_symbol(level)}-->/) do |(item_schema_json)|
364
+ svg.scan(/<!--SHAPE(.*?)SHAPE-->/) do |(item_schema_json)|
337
365
  item_schema = JSON.parse(item_schema_json)
338
366
  items[item_schema['id']] = item_schema
339
367
  end
340
368
  items
341
369
  end
342
370
 
343
- def normalize_svg(svg, level)
344
- svg.gsub!(/<!--#{level_symbol(level)}SHAPE.*?SHAPE#{level_symbol(level)}-->/, '')
345
- svg.gsub!(/<!--#{level_symbol(level)}LAYOUT(.*?)LAYOUT#{level_symbol(level)}-->/) { $1 }
346
- svg
347
- end
348
-
349
- def level_symbol(level)
350
- '-' * (level - 1)
371
+ def normalize_svg!(svg)
372
+ svg.gsub!(/<!--SHAPE.*?SHAPE-->/, '')
373
+ svg.gsub!(/<!--LAYOUT(.*?)LAYOUT-->/) { $1 }
351
374
  end
352
375
  end
353
376
  end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Thinreports
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.1'
5
5
  end
@@ -312,7 +312,8 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
312
312
  'x-overflow' => 'expand',
313
313
  'x-word-wrap' => 'break-word',
314
314
  'x-format-base' => '$ {value}',
315
- 'x-format-type' => ''
315
+ 'x-format-type' => '',
316
+ 'x-ref-id' => 'other_text_block_id'
316
317
  }
317
318
  assert_equal(
318
319
  {
@@ -325,6 +326,7 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
325
326
  'display' => true,
326
327
  'value' => 'default value',
327
328
  'multiple-line' => true,
329
+ 'reference-id' => 'other_text_block_id',
328
330
  'format' => {
329
331
  'base' => '$ {value}',
330
332
  'type' => ''
@@ -398,17 +400,15 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
398
400
  end
399
401
 
400
402
  def test_list_item_schema
401
- rect_item_svg = '<rect stroke="#000000" stroke-width="1" fill="#FFFFFF" class="s-rect" x-display="true" x-stroke-type="solid" stroke-dasharray="none" x-id="" rx="0" width="102.6" height="42" x="40" y="20"/>'
402
-
403
403
  legacy_schema = {
404
404
  'id' => 'default',
405
405
  'type' => 's-list',
406
406
  'content-height' => '300',
407
407
  'page-break' => 'true',
408
408
  'display' => 'false',
409
- 'header-enabled' => 'true',
409
+ 'header-enabled' => 'false',
410
410
  'page-footer-enabled' => 'true',
411
- 'footer-enabled' => 'false',
411
+ 'footer-enabled' => 'true',
412
412
  'header' => {
413
413
  'height' => '100.1',
414
414
  'translate' => {
@@ -423,9 +423,7 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
423
423
  'x' => '300',
424
424
  'y' => '400'
425
425
  },
426
- 'svg' => {
427
- 'content' => rect_item_svg
428
- }
426
+ 'svg' => { 'content' => '' }
429
427
  },
430
428
  'page-footer' => {
431
429
  'height' => '300.1',
@@ -444,6 +442,13 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
444
442
  'svg' => { 'content' => '' }
445
443
  }
446
444
  }
445
+
446
+ layout_legacy_schema.stubs(:legacy_item_schemas).returns({ 'default' => legacy_schema })
447
+
448
+ legacy_element = mock()
449
+ legacy_element.stubs(:attributes).returns({ 'x-id' => 'default' })
450
+ legacy_element.stubs(:elements).returns({})
451
+
447
452
  assert_equal(
448
453
  {
449
454
  'id' => 'default',
@@ -458,7 +463,7 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
458
463
  'y' => 200.0
459
464
  },
460
465
  'items' => [],
461
- 'enabled' => true
466
+ 'enabled' => false
462
467
  },
463
468
  'detail' => {
464
469
  'height' => 200.1,
@@ -466,27 +471,13 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
466
471
  'x' => 300.0,
467
472
  'y' => 400.0
468
473
  },
469
- 'items' => [{
470
- 'id' => '',
471
- 'type' => 'rect',
472
- 'x' => 40.0,
473
- 'y' => 20.0,
474
- 'width' => 102.6,
475
- 'height' => 42.0,
476
- 'display' => true,
477
- 'style' => {
478
- 'border-width' => 1.0,
479
- 'border-color' => '#000000',
480
- 'border-style' => 'solid',
481
- 'fill-color' => '#FFFFFF'
482
- }
483
- }]
474
+ 'items' => []
484
475
  },
485
476
  'page-footer' => {
486
477
  'height' => 300.1,
487
478
  'translate' => {
488
479
  'x' => 500.0,
489
- 'y' => 600.0
480
+ 'y' => 800.1
490
481
  },
491
482
  'items' => [],
492
483
  'enabled' => true
@@ -495,13 +486,13 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
495
486
  'height' => 400.1,
496
487
  'translate' => {
497
488
  'x' => 700.0,
498
- 'y' => 800.0
489
+ 'y' => 1300.2
499
490
  },
500
491
  'items' => [],
501
- 'enabled' => false
492
+ 'enabled' => true
502
493
  }
503
494
  },
504
- layout_legacy_schema.list_item_schema(legacy_schema)
495
+ layout_legacy_schema.list_item_schema(legacy_element)
505
496
  )
506
497
  end
507
498
 
@@ -537,7 +528,7 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
537
528
  end
538
529
 
539
530
  def test_vertical_align
540
- assert_equal nil, layout_legacy_schema.vertical_align(nil)
531
+ assert_equal '', layout_legacy_schema.vertical_align(nil)
541
532
  assert_equal 'top', layout_legacy_schema.vertical_align('top')
542
533
  assert_equal 'middle', layout_legacy_schema.vertical_align('center')
543
534
  assert_equal 'bottom', layout_legacy_schema.vertical_align('bottom')
@@ -546,6 +537,7 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
546
537
 
547
538
  def test_line_height
548
539
  assert_equal '', layout_legacy_schema.line_height('')
540
+ assert_equal '', layout_legacy_schema.line_height(nil)
549
541
  assert_equal 20.1, layout_legacy_schema.line_height('20.1')
550
542
  end
551
543
 
@@ -555,11 +547,6 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
555
547
  assert_equal 2.5, layout_legacy_schema.letter_spacing('2.5')
556
548
  end
557
549
 
558
- def test_level_symbol
559
- assert_equal '', layout_legacy_schema.level_symbol(1)
560
- assert_equal '-', layout_legacy_schema.level_symbol(2)
561
- end
562
-
563
550
  def test_extract_item_schemas
564
551
  svg = <<-SVG
565
552
  <!--SHAPE{"id":"item1"}SHAPE-->
@@ -568,20 +555,20 @@ class Thinreports::Layout::TestLegacySchema < Minitest::Test
568
555
  SVG
569
556
  assert_equal(
570
557
  { 'item1' => { 'id' => 'item1' }, 'item3' => { 'id' => 'item3' } },
571
- layout_legacy_schema.extract_item_schemas(svg, 1)
558
+ layout_legacy_schema.extract_legacy_item_schemas(svg)
572
559
  )
573
560
  end
574
561
 
575
562
  def test_normalize_svg
576
- svg = '<!---SHAPE{"id":"item1"}SHAPE---><!---LAYOUT<rect id="item2"/>LAYOUT---><!--SHAPE{"id":"item2"}SHAPE-->'
577
- normalized_svg = '<rect id="item2"/><!--SHAPE{"id":"item2"}SHAPE-->'
563
+ svg = '<!--SHAPE{"id":"item1"}SHAPE--><!--LAYOUT<rect id="item2"/>LAYOUT--><!--SHAPE{"id":"item2"}SHAPE-->'
578
564
 
579
- assert_equal normalized_svg, layout_legacy_schema.normalize_svg(svg, 2)
565
+ layout_legacy_schema.normalize_svg!(svg)
566
+ assert_equal '<rect id="item2"/>', svg
580
567
  end
581
568
 
582
569
  private
583
570
 
584
571
  def layout_legacy_schema
585
- @layout_legacy_schema ||= Layout::LegacySchema.new({})
572
+ @layout_legacy_schema ||= Layout::LegacySchema.new({ 'svg' => '' })
586
573
  end
587
574
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thinreports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matsukei Co.,Ltd.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-31 00:00:00.000000000 Z
11
+ date: 2016-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn