ydocx 1.2.2 → 1.2.3

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.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.2.3 / 12.07.2012
2
+
3
+ * Updated french char handling, lang in filename
4
+
1
5
  === 1.2.2 / 12.07.2012
2
6
 
3
7
  * Fixed typo in french
data/lib/ydocx/parser.rb CHANGED
@@ -55,7 +55,7 @@ module YDocx
55
55
  if symbol
56
56
  _text = ''
57
57
  text.unpack('U*').each do |char|
58
- _text << optional_replace(char.to_s(16))
58
+ _text << character_replace(char.to_s(16))
59
59
  end
60
60
  text = _text
61
61
  end
@@ -76,14 +76,14 @@ module YDocx
76
76
  end
77
77
  text
78
78
  end
79
- def optional_escape(text)
79
+ def character_encode(text)
80
80
  text.force_encoding('utf-8')
81
81
  # NOTE
82
82
  # :named only for escape at Builder
83
83
  text = @coder.encode(text, :named)
84
84
  text
85
85
  end
86
- def optional_replace(code)
86
+ def character_replace(code)
87
87
  code = '0x' + code
88
88
  # NOTE
89
89
  # replace with rsemble html character ref
@@ -143,6 +143,9 @@ module YDocx
143
143
  #p "char : " + @coder.decode("&#%s;" % code.hex.to_s)
144
144
  end
145
145
  end
146
+ def optional_escape(text)
147
+ text
148
+ end
146
149
  def parse_block(node)
147
150
  nil # default no block element
148
151
  end
@@ -230,7 +233,7 @@ module YDocx
230
233
  end
231
234
  unless r.xpath('w:sym').empty?
232
235
  code = r.xpath('w:sym').first['char'].downcase # w:char
233
- content << optional_replace(code)
236
+ content << character_replace(code)
234
237
  pos += 1
235
238
  end
236
239
  if !r.xpath('w:pict').empty? or !r.xpath('w:drawing').empty?
@@ -276,6 +279,7 @@ module YDocx
276
279
  end
277
280
  def parse_text(r, lstrip=false)
278
281
  text = r.xpath('w:t').map(&:text).join('')
282
+ text = character_encode(text)
279
283
  text = optional_escape(text)
280
284
  text = text.lstrip if lstrip
281
285
  if rpr = r.xpath('w:rPr')
@@ -6,6 +6,7 @@ require 'cgi'
6
6
  module YDocx
7
7
  class Parser
8
8
  attr_accessor :code, :lang
9
+ @@figure_pattern = /&lsquo;|&rsquo;|&apos;|&acute;/
9
10
  def init
10
11
  @image_path = 'image'
11
12
  @code = nil
@@ -93,7 +94,7 @@ module YDocx
93
94
  gsub(/\s*\/\s*|\s+|\/|\-/, '_').gsub(/\./, '').downcase)
94
95
  end
95
96
  def parse_code(text) # swissmedic number
96
- if text.gsub(/&lsquo;|&rsquo;|&apos;|&acute;/, '') =~
97
+ if text.gsub(@@figure_pattern, '') =~
97
98
  /^\s*(\d{5})(.*|\s*)\s*\(\s*Swiss\s*medic\s*\)(\s*|.)$/iu
98
99
  @code = "%5d" % $1
99
100
  else
@@ -116,7 +117,7 @@ module YDocx
116
117
  end
117
118
  def parse_block(node)
118
119
  text = node.inner_text.strip
119
- text = optional_escape text
120
+ text = character_encode(text)
120
121
  chapters.each_pair do |chapter, regexp|
121
122
  if text =~ regexp
122
123
  # allow without line break
@@ -124,13 +125,12 @@ module YDocx
124
125
  id = escape_id(chapter)
125
126
  @indecies << {:text => chapter, :id => id}
126
127
  return parse_heading(text, id)
127
- elsif parse_code(text)
128
- return nil
129
128
  end
130
129
  end
131
130
  if title = parse_title(node, text)
132
131
  return title
133
132
  end
133
+ parse_code(text)
134
134
  return nil
135
135
  end
136
136
  end
@@ -256,9 +256,10 @@ div#container {
256
256
  @files
257
257
  end
258
258
  def output_file(ext) # html
259
+ lang = (@parser.lang.downcase == 'fr' ? 'fr' : 'de')
259
260
  if @parser.code
260
261
  filename = @parser.code
261
- output_directory.join "#{filename}.#{ext.to_s}"
262
+ output_directory.join "#{lang}_#{filename}.#{ext.to_s}"
262
263
  else # default
263
264
  @path.sub_ext(".#{ext.to_s}")
264
265
  end
data/lib/ydocx.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  require 'ydocx/document'
5
5
 
6
6
  module YDocx
7
- VERSION = '1.2.2'
7
+ VERSION = '1.2.3'
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ydocx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
16
- requirement: &14401180 !ruby/object:Gem::Requirement
16
+ requirement: &21383980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.10'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *14401180
24
+ version_requirements: *21383980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
27
- requirement: &14400740 !ruby/object:Gem::Requirement
27
+ requirement: &21383540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.13'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *14400740
35
+ version_requirements: *21383540
36
36
  description: ''
37
37
  email:
38
38
  - yasaka@ywesee.com, zdavatz@ywesee.com