deplate 0.7.3 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/AUTHORS.TXT +3 -0
  2. data/CHANGES.TXT +248 -175
  3. data/LICENSE.TXT +0 -0
  4. data/NEWS.TXT +28 -24
  5. data/README.TXT +0 -0
  6. data/TODO.TXT +174 -88
  7. data/VERSION.TXT +1 -1
  8. data/bin/deplate +0 -0
  9. data/bin/deplate.bat +0 -0
  10. data/etc/deplate.ini +91 -3
  11. data/lib/action_view/helpers/deplate.rb +45 -0
  12. data/lib/deplate.rb +6 -1
  13. data/lib/deplate/abstract-class.rb +0 -0
  14. data/lib/deplate/bib.rb +576 -0
  15. data/lib/deplate/builtin.rb +0 -0
  16. data/lib/deplate/cache.rb +55 -5
  17. data/lib/deplate/commands.rb +346 -183
  18. data/lib/deplate/common.rb +209 -48
  19. data/lib/deplate/converter.rb +12 -6
  20. data/lib/deplate/core.rb +777 -378
  21. data/lib/deplate/counters.rb +254 -0
  22. data/lib/deplate/css/article.css +4 -3
  23. data/lib/deplate/css/deplate.css +121 -5
  24. data/lib/deplate/css/heading-navbar.css +0 -0
  25. data/lib/deplate/css/layout-deplate-print.css +0 -0
  26. data/lib/deplate/css/layout-deplate.css +0 -0
  27. data/lib/deplate/css/sans-serif.css +0 -0
  28. data/lib/deplate/css/serif-e.css +0 -0
  29. data/lib/deplate/css/serif-rel.css +0 -0
  30. data/lib/deplate/css/serif.css +9 -3
  31. data/lib/deplate/css/slides.css +0 -0
  32. data/lib/deplate/css/tabbar-left.css +0 -0
  33. data/lib/deplate/css/tabbar-right-ie.css +3 -9
  34. data/lib/deplate/css/tabbar-right.css +51 -18
  35. data/lib/deplate/css/tabbar-top.css +7 -1
  36. data/lib/deplate/css/tabbar.css +0 -0
  37. data/lib/deplate/css/text-sans-serif.css +0 -0
  38. data/lib/deplate/css/text-serif.css +0 -0
  39. data/lib/deplate/define.rb +183 -177
  40. data/lib/deplate/deplate-string.rb +82 -0
  41. data/lib/deplate/docbook.rb +236 -128
  42. data/lib/deplate/elements.rb +584 -417
  43. data/lib/deplate/etc.rb +163 -101
  44. data/lib/deplate/external.rb +42 -11
  45. data/lib/deplate/fmt/dbk-article-4.1.2.rb +0 -0
  46. data/lib/deplate/fmt/dbk-article.rb +0 -0
  47. data/lib/deplate/fmt/dbk-book.rb +0 -0
  48. data/lib/deplate/fmt/dbk-ref.rb +3 -3
  49. data/lib/deplate/fmt/dbk-slides.rb +0 -0
  50. data/lib/deplate/fmt/dbk-snippet.rb +0 -0
  51. data/lib/deplate/fmt/html-snippet.rb +0 -0
  52. data/lib/deplate/fmt/html.rb +783 -550
  53. data/lib/deplate/fmt/htmlsite.rb +192 -199
  54. data/lib/deplate/fmt/htmlslides.rb +0 -0
  55. data/lib/deplate/fmt/htmlwebsite.rb +3 -3
  56. data/lib/deplate/fmt/latex-snippet.rb +0 -0
  57. data/lib/deplate/fmt/latex.rb +242 -83
  58. data/lib/deplate/fmt/null.rb +32 -0
  59. data/lib/deplate/fmt/php.rb +4 -4
  60. data/lib/deplate/fmt/phpsite.rb +6 -5
  61. data/lib/deplate/fmt/plain.rb +160 -106
  62. data/lib/deplate/fmt/template.rb +0 -0
  63. data/lib/deplate/fmt/xhtml10t.rb +0 -0
  64. data/lib/deplate/formatter-snippet.rb +0 -0
  65. data/lib/deplate/formatter.rb +613 -301
  66. data/lib/deplate/input.rb +202 -142
  67. data/lib/deplate/input/deplate-headings.rb +4 -6
  68. data/lib/deplate/input/deplate-restricted.rb +15 -9
  69. data/lib/deplate/input/deplate.rb +2 -4
  70. data/lib/deplate/input/rdoc.rb +39 -38
  71. data/lib/deplate/input/template.rb +0 -0
  72. data/lib/deplate/lib/Makefile.config +29 -0
  73. data/lib/deplate/lib/latex/deplate.sty +54 -0
  74. data/lib/deplate/lib/latex/highlight-extra.sty +0 -0
  75. data/lib/deplate/lib/latex/highlight-typical.sty +0 -0
  76. data/lib/deplate/lib/php/page-comment.inc.php +216 -0
  77. data/lib/deplate/lib/tabmenu.js +0 -0
  78. data/lib/deplate/locale/de.latin1 +155 -17
  79. data/lib/deplate/locale/ru.koi8-r +0 -0
  80. data/lib/deplate/locale/zh_cn.gb2312 +0 -0
  81. data/lib/deplate/macros.rb +133 -82
  82. data/lib/deplate/messages.rb +6 -4
  83. data/lib/deplate/metadata.rb +0 -0
  84. data/lib/deplate/metadata/marshal.rb +0 -0
  85. data/lib/deplate/metadata/xml.rb +0 -0
  86. data/lib/deplate/metadata/yaml.rb +0 -0
  87. data/lib/deplate/mod/anyword.rb +3 -3
  88. data/lib/deplate/mod/babelfish.rb +4 -4
  89. data/lib/deplate/mod/code-gvim.rb +8 -4
  90. data/lib/deplate/mod/code-highlight.rb +3 -3
  91. data/lib/deplate/mod/colored-log.rb +0 -0
  92. data/lib/deplate/mod/de.rb +2 -2
  93. data/lib/deplate/mod/en.rb +0 -0
  94. data/lib/deplate/mod/endnotes.rb +0 -0
  95. data/lib/deplate/mod/fr.rb +0 -0
  96. data/lib/deplate/mod/html-asciimath.rb +0 -0
  97. data/lib/deplate/mod/html-deplate-button.rb +0 -0
  98. data/lib/deplate/mod/html-headings-navbar.rb +5 -13
  99. data/lib/deplate/mod/html-jsmath.rb +39 -0
  100. data/lib/deplate/mod/html-obfuscate-email.rb +3 -3
  101. data/lib/deplate/mod/html-sidebar.rb +0 -0
  102. data/lib/deplate/mod/htmlslides-navbar-fh.rb +3 -3
  103. data/lib/deplate/mod/iconv.rb +0 -0
  104. data/lib/deplate/mod/imgurl.rb +4 -4
  105. data/lib/deplate/mod/inlatex-compound.rb +7 -10
  106. data/lib/deplate/mod/koma.rb +0 -0
  107. data/lib/deplate/mod/latex-emph-table-head.rb +0 -0
  108. data/lib/deplate/mod/latex-styles.rb +7 -4
  109. data/lib/deplate/mod/latex-verbatim-small.rb +0 -0
  110. data/lib/deplate/mod/makefile.rb +23 -7
  111. data/lib/deplate/mod/mark-external-urls.rb +3 -3
  112. data/lib/deplate/mod/markup-1-warn.rb +10 -10
  113. data/lib/deplate/mod/markup-1.rb +0 -0
  114. data/lib/deplate/mod/navbar-png.rb +24 -8
  115. data/lib/deplate/mod/noindent.rb +0 -0
  116. data/lib/deplate/mod/numpara.rb +0 -0
  117. data/lib/deplate/mod/particle-math.rb +4 -4
  118. data/lib/deplate/mod/php-extra.rb +46 -6
  119. data/lib/deplate/mod/pstoedit.rb +0 -0
  120. data/lib/deplate/mod/recode.rb +0 -0
  121. data/lib/deplate/mod/ru_koi8-r.rb +0 -0
  122. data/lib/deplate/mod/smart-dash.rb +26 -0
  123. data/lib/deplate/mod/smiley.rb +69 -7
  124. data/lib/deplate/mod/soffice.rb +0 -0
  125. data/lib/deplate/mod/symbols-latin1.rb +14 -23
  126. data/lib/deplate/mod/symbols-od-utf-8.rb +5 -3
  127. data/lib/deplate/mod/symbols-plain.rb +5 -35
  128. data/lib/deplate/mod/symbols-sgml.rb +8 -9
  129. data/lib/deplate/mod/symbols-utf-8.rb +8 -9
  130. data/lib/deplate/mod/symbols-xml.rb +5 -9
  131. data/lib/deplate/mod/syntax-region-alt.rb +5 -5
  132. data/lib/deplate/mod/utf8.rb +0 -0
  133. data/lib/deplate/mod/validate-html.rb +0 -0
  134. data/lib/deplate/mod/xmlrpc.rb +0 -0
  135. data/lib/deplate/mod/zh-cn-autospace.rb +18 -20
  136. data/lib/deplate/mod/zh-cn.rb +4 -6
  137. data/lib/deplate/nukumi2.rb +71 -0
  138. data/lib/deplate/once-method.rb +0 -0
  139. data/lib/deplate/output.rb +19 -21
  140. data/lib/deplate/particles.rb +178 -116
  141. data/lib/deplate/regions.rb +99 -58
  142. data/lib/deplate/skeletons.rb +122 -0
  143. data/lib/deplate/structured.rb +164 -106
  144. data/lib/deplate/template.rb +67 -43
  145. data/lib/deplate/templates/html-doc.html +0 -0
  146. data/lib/deplate/templates/html-left-tabbar-js.html +0 -0
  147. data/lib/deplate/templates/html-left-tabbar.html +0 -0
  148. data/lib/deplate/templates/html-tabbar-right-pcomments.php +22 -0
  149. data/lib/deplate/templates/html-tabbar-right-step.html +24 -0
  150. data/lib/deplate/templates/html-tabbar-right-table.html +0 -0
  151. data/lib/deplate/templates/html-tabbar-right.html +2 -4
  152. data/lib/deplate/templates/html-tabbar-top.html +0 -9
  153. data/lib/deplate/templates/html-tabbar.html +0 -0
  154. data/lib/deplate/variables.rb +127 -0
  155. data/lib/deplate/wiki-markup.rb +99 -33
  156. data/lib/deplate/xml.rb +18 -18
  157. data/lib/deplate/zh-cn.rb +0 -0
  158. data/lib/ps2ppm.rb +0 -0
  159. data/man/man1/deplate.1 +564 -474
  160. metadata +201 -186
@@ -3,8 +3,8 @@
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 08-Mai-2004.
6
- # @Last Change: 27-Okt-2005.
7
- # @Revision: 0.1530
6
+ # @Last Change: 05-Jun-2006.
7
+ # @Revision: 0.1662
8
8
 
9
9
  # Description:
10
10
  #
@@ -18,9 +18,9 @@
18
18
  class Deplate::Region < Deplate::Element
19
19
  @@regions = {}
20
20
 
21
+ class_attribute :line_cont, true
22
+
21
23
  class << self
22
- attr_reader :line_cont
23
-
24
24
  def regions
25
25
  @@regions
26
26
  end
@@ -30,7 +30,7 @@ class Deplate::Region < Deplate::Element
30
30
  end
31
31
 
32
32
  def set_line_cont(val=true)
33
- @line_cont=val
33
+ self.line_cont=val
34
34
  end
35
35
  end
36
36
 
@@ -133,10 +133,16 @@ class Deplate::Region::SecondOrder < Deplate::Region
133
133
  process_etc
134
134
  @elt = @elt.collect {|e| e.process}.compact
135
135
  @prototype = @elt.first
136
- @prototype.put_label(@label) if @prototype
136
+ unless label_mode == :none
137
+ @prototype.put_label(@label) if @prototype
138
+ end
137
139
  return self
138
140
  end
139
141
 
142
+ def push_styles(*args)
143
+ @elt.each {|e| e.push_styles(*args)}
144
+ end
145
+
140
146
  alias format_special format_compound
141
147
  end
142
148
 
@@ -146,7 +152,6 @@ module Deplate::Regions; end
146
152
  class Deplate::Regions::UNKNOWN < Deplate::Region
147
153
  register_as 'UNKNOWN'
148
154
  set_formatter :format_unknown
149
- set_line_cont
150
155
 
151
156
  def finish
152
157
  # finish_accum
@@ -161,7 +166,7 @@ class Deplate::Regions::UNKNOWN < Deplate::Region
161
166
  end
162
167
 
163
168
  def format_special
164
- format_unknown(self)
169
+ @deplate.formatter.format_unknown(self)
165
170
  end
166
171
  end
167
172
 
@@ -173,13 +178,8 @@ class Deplate::Regions::Doc < Deplate::Region
173
178
 
174
179
  def finish
175
180
  finish_accum
176
- id = @args["id"] || @regNote
177
- @deplate.variables[id] = @accum
178
- @deplate.register_metadata(@source,
179
- "type" => "variable",
180
- "name" => id,
181
- "value" => @accum
182
- )
181
+ id = @args['id'] || @regNote
182
+ Deplate::Command::VAR.set_variable(@deplate, id, @accum, @args, @source)
183
183
  return nil
184
184
  end
185
185
  end
@@ -187,7 +187,9 @@ end
187
187
 
188
188
  class Deplate::Regions::Native < Deplate::Region
189
189
  register_as 'Native'
190
+ register_as 'Ins'
190
191
  set_line_cont false
192
+ self.label_mode = :once
191
193
 
192
194
  def finish
193
195
  finish_accum
@@ -207,9 +209,49 @@ class Deplate::Regions::Native < Deplate::Region
207
209
  end
208
210
 
209
211
 
212
+ class Deplate::Regions::Write < Deplate::Regions::Native
213
+ register_as 'Write'
214
+ self.label_mode = :none
215
+
216
+ def finish
217
+ @vars = @deplate.variables.dup
218
+ super
219
+ end
220
+
221
+ def format_special
222
+ @elt = Deplate::Template.new(:template => @elt,
223
+ :source => @source,
224
+ :container => self)
225
+ Deplate::Define.let_variables(@deplate, @vars) do
226
+ @elt = @elt.fill_in(@deplate, :source => @source)
227
+ end
228
+ @elt = @elt.join("\n")
229
+ fname = @args['file'] || @args['id']
230
+ if @deplate.is_allowed?(['w', 'W'], :logger => self)
231
+ if fname
232
+ unless @deplate.is_allowed?('W')
233
+ fname = File.basename(fname)
234
+ end
235
+ fname = Deplate::Core.get_out_fullname(fname, nil, @deplate.options)
236
+ sfx = @args['suffix'] || @args['sfx']
237
+ fname = [fname, sfx.gsub(/[^[:alnum:].]/, '_')].join('.') if sfx
238
+ mode = @args['append'] ? 'a' : 'w'
239
+ @deplate.write_file(fname, mode) do |io|
240
+ io.puts(@elt)
241
+ end
242
+ else
243
+ log(['No filename'], :error)
244
+ end
245
+ end
246
+ end
247
+
248
+ end
249
+
250
+
210
251
  class Deplate::Regions::Code < Deplate::Regions::Native
211
252
  register_as 'Code'
212
- set_line_cont false
253
+ # set_line_cont false
254
+ self.label_mode = :once
213
255
 
214
256
  @@code_idx = 0
215
257
  @general_highlighter = {}
@@ -229,7 +271,6 @@ class Deplate::Regions::Code < Deplate::Regions::Native
229
271
 
230
272
  def setup(region)
231
273
  super
232
- @label_mode = :once
233
274
  @syntax = @deplate.variables["codeSyntax"]
234
275
  @style = @deplate.variables["codeStyle"]
235
276
  end
@@ -257,7 +298,7 @@ class Deplate::Regions::Code < Deplate::Regions::Native
257
298
  fcode = @deplate.auxiliary_filename("code_#{id}")
258
299
  fout = @deplate.auxiliary_filename("code_#{id}.#{fmt_name}")
259
300
  else
260
- log("No id given", :anyway)
301
+ log("No ID given", :anyway)
261
302
  @@code_idx += 1
262
303
  fcode = @deplate.auxiliary_filename(@deplate.auxiliary_auto_filename('code', @@code_idx, @elt, @syntax))
263
304
  fout = @deplate.auxiliary_filename(@deplate.auxiliary_auto_filename('code', @@code_idx, @elt, fmt_name))
@@ -305,15 +346,14 @@ end
305
346
  class Deplate::Regions::Inlatex < Deplate::Region
306
347
  register_as 'Inlatex'
307
348
  register_as 'Ltx'
308
- set_line_cont
309
349
  set_formatter :format_inlatex
350
+ self.label_mode = :once
310
351
 
311
352
  attr_reader :content_type
312
353
 
313
354
  def setup(region)
314
355
  super
315
356
  @content_type = @args["type"] || "fig"
316
- @label_mode = :once
317
357
  end
318
358
 
319
359
  def finish
@@ -346,7 +386,6 @@ class Deplate::Regions::Img < Deplate::Region
346
386
  register_as 'Image'
347
387
  register_as 'Fig'
348
388
  register_as 'Figure'
349
- set_line_cont
350
389
 
351
390
  @@ImgAutoN = 0
352
391
  @@ImgSuffix = {}
@@ -514,42 +553,42 @@ module Deplate::Regions::Img_R
514
553
  end
515
554
 
516
555
 
517
- class Deplate::Regions::Footnote < Deplate::Region
556
+ class Deplate::Regions::Footnote < Deplate::Region::SecondOrder
557
+ # class Deplate::Regions::Footnote < Deplate::Region
518
558
  register_as 'Footnote'
519
559
  register_as 'Fn'
520
- set_line_cont
560
+ self.label_mode = :none
521
561
 
522
- FootnoteDef = Struct.new("DeplateFootnoteDef", :args, :body, :label, :n, :consumed)
562
+ attr_accessor :fn_label, :fn_n, :fn_consumed
523
563
 
524
564
  def finish
525
- finish_accum
526
- accum = @deplate.parsed_array_from_strings(@accum, 1 + @source.begin, @source.file)
527
- id = @args['id'] ||= @regNote
528
- @elt = FootnoteDef.new(@args, [accum], id)
529
- @deplate.footnotes[id] = self
530
- # @deplate.register_metadata(src,
531
- # "type" => "footnote",
532
- # "name" => id,
533
- # "value" => accum
534
- # )
565
+ rv = super
566
+ @prototype = Deplate::Element
567
+ id = (@args['id'] ||= @regNote)
568
+ if id
569
+ @deplate.footnotes[id] = rv
570
+ # @deplate.register_metadata(src,
571
+ # "type" => "footnote",
572
+ # "name" => id,
573
+ # "value" => accum
574
+ # )
575
+ else
576
+ log('Missing arguments', :error)
577
+ end
535
578
  return nil
536
579
  end
537
-
538
- def process_particles(&block)
539
- @elt.body = ( @elt.body.collect(&block) ).join
540
- end
541
580
  end
542
581
 
543
582
 
544
583
  class Deplate::Regions::Foreach < Deplate::Region
545
584
  register_as 'Foreach'
546
- set_line_cont
585
+ self.label_mode = :once
547
586
 
548
587
  def finish
549
588
  finish_accum
550
589
  @id = @args['@id'].split(/[\s,]+/)
551
590
  unless @id
552
- log('No id given', :error)
591
+ log('No ID given', :error)
553
592
  return nil
554
593
  end
555
594
  doc = @args['doc']
@@ -605,7 +644,6 @@ end
605
644
 
606
645
  class Deplate::Regions::Table < Deplate::Region
607
646
  register_as 'Table'
608
- set_line_cont
609
647
 
610
648
  def finish
611
649
  finish_accum
@@ -618,6 +656,10 @@ class Deplate::Regions::Table < Deplate::Region
618
656
  end
619
657
  end
620
658
 
659
+ # duck method
660
+ def register_caption
661
+ end
662
+
621
663
  class << self
622
664
  def make_char_separated(instance, accum, sep=nil)
623
665
  sep = Regexp.new(sep || "\t")
@@ -625,9 +667,9 @@ class Deplate::Regions::Table < Deplate::Region
625
667
  beg = 1 + instance.source.begin
626
668
  file = instance.source.file
627
669
  table = instance.deplate.parsed_array_from_strings(acc, beg, file)
628
- n = table[0]
670
+ n = table[0]
629
671
  n.collapse = false
630
- n.args = instance.args
672
+ n.unify_props(instance)
631
673
  return n
632
674
  end
633
675
  end
@@ -639,6 +681,7 @@ class Deplate::Regions::Verbatim < Deplate::Region
639
681
  register_as 'Verb'
640
682
  set_formatter :format_verbatim
641
683
  set_line_cont false
684
+ class_attribute :indentation_mode, :none
642
685
 
643
686
  def finish
644
687
  finish_accum
@@ -649,8 +692,11 @@ class Deplate::Regions::Verbatim < Deplate::Region
649
692
 
650
693
  def process
651
694
  process_etc
652
- @elt = @elt.join("\n")
653
- margin = @args["wrap"] || @verbatimMargin
695
+ @elt = @elt.join("\n")
696
+ if @args['removeBackslashes']
697
+ @elt = Deplate::Core.remove_backslashes(@elt)
698
+ end
699
+ margin = @args['wrap'] || @verbatimMargin
654
700
  if margin
655
701
  @elt = @deplate.formatter.wrap_text(@elt, :margin => margin.to_i)
656
702
  end
@@ -663,7 +709,6 @@ end
663
709
  class Deplate::Regions::Abstract < Deplate::Region::SecondOrder
664
710
  register_as 'Abstract'
665
711
  set_formatter :format_abstract, true
666
- set_line_cont
667
712
 
668
713
  def finish
669
714
  rv = super
@@ -676,9 +721,9 @@ class Deplate::Regions::Abstract < Deplate::Region::SecondOrder
676
721
  end
677
722
  else
678
723
  @deplate.register_metadata(@source,
679
- "type" => "abstract",
680
- "lang" => lang,
681
- "value" => @accum
724
+ 'type' => 'abstract',
725
+ 'lang' => lang,
726
+ 'value' => @accum
682
727
  )
683
728
  end
684
729
  rv
@@ -691,13 +736,11 @@ class Deplate::Regions::Quote < Deplate::Region::SecondOrder
691
736
  register_as 'Quote'
692
737
  register_as 'Qu'
693
738
  set_formatter :format_quote, true
694
- set_line_cont
695
739
  end
696
740
 
697
741
 
698
742
  class Deplate::Regions::R < Deplate::Region
699
743
  register_as 'R'
700
- set_line_cont
701
744
 
702
745
  @@RAutoN = 0
703
746
 
@@ -824,10 +867,13 @@ class Deplate::Regions::R < Deplate::Region
824
867
  @accum.collect! do |r|
825
868
  if r =~ /^\s*$/
826
869
  "| |"
827
- elsif @deplate.variables['rScanTable']
870
+ elsif @args['guess'] or @args['scanTable'] or @deplate.variables['rScanTable']
828
871
  cells = scn.match(r)
829
872
  if cells
830
- cells = cells.captures.collect {|c| c.strip}
873
+ cells = cells.captures.collect do |c|
874
+ v = c.strip
875
+ v.empty? ? @deplate.formatter.table_empty_cell : v
876
+ end
831
877
  ['|', cells.join(' | '), '|'].join(' ')
832
878
  else
833
879
  puts @accum.join("\n")
@@ -953,7 +999,6 @@ end
953
999
 
954
1000
  class Deplate::Regions::Ruby < Deplate::Region
955
1001
  register_as 'Ruby'
956
- set_line_cont
957
1002
 
958
1003
  def finish
959
1004
  finish_accum
@@ -980,7 +1025,6 @@ class Deplate::Regions::Clip < Deplate::Region::SecondOrder
980
1025
  register_as 'Clip'
981
1026
  register_as 'Put'
982
1027
  register_as 'Set'
983
- set_line_cont
984
1028
 
985
1029
  # attr_accessor :prototype
986
1030
  attr_reader :is_template, :inline
@@ -1028,7 +1072,6 @@ end
1028
1072
  class Deplate::Regions::Header < Deplate::Region
1029
1073
  register_as 'Header'
1030
1074
  set_formatter :format_header
1031
- set_line_cont
1032
1075
 
1033
1076
  def finish
1034
1077
  finish_accum
@@ -1050,14 +1093,12 @@ end
1050
1093
  class Deplate::Regions::Footer < Deplate::Regions::Header
1051
1094
  register_as 'Footer'
1052
1095
  set_formatter :format_footer
1053
- set_line_cont
1054
1096
  end
1055
1097
 
1056
1098
 
1057
1099
  class Deplate::Regions::Swallow < Deplate::Region
1058
1100
  register_as 'Swallow'
1059
1101
  register_as 'Skip'
1060
- set_line_cont
1061
1102
 
1062
1103
  def finish
1063
1104
  finish_accum
@@ -0,0 +1,122 @@
1
+ # skeletons.rb
2
+ # @Author: Thomas Link (samul AT web de)
3
+ # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
4
+ # @Created: 28-Apr-2006.
5
+ # @Last Change: 03-Jun-2006.
6
+ # @Revision: 0.147
7
+
8
+ # Skeletons:
9
+ class Deplate::SkeletonExpander < Deplate::CommonObject
10
+ def initialize(deplate)
11
+ @deplate = deplate
12
+ @formatter = deplate.formatter
13
+ @formatter_name = @formatter.class.myname
14
+ @max_iteration = 5
15
+ @skeletons = deplate.options.skeletons
16
+ @skeletons_tmpl = {}
17
+ @skel_ids = {}
18
+ @skel_names = @skeletons.collect {|n| Regexp.escape(n)}.join('|')
19
+ @rx = Deplate::Rx.builder("\\{\\{((#@skel_names)\\b(?>\\\\\\{|\\\\\\}|\\\\\\\\|[^{}]+?|{#})*)\\}\\}|^[[:blank:]]+",
20
+ Regexp::MULTILINE, 5, false)
21
+ srand(Time.now.to_i)
22
+ end
23
+
24
+ def require_skeleton(name, source=nil)
25
+ skels = @skeletons_tmpl[@formatter_name] ||= {}
26
+ # names = @deplate.formatter_family_members.collect {|f| "#{name}.#{f}"}
27
+ # names << name
28
+ # names.each do |name|
29
+ t = skels[name] ||= load_skeleton(name)
30
+ return t if t
31
+ # end
32
+ Deplate::Core.log(['Unknown skeleton', name], :error, source)
33
+ end
34
+
35
+ def load_skeleton(name)
36
+ # tmpl = @deplate.skeletons[name]
37
+ tmpl = @deplate.find_in_lib(name, :pwd => true)
38
+ if tmpl and File.exist?(tmpl)
39
+ t = File.open(tmpl) {|io| io.read}
40
+ return t
41
+ end
42
+ return nil
43
+ end
44
+
45
+ def expand(string, source=nil, iterations=@max_iteration)
46
+ if string.empty?
47
+ return string
48
+ end
49
+ expanded = false
50
+ indent = ''
51
+ string.gsub!(@rx) do |s|
52
+ text = $1
53
+ if text
54
+ expansion = expand_skeleton(text, indent, source)
55
+ if expansion
56
+ expanded ||= true
57
+ expansion
58
+ else
59
+ text
60
+ end
61
+ else
62
+ indent = s
63
+ end
64
+ end
65
+ if expanded and iterations > 0
66
+ return expand(string, source, iterations - 1)
67
+ else
68
+ return string
69
+ end
70
+ end
71
+
72
+ def split_name_args(string)
73
+ m = Regexp.new("^(#@skel_names)\s*").match(string)
74
+ name = m[1]
75
+ args = m.post_match.strip
76
+ if args
77
+ args = Deplate::Core.remove_backslashes(args)
78
+ args, body = @deplate.input.parse_args(args)
79
+ args['@body'] = body
80
+ else
81
+ args = {}
82
+ end
83
+ return name, args
84
+ end
85
+
86
+ def expand_skeleton(string, indent='', source=nil)
87
+ name, args = split_name_args(string)
88
+ if @skeletons.include?(name)
89
+ special = "skeleton_#{name}"
90
+ text = if respond_to?(special)
91
+ send(special, args)
92
+ else
93
+ skeleton = require_skeleton(name, source)
94
+ if skeleton
95
+ tmpl = Deplate::Template.new(:template => skeleton,
96
+ :source => source)
97
+ accum = Deplate::Define.let_variables(@deplate, args) do
98
+ tmpl.fill_in(@deplate, :source => source)
99
+ end
100
+ accum.flatten!
101
+ accum.join("\n")
102
+ else
103
+ nil
104
+ end
105
+ end
106
+ if text
107
+ return @formatter.indent_text(text, :hanging => true, :indenttail => indent)
108
+ end
109
+ end
110
+ return nil
111
+ end
112
+
113
+ def skeleton_id(args)
114
+ name = args['name'] || args['id'] || args['@body']
115
+ sep = '_' * (4 + rand(4))
116
+ # rid = Time.now.to_f
117
+ rid = '%x' % rand.to_s[2..-1].to_i
118
+ @skel_ids[name] ||= [sep, name, rid, sep].join('_')
119
+ return @skel_ids[name]
120
+ end
121
+ end
122
+