erubis 2.6.4 → 2.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGES.txt +9 -2
  2. data/README.txt +1 -1
  3. data/benchmark/bench.rb +1 -2
  4. data/bin/erubis +1 -2
  5. data/contrib/erubis +43 -68
  6. data/contrib/inline-require +53 -27
  7. data/doc-api/classes/ActionView/TemplateHandlers/ErubisHandler.html +3 -3
  8. data/doc-api/classes/Erubis.html +1 -1
  9. data/doc-api/classes/Erubis/ArrayBufferEnhancer.html +2 -2
  10. data/doc-api/classes/Erubis/ArrayEnhancer.html +2 -2
  11. data/doc-api/classes/Erubis/Basic/Converter.html +4 -4
  12. data/doc-api/classes/Erubis/BiPatternEnhancer.html +2 -2
  13. data/doc-api/classes/Erubis/CGenerator.html +10 -10
  14. data/doc-api/classes/Erubis/Context.html +7 -7
  15. data/doc-api/classes/Erubis/Converter.html +4 -4
  16. data/doc-api/classes/Erubis/DeleteIndentEnhancer.html +1 -1
  17. data/doc-api/classes/Erubis/Engine.html +5 -5
  18. data/doc-api/classes/Erubis/ErboutEnhancer.html +2 -2
  19. data/doc-api/classes/Erubis/EscapeEnhancer.html +1 -1
  20. data/doc-api/classes/Erubis/Evaluator.html +3 -3
  21. data/doc-api/classes/Erubis/Generator.html +10 -10
  22. data/doc-api/classes/Erubis/HeaderFooterEnhancer.html +2 -2
  23. data/doc-api/classes/Erubis/Helpers/RailsFormHelper.html +25 -25
  24. data/doc-api/classes/Erubis/Helpers/RailsHelper.html +8 -8
  25. data/doc-api/classes/Erubis/Helpers/RailsHelper/TemplateConverter.html +4 -4
  26. data/doc-api/classes/Erubis/InterpolationEnhancer.html +5 -5
  27. data/doc-api/classes/Erubis/JavaGenerator.html +9 -9
  28. data/doc-api/classes/Erubis/JavascriptGenerator.html +10 -10
  29. data/doc-api/classes/Erubis/Main.html +6 -5
  30. data/doc-api/classes/Erubis/NoCodeEnhancer.html +5 -5
  31. data/doc-api/classes/Erubis/NoTextEnhancer.html +1 -1
  32. data/doc-api/classes/Erubis/OptimizedEruby.html +1 -1
  33. data/doc-api/classes/Erubis/OptimizedGenerator.html +12 -12
  34. data/doc-api/classes/Erubis/OptimizedXmlEruby.html +1 -1
  35. data/doc-api/classes/Erubis/PI/Converter.html +3 -3
  36. data/doc-api/classes/Erubis/PI/Ec.html +1 -1
  37. data/doc-api/classes/Erubis/PI/Ejava.html +1 -1
  38. data/doc-api/classes/Erubis/PI/Ejavascript.html +1 -1
  39. data/doc-api/classes/Erubis/PI/Eperl.html +1 -1
  40. data/doc-api/classes/Erubis/PI/Ephp.html +1 -1
  41. data/doc-api/classes/Erubis/PI/Eruby.html +1 -1
  42. data/doc-api/classes/Erubis/PI/Escheme.html +1 -1
  43. data/doc-api/classes/Erubis/PI/TinyEruby.html +4 -4
  44. data/doc-api/classes/Erubis/PercentLineEnhancer.html +1 -1
  45. data/doc-api/classes/Erubis/PerlGenerator.html +9 -9
  46. data/doc-api/classes/Erubis/PhpGenerator.html +9 -9
  47. data/doc-api/classes/Erubis/PreprocessingEruby.html +2 -2
  48. data/doc-api/classes/Erubis/PreprocessingHelper.html +3 -3
  49. data/doc-api/classes/Erubis/PrintEnabledEnhancer.html +3 -3
  50. data/doc-api/classes/Erubis/PrintOutEnhancer.html +5 -5
  51. data/doc-api/classes/Erubis/RubyEvaluator.html +3 -3
  52. data/doc-api/classes/Erubis/RubyGenerator.html +8 -8
  53. data/doc-api/classes/Erubis/SchemeGenerator.html +10 -10
  54. data/doc-api/classes/Erubis/SimplifyEnhancer.html +1 -1
  55. data/doc-api/classes/Erubis/StdoutEnhancer.html +2 -2
  56. data/doc-api/classes/Erubis/StringBufferEnhancer.html +2 -2
  57. data/doc-api/classes/Erubis/TinyEruby.html +7 -8
  58. data/doc-api/classes/Erubis/XmlHelper.html +3 -3
  59. data/doc-api/created.rid +1 -1
  60. data/doc-api/files/README_txt.html +2 -2
  61. data/doc-api/files/erubis/context_rb.html +2 -2
  62. data/doc-api/files/erubis/converter_rb.html +2 -2
  63. data/doc-api/files/erubis/engine/ec_rb.html +2 -2
  64. data/doc-api/files/erubis/engine/ejava_rb.html +2 -2
  65. data/doc-api/files/erubis/engine/ejavascript_rb.html +2 -2
  66. data/doc-api/files/erubis/engine/enhanced_rb.html +2 -2
  67. data/doc-api/files/erubis/engine/eperl_rb.html +2 -2
  68. data/doc-api/files/erubis/engine/ephp_rb.html +2 -2
  69. data/doc-api/files/erubis/engine/eruby_rb.html +2 -2
  70. data/doc-api/files/erubis/engine/escheme_rb.html +2 -2
  71. data/doc-api/files/erubis/engine/optimized_rb.html +2 -2
  72. data/doc-api/files/erubis/engine_rb.html +2 -2
  73. data/doc-api/files/erubis/enhancer_rb.html +2 -2
  74. data/doc-api/files/erubis/error_rb.html +2 -2
  75. data/doc-api/files/erubis/evaluator_rb.html +2 -2
  76. data/doc-api/files/erubis/generator_rb.html +2 -2
  77. data/doc-api/files/erubis/helper_rb.html +2 -2
  78. data/doc-api/files/erubis/helpers/rails_form_helper_rb.html +2 -2
  79. data/doc-api/files/erubis/helpers/rails_helper_rb.html +2 -2
  80. data/doc-api/files/erubis/local-setting_rb.html +2 -2
  81. data/doc-api/files/erubis/main_rb.html +2 -2
  82. data/doc-api/files/erubis/preprocessing_rb.html +2 -2
  83. data/doc-api/files/erubis/tiny_rb.html +2 -2
  84. data/doc-api/files/erubis_rb.html +2 -2
  85. data/doc/users-guide.html +6 -6
  86. data/lib/erubis.rb +2 -3
  87. data/lib/erubis/context.rb +1 -2
  88. data/lib/erubis/converter.rb +1 -2
  89. data/lib/erubis/engine.rb +1 -2
  90. data/lib/erubis/engine/ec.rb +1 -2
  91. data/lib/erubis/engine/ejava.rb +1 -2
  92. data/lib/erubis/engine/ejavascript.rb +1 -2
  93. data/lib/erubis/engine/enhanced.rb +1 -2
  94. data/lib/erubis/engine/eperl.rb +1 -2
  95. data/lib/erubis/engine/ephp.rb +1 -2
  96. data/lib/erubis/engine/eruby.rb +1 -2
  97. data/lib/erubis/engine/escheme.rb +1 -2
  98. data/lib/erubis/engine/optimized.rb +1 -2
  99. data/lib/erubis/enhancer.rb +1 -2
  100. data/lib/erubis/error.rb +1 -2
  101. data/lib/erubis/evaluator.rb +1 -2
  102. data/lib/erubis/generator.rb +1 -2
  103. data/lib/erubis/helper.rb +1 -2
  104. data/lib/erubis/helpers/rails_form_helper.rb +1 -2
  105. data/lib/erubis/helpers/rails_helper.rb +1 -2
  106. data/lib/erubis/local-setting.rb +1 -2
  107. data/lib/erubis/main.rb +18 -21
  108. data/lib/erubis/preprocessing.rb +1 -2
  109. data/lib/erubis/tiny.rb +4 -6
  110. data/test/assert-text-equal.rb +1 -2
  111. data/test/test-engines.rb +1 -2
  112. data/test/test-enhancers.rb +1 -2
  113. data/test/test-erubis.rb +1 -2
  114. data/test/test-main.rb +36 -16
  115. data/test/test-users-guide.rb +1 -2
  116. data/test/test.rb +1 -2
  117. data/test/testutil.rb +3 -8
  118. metadata +2 -2
@@ -1,9 +1,16 @@
1
1
  # -*- coding: utf-8 -*-
2
- # $Rev: 129 $
3
- # $Release: 2.6.4 $
2
+ # $Release: 2.6.5 $
4
3
  # copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
5
4
 
6
5
 
6
+ - release: 2.6.5
7
+ date: 2009-07-20
8
+ bugfixes:
9
+
10
+ - |
11
+ Fixed bug around '-z' option.
12
+
13
+
7
14
  - release: 2.6.4
8
15
  date: 2009-02-18
9
16
  enhancemens:
data/README.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  = README
2
2
 
3
- release:: 2.6.4
3
+ release:: 2.6.5
4
4
  copyright:: copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
5
5
 
6
6
 
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  ###
4
- ### $Rev: 101 $
5
- ### $Release: 2.6.4 $
4
+ ### $Release: 2.6.5 $
6
5
  ### copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
7
6
  ###
8
7
 
data/bin/erubis CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  ###
4
- ### $Rev: 121 $
5
- ### $Release: 2.6.4 $
4
+ ### $Release: 2.6.5 $
6
5
  ### copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
7
6
  ###
8
7
 
@@ -1,23 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  ###
4
- ### $Rev: 121 $
5
- ### $Release: 2.6.4 $
4
+ ### $Release: 2.6.5 $
6
5
  ### copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
7
6
  ###
8
7
 
9
8
  #--begin of require 'erubis/main'
10
9
  ###
11
- ### $Rev: 122 $
12
- ### $Release: 2.6.4 $
10
+ ### $Release: 2.6.5 $
13
11
  ### copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
14
12
  ###
15
13
 
16
14
  require 'yaml'
17
15
  #--begin of require 'erubis'
18
16
  ##
19
- ## $Rev: 99 $
20
- ## $Release: 2.6.4 $
17
+ ## $Release: 2.6.5 $
21
18
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
22
19
  ##
23
20
 
@@ -65,21 +62,19 @@ require 'yaml'
65
62
 
66
63
 
67
64
  module Erubis
68
- VERSION = ('$Release: 2.6.4 $' =~ /([.\d]+)/) && $1
65
+ VERSION = ('$Release: 2.6.5 $' =~ /([.\d]+)/) && $1
69
66
  end
70
67
 
71
68
  #--begin of require 'erubis/engine'
72
69
  ##
73
- ## $Rev: 104 $
74
- ## $Release: 2.6.4 $
70
+ ## $Release: 2.6.5 $
75
71
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
76
72
  ##
77
73
 
78
74
 
79
75
  #--begin of require 'erubis/generator'
80
76
  ##
81
- ## $Rev: 77 $
82
- ## $Release: 2.6.4 $
77
+ ## $Release: 2.6.5 $
83
78
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
84
79
  ##
85
80
 
@@ -242,8 +237,7 @@ end
242
237
  #--end of require 'erubis/generator'
243
238
  #--begin of require 'erubis/converter'
244
239
  ##
245
- ## $Rev: 115 $
246
- ## $Release: 2.6.4 $
240
+ ## $Release: 2.6.5 $
247
241
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
248
242
  ##
249
243
 
@@ -602,15 +596,13 @@ end
602
596
  #--end of require 'erubis/converter'
603
597
  #--begin of require 'erubis/evaluator'
604
598
  ##
605
- ## $Rev: 115 $
606
- ## $Release: 2.6.4 $
599
+ ## $Release: 2.6.5 $
607
600
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
608
601
  ##
609
602
 
610
603
  #--begin of require 'erubis/error'
611
604
  ##
612
- ## $Rev: 77 $
613
- ## $Release: 2.6.4 $
605
+ ## $Release: 2.6.5 $
614
606
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
615
607
  ##
616
608
 
@@ -635,8 +627,7 @@ end
635
627
  #--end of require 'erubis/error'
636
628
  #--begin of require 'erubis/context'
637
629
  ##
638
- ## $Rev: 77 $
639
- ## $Release: 2.6.4 $
630
+ ## $Release: 2.6.5 $
640
631
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
641
632
  ##
642
633
 
@@ -920,8 +911,7 @@ end
920
911
  #require 'erubis/context'
921
912
  #--begin of require 'erubis/helper'
922
913
  ##
923
- ## $Rev: 89 $
924
- ## $Release: 2.6.4 $
914
+ ## $Release: 2.6.5 $
925
915
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
926
916
  ##
927
917
 
@@ -970,8 +960,7 @@ end
970
960
  #--end of require 'erubis/helper'
971
961
  #--begin of require 'erubis/enhancer'
972
962
  ##
973
- ## $Rev: 115 $
974
- ## $Release: 2.6.4 $
963
+ ## $Release: 2.6.5 $
975
964
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
976
965
  ##
977
966
 
@@ -1654,8 +1643,7 @@ end
1654
1643
  #require 'erubis/tiny'
1655
1644
  #--begin of require 'erubis/engine/eruby'
1656
1645
  ##
1657
- ## $Rev: 77 $
1658
- ## $Release: 2.6.4 $
1646
+ ## $Release: 2.6.5 $
1659
1647
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
1660
1648
  ##
1661
1649
 
@@ -1790,8 +1778,7 @@ end
1790
1778
 
1791
1779
  #--begin of require 'erubis/local-setting'
1792
1780
  ##
1793
- ## $Rev: 77 $
1794
- ## $Release: 2.6.4 $
1781
+ ## $Release: 2.6.5 $
1795
1782
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
1796
1783
  ##
1797
1784
 
@@ -1803,8 +1790,7 @@ end
1803
1790
  #--end of require 'erubis'
1804
1791
  #--begin of require 'erubis/tiny'
1805
1792
  ##
1806
- ## $Rev: 115 $
1807
- ## $Release: 2.6.4 $
1793
+ ## $Release: 2.6.5 $
1808
1794
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
1809
1795
  ##
1810
1796
 
@@ -1832,10 +1818,9 @@ module Erubis
1832
1818
  src = "_buf = '';" # preamble
1833
1819
  pos = 0
1834
1820
  input.scan(EMBEDDED_PATTERN) do |indicator, code|
1835
- match = Regexp.last_match
1836
- len = match.begin(0) - pos
1837
- text = input[pos, len]
1838
- pos = match.end(0)
1821
+ m = Regexp.last_match
1822
+ text = input[pos...m.begin(0)]
1823
+ pos = m.end(0)
1839
1824
  #src << " _buf << '" << escape_text(text) << "';"
1840
1825
  text.gsub!(/['\\]/, '\\\\\&')
1841
1826
  src << " _buf << '" << text << "';" unless text.empty?
@@ -1951,8 +1936,7 @@ end
1951
1936
  #--end of require 'erubis/tiny'
1952
1937
  #--begin of require 'erubis/engine/enhanced'
1953
1938
  ##
1954
- ## $Rev: 77 $
1955
- ## $Release: 2.6.4 $
1939
+ ## $Release: 2.6.5 $
1956
1940
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
1957
1941
  ##
1958
1942
 
@@ -2075,8 +2059,7 @@ end
2075
2059
  #--end of require 'erubis/engine/enhanced'
2076
2060
  #--begin of require 'erubis/engine/optimized'
2077
2061
  ##
2078
- ## $Rev: 77 $
2079
- ## $Release: 2.6.4 $
2062
+ ## $Release: 2.6.5 $
2080
2063
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
2081
2064
  ##
2082
2065
 
@@ -2206,8 +2189,7 @@ end
2206
2189
  #--already included require 'erubis/engine/eruby'
2207
2190
  #--begin of require 'erubis/engine/ephp'
2208
2191
  ##
2209
- ## $Rev: 77 $
2210
- ## $Release: 2.6.4 $
2192
+ ## $Release: 2.6.5 $
2211
2193
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
2212
2194
  ##
2213
2195
 
@@ -2308,8 +2290,7 @@ end
2308
2290
  #--end of require 'erubis/engine/ephp'
2309
2291
  #--begin of require 'erubis/engine/ec'
2310
2292
  ##
2311
- ## $Rev: 77 $
2312
- ## $Release: 2.6.4 $
2293
+ ## $Release: 2.6.5 $
2313
2294
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
2314
2295
  ##
2315
2296
 
@@ -2428,8 +2409,7 @@ end
2428
2409
  #--end of require 'erubis/engine/ec'
2429
2410
  #--begin of require 'erubis/engine/ejava'
2430
2411
  ##
2431
- ## $Rev: 77 $
2432
- ## $Release: 2.6.4 $
2412
+ ## $Release: 2.6.5 $
2433
2413
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
2434
2414
  ##
2435
2415
 
@@ -2541,8 +2521,7 @@ end
2541
2521
  #--end of require 'erubis/engine/ejava'
2542
2522
  #--begin of require 'erubis/engine/escheme'
2543
2523
  ##
2544
- ## $Rev: 77 $
2545
- ## $Release: 2.6.4 $
2524
+ ## $Release: 2.6.5 $
2546
2525
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
2547
2526
  ##
2548
2527
 
@@ -2658,8 +2637,7 @@ end
2658
2637
  #--end of require 'erubis/engine/escheme'
2659
2638
  #--begin of require 'erubis/engine/eperl'
2660
2639
  ##
2661
- ## $Rev: 77 $
2662
- ## $Release: 2.6.4 $
2640
+ ## $Release: 2.6.5 $
2663
2641
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
2664
2642
  ##
2665
2643
 
@@ -2756,8 +2734,7 @@ end
2756
2734
  #--end of require 'erubis/engine/eperl'
2757
2735
  #--begin of require 'erubis/engine/ejavascript'
2758
2736
  ##
2759
- ## $Rev: 95 $
2760
- ## $Release: 2.6.4 $
2737
+ ## $Release: 2.6.5 $
2761
2738
  ## copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
2762
2739
  ##
2763
2740
 
@@ -2950,7 +2927,7 @@ module Erubis
2950
2927
  filenames = argv
2951
2928
  options['h'] = true if properties[:help]
2952
2929
  opts = Object.new
2953
- arr = @option_names.collect { |ch, name| "def #{name}; @#{name}; end\n" }
2930
+ arr = @option_names.collect {|ch, name| "def #{name}; @#{name}; end\n" }
2954
2931
  opts.instance_eval arr.join
2955
2932
  options.each do |ch, val|
2956
2933
  name = @option_names[ch]
@@ -3026,7 +3003,8 @@ module Erubis
3026
3003
  msg = "Syntax OK\n"
3027
3004
  if filenames && !filenames.empty?
3028
3005
  filenames.each do |filename|
3029
- test(?f, filename) or raise CommandOptionError.new("#{filename}: file not found.")
3006
+ File.file?(filename) or
3007
+ raise CommandOptionError.new("#{filename}: file not found.")
3030
3008
  engine.filename = filename
3031
3009
  engine.convert!(File.read(filename))
3032
3010
  val = do_action(action, engine, context, filename, opts)
@@ -3144,14 +3122,13 @@ module Erubis
3144
3122
  end
3145
3123
 
3146
3124
  def show_enhancers
3125
+ dict = {}
3126
+ ObjectSpace.each_object(Module) do |mod|
3127
+ dict[$1] = mod if mod.name =~ /\AErubis::(.*)Enhancer\z/
3128
+ end
3147
3129
  s = "enhancers:\n"
3148
- list = []
3149
- ObjectSpace.each_object(Module) do |m| list << m end
3150
- list.sort_by { |m| m.name.to_s }.each do |m|
3151
- next unless m.name =~ /\AErubis::(.*)Enhancer\z/
3152
- name = $1
3153
- desc = m.desc
3154
- s << (" %-13s : %s\n" % [name, desc])
3130
+ dict.sort_by {|name, mod| name }.each do |name, mod|
3131
+ s << (" %-13s : %s\n" % [name, mod.desc])
3155
3132
  end
3156
3133
  return s
3157
3134
  end
@@ -3168,10 +3145,9 @@ module Erubis
3168
3145
  optstr = optstr[1, optstr.length-1]
3169
3146
  #
3170
3147
  if optstr[0] == ?- # context
3171
- unless optstr =~ /\A\-([-\w]+)(?:=(.*))?/
3148
+ optstr =~ /\A\-([-\w]+)(?:=(.*))?/ or
3172
3149
  raise CommandOptionError.new("-#{optstr}: invalid context value.")
3173
- end
3174
- name = $1; value = $2
3150
+ name, value = $1, $2
3175
3151
  name = name.gsub(/-/, '_').intern
3176
3152
  #value = value.nil? ? true : YAML.load(value) # error, why?
3177
3153
  value = value.nil? ? true : YAML.load("---\n#{value}\n")
@@ -3180,15 +3156,12 @@ module Erubis
3180
3156
  else # options
3181
3157
  while optstr && !optstr.empty?
3182
3158
  optchar = optstr[0].chr
3183
- optstr[0,1] = ""
3159
+ optstr = optstr[1..-1]
3184
3160
  if arg_none.include?(optchar)
3185
3161
  options[optchar] = true
3186
3162
  elsif arg_required.include?(optchar)
3187
- arg = optstr.empty? ? argv.shift : optstr
3188
- unless arg
3189
- mesg = "-#{optchar}: #{@option_names[optchar]} required."
3190
- raise CommandOptionError.new(mesg)
3191
- end
3163
+ arg = optstr.empty? ? argv.shift : optstr or
3164
+ raise CommandOptionError.new("-#{optchar}: #{@option_names[optchar]} required.")
3192
3165
  options[optchar] = arg
3193
3166
  optstr = nil
3194
3167
  elsif arg_optional.include?(optchar)
@@ -3333,7 +3306,9 @@ module Erubis
3333
3306
 
3334
3307
  def check_syntax(filename, src)
3335
3308
  require 'open3'
3336
- command = (ENV['_'] || 'ruby') + ' -wc' # ENV['_'] stores command name
3309
+ #command = (ENV['_'] || 'ruby') + ' -wc' # ENV['_'] stores command name
3310
+ bin = ENV['_'] && File.basename(ENV['_']) =~ /^ruby/ ? ENV['_'] : 'ruby'
3311
+ command = bin + ' -wc'
3337
3312
  stdin, stdout, stderr = Open3.popen3(command)
3338
3313
  stdin.write(src)
3339
3314
  stdin.close
@@ -6,13 +6,18 @@
6
6
  ### usage: inline-require [-h] [-I path[,path2,..]] script
7
7
  ###
8
8
  ### copyright(c) 2006-2009 kuwata-lab.com all rights reserved.
9
- ### 2.6.4
10
- ### $Rev: 2 $
9
+ ### 2.6.5
10
+ ### $Rev: 10 $
11
11
  ###
12
12
 
13
13
 
14
14
  class InlineRequire
15
15
 
16
+ def initialize(opts={})
17
+ @opts = opts.dup
18
+ end
19
+ attr_accessor :opts
20
+
16
21
  def expand(filename)
17
22
  sbuf = ''
18
23
  inlined = []
@@ -25,6 +30,10 @@ class InlineRequire
25
30
 
26
31
  def expand_require(filename, sbuf, inlined, level)
27
32
  raise "*** assertion error" if inlined.include?(filename)
33
+ remove_comment = @opts[:remove_comment]
34
+ expand_indented = @opts[:expand_indented]
35
+ keep_filename = @opts[:keep_filename]
36
+ loaded_features = @opts[:loaded_features]
28
37
  inlined << filename
29
38
  prog = File.read(filename)
30
39
  n = 0
@@ -48,7 +57,9 @@ class InlineRequire
48
57
 
49
58
  ## find 'require "foo"' and expand it to inline code
50
59
  flag_inline = false
51
- if line =~ /^\s*require ['"](.*)["']\s*$/
60
+ pattern = expand_indented ? /^[ \t]*require ['"](.*)["']\s*$/ \
61
+ : /^require ['"](.*)["']\s*$/
62
+ if line =~ pattern
52
63
  libname = $1
53
64
  libpath = find_library(libname)
54
65
  $stderr.puts "*** debug: libpath=#{libpath.inspect}" if $debug_mode
@@ -60,13 +71,19 @@ class InlineRequire
60
71
  end
61
72
  end
62
73
  if !flag_inline
63
- sbuf << line
74
+ sbuf << line unless remove_comment && line =~ /^[ \t]*\#/
64
75
  elsif inlined.include?(libpath)
65
- sbuf << "#--already included #{line}"
76
+ sbuf << "#--already included #{line}" unless remove_comment
66
77
  else
67
- sbuf << "#--begin of #{line}"
78
+ if keep_filename
79
+ @n ||= 0; @n += 1; n = @n
80
+ end
81
+ sbuf << "#--begin of #{line}" unless remove_comment
82
+ sbuf << "$LOADED_FEATURES << '#{libname}.rb'\n" if loaded_features
83
+ sbuf << "eval <<'END_OF_SCRIPT__#{n}', TOPLEVEL_BINDING, '#{libpath}', 1\n" if keep_filename
68
84
  expand_require(libpath, sbuf, inlined, level+1)
69
- sbuf << "#--end of #{line}"
85
+ sbuf << "END_OF_SCRIPT__#{n}\n" if keep_filename
86
+ sbuf << "#--end of #{line}" unless remove_comment
70
87
  end
71
88
  end
72
89
  #sbuf << "\n" if sbuf[-1] != ?\n
@@ -105,38 +122,47 @@ end
105
122
  if __FILE__ == $0
106
123
 
107
124
  begin
108
- rubylib_paths = []
109
- flag_help = false
110
- while ARGV[0] && ARGV[0][0] == ?-
111
- opt = ARGV.shift
112
- case opt
113
- when '-h', '--help'
114
- flag_help = true
115
- when '-I'
116
- arg = ARGV.shift
117
- raise "-I: library path required." unless arg
118
- rubylib_paths.concat(arg.split(/,/))
119
- when '-D'
120
- $debug_mode = true
121
- else
122
- raise "#{opt}: invalid option."
123
- end
124
- end
125
-
126
- if flag_help
125
+ require "optparse"
126
+ op = OptionParser.new
127
+ options = {}
128
+ op.on("-h", "--help") {|v| options[:help] = v }
129
+ op.on("-I libpath") {|v| options[:libpath] = v }
130
+ op.on("-i") {|v| options[:expand_indented] = v }
131
+ op.on("-c") {|v| options[:remove_comment] = v }
132
+ op.on("-k") {|v| options[:keep_filename] = v }
133
+ op.on("-l") {|v| options[:loaded_features] = v }
134
+ op.on("-D") {|v| options[:debug] = v }
135
+ op.parse!()
136
+
137
+ $debug_mode = options[:debug]
138
+
139
+ if options[:help]
127
140
  command = File.basename($0)
128
141
  puts "Usage: #{command} [-h] [-I path[,path2,..]] script"
129
142
  puts " -h : help"
143
+ puts " -i : expand indented require(), too"
144
+ puts " -c : remove comment lines start with '#'"
145
+ puts " -k : keep filename (for debugging)"
146
+ puts " -l : append libs to $LOADED_FEATURES"
130
147
  puts " -I path[,path2,...] : ruby library path"
131
148
  exit(0)
132
149
  end
133
150
 
151
+ if options[:libpath]
152
+ rubylib_paths = options[:libpath].split(/,/)
153
+ else
154
+ rubylib_paths = []
155
+ end
134
156
  $stderr.puts "*** debug: rubylib_paths=#{rubylib_paths.inspect}" if $debug_mode
135
157
  $LOAD_PATH.concat(rubylib_paths)
136
158
 
137
159
  filenames = ARGV
138
160
 
139
- inline_require = InlineRequire.new
161
+ opts = { :expand_indented => options[:expand_indented],
162
+ :remove_comment => options[:remove_comment],
163
+ :keep_filename => options[:keep_filename],
164
+ :loaded_features => options[:loaded_features] }
165
+ inline_require = InlineRequire.new(opts)
140
166
  filenames.each do |filename|
141
167
  print inline_require.expand(filename)
142
168
  end