kwartz 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. data/ChangeLog +36 -1
  2. data/LGPL +504 -0
  3. data/README.txt +16 -2
  4. data/bin/kwartz +1 -1
  5. data/doc-api/classes/Kwartz.html +47 -1
  6. data/doc-api/classes/Kwartz/Assertion.html +6 -6
  7. data/doc-api/classes/Kwartz/AssertionError.html +6 -6
  8. data/doc-api/classes/Kwartz/AttrInfo.html +42 -42
  9. data/doc-api/classes/Kwartz/BaseError.html +12 -12
  10. data/doc-api/classes/Kwartz/BaseTranslator.html +210 -43
  11. data/doc-api/classes/Kwartz/CharacterType.html +24 -24
  12. data/doc-api/classes/Kwartz/CommandOptionError.html +7 -7
  13. data/doc-api/classes/Kwartz/CommandOptions.html +49 -49
  14. data/doc-api/classes/Kwartz/Config.html +6 -1
  15. data/doc-api/classes/Kwartz/ConvertError.html +14 -14
  16. data/doc-api/classes/Kwartz/Converter.html +31 -30
  17. data/doc-api/classes/Kwartz/CssStyleParser.html +79 -57
  18. data/doc-api/classes/Kwartz/Defun.html +313 -0
  19. data/doc-api/classes/Kwartz/DocumentRuleset.html +58 -58
  20. data/doc-api/classes/Kwartz/ElementExpander.html +32 -32
  21. data/doc-api/classes/Kwartz/ElementInfo.html +29 -29
  22. data/doc-api/classes/Kwartz/ElementRuleset.html +126 -96
  23. data/doc-api/classes/Kwartz/EperlHandler.html +108 -84
  24. data/doc-api/classes/Kwartz/EperlTranslator.html +7 -7
  25. data/doc-api/classes/Kwartz/ErubisHandler.html +2 -2
  26. data/doc-api/classes/Kwartz/ErubisTranslator.html +8 -8
  27. data/doc-api/classes/Kwartz/ErubyHandler.html +2 -220
  28. data/doc-api/classes/Kwartz/ErubyTranslator.html +7 -7
  29. data/doc-api/classes/Kwartz/ExpandStatement.html +20 -20
  30. data/doc-api/classes/Kwartz/Handler.html +122 -117
  31. data/doc-api/classes/Kwartz/HandlerArgument.html +215 -0
  32. data/doc-api/classes/Kwartz/Helper.html +112 -0
  33. data/doc-api/classes/Kwartz/Helper/ActionViewHelper.html +221 -0
  34. data/doc-api/classes/Kwartz/Helper/RailsTemplate.html +630 -0
  35. data/doc-api/classes/Kwartz/JstlHandler.html +208 -193
  36. data/doc-api/classes/Kwartz/JstlTranslator.html +15 -15
  37. data/doc-api/classes/Kwartz/KwartzError.html +6 -6
  38. data/doc-api/classes/Kwartz/Main.html +39 -23
  39. data/doc-api/classes/Kwartz/NativeExpression.html +18 -18
  40. data/doc-api/classes/Kwartz/NativeStatement.html +25 -25
  41. data/doc-api/classes/Kwartz/Node.html +6 -6
  42. data/doc-api/classes/Kwartz/PIErubisHandler.html +113 -0
  43. data/doc-api/classes/Kwartz/PIErubisTranslator.html +200 -0
  44. data/doc-api/classes/Kwartz/ParseError.html +6 -6
  45. data/doc-api/classes/Kwartz/PhpHandler.html +102 -83
  46. data/doc-api/classes/Kwartz/PhpTranslator.html +14 -14
  47. data/doc-api/classes/Kwartz/PresentationLogicParser.html +136 -128
  48. data/doc-api/classes/Kwartz/PrintStatement.html +19 -19
  49. data/doc-api/classes/Kwartz/RailsHandler.html +121 -118
  50. data/doc-api/classes/Kwartz/RailsTranslator.html +7 -7
  51. data/doc-api/classes/Kwartz/RubyHandler.html +349 -0
  52. data/doc-api/classes/Kwartz/RubyStyleParser.html +85 -85
  53. data/doc-api/classes/Kwartz/RubyTranslator.html +218 -0
  54. data/doc-api/classes/Kwartz/StatementHelper.html +479 -0
  55. data/doc-api/classes/Kwartz/StrutsTranslator.html +12 -12
  56. data/doc-api/classes/Kwartz/TagInfo.html +28 -28
  57. data/doc-api/classes/Kwartz/TextConverter.html +28 -28
  58. data/doc-api/classes/Kwartz/Translator.html +42 -42
  59. data/doc-api/classes/Kwartz/Util.html +284 -0
  60. data/doc-api/created.rid +1 -1
  61. data/doc-api/files/__/README_txt.html +30 -3
  62. data/doc-api/files/kwartz/assert_rb.html +1 -1
  63. data/doc-api/files/kwartz/binding/eperl_rb.html +2 -2
  64. data/doc-api/files/kwartz/binding/erubis_rb.html +3 -3
  65. data/doc-api/files/kwartz/binding/eruby_rb.html +3 -2
  66. data/doc-api/files/kwartz/binding/jstl_rb.html +2 -2
  67. data/doc-api/files/kwartz/binding/php_rb.html +2 -2
  68. data/doc-api/files/kwartz/binding/pierubis_rb.html +116 -0
  69. data/doc-api/files/kwartz/binding/rails_rb.html +2 -2
  70. data/doc-api/files/kwartz/binding/ruby_rb.html +115 -0
  71. data/doc-api/files/kwartz/binding/struts_rb.html +1 -1
  72. data/doc-api/files/kwartz/config_rb.html +2 -2
  73. data/doc-api/files/kwartz/converter_rb.html +3 -2
  74. data/doc-api/files/kwartz/defun_rb.html +116 -0
  75. data/doc-api/files/kwartz/error_rb.html +1 -1
  76. data/doc-api/files/kwartz/helper/rails_rb.html +123 -0
  77. data/doc-api/files/kwartz/main_rb.html +5 -2
  78. data/doc-api/files/kwartz/node_rb.html +2 -2
  79. data/doc-api/files/kwartz/parser_rb.html +2 -2
  80. data/doc-api/files/kwartz/translator_rb.html +2 -2
  81. data/doc-api/files/kwartz/util/assert-text-equal_rb.html +1 -1
  82. data/doc-api/files/kwartz/util/testcase-helper_rb.html +2 -2
  83. data/doc-api/files/kwartz/util_rb.html +107 -0
  84. data/doc-api/files/kwartz_rb.html +3 -2
  85. data/doc-api/fr_class_index.html +11 -0
  86. data/doc-api/fr_file_index.html +5 -0
  87. data/doc-api/fr_method_index.html +242 -190
  88. data/doc/p-pattern.html +94 -94
  89. data/doc/reference.html +847 -612
  90. data/doc/users-guide.html +744 -241
  91. data/examples/rails1/README +2 -2
  92. data/examples/rails1/application_helper.rb +2 -27
  93. data/examples/rails1/link_to.plogic +5 -5
  94. data/examples/rails1/list.plogic +2 -2
  95. data/examples/rails2/app/controllers/application.rb +14 -0
  96. data/examples/rails2/app/controllers/groups_controller.rb +47 -0
  97. data/examples/rails2/app/controllers/members_controller.rb +56 -0
  98. data/examples/rails2/app/helpers/application_helper.rb +6 -0
  99. data/examples/rails2/app/helpers/groups_helper.rb +2 -0
  100. data/examples/rails2/app/helpers/members_helper.rb +2 -0
  101. data/examples/rails2/app/models/group.rb +2 -0
  102. data/examples/rails2/app/models/member.rb +3 -0
  103. data/examples/rails2/app/views/groups/_form.html +30 -0
  104. data/examples/rails2/app/views/groups/_form.plogic +11 -0
  105. data/examples/rails2/app/views/groups/_link.plogic +19 -0
  106. data/examples/rails2/app/views/groups/_read.plogic +7 -0
  107. data/examples/rails2/app/views/groups/edit.cfg.yaml +2 -0
  108. data/examples/rails2/app/views/groups/edit.html +26 -0
  109. data/examples/rails2/app/views/groups/edit.plogic +9 -0
  110. data/examples/rails2/app/views/groups/list.html +48 -0
  111. data/examples/rails2/app/views/groups/list.plogic +32 -0
  112. data/examples/rails2/app/views/groups/new.cfg.yaml +2 -0
  113. data/examples/rails2/app/views/groups/new.html +27 -0
  114. data/examples/rails2/app/views/groups/new.plogic +9 -0
  115. data/examples/rails2/app/views/groups/show.html +27 -0
  116. data/examples/rails2/app/views/groups/show.plogic +2 -0
  117. data/examples/rails2/app/views/layouts/groups.html +23 -0
  118. data/examples/rails2/app/views/layouts/groups.plogic +11 -0
  119. data/examples/rails2/app/views/layouts/members.html +23 -0
  120. data/examples/rails2/app/views/layouts/members.plogic +11 -0
  121. data/examples/rails2/app/views/layouts/members2.html +24 -0
  122. data/examples/rails2/app/views/layouts/members2.plogic +11 -0
  123. data/examples/rails2/app/views/members/_form.plogic +27 -0
  124. data/examples/rails2/app/views/members/_link.plogic +19 -0
  125. data/examples/rails2/app/views/members/_read.plogic +29 -0
  126. data/examples/rails2/app/views/members/edit.cfg.yaml +6 -0
  127. data/examples/rails2/app/views/members/edit.html +27 -0
  128. data/examples/rails2/app/views/members/edit.plogic +10 -0
  129. data/examples/rails2/app/views/members/list.html +53 -0
  130. data/examples/rails2/app/views/members/list.plogic +32 -0
  131. data/examples/rails2/app/views/members/new.html +61 -0
  132. data/examples/rails2/app/views/members/new.plogic +17 -0
  133. data/examples/rails2/app/views/members/show.html +41 -0
  134. data/examples/rails2/app/views/members/show.plogic +3 -0
  135. data/examples/rails2/db/create-tables.mysql.sql +27 -0
  136. data/examples/rails2/db/create-tables.pgsql.sql +27 -0
  137. data/examples/rails2/db/insert-data.sql +21 -0
  138. data/examples/rails2/db/tabledef.yaml +51 -0
  139. data/kwartz.gemspec +4 -4
  140. data/lib/kwartz.rb +10 -2
  141. data/lib/kwartz/assert.rb +1 -1
  142. data/lib/kwartz/binding/eperl.rb +85 -61
  143. data/lib/kwartz/binding/erubis.rb +6 -8
  144. data/lib/kwartz/binding/eruby.rb +5 -120
  145. data/lib/kwartz/binding/jstl.rb +116 -101
  146. data/lib/kwartz/binding/php.rb +79 -60
  147. data/lib/kwartz/binding/pierubis.rb +58 -0
  148. data/lib/kwartz/binding/rails.rb +45 -42
  149. data/lib/kwartz/binding/ruby.rb +193 -0
  150. data/lib/kwartz/binding/struts.rb +1 -1
  151. data/lib/kwartz/config.rb +4 -3
  152. data/lib/kwartz/converter.rb +231 -68
  153. data/lib/kwartz/defun.rb +126 -0
  154. data/lib/kwartz/error.rb +1 -1
  155. data/lib/kwartz/helper/rails.rb +437 -0
  156. data/lib/kwartz/main.rb +30 -38
  157. data/lib/kwartz/node.rb +46 -31
  158. data/lib/kwartz/parser.rb +43 -15
  159. data/lib/kwartz/translator.rb +104 -6
  160. data/lib/kwartz/util.rb +113 -0
  161. data/lib/kwartz/util/assert-text-equal.rb +1 -1
  162. data/lib/kwartz/util/testcase-helper.rb +26 -8
  163. data/test/test-compile.rb +3 -3
  164. data/test/test-compile.yaml +135 -5
  165. data/test/test-converter.rb +16 -8
  166. data/test/test-converter.yaml +307 -76
  167. data/test/test-directives.rb +1 -1
  168. data/test/test-directives.yaml +964 -979
  169. data/test/test-main.rb +61 -146
  170. data/test/test-main.yaml +235 -0
  171. data/test/test-parser.rb +10 -12
  172. data/test/test-parser.yaml +484 -326
  173. data/test/test-rails.rb +1 -1
  174. data/test/test-rails.yaml +37 -37
  175. data/test/test-ruleset.rb +1 -1
  176. data/test/test-ruleset.yaml +34 -40
  177. data/test/test.rb +1 -1
  178. metadata +82 -3
  179. data/COPYING +0 -340
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 117 $
3
- ### $Release: 3.0.0 $
2
+ ### $Rev: 135 $
3
+ ### $Release: 3.1.0 $
4
4
  ### copyright(c) 2004-2006 kuwata-lab.com all rights reserved
5
5
  ###
6
6
 
@@ -10,6 +10,7 @@ require 'kwartz/assert'
10
10
  require 'kwartz/error'
11
11
  require 'kwartz/node'
12
12
  require 'kwartz/config'
13
+ require 'kwartz/util'
13
14
 
14
15
  require 'abstract'
15
16
 
@@ -168,7 +169,7 @@ module Kwartz
168
169
 
169
170
 
170
171
  def merged?
171
- @merged
172
+ !@merged.nil?
172
173
  end
173
174
 
174
175
 
@@ -226,7 +227,7 @@ module Kwartz
226
227
 
227
228
  ## set @despan and @dattr
228
229
  def include_properties(properties)
229
- @dattr = properties[:dattr] || Config::PROPERTY_DATTR # default: 'title'
230
+ @dattr = properties[:dattr] || Config::PROPERTY_DATTR # default: 'kw:d'
230
231
  @delspan = properties.key?(:delspan) ? properties[:delspan] : Config::PROPERTY_DELSPAN # delete dummy <span> tag or not
231
232
  end
232
233
 
@@ -238,17 +239,50 @@ module Kwartz
238
239
 
239
240
 
240
241
  ## raise errror if etag_info is null
241
- def error_if_empty_tag(stag_info, etag_info, d_name, d_arg)
242
- unless etag_info
243
- raise convert_error("'#{d_name}:#{d_arg}': #{d_name} directive is not available with empty tag.", stag_info.linenum)
242
+ def error_if_empty_tag(handler_arg)
243
+ arg = handler_arg
244
+ unless arg.etag_info
245
+ d_name = arg.directive_name
246
+ d_str = arg.directive_str
247
+ msg = "'#{d_str}': #{d_name} directive is not available with empty tag."
248
+ raise convert_error(msg, arg.stag_info.linenum)
244
249
  end
245
250
  end
246
251
 
247
252
 
253
+ def error_when_last_stmt_is_not_if(stmt_list, handler_arg)
254
+ kind = _last_stmt_kind(stmt_list)
255
+ unless kind == :if || kind == :elseif
256
+ d_str = handler_arg.directive_str
257
+ linenum = handler_arg.stag_info.linenum
258
+ msg = "'#{d_str}': previous statement should be 'if' or 'elsif'."
259
+ raise convert_error(msg, linenum)
260
+ end
261
+ end
262
+
263
+
264
+ #private
265
+
266
+
267
+ def _last_stmt_kind(stmt_list)
268
+ return nil if stmt_list.nil? || stmt_list.empty?
269
+ stmt = stmt_list.last
270
+ return nil unless stmt.is_a?(NativeStatement)
271
+ return stmt.kind
272
+ end
273
+
274
+
275
+ end
276
+
277
+
278
+
279
+ module StatementHelper
280
+
281
+
248
282
  ## create print statement from text
249
283
  def create_text_print_stmt(text)
250
284
  return PrintStatement.new([text])
251
- #return new PritnStatement.new([TextExpression.new(text)])
285
+ #return PritnStatement.new([TextExpression.new(text)])
252
286
  end
253
287
 
254
288
 
@@ -311,12 +345,84 @@ module Kwartz
311
345
  end
312
346
 
313
347
 
348
+ ## build print statement of start-tag
349
+ def stag_stmt(handler_arg)
350
+ arg = handler_arg
351
+ return build_print_stmt(arg.stag_info, arg.attr_info, arg.append_exprs)
352
+ end
353
+
354
+
355
+ ## build print statemetn of end-tag
356
+ def etag_stmt(handler_arg)
357
+ arg = handler_arg
358
+ return build_print_stmt(arg.etag_info, nil, nil)
359
+ end
360
+
361
+
362
+ def add_native_code(stmt_list, code, kind)
363
+ if code.is_a?(String)
364
+ stmt_list << NativeStatement.new(code, kind)
365
+ elsif code.is_a?(Array)
366
+ stmt_list.concat(code.collect {|line| NativeStatement.new(line, kind)})
367
+ end
368
+ end
369
+
370
+
371
+ def wrap_element_with_native_stmt(stmt_list, handler_arg, start_code, end_code, kind=nil)
372
+ add_native_code(stmt_list, start_code, kind)
373
+ stmt_list << stag_stmt(handler_arg)
374
+ stmt_list.concat(handler_arg.cont_stmts)
375
+ stmt_list << etag_stmt(handler_arg)
376
+ add_native_code(stmt_list, end_code, kind)
377
+ end
378
+
379
+
380
+ def wrap_content_with_native_stmt(stmt_list, handler_arg, start_code, end_code, kind=nil)
381
+ stmt_list << stag_stmt(handler_arg)
382
+ add_native_code(stmt_list, start_code, kind)
383
+ stmt_list.concat(handler_arg.cont_stmts)
384
+ add_native_code(stmt_list, end_code, kind)
385
+ stmt_list << etag_stmt(handler_arg)
386
+ end
387
+
388
+
389
+ def add_foreach_stmts(stmt_list, handler_arg, foreach_code, endforeach_code,
390
+ content_only, counter, toggle, init_code, incr_code, toggle_code)
391
+ arg = handler_arg
392
+ stmt_list << stag_stmt(arg) if content_only
393
+ start_code.split(/\n/).each do |code|
394
+ stmt_list << NativeStatement.new(code, kind)
395
+ end if start_code
396
+ stmt_list << stag_stmt(arg) if !content_only
397
+ stmt_list.concat(arg.cont_stmts)
398
+ stmt_list << etag_stmt(arg) if !content_only
399
+ end_code.split(/\n/).each do |code|
400
+ stmt_list << NativeStatement.new(code, kind)
401
+ end
402
+ stmt_list << etag_stmt(arg) if content_only
403
+ end
404
+
405
+
406
+ def add_native_expr_with_default(stmt_list, handler_arg,
407
+ expr_code, flag_escape,
408
+ if_code, else_code, endif_code)
409
+ arg = handler_arg
410
+ stmt_list << stag_stmt(arg)
411
+ stmt_list << NativeStatement.new_without_newline(if_code, :if)
412
+ stmt_list << PrintStatement.new([ NativeExpression.new(expr_code, flag_escape) ])
413
+ stmt_list << NativeStatement.new_without_newline(else_code, :else)
414
+ stmt_list.concat(arg.cont_stmts)
415
+ stmt_list << NativeStatement.new_without_newline(endif_code, :else)
416
+ stmt_list << etag_stmt(arg)
417
+ end
418
+
419
+
314
420
  end
315
421
 
316
422
 
317
423
 
318
424
  ##
319
- ## .[abstract] expand ExpandStatement and ElementInfo
425
+ ## (abstract) expand ExpandStatement and ElementInfo
320
426
  ##
321
427
  ## Handler class includes this module.
322
428
  ##
@@ -324,13 +430,13 @@ module Kwartz
324
430
  include Assertion
325
431
 
326
432
 
327
- ## .[abstract] get ElementRuleset
433
+ ## (abstract) get ElementRuleset
328
434
  def get_element_ruleset(name)
329
435
  not_implemented
330
436
  end
331
437
 
332
438
 
333
- ## .[abstract] get ElementInfo
439
+ ## (abstract) get ElementInfo
334
440
  def get_element_info(name)
335
441
  not_implemented
336
442
  end
@@ -437,11 +543,40 @@ module Kwartz
437
543
 
438
544
 
439
545
  ##
440
- ## .[abstract] handle directives
546
+ ## argument data for handler
547
+ ##
548
+ class HandlerArgument
549
+ include StatementHelper
550
+
551
+
552
+ def initialize(directive_name, directive_arg, directive_str,
553
+ stag_info, etag_info, cont_stmts, attr_info, append_exprs)
554
+ @directive_name = directive_name
555
+ @directive_arg = directive_arg
556
+ @directive_str = directive_str
557
+ @stag_info = stag_info
558
+ @etag_info = etag_info
559
+ @cont_stmts = cont_stmts
560
+ @attr_info = attr_info
561
+ @append_exprs = append_exprs
562
+ end
563
+
564
+
565
+ attr_reader :directive_name, :directive_arg, :directive_str
566
+ attr_reader :stag_info, :etag_info, :cont_stmts, :attr_info, :append_exprs
567
+
568
+
569
+ end
570
+
571
+
572
+
573
+ ##
574
+ ## (abstract) handle directives
441
575
  ##
442
576
  class Handler
443
577
  include Assertion
444
578
  include ConverterHelper
579
+ include StatementHelper
445
580
  include ElementExpander
446
581
 
447
582
 
@@ -460,33 +595,52 @@ module Kwartz
460
595
 
461
596
 
462
597
  def get_element_ruleset(name) # for ElementExpander module and Converter class
463
- @elem_ruleset_table[name]
598
+ return @elem_ruleset_table[name]
464
599
  end
465
600
 
466
601
 
467
602
  def get_element_info(name) # for ElementExpander module
468
- @elem_info_table[name]
603
+ return @elem_info_table[name]
604
+ end
605
+
606
+
607
+ def _elem_info_table # :nodoc:
608
+ return @elem_info_table
609
+ end
610
+
611
+
612
+ def _import_element_info_from_handler(handler, names=nil) # :nodoc:
613
+ if names
614
+ regexp_list = names.collect { |name| Kwartz::Util.pattern_to_regexp(name) }
615
+ handler._elem_info_table.each do |name, elem_info|
616
+ if regexp_list.any? { |regexp| regexp =~ name }
617
+ @elem_info_table[name] = elem_info
618
+ end
619
+ end
620
+ else
621
+ @elem_info_table.update(handler._elem_info_table)
622
+ end
469
623
  end
470
624
 
471
625
 
472
626
  protected
473
627
 
474
628
 
475
- ## .[abstract] directive pattern, which is used to detect directives.
629
+ ## (abstract) directive pattern, which is used to detect directives.
476
630
  def directive_pattern
477
631
  not_implemented
478
632
  #return /\A(\w+):\s*(.*)/
479
633
  end
480
634
 
481
635
 
482
- ## .[abstract] mapping pattern, which is used to parse 'attr' directive.
636
+ ## (abstract) mapping pattern, which is used to parse 'attr' directive.
483
637
  def mapping_pattern
484
638
  not_implemented
485
639
  #return /\A'([-:\w]+)'\s+(.*)/
486
640
  end
487
641
 
488
642
 
489
- ## .[abstract] directive format, which is used at has_directive?() method
643
+ ## (abstract) directive format, which is used at has_directive?() method
490
644
  def directive_format
491
645
  not_implemented
492
646
  #return '%s: %s'
@@ -500,32 +654,35 @@ module Kwartz
500
654
  ##
501
655
  ## return true if directive name is one of 'stag', 'etag', 'elem', 'cont', and 'value',
502
656
  ## else return false.
503
- def handle(directive_name, directive_arg, directive_str, stag_info, etag_info, cont_stmts, attr_info, append_exprs, stmt_list)
504
- d_name = directive_name
505
- d_arg = directive_arg
506
- d_str = directive_str
657
+ def handle(stmt_list, handler_arg)
658
+ arg = handler_arg
659
+ d_name = arg.directive_name
660
+ d_arg = arg.directive_arg
661
+ d_str = arg.directive_str
507
662
 
508
- case directive_name
663
+ case d_name
509
664
 
510
665
  when nil
511
- assert unless !attr_info.empty? || !append_exprs.empty?
512
- stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
513
- stmt_list.concat(cont_stmts)
514
- stmt_list << build_print_stmt(etag_info, nil, nil) if etag_info # when empty-tag
666
+ assert unless !arg.attr_info.empty? || !arg.append_exprs.empty?
667
+ stmt_list << stag_stmt(arg)
668
+ stmt_list.concat(arg.cont_stmts)
669
+ stmt_list << etag_stmt(arg) if arg.etag_info # when empty-tag
515
670
 
516
671
  when :dummy
517
672
  # nothing
518
673
 
519
674
  when :id, :mark
520
- unless directive_arg =~ /\A(\w+)\z/ || directive_arg =~ /\A'(\w+)'\z/
521
- raise convert_error("'#{d_str}': invalid marking name.", stag_info.linenum)
675
+ unless d_arg =~ /\A(\w+)\z/ || d_arg =~ /\A'(\w+)'\z/
676
+ raise convert_error("'#{d_str}': invalid marking name.", arg.stag_info.linenum)
522
677
  end
523
678
  name = $1
524
- elem_info = ElementInfo.new(name, stag_info, etag_info, cont_stmts, attr_info, append_exprs)
679
+ elem_info = ElementInfo.new(name, arg.stag_info, arg.etag_info, arg.cont_stmts,
680
+ arg.attr_info, arg.append_exprs)
525
681
  if @elem_info_table[name]
526
682
  #unless Config::ALLOW_DUPLICATE_ID
527
683
  previous_linenum = @elem_info_table[name].stag_info.linenum
528
- raise convert_error("'#{d_str}': id '#{name}' is already used at line #{previous_linenum}.", stag_info.linenum)
684
+ msg = "'#{d_str}': id '#{name}' is already used at line #{previous_linenum}."
685
+ raise convert_error(msg, arg.stag_info.linenum)
529
686
  #end
530
687
  else
531
688
  @elem_info_table[name] = elem_info
@@ -534,47 +691,46 @@ module Kwartz
534
691
  expand_element_info(elem_info, stmt_list)
535
692
 
536
693
  when :stag, :Stag, :STAG
537
- error_if_empty_tag(stag_info, etag_info, d_name, d_arg)
694
+ error_if_empty_tag(arg)
538
695
  flag_escape = d_name == :stag ? nil : (d_name == :Stag)
539
696
  expr = NativeExpression.new(d_arg, flag_escape)
540
- stmt_list << build_print_expr_stmt(expr, stag_info, nil)
541
- stmt_list.concat(cont_stmts)
542
- stmt_list << build_print_stmt(etag_info, nil, nil)
697
+ stmt_list << build_print_expr_stmt(expr, arg.stag_info, nil)
698
+ stmt_list.concat(arg.cont_stmts)
699
+ stmt_list << etag_stmt(arg)
543
700
 
544
701
  when :etag, :Etag, :ETAG
545
- error_if_empty_tag(stag_info, etag_info, d_name, d_arg)
702
+ error_if_empty_tag(arg)
546
703
  flag_escape = d_name == :etag ? nil : (d_name == :Etag)
547
704
  expr = NativeExpression.new(d_arg, flag_escape)
548
- stmt_list << build_print_stmt(stag_info, attr_info, append_exprs)
549
- stmt_list.concat(cont_stmts)
550
- stmt_list << build_print_expr_stmt(expr, nil, etag_info)
705
+ stmt_list << stag_stmt(arg)
706
+ stmt_list.concat(arg.cont_stmts)
707
+ stmt_list << build_print_expr_stmt(expr, nil, arg.etag_info)
551
708
 
552
709
  when :elem, :Elem, :ELEM
553
710
  flag_escape = d_name == :elem ? nil : (d_name == :Elem)
554
711
  expr = NativeExpression.new(d_arg, flag_escape)
555
- stmt_list << build_print_expr_stmt(expr, stag_info, etag_info)
712
+ stmt_list << build_print_expr_stmt(expr, arg.stag_info, arg.etag_info)
556
713
 
557
714
  when :cont, :Cont, :CONT, :value, :Value, :VALUE
558
- error_if_empty_tag(stag_info, etag_info, d_name, d_arg)
559
- stag_info.tail_space = etag_info.head_space = nil # delete spaces
560
- args = build_print_args(stag_info, attr_info, append_exprs)
715
+ error_if_empty_tag(arg)
716
+ arg.stag_info.tail_space = arg.etag_info.head_space = nil # delete spaces
717
+ pargs = build_print_args(arg.stag_info, arg.attr_info, arg.append_exprs)
561
718
  flag_escape = (d_name == :cont || d_name == :value) ? nil : (d_name == :Cont || d_name == :Value)
562
- args << NativeExpression.new(d_arg, flag_escape)
563
- #args << etag_info.tag_text
564
- args << etag_info.tag_text if etag_info.tagname
565
- stmt_list << PrintStatement.new(args)
719
+ pargs << NativeExpression.new(d_arg, flag_escape)
720
+ pargs << arg.etag_info.tag_text if arg.etag_info.tagname
721
+ stmt_list << PrintStatement.new(pargs)
566
722
 
567
723
  when :attr, :Attr, :ATTR
568
724
  unless d_arg =~ self.mapping_pattern() # ex. /\A'([-:\w]+)'\s+(.*)\z/
569
- raise convert_error("'#{d_str}': invalid attr pattern.", stag_info.linenum)
725
+ raise convert_error("'#{d_str}': invalid attr pattern.", arg.stag_info.linenum)
570
726
  end
571
727
  aname = $1; avalue = $2
572
728
  flag_escape = d_name == :attr ? nil : (d_name == :Attr)
573
- attr_info[aname] = NativeExpression.new(avalue, flag_escape)
729
+ arg.attr_info[aname] = NativeExpression.new(avalue, flag_escape)
574
730
 
575
731
  when :append, :Append, :APPEND
576
732
  flag_escape = d_name == :append ? nil : (d_name == :Append)
577
- append_exprs << NativeExpression.new(d_arg, flag_escape)
733
+ arg.append_exprs << NativeExpression.new(d_arg, flag_escape)
578
734
 
579
735
  when :replace_element_with_element, :replace_element_with_content,
580
736
  :replace_content_with_element, :replace_content_with_content
@@ -583,15 +739,15 @@ module Kwartz
583
739
  with_content = arr[3] == 'content'
584
740
  name = d_arg
585
741
  #
586
- error_if_empty_tag(stag_info, etag_info, d_name, d_arg) if replace_cont
587
- stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if replace_cont
742
+ error_if_empty_tag(arg) if replace_cont
743
+ stmt_list << stag_stmt(arg) if replace_cont
588
744
  #stmt_list << ExpandStatement.new(:element, name)
589
745
  elem_info = @elem_info_table[name]
590
746
  unless elem_info
591
- raise convert_error("'#{d_str}': element '#{name}' not found.", stag_info.linenum)
747
+ raise convert_error("'#{d_str}': element '#{name}' not found.", arg.stag_info.linenum)
592
748
  end
593
749
  expand_element_info(elem_info, stmt_list, with_content)
594
- stmt_list << build_print_stmt(etag_info, nil, nil) if replace_cont
750
+ stmt_list << etag_stmt(arg) if replace_cont
595
751
 
596
752
  when :replace_element_with, :replace_content_with, :replace, :placeholder
597
753
  unless d_arg =~ /\A_?(element|content)\(["']?(\w+)["']?\)\z/
@@ -602,15 +758,17 @@ module Kwartz
602
758
  replace_cont = d_name == :replace_content_with || d_name == :placeholder
603
759
  with_content = kind == 'content'
604
760
  #
605
- error_if_empty_tag(stag_info, etag_info, d_name, d_arg) if replace_cont
606
- stmt_list << build_print_stmt(stag_info, attr_info, append_exprs) if replace_cont
761
+ error_if_empty_tag(arg) if replace_cont
762
+ stmt_list << stag_stmt(arg) if replace_cont
607
763
  #stmt_list << ExpandStatement.new(:element, name)
608
764
  elem_info = @elem_info_table[name]
609
765
  unless elem_info
610
- raise convert_error("'#{d_str}': element '#{name}' not found.", stag_info.linenum)
766
+ msg = "'#{d_str}': element '#{name}' not found."
767
+ raise convert_error(msg, arg.stag_info.linenum)
611
768
  end
612
769
  expand_element_info(elem_info, stmt_list, with_content)
613
- stmt_list << build_print_stmt(etag_info, nil, nil) if replace_cont
770
+ stmt_list << etag_stmt(arg) if replace_cont
771
+
614
772
  else
615
773
  return false
616
774
  end #case
@@ -648,10 +806,11 @@ module Kwartz
648
806
 
649
807
 
650
808
  ##
651
- ## .[abstract] covnert presentation data into list of Statement.
809
+ ## (abstract) covnert presentation data into list of Statement.
652
810
  ##
653
811
  class Converter
654
812
  include ConverterHelper
813
+ include StatementHelper
655
814
 
656
815
 
657
816
  def initialize(handler, properties={})
@@ -662,7 +821,7 @@ module Kwartz
662
821
  attr_reader :handler #, :dattr, :input
663
822
 
664
823
 
665
- ## .[abstract] convert string into list of Statement.
824
+ ## (abstract) convert string into list of Statement.
666
825
  def convert(input, filename='')
667
826
  not_implemented
668
827
  end
@@ -749,7 +908,7 @@ module Kwartz
749
908
  taginfo = TagInfo.new(@scanner)
750
909
  @linenum += (@linenum_delta + taginfo.prev_text.count("\n"))
751
910
  @linenum_delta = taginfo.tag_text.count("\n")
752
- taginfo.linenum = linenum
911
+ taginfo.linenum = @linenum
753
912
  return taginfo
754
913
  end
755
914
 
@@ -832,12 +991,14 @@ module Kwartz
832
991
  d_arg = $2 || '' # directive arg
833
992
  case d_name
834
993
  when :attr, :Attr, :ATTR
835
- @handler.handle(d_name, d_arg, d_str, stag_info, etag_info,
836
- cont_stmts, attr_info, append_exprs, stmt_list)
994
+ handler_args = HandlerArgument.new(d_name, d_arg, d_str, stag_info, etag_info,
995
+ cont_stmts, attr_info, append_exprs)
996
+ @handler.handle(stmt_list, handler_args)
837
997
  when :append, :Append, :APPEND
838
998
  append_exprs ||= []
839
- @handler.handle(d_name, d_arg, d_str, stag_info, etag_info,
840
- cont_stmts, attr_info, append_exprs, stmt_list)
999
+ handler_args = HandlerArgument.new(d_name, d_arg, d_str, stag_info, etag_info,
1000
+ cont_stmts, attr_info, append_exprs)
1001
+ @handler.handle(stmt_list, handler_args)
841
1002
  else
842
1003
  if directive_name
843
1004
  raise convert_error("'#{d_str}': not available with '#{directive_name}' directive.", stag_info.linenum)
@@ -854,8 +1015,10 @@ module Kwartz
854
1015
  end
855
1016
 
856
1017
  ## handle other directives
857
- ret = @handler.handle(directive_name, directive_arg, directive_str, stag_info, etag_info,
858
- cont_stmts, attr_info, append_exprs, stmt_list)
1018
+ handler_args = HandlerArgument.new(directive_name, directive_arg, directive_str,
1019
+ stag_info, etag_info, cont_stmts,
1020
+ attr_info, append_exprs)
1021
+ ret = @handler.handle(stmt_list, handler_args)
859
1022
  if directive_name && !ret
860
1023
  raise convert_error("'#{directive_str}': unknown directive.", stag_info.linenum)
861
1024
  end
@@ -865,8 +1028,8 @@ module Kwartz
865
1028
 
866
1029
  ## detect whether directive is exist or not
867
1030
  def has_directive?(attr_info, taginfo)
868
- ## title attribute
869
- val = attr_info[@dattr] # ex. @dattr == 'title'
1031
+ ## kw:d attribute
1032
+ val = attr_info[@dattr] # ex. @dattr == 'kw:d'
870
1033
  if val && val.is_a?(String) && !val.empty?
871
1034
  if val[0] == ?\ ;
872
1035
  val[0,1] = '' # delete a space