yard 0.2.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (365) hide show
  1. data/.yardopts +12 -10
  2. data/ChangeLog +5686 -0
  3. data/{README.markdown → README.md} +65 -11
  4. data/Rakefile +25 -13
  5. data/benchmarks/concat_vs_join.rb +12 -0
  6. data/benchmarks/erb_vs_erubis.rb +14 -14
  7. data/benchmarks/marshal_vs_dbm.rb +1 -1
  8. data/benchmarks/pathname_vs_string.rb +50 -0
  9. data/benchmarks/template_erb.rb +22 -0
  10. data/benchmarks/template_format.rb +6 -0
  11. data/benchmarks/template_profile.rb +17 -0
  12. data/bin/yri +16 -7
  13. data/docs/{CODE_OBJECTS.markdown → CodeObjects.md} +0 -0
  14. data/docs/{GETTING_STARTED.markdown → GettingStarted.md} +49 -11
  15. data/docs/{GLOSSARY.markdown → Glossary.md} +0 -0
  16. data/docs/{HANDLERS.markdown → Handlers.md} +5 -5
  17. data/docs/{OVERVIEW.markdown → Overview.md} +9 -13
  18. data/docs/{PARSER.markdown → Parser.md} +1 -1
  19. data/docs/{TAGS.markdown → Tags.md} +1 -1
  20. data/docs/Templates.md +286 -0
  21. data/docs/{WHATSNEW.markdown → WhatsNew.md} +82 -2
  22. data/lib/rubygems_plugin.rb +17 -20
  23. data/lib/yard.rb +47 -1
  24. data/lib/yard/autoload.rb +38 -47
  25. data/lib/yard/cli/yard_graph.rb +36 -13
  26. data/lib/yard/cli/yardoc.rb +74 -12
  27. data/lib/yard/code_objects/base.rb +182 -14
  28. data/lib/yard/code_objects/class_object.rb +39 -2
  29. data/lib/yard/code_objects/class_variable_object.rb +4 -0
  30. data/lib/yard/code_objects/constant_object.rb +8 -0
  31. data/lib/yard/code_objects/extended_method_object.rb +14 -0
  32. data/lib/yard/code_objects/method_object.rb +60 -2
  33. data/lib/yard/code_objects/module_object.rb +6 -0
  34. data/lib/yard/code_objects/namespace_object.rb +99 -2
  35. data/lib/yard/code_objects/proxy.rb +53 -6
  36. data/lib/yard/code_objects/root_object.rb +2 -0
  37. data/lib/yard/core_ext/array.rb +61 -0
  38. data/lib/yard/core_ext/file.rb +21 -4
  39. data/lib/yard/core_ext/module.rb +11 -1
  40. data/lib/yard/core_ext/string.rb +13 -2
  41. data/lib/yard/core_ext/symbol_hash.rb +51 -3
  42. data/lib/yard/docstring.rb +68 -19
  43. data/lib/yard/globals.rb +5 -2
  44. data/lib/yard/handlers/base.rb +13 -3
  45. data/lib/yard/handlers/processor.rb +64 -2
  46. data/lib/yard/handlers/ruby/class_handler.rb +1 -1
  47. data/lib/yard/handlers/ruby/class_variable_handler.rb +5 -1
  48. data/lib/yard/handlers/ruby/constant_handler.rb +38 -4
  49. data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
  50. data/lib/yard/handlers/ruby/legacy/base.rb +2 -2
  51. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +6 -3
  52. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +21 -2
  53. data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -0
  54. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +2 -1
  55. data/lib/yard/handlers/ruby/method_handler.rb +10 -0
  56. data/lib/yard/handlers/ruby/yield_handler.rb +2 -1
  57. data/lib/yard/logging.rb +17 -0
  58. data/lib/yard/parser/ruby/ast_node.rb +101 -0
  59. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +2 -2
  60. data/lib/yard/parser/ruby/legacy/statement_list.rb +10 -9
  61. data/lib/yard/parser/ruby/ruby_parser.rb +32 -3
  62. data/lib/yard/parser/source_parser.rb +82 -5
  63. data/lib/yard/rake/yardoc_task.rb +38 -3
  64. data/lib/yard/registry.rb +112 -2
  65. data/lib/yard/serializers/base.rb +48 -1
  66. data/lib/yard/serializers/file_system_serializer.rb +23 -2
  67. data/lib/yard/serializers/process_serializer.rb +10 -0
  68. data/lib/yard/serializers/stdout_serializer.rb +11 -0
  69. data/lib/yard/tags/library.rb +4 -1
  70. data/lib/yard/tags/overload_tag.rb +3 -12
  71. data/lib/yard/templates/engine.rb +162 -0
  72. data/lib/yard/{generators → templates}/helpers/base_helper.rb +14 -13
  73. data/lib/yard/{generators → templates}/helpers/filter_helper.rb +1 -1
  74. data/lib/yard/templates/helpers/html_helper.rb +287 -0
  75. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +29 -0
  76. data/lib/yard/templates/helpers/html_syntax_highlight_helper18.rb +27 -0
  77. data/lib/yard/{generators → templates}/helpers/markup_helper.rb +15 -11
  78. data/lib/yard/{generators → templates}/helpers/method_helper.rb +8 -1
  79. data/lib/yard/templates/helpers/module_helper.rb +15 -0
  80. data/lib/yard/templates/helpers/text_helper.rb +60 -0
  81. data/lib/yard/templates/helpers/uml_helper.rb +33 -0
  82. data/lib/yard/templates/template.rb +355 -0
  83. data/lib/yard/verifier.rb +110 -0
  84. data/spec/cli/yardoc_spec.rb +23 -1
  85. data/spec/code_objects/base_spec.rb +8 -0
  86. data/spec/code_objects/class_object_spec.rb +166 -156
  87. data/spec/code_objects/method_object_spec.rb +2 -2
  88. data/spec/code_objects/module_object_spec.rb +112 -110
  89. data/spec/code_objects/proxy_spec.rb +9 -0
  90. data/spec/core_ext/array_spec.rb +33 -0
  91. data/spec/core_ext/file_spec.rb +40 -12
  92. data/spec/core_ext/module_spec.rb +15 -0
  93. data/spec/core_ext/string_spec.rb +10 -2
  94. data/spec/docstring_spec.rb +157 -135
  95. data/spec/handlers/class_handler_spec.rb +3 -0
  96. data/spec/handlers/class_variable_handler_spec.rb +3 -1
  97. data/spec/handlers/constant_handler_spec.rb +38 -0
  98. data/spec/handlers/examples/class_handler_001.rb.txt +14 -1
  99. data/spec/handlers/examples/class_variable_handler_001.rb.txt +1 -0
  100. data/spec/handlers/examples/constant_handler_001.rb.txt +10 -1
  101. data/spec/handlers/examples/exception_handler_001.rb.txt +5 -0
  102. data/spec/handlers/examples/method_handler_001.rb.txt +15 -0
  103. data/spec/handlers/examples/mixin_handler_001.rb.txt +13 -0
  104. data/spec/handlers/exception_handler_spec.rb +4 -0
  105. data/spec/handlers/method_handler_spec.rb +22 -0
  106. data/spec/handlers/mixin_handler_spec.rb +5 -3
  107. data/spec/handlers/yield_handler_spec.rb +1 -1
  108. data/spec/parser/ruby/ast_node_spec.rb +16 -0
  109. data/spec/parser/ruby/legacy/statement_list_spec.rb +36 -0
  110. data/spec/parser/ruby/ruby_parser_spec.rb +80 -0
  111. data/spec/parser/source_parser_spec.rb +48 -2
  112. data/spec/rake/yardoc_task_spec.rb +62 -25
  113. data/spec/serializers/file_system_serializer_spec.rb +1 -1
  114. data/spec/templates/class_spec.rb +34 -0
  115. data/spec/templates/engine_spec.rb +121 -0
  116. data/spec/templates/examples/class001.html +271 -0
  117. data/spec/templates/examples/class001.txt +31 -0
  118. data/spec/templates/examples/method001.html +96 -0
  119. data/spec/templates/examples/method001.txt +28 -0
  120. data/spec/templates/examples/method002.html +81 -0
  121. data/spec/templates/examples/method002.txt +20 -0
  122. data/spec/templates/examples/method003.html +137 -0
  123. data/spec/templates/examples/method003.txt +45 -0
  124. data/spec/templates/examples/module001.dot +31 -0
  125. data/spec/templates/examples/module001.html +294 -0
  126. data/spec/templates/examples/module001.txt +33 -0
  127. data/spec/templates/examples/tag001.txt +82 -0
  128. data/spec/templates/helpers/base_helper_spec.rb +129 -0
  129. data/spec/{generators → templates}/helpers/html_helper_spec.rb +73 -16
  130. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +39 -0
  131. data/spec/{generators → templates}/helpers/markup_helper_spec.rb +6 -7
  132. data/spec/templates/method_spec.rb +75 -0
  133. data/spec/templates/module_spec.rb +50 -0
  134. data/spec/templates/spec_helper.rb +33 -0
  135. data/spec/templates/tag_spec.rb +39 -0
  136. data/spec/templates/template_spec.rb +398 -0
  137. data/spec/verifier_spec.rb +51 -0
  138. data/spec/yard_spec.rb +46 -0
  139. data/templates/default/class/dot/setup.rb +6 -0
  140. data/templates/default/class/dot/superklass.erb +3 -0
  141. data/templates/default/class/html/constructor_details.erb +8 -0
  142. data/templates/default/class/html/setup.rb +1 -0
  143. data/templates/default/class/html/subclasses.erb +4 -0
  144. data/templates/default/class/setup.rb +29 -0
  145. data/templates/default/class/text/setup.rb +11 -0
  146. data/templates/default/class/text/subclasses.erb +5 -0
  147. data/templates/default/docstring/html/abstract.erb +4 -0
  148. data/templates/default/docstring/html/deprecated.erb +1 -0
  149. data/templates/default/docstring/html/index.erb +5 -0
  150. data/templates/default/docstring/html/note.erb +6 -0
  151. data/templates/default/docstring/html/text.erb +1 -0
  152. data/templates/default/docstring/html/todo.erb +6 -0
  153. data/templates/default/docstring/setup.rb +39 -0
  154. data/templates/default/docstring/text/abstract.erb +2 -0
  155. data/templates/default/docstring/text/deprecated.erb +2 -0
  156. data/templates/default/docstring/text/index.erb +2 -0
  157. data/templates/default/docstring/text/note.erb +4 -0
  158. data/templates/default/docstring/text/text.erb +1 -0
  159. data/templates/default/docstring/text/todo.erb +4 -0
  160. data/templates/default/fulldoc/html/css/common.css +1 -0
  161. data/templates/default/fulldoc/html/css/full_list.css +23 -0
  162. data/templates/default/fulldoc/html/css/style.css +261 -0
  163. data/templates/default/fulldoc/html/full_list.erb +36 -0
  164. data/templates/default/fulldoc/html/js/app.js +91 -0
  165. data/templates/default/fulldoc/html/js/full_list.js +39 -0
  166. data/templates/default/fulldoc/html/js/jquery.js +19 -0
  167. data/templates/default/fulldoc/html/setup.rb +86 -0
  168. data/templates/default/{uml → layout}/dot/header.erb +2 -2
  169. data/templates/default/layout/dot/setup.rb +14 -0
  170. data/templates/default/layout/html/breadcrumb.erb +11 -0
  171. data/templates/default/layout/html/footer.erb +5 -0
  172. data/templates/default/layout/html/headers.erb +13 -0
  173. data/templates/default/layout/html/index.erb +49 -0
  174. data/templates/default/layout/html/layout.erb +20 -0
  175. data/templates/default/layout/html/search.erb +5 -0
  176. data/templates/default/layout/html/setup.rb +58 -0
  177. data/templates/default/method/html/header.erb +14 -3
  178. data/templates/default/method/setup.rb +3 -0
  179. data/templates/default/method/text/header.erb +1 -1
  180. data/templates/default/method_details/html/header.erb +3 -0
  181. data/templates/default/method_details/html/method_signature.erb +17 -0
  182. data/templates/default/method_details/html/source.erb +10 -0
  183. data/templates/default/method_details/setup.rb +8 -0
  184. data/templates/default/method_details/text/header.erb +10 -0
  185. data/templates/default/method_details/text/method_signature.erb +12 -0
  186. data/templates/default/method_details/text/setup.rb +10 -0
  187. data/templates/default/module/dot/child.erb +1 -0
  188. data/templates/default/module/dot/dependencies.erb +3 -0
  189. data/templates/default/{uml/dot/subgraph.erb → module/dot/header.erb} +3 -3
  190. data/templates/default/{uml → module}/dot/info.erb +4 -4
  191. data/templates/default/module/dot/setup.rb +14 -0
  192. data/templates/default/module/html/attribute_details.erb +11 -0
  193. data/templates/default/module/html/attribute_summary.erb +8 -0
  194. data/templates/default/module/html/box_info.erb +32 -0
  195. data/templates/default/module/html/children.erb +8 -0
  196. data/templates/default/module/html/constant_summary.erb +13 -0
  197. data/templates/default/module/html/defines.erb +3 -0
  198. data/templates/default/module/html/header.erb +4 -4
  199. data/templates/default/module/html/inherited_constants.erb +8 -0
  200. data/templates/default/module/html/inherited_methods.erb +9 -0
  201. data/templates/default/module/html/item_summary.erb +20 -0
  202. data/templates/default/module/html/method_details_list.erb +8 -0
  203. data/templates/default/module/html/method_summary.erb +8 -0
  204. data/templates/default/module/html/methodmissing.erb +12 -0
  205. data/templates/default/module/html/pre_docstring.erb +1 -0
  206. data/templates/default/module/setup.rb +83 -0
  207. data/templates/default/module/text/children.erb +10 -0
  208. data/templates/default/module/text/class_meths_list.erb +8 -0
  209. data/templates/default/module/text/extends.erb +8 -0
  210. data/templates/default/module/text/header.erb +7 -0
  211. data/templates/default/module/text/includes.erb +8 -0
  212. data/templates/default/module/text/instance_meths_list.erb +8 -0
  213. data/templates/default/module/text/setup.rb +12 -0
  214. data/templates/default/root/dot/child.erb +3 -0
  215. data/templates/default/root/dot/setup.rb +5 -0
  216. data/templates/default/tags/html/example.erb +5 -16
  217. data/templates/default/tags/html/index.erb +3 -0
  218. data/templates/default/tags/html/option.erb +17 -20
  219. data/templates/default/tags/html/overload.erb +13 -0
  220. data/templates/default/tags/html/see.erb +5 -10
  221. data/templates/default/tags/html/tag.erb +20 -0
  222. data/templates/default/tags/setup.rb +50 -0
  223. data/templates/default/tags/text/example.erb +8 -10
  224. data/templates/default/tags/text/index.erb +1 -0
  225. data/templates/default/tags/text/option.erb +18 -3
  226. data/templates/default/tags/text/overload.erb +19 -0
  227. data/templates/default/tags/text/see.erb +8 -2
  228. data/templates/default/tags/text/tag.erb +13 -0
  229. metadata +142 -158
  230. data/bin/view_generator +0 -17
  231. data/docs/FAQ.markdown +0 -34
  232. data/docs/GENERATORS.markdown +0 -211
  233. data/lib/yard/generators/attributes_generator.rb +0 -22
  234. data/lib/yard/generators/base.rb +0 -305
  235. data/lib/yard/generators/class_generator.rb +0 -27
  236. data/lib/yard/generators/constants_generator.rb +0 -74
  237. data/lib/yard/generators/constructor_generator.rb +0 -25
  238. data/lib/yard/generators/deprecated_generator.rb +0 -15
  239. data/lib/yard/generators/docstring_generator.rb +0 -15
  240. data/lib/yard/generators/full_doc_generator.rb +0 -127
  241. data/lib/yard/generators/helpers/html_helper.rb +0 -196
  242. data/lib/yard/generators/helpers/html_syntax_highlight_helper.rb +0 -49
  243. data/lib/yard/generators/helpers/uml_helper.rb +0 -16
  244. data/lib/yard/generators/inheritance_generator.rb +0 -16
  245. data/lib/yard/generators/method_details_generator.rb +0 -18
  246. data/lib/yard/generators/method_generator.rb +0 -43
  247. data/lib/yard/generators/method_listing_generator.rb +0 -105
  248. data/lib/yard/generators/method_missing_generator.rb +0 -25
  249. data/lib/yard/generators/method_signature_generator.rb +0 -19
  250. data/lib/yard/generators/method_summary_generator.rb +0 -21
  251. data/lib/yard/generators/mixins_generator.rb +0 -21
  252. data/lib/yard/generators/module_generator.rb +0 -23
  253. data/lib/yard/generators/overloads_generator.rb +0 -20
  254. data/lib/yard/generators/quick_doc_generator.rb +0 -25
  255. data/lib/yard/generators/root_generator.rb +0 -32
  256. data/lib/yard/generators/source_generator.rb +0 -11
  257. data/lib/yard/generators/tags_generator.rb +0 -99
  258. data/lib/yard/generators/uml_generator.rb +0 -102
  259. data/lib/yard/generators/visibility_group_generator.rb +0 -26
  260. data/spec/generators/base_spec.rb +0 -64
  261. data/spec/generators/full_doc_generator_spec.rb +0 -29
  262. data/spec/generators/helpers/base_helper_spec.rb +0 -15
  263. data/spec/generators/quick_doc_generator_spec.rb +0 -13
  264. data/templates/default/attributes/html/header.erb +0 -47
  265. data/templates/default/attributes/text/header.erb +0 -10
  266. data/templates/default/class/html/header.erb +0 -4
  267. data/templates/default/constants/html/constants.erb +0 -9
  268. data/templates/default/constants/html/header.erb +0 -3
  269. data/templates/default/constants/html/included.erb +0 -9
  270. data/templates/default/constants/html/inherited.erb +0 -9
  271. data/templates/default/constructor/html/header.erb +0 -10
  272. data/templates/default/deprecated/html/main.erb +0 -6
  273. data/templates/default/deprecated/text/main.erb +0 -3
  274. data/templates/default/docstring/html/main.erb +0 -3
  275. data/templates/default/docstring/text/main.erb +0 -3
  276. data/templates/default/fulldoc/html/all_files.erb +0 -19
  277. data/templates/default/fulldoc/html/all_methods.erb +0 -26
  278. data/templates/default/fulldoc/html/all_namespaces.erb +0 -22
  279. data/templates/default/fulldoc/html/app.js +0 -18
  280. data/templates/default/fulldoc/html/custom.css +0 -1
  281. data/templates/default/fulldoc/html/file.erb +0 -16
  282. data/templates/default/fulldoc/html/footer.erb +0 -5
  283. data/templates/default/fulldoc/html/header.erb +0 -16
  284. data/templates/default/fulldoc/html/html_head.erb +0 -4
  285. data/templates/default/fulldoc/html/index.erb +0 -19
  286. data/templates/default/fulldoc/html/jquery.js +0 -11
  287. data/templates/default/fulldoc/html/style.css +0 -81
  288. data/templates/default/fulldoc/html/syntax_highlight.css +0 -24
  289. data/templates/default/inheritance/html/header.erb +0 -8
  290. data/templates/default/inheritance/text/header.erb +0 -3
  291. data/templates/default/method/html/aliases.erb +0 -6
  292. data/templates/default/method/html/title.erb +0 -3
  293. data/templates/default/method/text/title.erb +0 -1
  294. data/templates/default/methoddetails/html/header.erb +0 -8
  295. data/templates/default/methoddetails/html/method_header.erb +0 -3
  296. data/templates/default/methodmissing/html/header.erb +0 -12
  297. data/templates/default/methodsignature/html/main.erb +0 -10
  298. data/templates/default/methodsignature/text/main.erb +0 -8
  299. data/templates/default/methodsummary/html/header.erb +0 -5
  300. data/templates/default/methodsummary/html/included.erb +0 -9
  301. data/templates/default/methodsummary/html/inherited.erb +0 -9
  302. data/templates/default/methodsummary/html/summary.erb +0 -29
  303. data/templates/default/methodsummary/text/header.erb +0 -5
  304. data/templates/default/methodsummary/text/included.erb +0 -0
  305. data/templates/default/methodsummary/text/inherited.erb +0 -0
  306. data/templates/default/methodsummary/text/summary.erb +0 -6
  307. data/templates/default/mixins/html/header.erb +0 -4
  308. data/templates/default/overloads/html/header.erb +0 -8
  309. data/templates/default/overloads/text/header.erb +0 -8
  310. data/templates/default/quickdoc/html/header.erb +0 -15
  311. data/templates/default/quickdoc/text/header.erb +0 -12
  312. data/templates/default/root/html/header.erb +0 -4
  313. data/templates/default/source/html/main.erb +0 -15
  314. data/templates/default/source/text/main.erb +0 -4
  315. data/templates/default/tags/html/header.erb +0 -4
  316. data/templates/default/tags/html/param.erb +0 -21
  317. data/templates/default/tags/html/tags.erb +0 -23
  318. data/templates/default/tags/html/todo.erb +0 -8
  319. data/templates/default/tags/text/header.erb +0 -3
  320. data/templates/default/tags/text/param.erb +0 -9
  321. data/templates/default/tags/text/tags.erb +0 -7
  322. data/templates/default/uml/dot/child.erb +0 -1
  323. data/templates/default/uml/dot/dependencies.erb +0 -10
  324. data/templates/default/uml/dot/superclasses.erb +0 -9
  325. data/templates/default/uml/dot/unknown.erb +0 -3
  326. data/templates/default/uml/dot/unknown_child.erb +0 -1
  327. data/templates/default/visibilitygroup/html/header.erb +0 -6
  328. data/templates/javadoc/attributes/html/header.erb +0 -16
  329. data/templates/javadoc/class/html/header.erb +0 -4
  330. data/templates/javadoc/constants/html/constants.erb +0 -9
  331. data/templates/javadoc/constants/html/header.erb +0 -3
  332. data/templates/javadoc/constants/html/included.erb +0 -12
  333. data/templates/javadoc/constants/html/inherited.erb +0 -12
  334. data/templates/javadoc/constructor/html/header.erb +0 -10
  335. data/templates/javadoc/deprecated/html/main.erb +0 -0
  336. data/templates/javadoc/docstring/html/main.erb +0 -6
  337. data/templates/javadoc/fulldoc/html/all_methods.erb +0 -25
  338. data/templates/javadoc/fulldoc/html/all_namespaces.erb +0 -19
  339. data/templates/javadoc/fulldoc/html/app.js +0 -18
  340. data/templates/javadoc/fulldoc/html/header.erb +0 -15
  341. data/templates/javadoc/fulldoc/html/html_head.erb +0 -3
  342. data/templates/javadoc/fulldoc/html/index.erb +0 -18
  343. data/templates/javadoc/fulldoc/html/jquery.js +0 -11
  344. data/templates/javadoc/fulldoc/html/readme.erb +0 -15
  345. data/templates/javadoc/fulldoc/html/style.css +0 -22
  346. data/templates/javadoc/fulldoc/html/syntax_highlight.css +0 -21
  347. data/templates/javadoc/inheritance/html/header.erb +0 -6
  348. data/templates/javadoc/method/html/aliases.erb +0 -6
  349. data/templates/javadoc/method/html/header.erb +0 -4
  350. data/templates/javadoc/method/html/title.erb +0 -4
  351. data/templates/javadoc/methoddetails/html/header.erb +0 -8
  352. data/templates/javadoc/methoddetails/html/method_header.erb +0 -0
  353. data/templates/javadoc/methodmissing/html/header.erb +0 -12
  354. data/templates/javadoc/methodsignature/html/main.erb +0 -8
  355. data/templates/javadoc/methodsummary/html/header.erb +0 -5
  356. data/templates/javadoc/methodsummary/html/included.erb +0 -12
  357. data/templates/javadoc/methodsummary/html/inherited.erb +0 -12
  358. data/templates/javadoc/methodsummary/html/summary.erb +0 -25
  359. data/templates/javadoc/mixins/html/header.erb +0 -5
  360. data/templates/javadoc/module/html/header.erb +0 -4
  361. data/templates/javadoc/source/html/main.erb +0 -15
  362. data/templates/javadoc/tags/html/header.erb +0 -5
  363. data/templates/javadoc/tags/html/see.erb +0 -8
  364. data/templates/javadoc/tags/html/tags.erb +0 -19
  365. data/templates/javadoc/visibilitygroup/html/header.erb +0 -5
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
- describe YARD::Generators::Helpers::HtmlHelper do
4
- include YARD::Generators::Helpers::HtmlHelper
3
+ describe YARD::Templates::Helpers::HtmlHelper do
4
+ include YARD::Templates::Helpers::HtmlHelper
5
5
 
6
6
  describe '#h' do
7
7
  it "should use #h to escape HTML" do
@@ -11,11 +11,53 @@ describe YARD::Generators::Helpers::HtmlHelper do
11
11
 
12
12
  describe '#fix_typewriter' do
13
13
  it "should use #fix_typewriter to convert +text+ to <tt>text</tt>" do
14
- fix_typewriter("Some +typewriter text+.").should == "Some <tt>typewriter text</tt>."
15
- fix_typewriter("Not +typewriter text.").should == "Not +typewriter text."
16
- fix_typewriter("Alternating +type writer+ text +here+.").should == "Alternating <tt>type writer</tt> text <tt>here</tt>."
17
- fix_typewriter("No ++problem.").should == "No ++problem."
18
- fix_typewriter("Math + stuff +is ok+").should == "Math + stuff <tt>is ok</tt>"
14
+ fix_typewriter("Some +typewriter text+.").should ==
15
+ "Some <tt>t\x04y\x04p\x04e\x04w\x04r\x04i\x04t\x04e\x04r\x04" +
16
+ " \x04t\x04e\x04x\x04t\x04</tt>."
17
+ fix_typewriter("Not +typewriter text.").should ==
18
+ "Not +typewriter text."
19
+ fix_typewriter("Alternating +type writer+ text +here+.").should ==
20
+ "Alternating <tt>t\x04y\x04p\x04e\x04 \x04w\x04r\x04i\x04t\x04e\x04r" +
21
+ "\x04</tt> text <tt>h\x04e\x04r\x04e\x04</tt>."
22
+ fix_typewriter("No ++problem.").should ==
23
+ "No ++problem."
24
+ fix_typewriter("Math + stuff +is ok+").should ==
25
+ "Math + stuff <tt>i\x04s\x04 \x04o\x04k\x04</tt>"
26
+ end
27
+ end
28
+
29
+ describe '#format_types' do
30
+ it "should include brackets by default" do
31
+ text = ["String"]
32
+ should_receive(:linkify).at_least(1).times.with("String", "String").and_return("String")
33
+ format_types(text).should == format_types(text, true)
34
+ format_types(text).should == "(<tt>String</tt>)"
35
+ end
36
+
37
+ it "should avoid brackets if brackets=false" do
38
+ should_receive(:linkify).with("String", "String").and_return("String")
39
+ should_receive(:linkify).with("Symbol", "Symbol").and_return("Symbol")
40
+ format_types(["String", "Symbol"], false).should == "<tt>String</tt>, <tt>Symbol</tt>"
41
+ end
42
+
43
+ { "String" => [["String"],
44
+ "<tt><a href=''>String</a></tt>"],
45
+ "A::B::C" => [["A::B::C"],
46
+ "<tt><a href=''>A::B::C</a></tt>"],
47
+ "Array<String>" => [["Array", "String"],
48
+ "<tt><a href=''>Array</a>&lt;<a href=''>String</a>&gt;</tt>"],
49
+ "Array<String, Symbol>" => [["Array", "String", "Symbol"],
50
+ "<tt><a href=''>Array</a>&lt;<a href=''>String</a>, <a href=''>Symbol</a>&gt;</tt>"],
51
+ "Array<{String => Array<Symbol>}>" => [["Array", "String", "Array", "Symbol"],
52
+ "<tt><a href=''>Array</a>&lt;{<a href=''>String</a> =&gt; " +
53
+ "<a href=''>Array</a>&lt;<a href=''>Symbol</a>&gt;}&gt;</tt>"]
54
+ }.each do |text, values|
55
+ it "should link all classes in #{text}" do
56
+ should_receive(:h).with('<').at_least(text.count('<')).times.and_return("&lt;")
57
+ should_receive(:h).with('>').at_least(text.count('>')).times.and_return("&gt;")
58
+ values[0].each {|v| should_receive(:linkify).with(v, v).and_return("<a href=''>#{v}</a>") }
59
+ format_types([text], false).should == values[1]
60
+ end
19
61
  end
20
62
  end
21
63
 
@@ -42,19 +84,19 @@ describe YARD::Generators::Helpers::HtmlHelper do
42
84
 
43
85
  it "should return nil if serializer is nil" do
44
86
  stub!(:serializer).and_return nil
45
- stub!(:current_object).and_return Registry.root
87
+ stub!(:object).and_return Registry.root
46
88
  url_for(P("Mod::Class#meth")).should be_nil
47
89
  end
48
90
 
49
91
  it "should return nil if serializer does not implement #serialized_path" do
50
92
  stub!(:serializer).and_return Serializers::Base.new
51
- stub!(:current_object).and_return Registry.root
93
+ stub!(:object).and_return Registry.root
52
94
  url_for(P("Mod::Class#meth")).should be_nil
53
95
  end
54
96
 
55
97
  it "should link to a path/file for a namespace object" do
56
98
  stub!(:serializer).and_return Serializers::FileSystemSerializer.new
57
- stub!(:current_object).and_return Registry.root
99
+ stub!(:object).and_return Registry.root
58
100
 
59
101
  yard = CodeObjects::ModuleObject.new(:root, :YARD)
60
102
  url_for(yard).should == 'YARD.html'
@@ -62,7 +104,7 @@ describe YARD::Generators::Helpers::HtmlHelper do
62
104
 
63
105
  it "should link to the object's namespace path/file and use the object as the anchor" do
64
106
  stub!(:serializer).and_return Serializers::FileSystemSerializer.new
65
- stub!(:current_object).and_return Registry.root
107
+ stub!(:object).and_return Registry.root
66
108
 
67
109
  yard = CodeObjects::ModuleObject.new(:root, :YARD)
68
110
  meth = CodeObjects::MethodObject.new(yard, :meth)
@@ -74,7 +116,7 @@ describe YARD::Generators::Helpers::HtmlHelper do
74
116
  serializer = mock(:serializer)
75
117
  serializer.stub!(:serialized_path).and_return("file.html")
76
118
  stub!(:serializer).and_return(serializer)
77
- stub!(:current_object).and_return(obj)
119
+ stub!(:object).and_return(obj)
78
120
  url_for(obj).should == "#%2F-instance_method"
79
121
  end
80
122
  end
@@ -100,17 +142,17 @@ describe YARD::Generators::Helpers::HtmlHelper do
100
142
 
101
143
  it "should link static files with file: prefix" do
102
144
  stub!(:serializer).and_return Serializers::FileSystemSerializer.new
103
- stub!(:current_object).and_return Registry.root
145
+ stub!(:object).and_return Registry.root
104
146
 
105
147
  parse_link(resolve_links("{file:TEST.txt#abc}")).should == {
106
148
  :inner_text => "TEST.txt",
107
149
  :title => "TEST.txt",
108
- :href => "TEST.txt.html#abc"
150
+ :href => "file.TEST.html#abc"
109
151
  }
110
152
  parse_link(resolve_links("{file:TEST.txt title}")).should == {
111
153
  :inner_text => "title",
112
154
  :title => "title",
113
- :href => "TEST.txt.html"
155
+ :href => "file.TEST.html"
114
156
  }
115
157
  end
116
158
 
@@ -128,5 +170,20 @@ describe YARD::Generators::Helpers::HtmlHelper do
128
170
  :title => "title"
129
171
  }
130
172
  end
173
+
174
+ it "should create mailto links with mailto: prefixes" do
175
+ parse_link(resolve_links('{mailto:joanna@example.com}')).should == {
176
+ :inner_text => 'mailto:joanna@example.com',
177
+ :target => '_parent',
178
+ :href => 'mailto:joanna@example.com',
179
+ :title => 'mailto:joanna@example.com'
180
+ }
181
+ parse_link(resolve_links('{mailto:steve@example.com Steve}')).should == {
182
+ :inner_text => 'Steve',
183
+ :target => '_parent',
184
+ :href => 'mailto:steve@example.com',
185
+ :title => 'Steve'
186
+ }
187
+ end
131
188
  end
132
- end
189
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe YARD::Templates::Helpers::HtmlSyntaxHighlightHelper do
4
+ include YARD::Templates::Helpers::HtmlHelper
5
+ include YARD::Templates::Helpers::HtmlSyntaxHighlightHelper
6
+
7
+ describe '#html_syntax_highlight' do
8
+ it "should not highlight source if options[:no_highlight] is set" do
9
+ should_receive(:options).and_return(:no_highlight => true)
10
+ html_syntax_highlight("def x\nend").should == "def x\nend"
11
+ end
12
+
13
+ it "should highlight source (ruby18)" do
14
+ should_receive(:options).and_return(:no_highlight => false)
15
+ expect = "<span class='def def kw'>def</span><span class='x identifier id'>x</span>
16
+ <span class='string val'>'x'</span><span class='plus op'>+</span>
17
+ <span class='regexp val'>/x/i</span><span class='end end kw'>end</span>"
18
+ result = html_syntax_highlight("def x\n 'x' + /x/i\nend")
19
+ html_equals_string(result, expect)
20
+ end if RUBY18
21
+
22
+ it "should highlight source (ruby19)" do
23
+ should_receive(:options).and_return(:no_highlight => false)
24
+ expect = "<span class='kw'>def</span> <span class='id x'>x</span>
25
+ <span class='tstring'><span class='tstring_beg'>'</span>
26
+ <span class='tstring_content'>x</span><span class='tstring_end'>'</span>
27
+ </span> <span class='op'>+</span> <span class='tstring'>
28
+ <span class='regexp_beg'>/</span><span class='tstring_content'>x</span>
29
+ <span class='regexp_end'>/i</span></span>\n<span class='kw'>end</span>"
30
+ result = html_syntax_highlight("def x\n 'x' + /x/i\nend")
31
+ html_equals_string(result, expect)
32
+ end if RUBY19
33
+
34
+ it "should return escaped unhighlighted source if a syntax error is found (ruby19)" do
35
+ should_receive(:options).and_return(:no_highlight => false)
36
+ html_syntax_highlight("def &x; ... end").should == "def &amp;x; ... end"
37
+ end if RUBY19
38
+ end
39
+ end
@@ -1,18 +1,18 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
- module YARD::Generators::Helpers::MarkupHelper
3
+ module YARD::Templates::Helpers::MarkupHelper
4
4
  public :load_markup_provider, :markup_class, :markup_provider
5
5
  end
6
6
 
7
7
  class MyMock
8
8
  attr_accessor :options
9
- include YARD::Generators::Helpers::MarkupHelper
9
+ include YARD::Templates::Helpers::MarkupHelper
10
10
  end
11
11
 
12
- describe YARD::Generators::Helpers::MarkupHelper do
12
+ describe YARD::Templates::Helpers::MarkupHelper do
13
13
  before do
14
14
  @gen = mock('Generator')
15
- @gen.extend(YARD::Generators::Helpers::MarkupHelper)
15
+ @gen.extend(YARD::Templates::Helpers::MarkupHelper)
16
16
  end
17
17
 
18
18
  def generator_should_exit
@@ -42,7 +42,7 @@ describe YARD::Generators::Helpers::MarkupHelper do
42
42
  it "should load nothing if rdoc is specified" do
43
43
  @gen.stub!(:options).and_return({:markup => :rdoc})
44
44
  @gen.load_markup_provider
45
- @gen.markup_class.should == YARD::Generators::Helpers::MarkupHelper::SimpleMarkup
45
+ @gen.markup_class.should == YARD::Templates::Helpers::MarkupHelper::SimpleMarkup
46
46
  end
47
47
 
48
48
  it "should search through available markup providers for the markup type if none is set" do
@@ -76,7 +76,7 @@ describe YARD::Generators::Helpers::MarkupHelper do
76
76
 
77
77
  it "should fail if no provider is found" do
78
78
  generator_should_exit
79
- YARD::Generators::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown].each do |p|
79
+ YARD::Templates::Helpers::MarkupHelper::MARKUP_PROVIDERS[:markdown].each do |p|
80
80
  @gen.should_receive(:require).with(p[:lib].to_s).and_raise(LoadError)
81
81
  end
82
82
  @gen.stub!(:options).and_return({:markup => :markdown})
@@ -92,4 +92,3 @@ describe YARD::Generators::Helpers::MarkupHelper do
92
92
  @gen.markup_provider.should == nil
93
93
  end
94
94
  end
95
-
@@ -0,0 +1,75 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe YARD::Templates::Engine.template(:default, :method) do
4
+ before { Registry.clear }
5
+
6
+ describe 'regular (deprecated) method' do
7
+ before do
8
+ YARD.parse_string <<-'eof'
9
+ private
10
+ # Comments
11
+ # @param [String] x the x argument
12
+ # @return [String] the result
13
+ # @raise [Exception] hi!
14
+ # @deprecated for great justice
15
+ def m(x) end
16
+ alias x m
17
+ eof
18
+ end
19
+
20
+ it "should render html format correctly" do
21
+ html_equals(Registry.at('#m').format(:format => :html, :no_highlight => true), :method001)
22
+ end
23
+
24
+ it "should render text format correctly" do
25
+ text_equals(Registry.at('#m').format, :method001)
26
+ end
27
+ end
28
+
29
+ describe 'method with 1 overload' do
30
+ before do
31
+ YARD.parse_string <<-'eof'
32
+ private
33
+ # Comments
34
+ # @overload m(x, y)
35
+ # @param [String] x parameter x
36
+ # @param [Boolean] y parameter y
37
+ def m(x) end
38
+ eof
39
+ end
40
+
41
+ it "should render html format correctly" do
42
+ html_equals(Registry.at('#m').format(:format => :html, :no_highlight => true), :method002)
43
+ end
44
+
45
+ it "should render text format correctly" do
46
+ text_equals(Registry.at('#m').format, :method002)
47
+ end
48
+ end
49
+
50
+ describe 'method with 2 overloads' do
51
+ before do
52
+ YARD.parse_string <<-'eof'
53
+ private
54
+ # Method comments
55
+ # @overload m(x, y)
56
+ # Overload docstring
57
+ # @param [String] x parameter x
58
+ # @param [Boolean] y parameter y
59
+ # @overload m(x, y, z)
60
+ # @param [String] x parameter x
61
+ # @param [Boolean] y parameter y
62
+ # @param [Boolean] z parameter z
63
+ def m(*args) end
64
+ eof
65
+ end
66
+
67
+ it "should render html format correctly" do
68
+ html_equals(Registry.at('#m').format(:format => :html, :no_highlight => true), :method003)
69
+ end
70
+
71
+ it "should render text format correctly" do
72
+ text_equals(Registry.at('#m').format, :method003)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe YARD::Templates::Engine.template(:default, :method) do
4
+ before do
5
+ Registry.clear
6
+ YARD.parse_string <<-'eof'
7
+ module B
8
+ def c; end
9
+ def d; end
10
+ end
11
+
12
+ # Comments
13
+ module A
14
+ attr_accessor :attr1
15
+ attr_reader :attr2
16
+
17
+ def self.a; end
18
+ def a; end
19
+ alias b a
20
+
21
+ include B
22
+
23
+ class Y; end
24
+ class Q; end
25
+ class X; end
26
+ module Z; end
27
+ CONSTANT = 'value'
28
+ @@cvar = 'value'
29
+ end
30
+ eof
31
+ end
32
+
33
+ it "should render html format correctly" do
34
+ html_equals(Registry.at('A').format(:format => :html, :no_highlight => true), :module001)
35
+ end
36
+
37
+ it "should render text format correctly" do
38
+ YARD.parse_string <<-'eof'
39
+ module A
40
+ include D, E, F, A::B::C
41
+ end
42
+ eof
43
+
44
+ text_equals(Registry.at('A').format, :module001)
45
+ end
46
+
47
+ it "should render dot format correctly" do
48
+ Registry.at('A').format(:format => :dot, :dependencies => true, :full => true).should == example(:module001, 'dot')
49
+ end
50
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ include YARD::Templates
4
+
5
+ def text_equals(result, expected_example)
6
+ text_equals_string(result, example(expected_example, :txt))
7
+ end
8
+
9
+ def text_equals_string(result, expected)
10
+ result.should == expected
11
+ end
12
+
13
+ def html_equals(result, expected_example)
14
+ html_equals_string(result, example(expected_example))
15
+ end
16
+
17
+ def html_equals_string(result, expected)
18
+ [expected, result].each do |value|
19
+ value.gsub!(/(>)\s+|\s+(<)/, '\1\2')
20
+ value.strip!
21
+ end
22
+ result.should == expected
23
+ end
24
+
25
+ def example(filename, ext = 'html')
26
+ File.read(File.join(File.dirname(__FILE__), 'examples', "#{filename}.#{ext}"))
27
+ end
28
+
29
+ module YARD::Templates::Engine
30
+ class << self
31
+ public :find_template_paths
32
+ end
33
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe YARD::Templates::Engine.template(:default, :tags) do
4
+ before { Registry.clear }
5
+
6
+ describe 'all known tags' do
7
+ before do
8
+ YARD.parse_string <<-'eof'
9
+ # Comments
10
+ # @abstract override me
11
+ # @param [Hash] opts the options
12
+ # @option opts :key ('') hello
13
+ # @option opts :key2 (X) hello
14
+ # @return [String] the result
15
+ # @raise [Exception] Exception class
16
+ # @deprecated for great justice
17
+ # @see A
18
+ # @see http://url.com
19
+ # @see http://url.com Example
20
+ # @author Name
21
+ # @since 1.0
22
+ # @version 1.0
23
+ # @yield a block
24
+ # @yieldparam [String] a a value
25
+ # @yieldreturn [Hash] a hash
26
+ # @example Wash your car
27
+ # car.wash
28
+ # @example To kill a mockingbird
29
+ # a = String.new
30
+ # flip(a.reverse)
31
+ def m(opts = {}) end
32
+ eof
33
+ end
34
+
35
+ it "should render text format correctly" do
36
+ text_equals(Registry.at('#m').format, :tag001)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,398 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe YARD::Templates::Template do
4
+ def template(path)
5
+ YARD::Templates::Engine.template!(path, '/full/path/' + path.to_s)
6
+ end
7
+
8
+ describe '#initialize' do
9
+ it "should not include parent directory if parent directory is a template root path" do
10
+ mod = template('q')
11
+ mod.should_not include(template(''))
12
+ end
13
+
14
+ it "should include parent directory template if exists" do
15
+ mod1 = template('x')
16
+ mod2 = template('x/y')
17
+ mod2.should include(mod1)
18
+ end
19
+ end
20
+
21
+ describe '.full_paths' do
22
+ it "should list full_path" do
23
+ mod = template(:a)
24
+ mod.full_paths.should == ['/full/path/a']
25
+ end
26
+
27
+ it "should list paths of included modules" do
28
+ mod = template(:a)
29
+ mod.send(:include, template(:b))
30
+ mod.full_paths.should == ['/full/path/a', '/full/path/b']
31
+ end
32
+
33
+ it "should list paths from modules of included modules" do
34
+ mod = template(:c)
35
+ mod.send(:include, template(:d))
36
+ mod.send(:include, template(:a))
37
+ mod.full_paths.should == ['c', 'a', 'b', 'd'].map {|o| '/full/path/' + o }
38
+ end
39
+
40
+ it "should only list full paths of modules that respond to full_paths" do
41
+ mod = template(:d)
42
+ mod.send(:include, Enumerable)
43
+ mod.full_paths.should == ['/full/path/d']
44
+ end
45
+ end
46
+
47
+ describe '.load_setup_rb' do
48
+ it "should load setup.rb file for module" do
49
+ File.should_receive(:file?).with('/full/path/e/setup.rb').and_return(true)
50
+ File.should_receive(:read).with('/full/path/e/setup.rb').and_return('def success; end')
51
+ template(:e).new.should respond_to(:success)
52
+ end
53
+ end
54
+
55
+ describe '.T' do
56
+ it "should load template from absolute path" do
57
+ mod = template(:a)
58
+ Engine.should_receive(:template).with('other')
59
+ mod.T('other')
60
+ end
61
+ end
62
+
63
+ describe '.find_file' do
64
+ it "should find file in module's full_path" do
65
+ File.should_receive(:file?).with('/full/path/a/basename').and_return(false)
66
+ File.should_receive(:file?).with('/full/path/b/basename').and_return(true)
67
+ template(:a).find_file('basename').should == '/full/path/b/basename'
68
+ end
69
+
70
+ it "should return nil if no file is found" do
71
+ File.should_receive(:file?).with('/full/path/a/basename').and_return(false)
72
+ File.should_receive(:file?).with('/full/path/b/basename').and_return(false)
73
+ template(:a).find_file('basename').should be_nil
74
+ end
75
+ end
76
+
77
+ describe '.find_nth_file' do
78
+ it "should find 2nd existing file in template paths" do
79
+ File.should_receive(:file?).with('/full/path/a/basename').and_return(true)
80
+ File.should_receive(:file?).with('/full/path/b/basename').and_return(true)
81
+ template(:a).find_nth_file('basename', 2).should == '/full/path/b/basename'
82
+ end
83
+
84
+ it "should return nil if no file is found" do
85
+ File.should_receive(:file?).with('/full/path/a/basename').and_return(true)
86
+ File.should_receive(:file?).with('/full/path/b/basename').and_return(true)
87
+ template(:a).find_nth_file('basename', 3).should be_nil
88
+ end
89
+ end
90
+
91
+ describe '.extra_includes' do
92
+ it "should be included when a module is initialized" do
93
+ module MyModule; end
94
+ Template.extra_includes << MyModule
95
+ template(:e).new.should be_kind_of(MyModule)
96
+ end
97
+ end
98
+
99
+ describe '.is_a?' do
100
+ it "should be kind of Template" do
101
+ template(:e).is_a?(Template).should == true
102
+ end
103
+ end
104
+
105
+ describe '#T' do
106
+ it "should delegate to class method" do
107
+ template(:e).should_receive(:T).with('test')
108
+ template(:e).new.T('test')
109
+ end
110
+ end
111
+
112
+ describe '#init' do
113
+ it "should be called during initialization" do
114
+ module YARD::Templates::Engine::Template__full_path_e
115
+ def init; sections 1, 2, 3 end
116
+ end
117
+ template(:e).new.sections.should == [1, 2, 3]
118
+ end
119
+ end
120
+
121
+ describe '#file' do
122
+ it "should read the file if it exists" do
123
+ File.should_receive(:file?).with('/full/path/e/abc').and_return(true)
124
+ IO.should_receive(:read).with('/full/path/e/abc').and_return('hello world')
125
+ template(:e).new.file('abc').should == 'hello world'
126
+ end
127
+
128
+ it "should raise ArgumentError if the file does not exist" do
129
+ File.should_receive(:file?).with('/full/path/e/abc').and_return(false)
130
+ lambda { template(:e).new.file('abc') }.should raise_error(ArgumentError)
131
+ end
132
+
133
+ it "should replace {{{__super__}}} with inherited template contents if allow_inherited=true" do
134
+ File.should_receive(:file?).with('/full/path/a/abc').twice.and_return(true)
135
+ File.should_receive(:file?).with('/full/path/b/abc').and_return(true)
136
+ IO.should_receive(:read).with('/full/path/a/abc').and_return('foo {{{__super__}}}')
137
+ IO.should_receive(:read).with('/full/path/b/abc').and_return('bar')
138
+ template(:a).new.file('abc', true).should == "foo bar"
139
+ end
140
+
141
+ it "should not replace {{{__super__}}} with inherited template contents if allow_inherited=false" do
142
+ File.should_receive(:file?).with('/full/path/a/abc').and_return(true)
143
+ IO.should_receive(:read).with('/full/path/a/abc').and_return('foo {{{__super__}}}')
144
+ template(:a).new.file('abc').should == "foo {{{__super__}}}"
145
+ end
146
+ end
147
+
148
+ describe '#superb' do
149
+ it "should return the inherited erb template contents" do
150
+ File.should_receive(:file?).with('/full/path/a/test.erb').and_return(true)
151
+ File.should_receive(:file?).with('/full/path/b/test.erb').and_return(true)
152
+ IO.should_receive(:read).with('/full/path/b/test.erb').and_return('bar')
153
+ template = template(:a).new
154
+ template.section = :test
155
+ template.superb.should == "bar"
156
+ end
157
+
158
+ it "should work inside an erb template" do
159
+ File.should_receive(:file?).with('/full/path/a/test.erb').twice.and_return(true)
160
+ File.should_receive(:file?).with('/full/path/b/test.erb').and_return(true)
161
+ IO.should_receive(:read).with('/full/path/a/test.erb').and_return('foo<%= superb %>!')
162
+ IO.should_receive(:read).with('/full/path/b/test.erb').and_return('bar')
163
+ template = template(:a).new
164
+ template.section = :test
165
+ template.erb(:test).should == "foobar!"
166
+ end
167
+ end
168
+
169
+ describe '#sections' do
170
+ it "should allow sections to be set if arguments are provided" do
171
+ mod = template(:e).new
172
+ mod.sections 1, 2, [3]
173
+ mod.sections.should == [1, 2, [3]]
174
+ end
175
+ end
176
+
177
+ describe '#run' do
178
+ it "should render all sections" do
179
+ mod = template(:e).new
180
+ mod.should_receive(:render_section).with(:a).and_return('a')
181
+ mod.should_receive(:render_section).with(:b).and_return('b')
182
+ mod.should_receive(:render_section).with(:c).and_return('c')
183
+ mod.sections :a, :b, :c
184
+ mod.run.should == 'abc'
185
+ end
186
+
187
+ it "should render all sections with options" do
188
+ mod = template(:e).new
189
+ mod.should_receive(:render_section).with(:a).and_return('a')
190
+ mod.should_receive(:add_options).with(:a => 1).and_yield
191
+ mod.sections :a
192
+ mod.run(:a => 1).should == 'a'
193
+ end
194
+
195
+ it "should run section list if provided" do
196
+ mod = template(:e).new
197
+ mod.should_receive(:render_section).with(:q)
198
+ mod.should_receive(:render_section).with(:x)
199
+ mod.run({}, [:q, :x])
200
+ end
201
+
202
+ it "should accept a nil section as empty string" do
203
+ mod = template(:e).new
204
+ mod.should_receive(:render_section).with(:a)
205
+ mod.sections :a
206
+ mod.run.should == ""
207
+ end
208
+ end
209
+
210
+ describe '#add_options' do
211
+ it "should set instance variables in addition to options" do
212
+ mod = template(:f).new
213
+ mod.send(:add_options, {:a => 1, :b => 2})
214
+ mod.options.should == {:a => 1, :b => 2}
215
+ mod.instance_variable_get("@a").should == 1
216
+ mod.instance_variable_get("@b").should == 2
217
+ end
218
+
219
+ it "should set instance variables and options only for the block" do
220
+ mod = template(:f).new
221
+ mod.send(:add_options, {:a => 100, :b => 200}) do
222
+ mod.options.should == {:a => 100, :b => 200}
223
+ end
224
+ mod.options.should_not == {:a => 100, :b => 200}
225
+ end
226
+ end
227
+
228
+ describe '#render_section' do
229
+ it "should call method if method exists by section name as Symbol" do
230
+ mod = template(:f).new
231
+ mod.should_receive(:respond_to?).with(:a).and_return(true)
232
+ mod.should_receive(:respond_to?).with('a').and_return(true)
233
+ mod.should_receive(:send).with(:a).and_return('a')
234
+ mod.should_receive(:send).with('a').and_return('a')
235
+ mod.run({}, [:a, 'a']).should == 'aa'
236
+ end
237
+
238
+ it "should call erb if no method exists by section name" do
239
+ mod = template(:f).new
240
+ mod.should_receive(:respond_to?).with(:a).and_return(false)
241
+ mod.should_receive(:respond_to?).with('a').and_return(false)
242
+ mod.should_receive(:erb).with(:a).and_return('a')
243
+ mod.should_receive(:erb).with('a').and_return('a')
244
+ mod.run({}, [:a, 'a']).should == 'aa'
245
+ end
246
+
247
+ it "should run a template if section is one" do
248
+ mod2 = template(:g)
249
+ mod2.should_receive(:run)
250
+ mod = template(:f).new
251
+ mod.sections mod2
252
+ mod.run
253
+ end
254
+
255
+ it "should run a template instance if section is one" do
256
+ mod2 = template(:g).new
257
+ mod2.should_receive(:run)
258
+ mod = template(:f).new
259
+ mod.sections mod2
260
+ mod.run
261
+ end
262
+ end
263
+
264
+ describe '#subsections' do
265
+ it "should set subsections when they are available" do
266
+ mod = template(:e).new
267
+ mod.sections :a, [:b, :c]
268
+ mod.should_receive(:render_section).with(:a) do
269
+ mod.subsections.should == [:b, :c]
270
+ end
271
+ mod.run
272
+ end
273
+ end
274
+
275
+ describe '#yield' do
276
+ it "should yield a subsection" do
277
+ mod = template(:e).new
278
+ mod.sections :a, [:b, :c]
279
+ class << mod
280
+ def a; "(" + yield + ")" end
281
+ def b; "b" end
282
+ def c; "c" end
283
+ end
284
+
285
+ mod.run.should == "(b)"
286
+ end
287
+
288
+ it "should yield a subsection within a yielded subsection" do
289
+ mod = template(:e).new
290
+ mod.sections :a, [:b, [:c]]
291
+ class << mod
292
+ def a; "(" + yield + ")" end
293
+ def b; yield end
294
+ def c; "c" end
295
+ end
296
+
297
+ mod.run.should == "(c)"
298
+ end
299
+
300
+ it "should support arbitrary nesting" do
301
+ mod = template(:e).new
302
+ mod.sections :a, [:b, [:c, [:d, [:e]]]]
303
+ class << mod
304
+ def a; "(" + yield + ")" end
305
+ def b; yield end
306
+ def c; yield end
307
+ def d; yield end
308
+ def e; "e" end
309
+ end
310
+
311
+ mod.run.should == "(e)"
312
+ end
313
+
314
+ it "should yield first two elements if yield is called twice" do
315
+ mod = template(:e).new
316
+ mod.sections :a, [:b, :c, :d]
317
+ class << mod
318
+ def a; "(" + yield + yield + ")" end
319
+ def b; 'b' end
320
+ def c; "c" end
321
+ end
322
+
323
+ mod.run.should == "(bc)"
324
+ end
325
+
326
+ it "should ignore any subsections inside subsection yields" do
327
+ mod = template(:e).new
328
+ mod.sections :a, [:b, [:c], :d]
329
+ class << mod
330
+ def a; "(" + yield + yield + ")" end
331
+ def b; 'b' end
332
+ def d; "d" end
333
+ end
334
+
335
+ mod.run.should == "(bd)"
336
+ end
337
+
338
+ it "should allow extra options passed via yield" do
339
+ mod = template(:e).new
340
+ mod.sections :a, [:b]
341
+ class << mod
342
+ def a; "(" + yield(:x => "a") + ")" end
343
+ def b; options[:x] + @x end
344
+ end
345
+
346
+ mod.run.should == "(aa)"
347
+ end
348
+ end
349
+
350
+ describe '#yieldall' do
351
+ it "should yield all subsections" do
352
+ mod = template(:e).new
353
+ mod.sections :a, [:b, [:d, [:e]], :c]
354
+ class << mod
355
+ def a; "(" + yieldall + ")" end
356
+ def b; "b" + yieldall end
357
+ def c; "c" end
358
+ def d; 'd' + yieldall end
359
+ def e; 'e' end
360
+ end
361
+
362
+ mod.run.should == "(bdec)"
363
+ end
364
+
365
+ it "should yield options to all subsections" do
366
+ mod = template(:e).new
367
+ mod.sections :a, [:b, :c]
368
+ class << mod
369
+ def a; "(" + yieldall(:x => "2") + ")" end
370
+ def b; @x end
371
+ def c; @x end
372
+ end
373
+ mod.run.should == "(22)"
374
+ end
375
+
376
+ it "should yield all subsections more than once" do
377
+ mod = template(:e).new
378
+ mod.sections :a, [:b]
379
+ class << mod
380
+ def a; "(" + yieldall + yieldall + ")" end
381
+ def b; "b" end
382
+ end
383
+
384
+ mod.run.should == "(bb)"
385
+ end
386
+
387
+ it "should not yield if no yieldall is called" do
388
+ mod = template(:e).new
389
+ mod.sections :a, [:b]
390
+ class << mod
391
+ def a; "()" end
392
+ def b; "b" end
393
+ end
394
+
395
+ mod.run.should == "()"
396
+ end
397
+ end
398
+ end