mok-parser 0.3.1 → 0.3.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
  SHA1:
3
- metadata.gz: 979f9c3bab2b80999ba5c86cc58cd43b7f5007e3
4
- data.tar.gz: 0f4e4a31757eb142a6907d4bc803ccbaf0d6f177
3
+ metadata.gz: e8d9c6ea441f7a52b43f6409470471656918817b
4
+ data.tar.gz: 5ccf2028ee649ae65ed8b24a3d9abeba5d0227a6
5
5
  SHA512:
6
- metadata.gz: ce4ba3be3ad44a4ebf2e9d03ab1c618d32c8c6f1058c959b4fde44b9ef27d3473a2d6b885a4353cc1cc913f73e317206d7fbf67f528f51a7d7ee1b172c4556fb
7
- data.tar.gz: 511c408a35309c8938fd30e8272a15529e3a0c3417ea81a8b5bf116381584bafe8f050ecf8157ece11a6c5e422b1fe122c551952acd57c79adc24a182f7c3f23
6
+ metadata.gz: f1aa94bb504512f5e2d6ecd73fe811b03e8be38ede030a347457dae34bc22b09905b4c9f428c76e30deca025f178e68201e03b04e64340ce9c3bddf32d580cb0
7
+ data.tar.gz: 01db7cdb5d42e0179d6f19d2b22f1e67aa8336dfeaaa0844778166eed55f8409693d515e393548c000136e3fca1fead56ea24d25e7a8bf0a88f2946f4ec18281
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mok-parser (0.3.0)
4
+ mok-parser (0.3.2)
5
5
  mimemagic
6
6
 
7
7
  GEM
@@ -1,3 +1,7 @@
1
+ == 0.3.2 2013-12-20
2
+ * new: 部分テンプレート(partial)機能を試験的に追加
3
+ * change: _base_directory オプションを *_directory に変更
4
+
1
5
  == 0.3.1 2013-12-14
2
6
  * new: Referenceエレメントにreference_base_directoryオプションを追加
3
7
  * change: Mediaエレメントの media_directory オプションを media_base_directory
data/RELEASE CHANGED
@@ -1 +1 @@
1
- 2013-12-14
1
+ 2013-12-21
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -10,7 +10,10 @@ opt = OptionParser.new do |opt|
10
10
  opt.version = Mok::VERSION
11
11
  opt.release = Mok::RELEASE
12
12
  opt.banner = <<EOL
13
- "mok" is simple document format.
13
+ #{opt.ver}
14
+
15
+ == Description
16
+ "mok-parser" is mok document parser by racc.
14
17
  Read more: https://github.com/garin/mok-parser
15
18
  EOL
16
19
  end
@@ -147,6 +147,7 @@ end
147
147
 
148
148
 
149
149
  def initialize(options = {})
150
+ @options = options
150
151
  @inline_parser = InlineParser.new(options)
151
152
  @metadata = {}
152
153
  @inline_index = @inline_parser.index
@@ -160,6 +161,9 @@ def parse(src)
160
161
  # srcをerbで処理
161
162
  src = ERB.new(src.join,4).result(binding.taint).split("\n").map {|s| "#{s}\n"}
162
163
 
164
+ # 部分テンプレート(partial)
165
+ src = insert_partial(src)
166
+
163
167
  @src = Array(src)
164
168
  @line = Line.new("")
165
169
  @line_pre = @line.dup
@@ -364,6 +368,26 @@ def if_current_indent_equal(ident)
364
368
  end
365
369
  end
366
370
 
371
+ def insert_partial(src)
372
+ src.map do |line|
373
+ if line =~ /^\(\(\!(.*?)\!\)\)/
374
+ file = File.join(File.dirname($1), "_#{File.basename($1)}.mok")
375
+ file_path = file
376
+ file_path = File.join(File.dirname(@options[:src_file]),file) if @options[:src_file]
377
+ unless @options[:partial_directory].nil?
378
+ file_path = File.join(@options[:partial_directory],file) unless @options[:partial_directory].empty?
379
+ end
380
+ if File.exist?(file_path)
381
+ File.open(file_path).readlines
382
+ else
383
+ ["((*Warning*)): [partial] #{file} is not found\n"]
384
+ end
385
+ else
386
+ line
387
+ end
388
+ end.flatten
389
+ end
390
+
367
391
  ---- header
368
392
  require "parserutility"
369
393
  require "mokinlineparser.tab"
@@ -38,6 +38,7 @@ end
38
38
 
39
39
 
40
40
  def initialize(options = {})
41
+ @options = options
41
42
  @inline_parser = InlineParser.new(options)
42
43
  @metadata = {}
43
44
  @inline_index = @inline_parser.index
@@ -51,6 +52,9 @@ def parse(src)
51
52
  # srcをerbで処理
52
53
  src = ERB.new(src.join,4).result(binding.taint).split("\n").map {|s| "#{s}\n"}
53
54
 
55
+ # 部分テンプレート(partial)
56
+ src = insert_partial(src)
57
+
54
58
  @src = Array(src)
55
59
  @line = Line.new("")
56
60
  @line_pre = @line.dup
@@ -255,6 +259,26 @@ def if_current_indent_equal(ident)
255
259
  end
256
260
  end
257
261
 
262
+ def insert_partial(src)
263
+ src.map do |line|
264
+ if line =~ /^\(\(\!(.*?)\!\)\)/
265
+ file = File.join(File.dirname($1), "_#{File.basename($1)}.mok")
266
+ file_path = file
267
+ file_path = File.join(File.dirname(@options[:src_file]),file) if @options[:src_file]
268
+ unless @options[:partial_directory].nil?
269
+ file_path = File.join(@options[:partial_directory],file) unless @options[:partial_directory].empty?
270
+ end
271
+ if File.exist?(file_path)
272
+ File.open(file_path).readlines
273
+ else
274
+ ["((*Warning*)): [partial] #{file} is not found\n"]
275
+ end
276
+ else
277
+ line
278
+ end
279
+ end.flatten
280
+ end
281
+
258
282
  ...end mokblockparser.ry/module_eval...
259
283
  ##### State transition tables begin ###
260
284
 
@@ -72,7 +72,7 @@ class InlineParser
72
72
 
73
73
  media_strings : media_strings media_string { val.join }
74
74
  | media_string {
75
- mok_link_path(val[0], @options[:media_base_directory])
75
+ mok_link_path(val[0], @options[:media_directory])
76
76
  }
77
77
  media : MEDIA_OPEN media_strings MEDIA_CLOSE {
78
78
  mime = MimeMagic.by_extension(val[1].split(".").last)
@@ -219,7 +219,7 @@ class InlineParser
219
219
  uri.slice!(-2,2)
220
220
  uri = "#{uri}#{@options[:reference_extension]}"
221
221
  end
222
- uri = mok_link_path(uri, @options[:reference_base_directory])
222
+ uri = mok_link_path(uri, @options[:reference_directory])
223
223
  Reference.new([title, uri])
224
224
  }
225
225
  # --- reference : end
@@ -366,6 +366,8 @@ def parse(src)
366
366
  end
367
367
  def initialize(options = {})
368
368
  @options = options
369
+ @variables = options[:variables]
370
+ @variables ||= {}
369
371
  @index = {}
370
372
  end
371
373
  attr_reader :index
@@ -116,6 +116,8 @@ def parse(src)
116
116
  end
117
117
  def initialize(options = {})
118
118
  @options = options
119
+ @variables = options[:variables]
120
+ @variables ||= {}
119
121
  @index = {}
120
122
  end
121
123
  attr_reader :index
@@ -898,7 +900,7 @@ module_eval(<<'.,.,', 'mokinlineparser.ry', 72)
898
900
 
899
901
  module_eval(<<'.,.,', 'mokinlineparser.ry', 74)
900
902
  def _reduce_55(val, _values)
901
- mok_link_path(val[0], @options[:media_base_directory])
903
+ mok_link_path(val[0], @options[:media_directory])
902
904
 
903
905
  end
904
906
  .,.,
@@ -1164,7 +1166,7 @@ module_eval(<<'.,.,', 'mokinlineparser.ry', 215)
1164
1166
  uri.slice!(-2,2)
1165
1167
  uri = "#{uri}#{@options[:reference_extension]}"
1166
1168
  end
1167
- uri = mok_link_path(uri, @options[:reference_base_directory])
1169
+ uri = mok_link_path(uri, @options[:reference_directory])
1168
1170
  Reference.new([title, uri])
1169
1171
 
1170
1172
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mok-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - garin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-14 00:00:00.000000000 Z
11
+ date: 2013-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler