docks_app 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (313) hide show
  1. data/.editorconfig +8 -0
  2. data/.gitignore +22 -0
  3. data/.rubocop.yml +20 -0
  4. data/.travis.yml +10 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +35 -0
  8. data/Rakefile +3 -0
  9. data/bin/docks +5 -0
  10. data/config/json/docks_config.json +71 -0
  11. data/config/ruby/docks_config.rb +127 -0
  12. data/config/yaml/docks_config.yml +70 -0
  13. data/docks.gemspec +38 -0
  14. data/lib/docks/build.rb +300 -0
  15. data/lib/docks/cache.rb +143 -0
  16. data/lib/docks/command_line.rb +65 -0
  17. data/lib/docks/configuration.rb +217 -0
  18. data/lib/docks/containers/base_container.rb +103 -0
  19. data/lib/docks/containers/class_container.rb +39 -0
  20. data/lib/docks/containers/component_container.rb +92 -0
  21. data/lib/docks/containers/demo_container.rb +105 -0
  22. data/lib/docks/containers/factory_container.rb +12 -0
  23. data/lib/docks/containers/function_container.rb +46 -0
  24. data/lib/docks/containers/mixin_container.rb +19 -0
  25. data/lib/docks/containers/pattern_container.rb +168 -0
  26. data/lib/docks/containers/pattern_library_container.rb +77 -0
  27. data/lib/docks/containers/state_container.rb +9 -0
  28. data/lib/docks/containers/symbol_container.rb +77 -0
  29. data/lib/docks/containers/variable_container.rb +47 -0
  30. data/lib/docks/containers/variant_container.rb +9 -0
  31. data/lib/docks/containers/variation_container.rb +38 -0
  32. data/lib/docks/containers.rb +25 -0
  33. data/lib/docks/descriptor.rb +60 -0
  34. data/lib/docks/errors.rb +5 -0
  35. data/lib/docks/group.rb +66 -0
  36. data/lib/docks/helpers/github_helper.rb +29 -0
  37. data/lib/docks/helpers/path_helper.rb +94 -0
  38. data/lib/docks/helpers/render_helper.rb +87 -0
  39. data/lib/docks/helpers.rb +19 -0
  40. data/lib/docks/languages/base_language.rb +17 -0
  41. data/lib/docks/languages/coffeescript_language.rb +30 -0
  42. data/lib/docks/languages/common_types/markup_language.rb +71 -0
  43. data/lib/docks/languages/css_language.rb +13 -0
  44. data/lib/docks/languages/erb_language.rb +21 -0
  45. data/lib/docks/languages/haml_language.rb +21 -0
  46. data/lib/docks/languages/html_language.rb +10 -0
  47. data/lib/docks/languages/javascript_language.rb +42 -0
  48. data/lib/docks/languages/json_language.rb +18 -0
  49. data/lib/docks/languages/less_language.rb +33 -0
  50. data/lib/docks/languages/markdown_language.rb +10 -0
  51. data/lib/docks/languages/sass_language.rb +36 -0
  52. data/lib/docks/languages/slim_language.rb +21 -0
  53. data/lib/docks/languages/stylus_language.rb +26 -0
  54. data/lib/docks/languages/yaml_language.rb +18 -0
  55. data/lib/docks/languages.rb +103 -0
  56. data/lib/docks/markdown.rb +18 -0
  57. data/lib/docks/messenger.rb +69 -0
  58. data/lib/docks/naming_conventions/base_naming_convention.rb +9 -0
  59. data/lib/docks/naming_conventions/bem_naming_convention.rb +45 -0
  60. data/lib/docks/naming_conventions/suit_naming_convention.rb +45 -0
  61. data/lib/docks/naming_conventions.rb +21 -0
  62. data/lib/docks/ostruct.rb +17 -0
  63. data/lib/docks/parser.rb +86 -0
  64. data/lib/docks/parsers/base_parser.rb +128 -0
  65. data/lib/docks/parsers/coffeescript_parser.rb +30 -0
  66. data/lib/docks/parsers/css_parser.rb +27 -0
  67. data/lib/docks/parsers/javascript_parser.rb +30 -0
  68. data/lib/docks/parsers/less_parser.rb +22 -0
  69. data/lib/docks/parsers/sass_parser.rb +31 -0
  70. data/lib/docks/parsers/stylus_parser.rb +28 -0
  71. data/lib/docks/process.rb +60 -0
  72. data/lib/docks/processors.rb +416 -0
  73. data/lib/docks/renderers/base_renderer.rb +64 -0
  74. data/lib/docks/renderers/common_features/capturable.rb +69 -0
  75. data/lib/docks/renderers/common_features/helperable.rb +23 -0
  76. data/lib/docks/renderers/erb_renderer.rb +68 -0
  77. data/lib/docks/renderers/haml_renderer.rb +37 -0
  78. data/lib/docks/renderers/slim_renderer.rb +33 -0
  79. data/lib/docks/symbol_sources/base_symbol_source.rb +12 -0
  80. data/lib/docks/symbol_sources/jquery_symbol_source.rb +17 -0
  81. data/lib/docks/symbol_sources/mdn_symbol_source.rb +35 -0
  82. data/lib/docks/symbol_sources/sass_symbol_source.rb +27 -0
  83. data/lib/docks/symbol_sources.rb +28 -0
  84. data/lib/docks/tags/access_tag.rb +27 -0
  85. data/lib/docks/tags/activate_with_tag.rb +17 -0
  86. data/lib/docks/tags/active_tag.rb +14 -0
  87. data/lib/docks/tags/alias_tag.rb +17 -0
  88. data/lib/docks/tags/author_tag.rb +19 -0
  89. data/lib/docks/tags/base_tag.rb +52 -0
  90. data/lib/docks/tags/beta_tag.rb +26 -0
  91. data/lib/docks/tags/class_tag.rb +16 -0
  92. data/lib/docks/tags/compatibility_tag.rb +19 -0
  93. data/lib/docks/tags/demo_type_tag.rb +14 -0
  94. data/lib/docks/tags/deprecated_tag.rb +26 -0
  95. data/lib/docks/tags/description_tag.rb +99 -0
  96. data/lib/docks/tags/example_tag.rb +20 -0
  97. data/lib/docks/tags/factory_tag.rb +16 -0
  98. data/lib/docks/tags/for_tag.rb +23 -0
  99. data/lib/docks/tags/group_tag.rb +10 -0
  100. data/lib/docks/tags/helper_tag.rb +13 -0
  101. data/lib/docks/tags/include_with_tag.rb +57 -0
  102. data/lib/docks/tags/javascript_action_tag.rb +10 -0
  103. data/lib/docks/tags/link_tag.rb +18 -0
  104. data/lib/docks/tags/markup_tag.rb +106 -0
  105. data/lib/docks/tags/member_tag.rb +37 -0
  106. data/lib/docks/tags/method_tag.rb +18 -0
  107. data/lib/docks/tags/name_tag.rb +10 -0
  108. data/lib/docks/tags/object_tag.rb +15 -0
  109. data/lib/docks/tags/param_tag.rb +94 -0
  110. data/lib/docks/tags/pattern_tag.rb +21 -0
  111. data/lib/docks/tags/preclude_tag.rb +17 -0
  112. data/lib/docks/tags/private_tag.rb +15 -0
  113. data/lib/docks/tags/property_tag.rb +18 -0
  114. data/lib/docks/tags/public_tag.rb +15 -0
  115. data/lib/docks/tags/require_tag.rb +47 -0
  116. data/lib/docks/tags/returns_tag.rb +31 -0
  117. data/lib/docks/tags/set_by_tag.rb +18 -0
  118. data/lib/docks/tags/signature_tag.rb +35 -0
  119. data/lib/docks/tags/since_tag.rb +26 -0
  120. data/lib/docks/tags/source_tag.rb +12 -0
  121. data/lib/docks/tags/state_tag.rb +21 -0
  122. data/lib/docks/tags/static_tag.rb +14 -0
  123. data/lib/docks/tags/subcomponent_tag.rb +68 -0
  124. data/lib/docks/tags/subtitle_tag.rb +11 -0
  125. data/lib/docks/tags/symbol_type_tag.rb +10 -0
  126. data/lib/docks/tags/throws_tag.rb +30 -0
  127. data/lib/docks/tags/title_tag.rb +10 -0
  128. data/lib/docks/tags/type_tag.rb +10 -0
  129. data/lib/docks/tags/value_tag.rb +10 -0
  130. data/lib/docks/tags/variant_tag.rb +21 -0
  131. data/lib/docks/tags/variation_tag.rb +136 -0
  132. data/lib/docks/tags.rb +103 -0
  133. data/lib/docks/templates.rb +122 -0
  134. data/lib/docks/themes.rb +19 -0
  135. data/lib/docks/types.rb +26 -0
  136. data/lib/docks/version.rb +3 -0
  137. data/lib/docks.rb +37 -0
  138. data/spec/fixtures/build/scripts/bar/bar_2.js +1 -0
  139. data/spec/fixtures/build/scripts/bar.js +1 -0
  140. data/spec/fixtures/build/styles/foo/foo-2.css +1 -0
  141. data/spec/fixtures/build/styles/foo.css +1 -0
  142. data/spec/fixtures/build/templates/baz/baz_2.erb +1 -0
  143. data/spec/fixtures/build/templates/baz.erb +1 -0
  144. data/spec/fixtures/grouper/components/button/button.coffee +0 -0
  145. data/spec/fixtures/grouper/components/button/button.haml +0 -0
  146. data/spec/fixtures/grouper/components/button/button.scss +0 -0
  147. data/spec/fixtures/grouper/components/checkbox/_checkbox.haml +0 -0
  148. data/spec/fixtures/grouper/components/checkbox/_checkbox.scss +0 -0
  149. data/spec/fixtures/grouper/components/checkbox/checkbox.coffee +0 -0
  150. data/spec/fixtures/grouper/components/form/form.coffee +0 -0
  151. data/spec/fixtures/grouper/components/form/form.m +0 -0
  152. data/spec/fixtures/grouper/components/form/form.scss +0 -0
  153. data/spec/fixtures/grouper/components/next-expanding-textarea/_next-expanding-textarea.scss +0 -0
  154. data/spec/fixtures/grouper/components/next-expanding-textarea/_next_expanding_textarea.coffee +0 -0
  155. data/spec/fixtures/grouper/components/next-expanding-textarea/next-expanding-textarea.haml +0 -0
  156. data/spec/fixtures/grouper/components/next-tab/next-tab.coffee +0 -0
  157. data/spec/fixtures/grouper/components/next-tab/next-tab.haml +0 -0
  158. data/spec/fixtures/grouper/components/next-tab/next-tab.scss +0 -0
  159. data/spec/fixtures/grouper/components/segmented control/segmented control.coffee +0 -0
  160. data/spec/fixtures/grouper/components/segmented control/segmented control.haml +0 -0
  161. data/spec/fixtures/grouper/components/segmented control/segmented control.min.html +0 -0
  162. data/spec/fixtures/grouper/components/segmented control/segmented control.scss +0 -0
  163. data/spec/fixtures/grouper/markup/list-view.haml +0 -0
  164. data/spec/fixtures/grouper/markup/resizable/resizable.haml +0 -0
  165. data/spec/fixtures/grouper/markup/toggle.haml +0 -0
  166. data/spec/fixtures/grouper/scripts/resizable/resizable.coffee +0 -0
  167. data/spec/fixtures/grouper/scripts/toggle.coffee +0 -0
  168. data/spec/fixtures/grouper/style/_list-view.scss +0 -0
  169. data/spec/fixtures/grouper/style/_toggle.scss +0 -0
  170. data/spec/fixtures/languages/stub.json +3 -0
  171. data/spec/fixtures/languages/stub.yml +2 -0
  172. data/spec/fixtures/parsers/coffeescript_parser_fixture_basic.coffee +20 -0
  173. data/spec/fixtures/parsers/coffeescript_parser_fixture_complex.coffee +80 -0
  174. data/spec/fixtures/parsers/css_parser_fixture_basic.css +44 -0
  175. data/spec/fixtures/parsers/css_parser_fixture_complex.css +120 -0
  176. data/spec/fixtures/parsers/javascript_parser_fixture_basic.js +27 -0
  177. data/spec/fixtures/parsers/javascript_parser_fixture_complex.js +85 -0
  178. data/spec/fixtures/parsers/sass_parser_fixture_basic.scss +39 -0
  179. data/spec/fixtures/parsers/sass_parser_fixture_complex.scss +149 -0
  180. data/spec/fixtures/parsers/stylus_parser_fixture_basic.styl +34 -0
  181. data/spec/fixtures/parsers/stylus_parser_fixture_complex.styl +113 -0
  182. data/spec/fixtures/processors/join_with_smart_line_breaks/code_blocks.txt +10 -0
  183. data/spec/fixtures/processors/join_with_smart_line_breaks/headings.txt +15 -0
  184. data/spec/fixtures/processors/join_with_smart_line_breaks/lists.txt +21 -0
  185. data/spec/fixtures/processors/join_with_smart_line_breaks/lists_with_nesting.txt +13 -0
  186. data/spec/fixtures/processors/join_with_smart_line_breaks/multiple_paragraphs.txt +11 -0
  187. data/spec/fixtures/renderers/helpers.rb +37 -0
  188. data/spec/fixtures/renderers/html_output.html +7 -0
  189. data/spec/fixtures/renderers/templates/layouts/application.html.erb +0 -0
  190. data/spec/fixtures/renderers/templates/layouts/more/subdirectory.html.erb +0 -0
  191. data/spec/fixtures/renderers/templates/partials/_leading_underscore.html.erb +1 -0
  192. data/spec/fixtures/renderers/templates/partials/more/_subdirectory.html.erb +1 -0
  193. data/spec/fixtures/renderers/templates/partials/partial.html.erb +0 -0
  194. data/spec/fixtures/renderers/templates/partials/template.html.erb +1 -0
  195. data/spec/fixtures/renderers/templates/template.html.erb +1 -0
  196. data/spec/fixtures/tags/description/button.md +24 -0
  197. data/spec/fixtures/tags/description/class.md +27 -0
  198. data/spec/fixtures/tags/description/component.md +23 -0
  199. data/spec/fixtures/tags/description/function.md +30 -0
  200. data/spec/lib/build_spec.rb +467 -0
  201. data/spec/lib/cache_spec.rb +175 -0
  202. data/spec/lib/command_line_spec.rb +77 -0
  203. data/spec/lib/configuration_spec.rb +180 -0
  204. data/spec/lib/containers/base_container_spec.rb +214 -0
  205. data/spec/lib/containers/class_container_spec.rb +209 -0
  206. data/spec/lib/containers/component_container_spec.rb +158 -0
  207. data/spec/lib/containers/demo_container_spec.rb +113 -0
  208. data/spec/lib/containers/function_container_spec.rb +116 -0
  209. data/spec/lib/containers/mixin_container_spec.rb +4 -0
  210. data/spec/lib/containers/pattern_container_spec.rb +291 -0
  211. data/spec/lib/containers/pattern_library_container_spec.rb +130 -0
  212. data/spec/lib/containers/symbol_container_spec.rb +216 -0
  213. data/spec/lib/containers/variable_container_spec.rb +116 -0
  214. data/spec/lib/containers/variation_container_spec.rb +52 -0
  215. data/spec/lib/containers_spec.rb +22 -0
  216. data/spec/lib/descriptor_spec.rb +73 -0
  217. data/spec/lib/group_spec.rb +151 -0
  218. data/spec/lib/helpers/path_helper_spec.rb +202 -0
  219. data/spec/lib/helpers/render_helper_spec.rb +159 -0
  220. data/spec/lib/helpers_spec.rb +35 -0
  221. data/spec/lib/languages/base_language_spec.rb +32 -0
  222. data/spec/lib/languages/coffeescript_language_spec.rb +52 -0
  223. data/spec/lib/languages/css_language_spec.rb +13 -0
  224. data/spec/lib/languages/erb_language_spec.rb +33 -0
  225. data/spec/lib/languages/haml_language_spec.rb +32 -0
  226. data/spec/lib/languages/javascript_language_spec.rb +54 -0
  227. data/spec/lib/languages/json_language_spec.rb +24 -0
  228. data/spec/lib/languages/less_language_spec.rb +39 -0
  229. data/spec/lib/languages/markup_language_spec.rb +95 -0
  230. data/spec/lib/languages/sass_language_spec.rb +53 -0
  231. data/spec/lib/languages/slim_language_spec.rb +32 -0
  232. data/spec/lib/languages/stylus_language_spec.rb +34 -0
  233. data/spec/lib/languages/yaml_language_spec.rb +24 -0
  234. data/spec/lib/languages_spec.rb +127 -0
  235. data/spec/lib/markdown_spec.rb +63 -0
  236. data/spec/lib/messenger_spec.rb +1 -0
  237. data/spec/lib/naming_conventions/bem_naming_convention_spec.rb +112 -0
  238. data/spec/lib/naming_conventions/suit_naming_convention_spec.rb +107 -0
  239. data/spec/lib/naming_conventions_spec.rb +28 -0
  240. data/spec/lib/ostruct_spec.rb +15 -0
  241. data/spec/lib/parser_spec.rb +93 -0
  242. data/spec/lib/parsers/base_parser_spec.rb +128 -0
  243. data/spec/lib/parsers/coffeescript_parser_spec.rb +184 -0
  244. data/spec/lib/parsers/css_parser_spec.rb +136 -0
  245. data/spec/lib/parsers/javascript_parser_spec.rb +216 -0
  246. data/spec/lib/parsers/less_parser_spec.rb +111 -0
  247. data/spec/lib/parsers/sass_parser_spec.rb +233 -0
  248. data/spec/lib/parsers/stylus_parser_spec.rb +212 -0
  249. data/spec/lib/process_spec.rb +96 -0
  250. data/spec/lib/processors_spec.rb +555 -0
  251. data/spec/lib/renderers/base_renderer_spec.rb +122 -0
  252. data/spec/lib/renderers/common_features/helperable_spec.rb +30 -0
  253. data/spec/lib/renderers/erb_renderer_spec.rb +119 -0
  254. data/spec/lib/renderers/haml_renderer_spec.rb +103 -0
  255. data/spec/lib/renderers/slim_renderer_spec.rb +103 -0
  256. data/spec/lib/symbol_sources/jquery_symbol_source_spec.rb +25 -0
  257. data/spec/lib/symbol_sources/mdn_symbol_source_spec.rb +40 -0
  258. data/spec/lib/symbol_sources/sass_symbol_source_spec.rb +39 -0
  259. data/spec/lib/symbol_sources_spec.rb +19 -0
  260. data/spec/lib/tags/access_tag_spec.rb +32 -0
  261. data/spec/lib/tags/activate_with_tag_spec.rb +31 -0
  262. data/spec/lib/tags/active_tag_spec.rb +24 -0
  263. data/spec/lib/tags/alias_tag_spec.rb +31 -0
  264. data/spec/lib/tags/author_tag_spec.rb +172 -0
  265. data/spec/lib/tags/base_tag_spec.rb +21 -0
  266. data/spec/lib/tags/beta_tag_spec.rb +52 -0
  267. data/spec/lib/tags/class_tag_spec.rb +29 -0
  268. data/spec/lib/tags/compatibility_tag_spec.rb +159 -0
  269. data/spec/lib/tags/demo_type_tag_spec.rb +24 -0
  270. data/spec/lib/tags/deprecated_tag_spec.rb +50 -0
  271. data/spec/lib/tags/description_tag_spec.rb +242 -0
  272. data/spec/lib/tags/example_tag_spec.rb +37 -0
  273. data/spec/lib/tags/factory_tag_spec.rb +29 -0
  274. data/spec/lib/tags/for_tag_spec.rb +45 -0
  275. data/spec/lib/tags/group_tag_spec.rb +20 -0
  276. data/spec/lib/tags/helper_tag_spec.rb +22 -0
  277. data/spec/lib/tags/include_with_tag_spec.rb +74 -0
  278. data/spec/lib/tags/javascript_action_tag_spec.rb +20 -0
  279. data/spec/lib/tags/link_tag_spec.rb +49 -0
  280. data/spec/lib/tags/markup_tag_spec.rb +255 -0
  281. data/spec/lib/tags/member_tag_spec.rb +167 -0
  282. data/spec/lib/tags/method_tag_spec.rb +27 -0
  283. data/spec/lib/tags/name_tag_spec.rb +20 -0
  284. data/spec/lib/tags/object_tag_spec.rb +24 -0
  285. data/spec/lib/tags/param_tag_spec.rb +261 -0
  286. data/spec/lib/tags/pattern_tag_spec.rb +49 -0
  287. data/spec/lib/tags/preclude_tag_spec.rb +31 -0
  288. data/spec/lib/tags/private_tag_spec.rb +31 -0
  289. data/spec/lib/tags/property_tag_spec.rb +27 -0
  290. data/spec/lib/tags/public_tag_spec.rb +29 -0
  291. data/spec/lib/tags/require_tag_spec.rb +133 -0
  292. data/spec/lib/tags/returns_tag_spec.rb +85 -0
  293. data/spec/lib/tags/set_by_tag_spec.rb +92 -0
  294. data/spec/lib/tags/signature_tag_spec.rb +125 -0
  295. data/spec/lib/tags/since_tag_spec.rb +48 -0
  296. data/spec/lib/tags/state_tag_spec.rb +199 -0
  297. data/spec/lib/tags/static_tag_spec.rb +27 -0
  298. data/spec/lib/tags/subcomponent_tag_spec.rb +78 -0
  299. data/spec/lib/tags/subtitle_tag_spec.rb +13 -0
  300. data/spec/lib/tags/symbol_type_tag_spec.rb +20 -0
  301. data/spec/lib/tags/throws_tag_spec.rb +49 -0
  302. data/spec/lib/tags/title_tag_spec.rb +20 -0
  303. data/spec/lib/tags/type_tag_spec.rb +20 -0
  304. data/spec/lib/tags/value_tag_spec.rb +20 -0
  305. data/spec/lib/tags/variant_tag_spec.rb +13 -0
  306. data/spec/lib/tags/variation_tag_spec.rb +154 -0
  307. data/spec/lib/tags_spec.rb +264 -0
  308. data/spec/lib/templates_spec.rb +185 -0
  309. data/spec/lib/themes_spec.rb +32 -0
  310. data/spec/spec_helper.rb +34 -0
  311. data/tasks/rspec.rake +7 -0
  312. data/tasks/rubocop.rake +8 -0
  313. metadata +740 -0
@@ -0,0 +1,233 @@
1
+ require "spec_helper"
2
+
3
+ describe Docks::Parsers::Sass do
4
+ subject { Docks::Parsers::Sass.instance }
5
+
6
+ let(:basic_fixture) { File.join(File.dirname(__FILE__), "..", "..", "fixtures", "parsers", "sass_parser_fixture_basic.scss") }
7
+ let(:complex_fixture) { File.join(File.dirname(__FILE__), "..", "..", "fixtures", "parsers", "sass_parser_fixture_complex.scss") }
8
+
9
+ describe "#parse" do
10
+ let(:basic_parsed_symbols) { subject.parse(basic_fixture) }
11
+ let(:complex_parsed_symbols) { subject.parse(complex_fixture) }
12
+
13
+ it "captures the correct number of documentation blocks" do
14
+ expect(basic_parsed_symbols.length).to eq 2
15
+ expect(complex_parsed_symbols.length).to eq 6
16
+ end
17
+
18
+ it "doesn't add text in between the pattern block and the following documentation block to the pattern block" do
19
+ expect(complex_parsed_symbols.first.description).to be nil
20
+ end
21
+
22
+ it 'captures the pattern comment block when one exists' do
23
+ expect(basic_parsed_symbols.first[:pattern]).to be nil
24
+ expect(complex_parsed_symbols.first[:pattern]).to_not be nil
25
+ end
26
+
27
+ it "captures the pattern comment block when it is written using the page synonym" do
28
+ complex_parsed_symbols = subject.parse(File.read(complex_fixture).sub("@pattern", "@page"))
29
+ expect(complex_parsed_symbols.first[:page]).to_not be nil
30
+ end
31
+
32
+ it "adds line number for the first line following all other comment blocks" do
33
+ expected_line_numbers = [8, 25]
34
+ basic_parsed_symbols.each_with_index do |symbol, index|
35
+ expect(symbol.source.line_number).to be expected_line_numbers[index]
36
+ end
37
+
38
+ expected_line_numbers = [1, 21, 38, 59, 92, 110]
39
+ complex_parsed_symbols.each_with_index do |symbol, index|
40
+ expect(symbol.source.line_number).to be expected_line_numbers[index]
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#symbol_block_extractor" do
46
+ it "provides the first non-comment line as the second capture group" do
47
+ [
48
+ ".button {",
49
+ "#button {",
50
+ "&--is-active {",
51
+ "[button] {",
52
+ "body {",
53
+ "$variable",
54
+ "@function() {",
55
+ "+button-style()",
56
+ "=button-style {"
57
+ ].each do |non_comment|
58
+ match = " //*\n // Description\n\n #{non_comment}".match(subject.symbol_block_extractor)
59
+ expect(match[:first_line]).to eq non_comment
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "#comment_line_pattern" do
65
+ let(:basic_comment) { "This is a comment" }
66
+ let(:complex_comment) { "// This comment has some extra comment-like symbols/characters //" }
67
+
68
+ context "when using line comments" do
69
+ it "strips line comments" do
70
+ expect("// #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
71
+ end
72
+
73
+ it "strips line comments with leading whitespace" do
74
+ expect(" // #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
75
+ end
76
+
77
+ it "strips line complex comments" do
78
+ expect("// #{complex_comment}".gsub(subject.comment_line_pattern, "")).to eq complex_comment
79
+ end
80
+
81
+ it "leaves empty lines intact" do
82
+ content = "// Foo\n//\n// 1. Bar\n\n// 2. Baz"
83
+ expect(content.gsub(subject.comment_line_pattern, "")).to eq "Foo\n\n1. Bar\n\n2. Baz"
84
+ end
85
+ end
86
+
87
+ context "when using block commments" do
88
+ it "strips line comments" do
89
+ expect("* #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
90
+ end
91
+
92
+ it "strips line comments with leading whitespace" do
93
+ expect(" * #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
94
+ end
95
+
96
+ it "strips line complex comments" do
97
+ expect("* #{complex_comment}".gsub(subject.comment_line_pattern, "")).to eq complex_comment
98
+ end
99
+
100
+ it "leaves empty lines intact" do
101
+ content = "* Foo\n*\n* 1. Bar\n\n* 2. Baz"
102
+ expect(content.gsub(subject.comment_line_pattern, "")).to eq "Foo\n\n1. Bar\n\n2. Baz"
103
+ end
104
+ end
105
+ end
106
+
107
+ describe "#symbol_details_from_first_line" do
108
+ it "identifies a placeholder" do
109
+ target_name = "clearfix"
110
+ name, type = subject.symbol_details_from_first_line("%#{target_name} {").values
111
+ expect(type).to eq Docks::Types::Symbol::PLACEHOLDER
112
+ expect(name).to eq "%#{target_name}"
113
+ end
114
+
115
+ it "identifies a mixin" do
116
+ target_name = "full-size"
117
+ name, type = subject.symbol_details_from_first_line("@mixin #{target_name}($height, $width) {").values
118
+ expect(type).to eq Docks::Types::Symbol::MIXIN
119
+ expect(name).to eq target_name
120
+ end
121
+
122
+ it "identifies a mixin in Sass format" do
123
+ target_name = "full-size"
124
+ name, type = subject.symbol_details_from_first_line("=#{target_name}($height, $width) {").values
125
+ expect(type).to eq Docks::Types::Symbol::MIXIN
126
+ expect(name).to eq target_name
127
+ end
128
+
129
+ it "identifies a function" do
130
+ target_name = "strip-units"
131
+ name, type = subject.symbol_details_from_first_line("@function #{target_name}($num) {").values
132
+ expect(type).to eq Docks::Types::Symbol::FUNCTION
133
+ expect(name).to eq target_name
134
+ end
135
+
136
+ it "identifies a variable" do
137
+ target_name = "message-width"
138
+ name, type = subject.symbol_details_from_first_line("$#{target_name}: 40rem;").values
139
+ expect(type).to eq Docks::Types::Symbol::VARIABLE
140
+ expect(name).to eq "$#{target_name}"
141
+ end
142
+
143
+ describe "states" do
144
+ it "identifies a state as a class starting with `is-`" do
145
+ target_name = "is-active"
146
+ name, type = subject.symbol_details_from_first_line("#{target_name} {").values
147
+ expect(type).to eq Docks::Types::Symbol::STATE
148
+ expect(name).to eq target_name
149
+ end
150
+
151
+ it "identifies a state as a class starting with `&.is-`" do
152
+ target_name = "is-active"
153
+ name, type = subject.symbol_details_from_first_line("&.#{target_name} {").values
154
+ expect(type).to eq Docks::Types::Symbol::STATE
155
+ expect(name).to eq target_name
156
+ end
157
+
158
+ it "identifies a state as a class containing `--is-`" do
159
+ target_name = "tab-list__tab--is-active"
160
+ name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
161
+ expect(type).to eq Docks::Types::Symbol::STATE
162
+ expect(name).to eq target_name
163
+ end
164
+
165
+ it "identifies a state as a class starting with `&--is-`" do
166
+ target_name = "--is-active"
167
+ name, type = subject.symbol_details_from_first_line("&#{target_name} {").values
168
+ expect(type).to eq Docks::Types::Symbol::STATE
169
+ expect(name).to eq target_name
170
+ end
171
+
172
+ it "identifies a state as a class starting with `js-`" do
173
+ target_name = "js-active"
174
+ name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
175
+ expect(type).to eq Docks::Types::Symbol::STATE
176
+ expect(name).to eq target_name
177
+ end
178
+
179
+ it "identifies a state as a class starting with `&.js-`" do
180
+ target_name = "js-active"
181
+ name, type = subject.symbol_details_from_first_line("&.#{target_name} {").values
182
+ expect(type).to eq Docks::Types::Symbol::STATE
183
+ expect(name).to eq target_name
184
+ end
185
+
186
+ it "identifies a state as a class containing `--js-`" do
187
+ target_name = "tab-list__tab--js-active"
188
+ name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
189
+ expect(type).to eq Docks::Types::Symbol::STATE
190
+ expect(name).to eq target_name
191
+ end
192
+
193
+ it "identifies a state as a class starting with `&--js-`" do
194
+ target_name = "--js-active"
195
+ name, type = subject.symbol_details_from_first_line("&#{target_name} {").values
196
+ expect(type).to eq Docks::Types::Symbol::STATE
197
+ expect(name).to eq target_name
198
+ end
199
+ end
200
+
201
+ describe "variants" do
202
+ it "identifies a variant as a class containing `--`" do
203
+ target_name = "tab-list__tab--large"
204
+ name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
205
+ expect(type).to eq Docks::Types::Symbol::VARIANT
206
+ expect(name).to eq target_name
207
+ end
208
+
209
+ it "identifies a variant as a class starting with `&--`" do
210
+ target_name = "--large"
211
+ name, type = subject.symbol_details_from_first_line("&#{target_name} {").values
212
+ expect(type).to eq Docks::Types::Symbol::VARIANT
213
+ expect(name).to eq target_name
214
+ end
215
+ end
216
+
217
+ describe "component" do
218
+ it "identifies a component as any class not matching state/ variant" do
219
+ target_name = "tab-list__tab"
220
+ name, type = subject.symbol_details_from_first_line(".#{target_name} { flex: 1 1 0; }").values
221
+ expect(type).to eq Docks::Types::Symbol::COMPONENT
222
+ expect(name).to eq target_name
223
+ end
224
+
225
+ it "identifies a component as a class starting with `&__`" do
226
+ target_name = "__tab"
227
+ name, type = subject.symbol_details_from_first_line("&#{target_name} { flex: 1 1 0; }").values
228
+ expect(type).to eq Docks::Types::Symbol::COMPONENT
229
+ expect(name).to eq target_name
230
+ end
231
+ end
232
+ end
233
+ end
@@ -0,0 +1,212 @@
1
+ require "spec_helper"
2
+
3
+ describe Docks::Parsers::Stylus do
4
+ subject { Docks::Parsers::Stylus.instance }
5
+
6
+ let(:basic_fixture) { File.join(File.dirname(__FILE__), "..", "..", "fixtures", "parsers", "stylus_parser_fixture_basic.styl") }
7
+ let(:complex_fixture) { File.join(File.dirname(__FILE__), "..", "..", "fixtures", "parsers", "stylus_parser_fixture_complex.styl") }
8
+
9
+ describe "#parse" do
10
+ let(:basic_parsed_symbols) { subject.parse(basic_fixture) }
11
+ let(:complex_parsed_symbols) { subject.parse(complex_fixture) }
12
+
13
+ it "captures the correct number of documentation blocks" do
14
+ expect(basic_parsed_symbols.length).to eq 2
15
+ expect(complex_parsed_symbols.length).to eq 6
16
+ end
17
+
18
+ it 'captures the pattern comment block when one exists' do
19
+ expect(basic_parsed_symbols.first[:pattern]).to be nil
20
+ expect(complex_parsed_symbols.first[:pattern]).to_not be nil
21
+ end
22
+
23
+ it "captures the pattern comment block when it is written using the page synonym" do
24
+ complex_parsed_symbols = subject.parse(File.read(complex_fixture).sub("@pattern", "@page"))
25
+ expect(complex_parsed_symbols.first[:page]).to_not be nil
26
+ end
27
+
28
+ it "adds line number for the first line following all other comment blocks" do
29
+ expected_line_numbers = [8, 24]
30
+ basic_parsed_symbols.each_with_index do |symbol, index|
31
+ expect(symbol.source.line_number).to be expected_line_numbers[index]
32
+ end
33
+
34
+ expected_line_numbers = [1, 19, 34, 50, 76, 89]
35
+ complex_parsed_symbols.each_with_index do |symbol, index|
36
+ expect(symbol.source.line_number).to be expected_line_numbers[index]
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#symbol_block_extractor" do
42
+ it "provides the first non-comment line as the second capture group" do
43
+ [
44
+ ".button",
45
+ "#button",
46
+ "&--is-active",
47
+ "[button]",
48
+ "body",
49
+ "@media large",
50
+ "+button-style()"
51
+ ].each do |non_comment|
52
+ match = " //*\n // Description\n\n #{non_comment}".match(subject.symbol_block_extractor)
53
+ expect(match[:first_line]).to eq non_comment
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#comment_line_pattern" do
59
+ let(:basic_comment) { "This is a comment" }
60
+ let(:complex_comment) { "// This comment has some extra comment-like symbols/characters //" }
61
+
62
+ context "when using line comments" do
63
+ it "strips line comments" do
64
+ expect("// #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
65
+ end
66
+
67
+ it "strips line comments with leading whitespace" do
68
+ expect(" // #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
69
+ end
70
+
71
+ it "strips line complex comments" do
72
+ expect("// #{complex_comment}".gsub(subject.comment_line_pattern, "")).to eq complex_comment
73
+ end
74
+
75
+ it "leaves empty lines intact" do
76
+ content = "// Foo\n//\n// 1. Bar\n\n// 2. Baz"
77
+ expect(content.gsub(subject.comment_line_pattern, "")).to eq "Foo\n\n1. Bar\n\n2. Baz"
78
+ end
79
+ end
80
+
81
+ context "when using block commments" do
82
+ it "strips line comments" do
83
+ expect("* #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
84
+ end
85
+
86
+ it "strips line comments with leading whitespace" do
87
+ expect(" * #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
88
+ end
89
+
90
+ it "strips line complex comments" do
91
+ expect("* #{complex_comment}".gsub(subject.comment_line_pattern, "")).to eq complex_comment
92
+ end
93
+
94
+ it "leaves empty lines intact" do
95
+ content = "* Foo\n*\n* 1. Bar\n\n* 2. Baz"
96
+ expect(content.gsub(subject.comment_line_pattern, "")).to eq "Foo\n\n1. Bar\n\n2. Baz"
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "#symbol_details_from_first_line" do
102
+ it "identifies a mixin/ function without params" do
103
+ target_name = "full-size"
104
+ name, type = subject.symbol_details_from_first_line("#{target_name}()").values
105
+ expect(type).to eq Docks::Types::Symbol::MIXIN
106
+ expect(name).to eq target_name
107
+ end
108
+ it "identifies a mixin/ function with params" do
109
+ target_name = "strip-units"
110
+ name, type = subject.symbol_details_from_first_line("#{target_name}(num)").values
111
+ expect(type).to eq Docks::Types::Symbol::MIXIN
112
+ expect(name).to eq target_name
113
+ end
114
+
115
+ it "identifies a variable" do
116
+ target_name = "message-width"
117
+ name, type = subject.symbol_details_from_first_line("#{target_name} = 40rem").values
118
+ expect(type).to eq Docks::Types::Symbol::VARIABLE
119
+ expect(name).to eq target_name
120
+ end
121
+
122
+ describe "states" do
123
+ it "identifies a state as a class starting with `is-`" do
124
+ target_name = "is-active"
125
+ name, type = subject.symbol_details_from_first_line("#{target_name}").values
126
+ expect(type).to eq Docks::Types::Symbol::STATE
127
+ expect(name).to eq target_name
128
+ end
129
+
130
+ it "identifies a state as a class starting with `&.is-`" do
131
+ target_name = "is-active"
132
+ name, type = subject.symbol_details_from_first_line("&.#{target_name}").values
133
+ expect(type).to eq Docks::Types::Symbol::STATE
134
+ expect(name).to eq target_name
135
+ end
136
+
137
+ it "identifies a state as a class containing `--is-`" do
138
+ target_name = "tab-list__tab--is-active"
139
+ name, type = subject.symbol_details_from_first_line(".#{target_name}").values
140
+ expect(type).to eq Docks::Types::Symbol::STATE
141
+ expect(name).to eq target_name
142
+ end
143
+
144
+ it "identifies a state as a class starting with `&--is-`" do
145
+ target_name = "--is-active"
146
+ name, type = subject.symbol_details_from_first_line("&#{target_name}").values
147
+ expect(type).to eq Docks::Types::Symbol::STATE
148
+ expect(name).to eq target_name
149
+ end
150
+
151
+ it "identifies a state as a class starting with `js-`" do
152
+ target_name = "js-active"
153
+ name, type = subject.symbol_details_from_first_line(".#{target_name}").values
154
+ expect(type).to eq Docks::Types::Symbol::STATE
155
+ expect(name).to eq target_name
156
+ end
157
+
158
+ it "identifies a state as a class starting with `&.js-`" do
159
+ target_name = "js-active"
160
+ name, type = subject.symbol_details_from_first_line("&.#{target_name}").values
161
+ expect(type).to eq Docks::Types::Symbol::STATE
162
+ expect(name).to eq target_name
163
+ end
164
+
165
+ it "identifies a state as a class containing `--js-`" do
166
+ target_name = "tab-list__tab--js-active"
167
+ name, type = subject.symbol_details_from_first_line(".#{target_name}").values
168
+ expect(type).to eq Docks::Types::Symbol::STATE
169
+ expect(name).to eq target_name
170
+ end
171
+
172
+ it "identifies a state as a class starting with `&--js-`" do
173
+ target_name = "--js-active"
174
+ name, type = subject.symbol_details_from_first_line("&#{target_name}").values
175
+ expect(type).to eq Docks::Types::Symbol::STATE
176
+ expect(name).to eq target_name
177
+ end
178
+ end
179
+
180
+ describe "variants" do
181
+ it "identifies a variant as a class containing `--`" do
182
+ target_name = "tab-list__tab--large"
183
+ name, type = subject.symbol_details_from_first_line(".#{target_name}").values
184
+ expect(type).to eq Docks::Types::Symbol::VARIANT
185
+ expect(name).to eq target_name
186
+ end
187
+
188
+ it "identifies a variant as a class starting with `&--`" do
189
+ target_name = "--large"
190
+ name, type = subject.symbol_details_from_first_line("&#{target_name}").values
191
+ expect(type).to eq Docks::Types::Symbol::VARIANT
192
+ expect(name).to eq target_name
193
+ end
194
+ end
195
+
196
+ describe "component" do
197
+ it "identifies a component as any class not matching state/ variant" do
198
+ target_name = "tab-list__tab"
199
+ name, type = subject.symbol_details_from_first_line(".#{target_name}").values
200
+ expect(type).to eq Docks::Types::Symbol::COMPONENT
201
+ expect(name).to eq target_name
202
+ end
203
+
204
+ it "identifies a component as a class starting with `&__`" do
205
+ target_name = "__tab"
206
+ name, type = subject.symbol_details_from_first_line("&#{target_name}").values
207
+ expect(type).to eq Docks::Types::Symbol::COMPONENT
208
+ expect(name).to eq target_name
209
+ end
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,96 @@
1
+ require "spec_helper"
2
+
3
+ describe Docks::Process do
4
+ subject { Docks::Process }
5
+
6
+ before(:each) { Docks::Tags.register_bundled_tags }
7
+
8
+ describe ".process" do
9
+ context "when the argument is a symbol" do
10
+ let(:symbol) { Docks::Containers::Symbol.new(name: "bar", private: "true") }
11
+
12
+ it "returns the processed symbol" do
13
+ expect(subject.process(symbol)).to be symbol
14
+ end
15
+
16
+ it "runs the process method for every tag in the symbol" do
17
+ expect(symbol).to receive(:tags).and_call_original
18
+ expect(Docks::Tags::Name.instance).to receive(:process).with(symbol)
19
+ expect(Docks::Tags::Private.instance).to receive(:process).with(symbol)
20
+ subject.process(symbol)
21
+ end
22
+
23
+ it "updates the symbol type if it was overwritten in the comment block" do
24
+ symbol.symbol_type = Docks::Types::Symbol::COMPONENT
25
+ expect(Docks::Tags::Name.instance).to receive(:process).with instance_of(Docks::Containers::Component)
26
+ expect(Docks::Tags::Private.instance).to receive(:process).with instance_of(Docks::Containers::Component)
27
+ result = subject.process(symbol)
28
+ expect(result).to be_a Docks::Containers::Component
29
+ end
30
+ end
31
+
32
+ context "when the argument is a pattern" do
33
+ let(:pattern) { Docks::Containers::Pattern.new(name: "foo") }
34
+
35
+ it "returns the processed pattern" do
36
+ expect(subject.process(pattern)).to be pattern
37
+ end
38
+
39
+ it "calls a registered pattern processor with the pattern as the only argument" do
40
+ arg = nil
41
+ subject.register_pattern_processor { |pattern| arg = pattern }
42
+ subject.process(pattern)
43
+ expect(arg).to be pattern
44
+ end
45
+
46
+ it "calls processors for a given hook in the order they were registered" do
47
+ positions = []
48
+ subject.register_pattern_processor { positions << 1 }
49
+ subject.register_pattern_processor { positions << 2 }
50
+ subject.process(pattern)
51
+ expect(positions).to eq [1, 2]
52
+ end
53
+
54
+ it "calls processors in the early hook, then the middle hook, then the late hook" do
55
+ positions = []
56
+ subject.register_pattern_processor(:late) { positions << 1 }
57
+ subject.register_pattern_processor(:middle) { positions << 2 }
58
+ subject.register_pattern_processor(:early) { positions << 3 }
59
+ subject.process(pattern)
60
+ expect(positions).to eq [3, 2, 1]
61
+ end
62
+ end
63
+
64
+ context "when the argument is a pattern library" do
65
+ let(:pattern_library) { Docks::Containers::PatternLibrary.new }
66
+
67
+ it "returns the processed pattern_library" do
68
+ expect(subject.process(pattern_library)).to be pattern_library
69
+ end
70
+
71
+ it "calls a registered pattern_library processor with the pattern_library as the only argument" do
72
+ arg = nil
73
+ subject.register_pattern_library_processor { |pattern_library| arg = pattern_library }
74
+ subject.process(pattern_library)
75
+ expect(arg).to be pattern_library
76
+ end
77
+
78
+ it "calls processors for a given hook in the order they were registered" do
79
+ positions = []
80
+ subject.register_pattern_library_processor { positions << 1 }
81
+ subject.register_pattern_library_processor { positions << 2 }
82
+ subject.process(pattern_library)
83
+ expect(positions).to eq [1, 2]
84
+ end
85
+
86
+ it "calls processors in the early hook, then the middle hook, then the late hook" do
87
+ positions = []
88
+ subject.register_pattern_library_processor(:late) { positions << 1 }
89
+ subject.register_pattern_library_processor(:middle) { positions << 2 }
90
+ subject.register_pattern_library_processor(:early) { positions << 3 }
91
+ subject.process(pattern_library)
92
+ expect(positions).to eq [3, 2, 1]
93
+ end
94
+ end
95
+ end
96
+ end