tap 0.9.1 → 0.10.0

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.
Files changed (244) hide show
  1. data/History +37 -30
  2. data/MIT-LICENSE +1 -1
  3. data/README +92 -44
  4. data/bin/tap +62 -75
  5. data/cmd/console.rb +42 -0
  6. data/cmd/destroy.rb +16 -0
  7. data/cmd/generate.rb +16 -0
  8. data/cmd/run.rb +126 -0
  9. data/doc/Class Reference +362 -0
  10. data/doc/Command Reference +153 -0
  11. data/doc/Tutorial +237 -0
  12. data/lib/tap.rb +6 -45
  13. data/lib/tap/app.rb +126 -500
  14. data/lib/tap/constants.rb +2 -29
  15. data/lib/tap/env.rb +555 -250
  16. data/lib/tap/file_task.rb +60 -103
  17. data/lib/tap/generator/base.rb +109 -0
  18. data/lib/tap/generator/destroy.rb +37 -0
  19. data/lib/tap/generator/generate.rb +61 -0
  20. data/lib/tap/generator/generators/command/command_generator.rb +16 -12
  21. data/lib/tap/generator/generators/command/templates/command.erb +13 -19
  22. data/lib/tap/generator/generators/config/config_generator.rb +18 -27
  23. data/lib/tap/generator/generators/config/templates/doc.erb +12 -0
  24. data/lib/tap/generator/generators/config/templates/nodoc.erb +8 -0
  25. data/lib/tap/generator/generators/file_task/file_task_generator.rb +16 -11
  26. data/lib/tap/generator/generators/file_task/templates/file.txt +11 -2
  27. data/lib/tap/generator/generators/file_task/templates/result.yml +6 -0
  28. data/lib/tap/generator/generators/file_task/templates/task.erb +24 -31
  29. data/lib/tap/generator/generators/file_task/templates/test.erb +18 -22
  30. data/lib/tap/generator/generators/root/root_generator.rb +45 -31
  31. data/lib/tap/generator/generators/root/templates/Rakefile +64 -41
  32. data/lib/tap/generator/generators/root/templates/gemspec +27 -0
  33. data/lib/tap/generator/generators/root/templates/tapfile +8 -0
  34. data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +0 -0
  35. data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +1 -1
  36. data/lib/tap/generator/generators/root/templates/test/tapfile_test.rb +15 -0
  37. data/lib/tap/generator/generators/task/task_generator.rb +21 -28
  38. data/lib/tap/generator/generators/task/templates/task.erb +13 -23
  39. data/lib/tap/generator/generators/task/templates/test.erb +15 -18
  40. data/lib/tap/generator/manifest.rb +14 -0
  41. data/lib/tap/patches/rake/rake_test_loader.rb +0 -0
  42. data/lib/tap/patches/rake/testtask.rb +0 -0
  43. data/lib/tap/patches/ruby19/backtrace_filter.rb +0 -0
  44. data/lib/tap/patches/ruby19/parsedate.rb +0 -0
  45. data/lib/tap/root.rb +260 -21
  46. data/lib/tap/support/aggregator.rb +11 -11
  47. data/lib/tap/support/assignments.rb +172 -0
  48. data/lib/tap/support/audit.rb +20 -18
  49. data/lib/tap/support/batchable.rb +21 -10
  50. data/lib/tap/support/batchable_class.rb +107 -0
  51. data/lib/tap/support/class_configuration.rb +154 -239
  52. data/lib/tap/support/command_line.rb +97 -102
  53. data/lib/tap/support/comment.rb +270 -0
  54. data/lib/tap/support/configurable.rb +86 -65
  55. data/lib/tap/support/configurable_class.rb +296 -0
  56. data/lib/tap/support/configuration.rb +122 -0
  57. data/lib/tap/support/constant.rb +70 -0
  58. data/lib/tap/support/constant_utils.rb +127 -0
  59. data/lib/tap/support/declarations.rb +111 -0
  60. data/lib/tap/support/executable.rb +30 -17
  61. data/lib/tap/support/executable_queue.rb +0 -0
  62. data/lib/tap/support/framework.rb +71 -0
  63. data/lib/tap/support/framework_class.rb +199 -0
  64. data/lib/tap/support/instance_configuration.rb +147 -0
  65. data/lib/tap/support/lazydoc.rb +428 -0
  66. data/lib/tap/support/manifest.rb +89 -0
  67. data/lib/tap/support/run_error.rb +0 -0
  68. data/lib/tap/support/shell_utils.rb +33 -9
  69. data/lib/tap/support/summary.rb +30 -0
  70. data/lib/tap/support/tdoc.rb +339 -134
  71. data/lib/tap/support/tdoc/tdoc_html_generator.rb +0 -0
  72. data/lib/tap/support/tdoc/tdoc_html_template.rb +0 -0
  73. data/lib/tap/support/templater.rb +180 -0
  74. data/lib/tap/support/validation.rb +409 -76
  75. data/lib/tap/support/versions.rb +5 -3
  76. data/lib/tap/task.rb +78 -174
  77. data/lib/tap/tasks/dump.rb +56 -0
  78. data/lib/tap/tasks/rake.rb +93 -0
  79. data/lib/tap/test.rb +3 -3
  80. data/lib/tap/test/env_vars.rb +2 -2
  81. data/lib/tap/test/file_methods.rb +19 -20
  82. data/lib/tap/test/script_methods.rb +144 -0
  83. data/lib/tap/test/subset_methods.rb +1 -1
  84. data/lib/tap/test/tap_methods.rb +28 -62
  85. data/lib/tap/workflow.rb +22 -39
  86. metadata +48 -179
  87. data/Basic Overview +0 -151
  88. data/Command Reference +0 -99
  89. data/Rakefile +0 -127
  90. data/Tutorial +0 -287
  91. data/lib/tap/cmd/console.rb +0 -31
  92. data/lib/tap/cmd/destroy.rb +0 -20
  93. data/lib/tap/cmd/generate.rb +0 -20
  94. data/lib/tap/cmd/run.rb +0 -151
  95. data/lib/tap/dump.rb +0 -57
  96. data/lib/tap/generator.rb +0 -91
  97. data/lib/tap/generator/generators/command/USAGE +0 -6
  98. data/lib/tap/generator/generators/config/USAGE +0 -21
  99. data/lib/tap/generator/generators/config/templates/config.erb +0 -1
  100. data/lib/tap/generator/generators/file_task/USAGE +0 -3
  101. data/lib/tap/generator/generators/file_task/templates/file.yml +0 -3
  102. data/lib/tap/generator/generators/generator/USAGE +0 -0
  103. data/lib/tap/generator/generators/generator/generator_generator.rb +0 -21
  104. data/lib/tap/generator/generators/generator/templates/generator.erb +0 -32
  105. data/lib/tap/generator/generators/generator/templates/usage.erb +0 -1
  106. data/lib/tap/generator/generators/root/USAGE +0 -0
  107. data/lib/tap/generator/generators/root/templates/ReadMe.txt +0 -0
  108. data/lib/tap/generator/generators/root/templates/tap.yml +0 -80
  109. data/lib/tap/generator/generators/task/USAGE +0 -3
  110. data/lib/tap/generator/generators/workflow/USAGE +0 -0
  111. data/lib/tap/generator/generators/workflow/templates/task.erb +0 -16
  112. data/lib/tap/generator/generators/workflow/templates/test.erb +0 -7
  113. data/lib/tap/generator/generators/workflow/workflow_generator.rb +0 -6
  114. data/lib/tap/generator/options.rb +0 -26
  115. data/lib/tap/generator/usage.rb +0 -26
  116. data/lib/tap/support/batchable_methods.rb +0 -34
  117. data/lib/tap/support/command_line_methods.rb +0 -76
  118. data/lib/tap/support/configurable_methods.rb +0 -224
  119. data/lib/tap/support/logger.rb +0 -88
  120. data/lib/tap/support/rake.rb +0 -43
  121. data/lib/tap/support/tdoc/config_attr.rb +0 -362
  122. data/test/app/config/another/task.yml +0 -1
  123. data/test/app/config/batch.yml +0 -2
  124. data/test/app/config/empty.yml +0 -0
  125. data/test/app/config/erb.yml +0 -2
  126. data/test/app/config/some/task.yml +0 -1
  127. data/test/app/config/template.yml +0 -2
  128. data/test/app/config/version-0.1.yml +0 -1
  129. data/test/app/config/version.yml +0 -1
  130. data/test/app/lib/app_test_task.rb +0 -3
  131. data/test/app_test.rb +0 -1849
  132. data/test/env/test_configure/recurse_a.yml +0 -2
  133. data/test/env/test_configure/recurse_b.yml +0 -2
  134. data/test/env/test_configure/tap.yml +0 -23
  135. data/test/env/test_load_env_config/dir/tap.yml +0 -3
  136. data/test/env/test_load_env_config/recurse_a.yml +0 -2
  137. data/test/env/test_load_env_config/recurse_b.yml +0 -2
  138. data/test/env/test_load_env_config/tap.yml +0 -3
  139. data/test/env_test.rb +0 -198
  140. data/test/file_task/config/batch.yml +0 -2
  141. data/test/file_task/config/configured.yml +0 -1
  142. data/test/file_task/old_file_one.txt +0 -0
  143. data/test/file_task/old_file_two.txt +0 -0
  144. data/test/file_task_test.rb +0 -1291
  145. data/test/root/alt_lib/alt_module.rb +0 -4
  146. data/test/root/file.txt +0 -0
  147. data/test/root/glob/one.txt +0 -0
  148. data/test/root/glob/two.txt +0 -0
  149. data/test/root/lib/absolute_alt_filepath.rb +0 -2
  150. data/test/root/lib/alternative_filepath.rb +0 -2
  151. data/test/root/lib/another_module.rb +0 -2
  152. data/test/root/lib/nested/some_module.rb +0 -4
  153. data/test/root/lib/no_module_included.rb +0 -0
  154. data/test/root/lib/some/module.rb +0 -4
  155. data/test/root/lib/some_class.rb +0 -2
  156. data/test/root/lib/some_module.rb +0 -3
  157. data/test/root/load_path/load_path_module.rb +0 -2
  158. data/test/root/load_path/skip_module.rb +0 -2
  159. data/test/root/mtime/older.txt +0 -0
  160. data/test/root/unload/full_path.rb +0 -2
  161. data/test/root/unload/loaded_by_nested.rb +0 -2
  162. data/test/root/unload/nested/nested_load.rb +0 -6
  163. data/test/root/unload/nested/nested_with_ext.rb +0 -4
  164. data/test/root/unload/nested/relative_path.rb +0 -4
  165. data/test/root/unload/older.rb +0 -2
  166. data/test/root/unload/unload_base.rb +0 -9
  167. data/test/root/versions/another.yml +0 -0
  168. data/test/root/versions/file-0.1.2.yml +0 -0
  169. data/test/root/versions/file-0.1.yml +0 -0
  170. data/test/root/versions/file.yml +0 -0
  171. data/test/root_test.rb +0 -718
  172. data/test/support/aggregator_test.rb +0 -99
  173. data/test/support/audit_test.rb +0 -445
  174. data/test/support/batchable_test.rb +0 -74
  175. data/test/support/class_configuration_test.rb +0 -331
  176. data/test/support/command_line_test.rb +0 -58
  177. data/test/support/configurable/config/configured.yml +0 -2
  178. data/test/support/configurable_test.rb +0 -295
  179. data/test/support/executable_queue_test.rb +0 -103
  180. data/test/support/executable_test.rb +0 -38
  181. data/test/support/logger_test.rb +0 -31
  182. data/test/support/rake_test.rb +0 -37
  183. data/test/support/shell_utils_test.rb +0 -24
  184. data/test/support/tdoc_test.rb +0 -370
  185. data/test/support/validation_test.rb +0 -54
  186. data/test/support/versions_test.rb +0 -103
  187. data/test/tap_test_helper.rb +0 -57
  188. data/test/tap_test_suite.rb +0 -7
  189. data/test/task/config/batch.yml +0 -2
  190. data/test/task/config/batched.yml +0 -2
  191. data/test/task/config/configured.yml +0 -1
  192. data/test/task/config/example.yml +0 -1
  193. data/test/task_base_test.rb +0 -24
  194. data/test/task_syntax_test.rb +0 -300
  195. data/test/task_test.rb +0 -320
  196. data/test/test/env_vars_test.rb +0 -48
  197. data/test/test/file_methods/test_assert_files/expected/one.txt +0 -1
  198. data/test/test/file_methods/test_assert_files/expected/two.txt +0 -1
  199. data/test/test/file_methods/test_assert_files/input/one.txt +0 -1
  200. data/test/test/file_methods/test_assert_files/input/two.txt +0 -1
  201. data/test/test/file_methods/test_assert_files_can_have_no_expected_files_if_specified/input/one.txt +0 -1
  202. data/test/test/file_methods/test_assert_files_can_have_no_expected_files_if_specified/input/two.txt +0 -1
  203. data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/one.txt +0 -1
  204. data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/two.txt +0 -1
  205. data/test/test/file_methods/test_assert_files_fails_for_different_content/input/one.txt +0 -1
  206. data/test/test/file_methods/test_assert_files_fails_for_different_content/input/two.txt +0 -1
  207. data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/expected/one.txt +0 -1
  208. data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/one.txt +0 -1
  209. data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/two.txt +0 -1
  210. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/one.txt +0 -1
  211. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/two.txt +0 -1
  212. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/one.txt +0 -1
  213. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/two.txt +0 -1
  214. data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/one.txt +0 -1
  215. data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/two.txt +0 -1
  216. data/test/test/file_methods/test_method_glob/expected/file.yml +0 -0
  217. data/test/test/file_methods/test_method_glob/expected/file_1.txt +0 -0
  218. data/test/test/file_methods/test_method_glob/expected/file_2.txt +0 -0
  219. data/test/test/file_methods_doc/test_sub/expected/one.txt +0 -1
  220. data/test/test/file_methods_doc/test_sub/expected/two.txt +0 -1
  221. data/test/test/file_methods_doc/test_sub/input/one.txt +0 -1
  222. data/test/test/file_methods_doc/test_sub/input/two.txt +0 -1
  223. data/test/test/file_methods_doc_test.rb +0 -29
  224. data/test/test/file_methods_test.rb +0 -275
  225. data/test/test/subset_methods_test.rb +0 -171
  226. data/test/test/tap_methods/test_assert_files/expected/task/name/a.txt +0 -1
  227. data/test/test/tap_methods/test_assert_files/expected/task/name/b.txt +0 -1
  228. data/test/test/tap_methods/test_assert_files/input/a.txt +0 -1
  229. data/test/test/tap_methods/test_assert_files/input/b.txt +0 -1
  230. data/test/test/tap_methods_test.rb +0 -399
  231. data/test/workflow_test.rb +0 -120
  232. data/vendor/rails_generator.rb +0 -56
  233. data/vendor/rails_generator/base.rb +0 -263
  234. data/vendor/rails_generator/commands.rb +0 -581
  235. data/vendor/rails_generator/generated_attribute.rb +0 -42
  236. data/vendor/rails_generator/lookup.rb +0 -209
  237. data/vendor/rails_generator/manifest.rb +0 -53
  238. data/vendor/rails_generator/options.rb +0 -143
  239. data/vendor/rails_generator/scripts.rb +0 -83
  240. data/vendor/rails_generator/scripts/destroy.rb +0 -7
  241. data/vendor/rails_generator/scripts/generate.rb +0 -7
  242. data/vendor/rails_generator/scripts/update.rb +0 -12
  243. data/vendor/rails_generator/simple_logger.rb +0 -46
  244. data/vendor/rails_generator/spec.rb +0 -44
@@ -1,88 +0,0 @@
1
- require 'logger'
2
-
3
- module Tap
4
- module Support
5
-
6
- # == UNDER CONSTRUCTION
7
- # Logger provides methods to extend Logger objects.
8
- #
9
- # The output format is designed to look nice in a command prompt, but provide useful information
10
- # if directed at a log file. The Logger output format is like:
11
- #
12
- # I[datetime] action message
13
- #--
14
- # The first letter ('I' - INFO) indicates the severity of the message, next comes the datetime of the
15
- # log, the type of log message, then the message itself. Specify the log type and message like:
16
- #
17
- # logger.type "message"
18
- #
19
- # Typed logging occurs through +method_missing+. Any type is possible so long as the logger doesn't
20
- # already have a method of the input type.
21
- #++
22
- #
23
- #--
24
- # TODO
25
- # multiplex logger so that logging can be directed to two locations; a log file and the console for
26
- # example, or log files in multiple locations.
27
- #++
28
- module Logger
29
- Format = " %s[%s] %18s %s\n"
30
-
31
- def self.extended(base)
32
- # On OS X (and maybe other systems), $stdout is not sync-ed.
33
- # Set sync to true so that writes are immediately flushed
34
- # to the console.
35
- base.logdev.dev.sync = true if base.logdev.dev == $stdout
36
- end
37
-
38
- attr_writer :format
39
- def format
40
- (@format ||= nil) || Format
41
- end
42
-
43
- # Provides direct access to the log device
44
- def logdev
45
- @logdev
46
- end
47
-
48
- # Same as add, but uses the format provided by the block.
49
- # BUG: not thread safe
50
- def format_add(level, msg, action=nil, &block)
51
- current_format = self.format
52
- self.format = yield(current_format)
53
- add(level, msg, action.to_s)
54
- self.format = current_format
55
- end
56
-
57
- # Overrides the default format message to produce output like:
58
- #
59
- # I[H:M:S] type message
60
- #
61
- # If no progname is specified, '--' is used.
62
- def format_message(severity, timestamp, progname, msg, format=self.format)
63
- if timestamp.respond_to?(:strftime) && self.datetime_format
64
- timestamp = timestamp.strftime(self.datetime_format)
65
- end
66
-
67
- format % [severity[0..0], timestamp, progname || '--' , msg]
68
- end
69
-
70
- # Convenience method for creating section breaks in the output, formatted like:
71
- #
72
- # ----- message -----
73
- def section_break(message)
74
- @logdev.write(" ----- #{message} -----\n")
75
- end
76
-
77
- private
78
-
79
- INFO = Object::Logger::INFO
80
-
81
- # Specifies that any unknown method calls will be treated as logging calls where the method
82
- # is the log type, and the first argument is the message. Types are underscored before logging.
83
- def method_missing(method, *args, &block)
84
- add(INFO, args.first, method.to_s.underscore, &block)
85
- end
86
- end
87
- end
88
- end
@@ -1,43 +0,0 @@
1
- require 'rake'
2
-
3
- module Tap
4
- module Support
5
-
6
- # Used to modify an App so that it will lookup Rake tasks as well as Tap tasks. Simply use:
7
- # app.extend(RakeLookup)
8
- #--
9
- # Note: Do not refactor Tap:Support::Rake without attending to the line in 'script/run' that
10
- # extends app. As it stands, this module is loaded as needed using Dependencies.
11
- module Rake
12
- def task(td, config={}, &block)
13
- Object::Rake.application.lookup(td) || super
14
- end
15
-
16
- # Modifies Rake::Task to behave like Tap::Task. The essential code is this:
17
- #
18
- # module Tap::Support::Rake::Task
19
- # def new(*args)
20
- # task = super
21
- # Tap::Task::Base.initialize(task, :invoke)
22
- # task
23
- # end
24
- # end
25
- #
26
- # Here the new method creates a new Rake task as normal, then initializes the
27
- # Rake task based on the invoke method. The modifed code is applied to Rake
28
- # in the following fashion:
29
- #
30
- # Rake::Task.extend(Tap::Support::Rake::Task)
31
- #
32
- module Task
33
- def new(*args)
34
- task = super
35
- Tap::Task::Base.initialize(task, :invoke)
36
- task
37
- end
38
- end
39
- end
40
- end
41
- end
42
-
43
- Rake::Task.extend(Tap::Support::Rake::Task)
@@ -1,362 +0,0 @@
1
- # RDoc creates a namespace conflict with IRB within 'rdoc/parsers/parse_rb'
2
- # In that file, RubyToken and RubyLex get defined in the Object namespace,
3
- # which will conflict with prior definitions from, for instance, IRB.
4
- #
5
- # This code redefines the RDoc RubyToken and RubyLex within the RDoc
6
- # namespace. RDoc is not affected because all includes and uses of
7
- # RubyToken and RubyLex are set when RDoc is loaded. The single exception
8
- # I know of are several calls to class methods of RubyLex (ex RubyLex.debug?).
9
- # These calls will be routed to the existing RubyLex.
10
- #
11
- # Uses of the existing RubyToken and RubyLex (as by irb) should be
12
- # unaffected as the constants are reset after RDoc loads.
13
- #
14
- if Object.const_defined?(:RubyToken) || Object.const_defined?(:RubyLex)
15
- class Object
16
- old_ruby_token = const_defined?(:RubyToken) ? remove_const(:RubyToken) : nil
17
- old_ruby_lex = const_defined?(:RubyLex) ? remove_const(:RubyLex) : nil
18
-
19
- require 'rdoc/rdoc'
20
-
21
- # if by chance rdoc has ALREADY been loaded then requiring
22
- # rdoc will not reset RubyToken and RubyLex... in this case
23
- # the old constants are what you want.
24
- new_ruby_token = const_defined?(:RubyToken) ? remove_const(:RubyToken) : old_ruby_token
25
- new_ruby_lex = const_defined?(:RubyLex) ? remove_const(:RubyLex) : old_ruby_lex
26
-
27
- RDoc.const_set(:RubyToken, new_ruby_token)
28
- RDoc.const_set(:RubyLex, new_ruby_lex)
29
-
30
- const_set(:RubyToken, old_ruby_token) unless old_ruby_token == nil
31
- const_set(:RubyLex, old_ruby_lex) unless old_ruby_lex == nil
32
- end
33
- else
34
- require 'rdoc/rdoc'
35
-
36
- if Object.const_defined?(:RubyToken) && !RDoc.const_defined?(:RubyToken)
37
- class Object
38
- RDoc.const_set(:RubyToken, remove_const(:RubyToken))
39
- end
40
- end
41
-
42
- if Object.const_defined?(:RubyLex) && !RDoc.const_defined?(:RubyLex)
43
- class Object
44
- RDoc.const_set(:RubyLex, remove_const(:RubyLex))
45
- RDoc::RubyLex.const_set(:RubyLex, RDoc::RubyLex)
46
- end
47
- end
48
- end
49
-
50
- module Tap
51
- module Support
52
- class TDoc
53
-
54
- # Encasulates information about the configuration. Designed to be utilized
55
- # by the TDocHTMLGenerator as similarly as possible to standard attributes.
56
- class ConfigAttr < RDoc::Attr
57
- # Contains the actual declaration for the config attribute. ex: "c [:key, 'value'] # comment"
58
- attr_accessor :config_declaration
59
-
60
- alias original_comment comment
61
-
62
- def desc
63
- case text.to_s
64
- when /^#--(.*)/ then $1.strip
65
- when /^#(.*)/ then $1.strip
66
- else
67
- nil
68
- end
69
- end
70
-
71
- # The description for the config. Comment is formed from the standard
72
- # attribute comment and the text following the attribute, which is slightly
73
- # different than normal:
74
- #
75
- # # standard comment
76
- # attr_accessor :attribute
77
- #
78
- # # standard comment
79
- # config_accessor :config # ...added to standard comment
80
- #
81
- # c [:key, 'value'] # hence you can comment inline like this.
82
- #
83
- # The comments for each of these will be:
84
- # attribute:: standard comment
85
- # config:: standard comment ...added to standard comment
86
- # key:: hence you can comment inline like this.
87
- #
88
- def comment
89
- text_comment = text.to_s.sub(/^#--.*/m, '')
90
- original_comment.to_s + text_comment
91
- end
92
- end
93
-
94
- module CodeObjectAccess # :nodoc:
95
- def comment_sections(section_regexp=//, normalize_comments=false)
96
- res = {}
97
-
98
- section = nil
99
- lines = []
100
- comment_lines = comment.split(/\r?\n/)
101
- comment_lines << nil
102
- comment_lines.each do |line|
103
- case line
104
- when nil, /^\s*#\s*=+(.*)/
105
- next_section = (line == nil ? nil : $1.to_s.strip)
106
-
107
- if section =~ section_regexp
108
- lines << "" unless normalize_comments
109
- res[section] = lines.join("\n") unless section == nil
110
- end
111
-
112
- section = next_section
113
- lines = []
114
- else
115
- if normalize_comments
116
- line =~ /^\s*#\s?(.*)/
117
- line = $1.to_s
118
- end
119
-
120
- lines << line
121
- end
122
- end
123
-
124
- res
125
- end
126
- end
127
-
128
- module ClassModuleAccess # :nodoc:
129
- def find_class_or_module_named(name)
130
- return self if full_name == name
131
- (@classes.values + @modules.values).each do |c|
132
- res = c.find_class_or_module_named(name)
133
- return res if res
134
- end
135
- nil
136
- end
137
-
138
- def configurations
139
- @attributes.select do |attribute|
140
- attribute.kind_of?(TDoc::ConfigAttr)
141
- end
142
- end
143
-
144
- def find_configuration_named(name)
145
- @attributes.each do |attribute|
146
- next unless attribute.kind_of?(TDoc::ConfigAttr)
147
- return attribute if attribute.name == name
148
- end
149
- nil
150
- end
151
- end
152
-
153
- # Overrides the new method automatically extend the new object with
154
- # ConfigParser. Intended to be used like:
155
- # RDoc::RubyParser.extend InitializeConfigParser
156
- module InitializeConfigParser # :nodoc:
157
- def new(*args)
158
- parser = super
159
- parser.extend ConfigParser
160
- parser.config_mode = 'config_accessor'
161
- parser
162
- end
163
- end
164
-
165
- # Provides methods extending an RDoc::RubyParser such that the parser will produce
166
- # TDoc::ConfigAttr instances in the place of RDoc::Attr instances during attribute
167
- # parsing.
168
- module ConfigParser # :nodoc:
169
- include RDoc::RubyToken
170
- include TokenStream
171
-
172
- CONFIG_ACCESSORS = ['config', 'declare_config', 'config_reader', 'config_writer', 'config_accessor']
173
- attr_accessor :config_mode
174
-
175
- # Returns the current config_rw mode, based on the config_mode flag.
176
- def config_rw
177
- case self.config_mode
178
- when "config_accessor" then "RW"
179
- when "declare_config" then nil
180
- when "config_reader" then "R"
181
- when "config_writer" then "W"
182
- else
183
- raise "unknown config mode: #{self.config_mode}"
184
- end
185
- end
186
-
187
- # Gets tokens until the next TkNL
188
- def get_tk_to_nl
189
- tokens = []
190
- while !(tk = get_tk).kind_of?(TkNL)
191
- tokens.push tk
192
- end
193
- unget_tk(tk)
194
- tokens
195
- end
196
-
197
- # Works like the original parse_attr_accessor, except that the arg
198
- # name is parsed from the config syntax and added attribute will
199
- # be a TDoc::ConfigAttr. For example:
200
- #
201
- # class TaskDoc < Tap::Task
202
- # config [:key, 'value'] # comment
203
- # end
204
- #
205
- # produces an attribute named :key in the current config_rw mode.
206
- #
207
- # (see 'rdoc/parsers/parse_rb' line 2509)
208
- def parse_config(context, single, tk, comment)
209
- tks = get_tk_to_nl
210
-
211
- key_tk = nil
212
- value_tk = nil
213
-
214
- tks.each do |token|
215
- next if token.kind_of?(TkSPACE)
216
-
217
- if key_tk == nil
218
- key_tk = token if token.kind_of?(TkSYMBOL)
219
- else
220
- case token
221
- when TkCOMMA then value_tk = token
222
- else
223
- value_tk = token if value_tk.kind_of?(TkCOMMA)
224
- break
225
- end
226
- end
227
- end
228
-
229
- text = ""
230
- if tks.last.kind_of?(TkCOMMENT)
231
- text = tks.last.text.chomp("\n").chomp("\r")
232
- unget_tk(tks.last)
233
-
234
- # If nodoc is given, don't document
235
-
236
- tmp = RDoc::CodeObject.new
237
- read_documentation_modifiers(tmp, RDoc::ATTR_MODIFIERS)
238
- text = nil unless tmp.document_self
239
- end
240
-
241
- tks.reverse_each {|token| unget_tk(token) }
242
- return if key_tk == nil || text == nil
243
-
244
- arg = key_tk.text[1..-1]
245
- if value_tk
246
- if text =~ /(.*):no_default:(.*)/
247
- text = $1 + $2
248
- else
249
- text += " (#{value_tk.text})"
250
- end
251
- end
252
- att = TDoc::ConfigAttr.new(text, arg, config_rw, comment)
253
- att.config_declaration = get_tkread
254
-
255
- context.add_attribute(att)
256
- end
257
-
258
- # Works like the original parse_attr_accessor, except that the added
259
- # attribute will be a TDoc::ConfigAttr. config_mode is updated to the input
260
- # token name, such that, for example, if tk.name == 'config_accessor'
261
- # then config_rw will return 'RW'.
262
- #
263
- # (see 'rdoc/parsers/parse_rb' line 2509)
264
- def parse_config_accessor(context, single, tk, comment)
265
- self.config_mode = tk.name
266
-
267
- tks = get_tk_to_nl
268
- is_config_mode_flag = tks.select do |token|
269
- !token.kind_of?(TkSPACE) && !token.kind_of?(TkCOMMENT)
270
- end.empty?
271
-
272
- # If no args are given, take this as a flag for c
273
- return if is_config_mode_flag
274
-
275
- tks.reverse_each {|token| unget_tk(token) }
276
- args = parse_symbol_arg
277
- read = get_tkread
278
- rw = "?"
279
-
280
- # If nodoc is given, don't document any of them
281
-
282
- tmp = RDoc::CodeObject.new
283
- read_documentation_modifiers(tmp, RDoc::ATTR_MODIFIERS)
284
- return unless tmp.document_self
285
-
286
- for name in args
287
- att = TDoc::ConfigAttr.new(get_tkread, name, config_rw, comment)
288
- context.add_attribute(att)
289
- end
290
- end
291
-
292
- # Overrides the standard parse_attr_accessor method to hook in parsing
293
- # of the config accessors. If the input token is not named as one of the
294
- # CONFIG_ACCESSORS, it will be processed normally.
295
- def parse_attr_accessor(context, single, tk, comment)
296
- case tk.name
297
- when 'config'
298
- parse_config(context, single, tk, comment)
299
- when 'declare_config', 'config_reader', 'config_writer', 'config_accessor'
300
- parse_config_accessor(context, single, tk, comment)
301
- else
302
- super
303
- end
304
- end
305
- end
306
- end
307
- end
308
- end
309
-
310
- # Register the TDoc generator (in case you want to actually use it).
311
- # method echos RDoc generator registration (see 'rdoc/rdoc' line 76)
312
- Generator = Struct.new(:file_name, :class_name, :key)
313
- RDoc::RDoc::GENERATORS['tdoc'] = Generator.new(
314
- "tap/support/tdoc/tdoc_html_generator.rb",
315
- "TDocHTMLGenerator".intern,
316
- "tdoc")
317
-
318
- # Add the extended accessors to context classes.
319
- module RDoc # :nodoc:
320
- class CodeObject # :nodoc:
321
- include Tap::Support::TDoc::CodeObjectAccess
322
- end
323
-
324
- class ClassModule # :nodoc:
325
- include Tap::Support::TDoc::ClassModuleAccess
326
- end
327
- end
328
-
329
- # Override methods in Options to in effect incorporate the accessor
330
- # flags for TDoc parsing. (see 'rdoc/options') Raise an error if an
331
- # accessor flag has already been specified.
332
- class Options # :nodoc:
333
- alias tdoc_original_parse parse
334
-
335
- def parse(argv, generators)
336
- tdoc_original_parse(argv, generators)
337
- return unless @generator_name == 'tdoc'
338
-
339
- accessors = Tap::Support::TDoc::ConfigParser::CONFIG_ACCESSORS
340
-
341
- # check the config_accessor_flags for accessor conflicts
342
- extra_accessor_flags.each_pair do |accessor, flag|
343
- if accessors.include?(accessor)
344
- raise OptionList.error("tdoc format already handles the accessor '#{accessor}'")
345
- end
346
- end
347
-
348
- # extra_accessors will be nil if no extra accessors were
349
- # specifed, otherwise it'll be a regexp like /^(...)$/
350
- # the string subset assumes
351
- # regexp.to_s # => /(?-mix:^(...)$)/
352
- @extra_accessors ||= /^()$/
353
- current_accessors_str = @extra_accessors.to_s[9..-4]
354
-
355
- # echos the Regexp production code in rdoc/options.rb
356
- # (see the parse method, line 501)
357
- re = '^(' + current_accessors_str + accessors.map{|a| Regexp.quote(a)}.join('|') + ')$'
358
- @extra_accessors = Regexp.new(re)
359
-
360
- RDoc::RubyParser.extend Tap::Support::TDoc::InitializeConfigParser
361
- end
362
- end