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,130 @@
1
+ require "spec_helper"
2
+
3
+ describe Docks::Containers::PatternLibrary do
4
+ subject { described_class.new }
5
+
6
+ let(:name) { "button" }
7
+
8
+ let(:pattern_one) do
9
+ Docks::Containers::Pattern.new(name: name)
10
+ end
11
+
12
+ let(:factory) do
13
+ Docks::Containers::Factory.new(name: "CodeBlock")
14
+ end
15
+
16
+ let(:pattern_two) do
17
+ pattern = Docks::Containers::Pattern.new(name: "code_block")
18
+ pattern.add(:script, factory)
19
+ pattern
20
+ end
21
+
22
+ describe "#<<" do
23
+ it "adds a pattern" do
24
+ subject << pattern_one
25
+ expect(subject.has_pattern?(name)).to be true
26
+ end
27
+ end
28
+
29
+ describe "#[]" do
30
+ it "returns nil for a name that doesn't match any patterns" do
31
+ expect(subject["foo"]).to be nil
32
+ end
33
+
34
+ it "returns a pattern whose name matches the passed name" do
35
+ subject << pattern_two
36
+ subject << pattern_one
37
+ expect(subject[pattern_one.name]).to be pattern_one
38
+ expect(subject[pattern_two.name.split("_").join("-")]).to be pattern_two
39
+ end
40
+ end
41
+
42
+ describe "#has_pattern?" do
43
+ it "returns false for a pattern that doesn't exist" do
44
+ expect(subject.has_pattern?("foo")).to be false
45
+ end
46
+
47
+ it "returns true for a pattern that matches the passed name" do
48
+ subject << pattern_two
49
+ subject << pattern_one
50
+ expect(subject.has_pattern?(pattern_one.name)).to be true
51
+ expect(subject.has_pattern?(pattern_two.name.split("_").join("-"))).to be true
52
+ end
53
+ end
54
+
55
+ describe "#group_by" do
56
+ it "groups symbols on the passed attribute" do
57
+ result = {}
58
+ subject << pattern_one
59
+ subject << pattern_two
60
+
61
+ subject.group_by(:name) do |name, group|
62
+ result[name] = group
63
+ end
64
+
65
+ expect(result).to eq("button" => [pattern_one], "code_block" => [pattern_two])
66
+ end
67
+ end
68
+
69
+ describe "#groups" do
70
+ it "groups by each pattern's group" do
71
+ result = {}
72
+ pattern_one.group = "foo"
73
+ pattern_two.group = "foo"
74
+ subject << pattern_one
75
+ subject << pattern_two
76
+
77
+ subject.groups do |group_name, group|
78
+ result[group_name] = group
79
+ end
80
+
81
+ expect(result).to eq("foo" => [pattern_one, pattern_two])
82
+ end
83
+ end
84
+
85
+ describe "#find" do
86
+ before :each do
87
+ subject << pattern_one
88
+ subject << pattern_two
89
+ end
90
+
91
+ it "returns false when no pattern matches the passed descriptor" do
92
+ expect(subject.find("foo")).to be false
93
+ expect(subject.find("foo::bar")).to be false
94
+ expect(subject.find("foo#bar")).to be false
95
+ end
96
+
97
+ it "finds a pattern with a name matching the passed descriptor" do
98
+ expect(subject.find(pattern_two.name)).to eq OpenStruct.new(pattern: pattern_two, symbol: nil)
99
+ end
100
+
101
+ it "finds a pattern with a contained symbol" do
102
+ expect(subject.find("#{pattern_two.name}::CodeBlock")).to eq OpenStruct.new(pattern: pattern_two, symbol: factory)
103
+ end
104
+ end
105
+
106
+ describe "#summary" do
107
+ it "returns a pattern library with all patterns summarized" do
108
+ subject << pattern_two
109
+ summary = subject.summary
110
+ expect(subject).not_to be_summarized
111
+ expect(summary).to be_summarized
112
+
113
+ summary.patterns.each do |name, pattern|
114
+ expect(pattern).to be_summarized
115
+ end
116
+ end
117
+ end
118
+
119
+ describe "#summary!" do
120
+ it "returns a pattern library with all patterns summarized" do
121
+ subject << pattern_two
122
+ expect { subject.summary! }.not_to change { subject.patterns.keys.length }
123
+ expect(subject).to be_summarized
124
+
125
+ subject.patterns.each do |name, pattern|
126
+ expect(pattern).to be_summarized
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,216 @@
1
+ require "spec_helper"
2
+
3
+ describe Docks::Containers::Symbol do
4
+ ACCESS_TYPES = Docks::Types::Access
5
+
6
+ subject { described_class.new(name: "foo") }
7
+ let(:access) { Docks::Tags::Access }
8
+
9
+ describe "#symbol_type" do
10
+ class Example < described_class
11
+ def self.type; "foo" end
12
+ end
13
+
14
+ it "uses the symbol type of the class" do
15
+ expect(subject.symbol_type).to eq described_class.type
16
+ expect(Example.new.symbol_type).to eq Example.type
17
+ end
18
+
19
+ it "adds the symbol type to the backing hash" do
20
+ expect(subject.to_h[:symbol_type]).to eq described_class.type
21
+ end
22
+ end
23
+
24
+ describe "#private?" do
25
+ it "identifies a private symbol based on its access type" do
26
+ expect(subject.private?).to be false
27
+
28
+ subject[access] = ACCESS_TYPES::PUBLIC
29
+ expect(subject.private?).to be false
30
+
31
+ subject[access] = ACCESS_TYPES::PRIVATE
32
+ expect(subject.private?).to be true
33
+ end
34
+ end
35
+
36
+ describe "#public?" do
37
+ it "identifies a public variable based on its access type" do
38
+ expect(subject.public?).to be true
39
+
40
+ subject[access] = ACCESS_TYPES::PUBLIC
41
+ expect(subject.public?).to be true
42
+
43
+ subject[access] = ACCESS_TYPES::PRIVATE
44
+ expect(subject.public?).to be false
45
+ end
46
+ end
47
+
48
+ describe "#symbol_id" do
49
+ it "creates a symbol_id" do
50
+ expect(subject.symbol_id).to eq "#{subject.symbol_type}-#{subject.name}"
51
+ end
52
+
53
+ it "creates a symbol_id that is unique between two symbol types with the same name" do
54
+ descendants = ObjectSpace.each_object(Class).select { |klass| klass < described_class }.sample(2)
55
+ descendants.map! { |descendant| descendant.new(name: "foo") }
56
+ expect(descendants.first.symbol_id).to_not eq descendants.last.symbol_id
57
+ end
58
+ end
59
+
60
+ describe "#to_descriptor" do
61
+ it "returns the name of the symbol" do
62
+ expect(subject.to_descriptor).to eq subject.name
63
+ end
64
+
65
+ it "returns the pattern and name of the symbol when the symbol is part of a pattern" do
66
+ pattern = Docks::Containers::Pattern.new(name: subject.name)
67
+ pattern.add(:style, subject)
68
+ expect(subject.to_descriptor).to eq "#{pattern.name}::#{subject.name}"
69
+ end
70
+ end
71
+
72
+ describe "#member?" do
73
+ it "is a member when it is a property or method" do
74
+ expect(Docks::Containers::Variable.new(property: true)).to be_member
75
+ expect(Docks::Containers::Function.new(method: true)).to be_member
76
+ end
77
+
78
+ it "is not a member when it is not a property or method" do
79
+ expect(Docks::Containers::Variable.new).to_not be_member
80
+ expect(Docks::Containers::Function.new).to_not be_member
81
+ expect(Docks::Containers::Klass.new).to_not be_member
82
+ expect(Docks::Containers::Factory.new).to_not be_member
83
+ end
84
+ end
85
+
86
+ describe "members" do
87
+ let(:property) { Docks::Containers::Variable.new(name: "baz") }
88
+ let(:method) { Docks::Containers::Function.new(name: "qux") }
89
+
90
+ describe "#add_member" do
91
+ context "when a variable is added" do
92
+ it "adds all the relevant details" do
93
+ subject.add_member(property)
94
+ expect(property.for).to eq subject.name
95
+ expect(property.belongs_to).to be subject
96
+ expect(property.property?).to be true
97
+ expect(property.static?).to be true
98
+ end
99
+
100
+ it "adds the property to the symbol's properties" do
101
+ subject.add_member(property)
102
+ expect(subject.properties).to include property
103
+ end
104
+ end
105
+
106
+ context "when a function is added" do
107
+ it "adds all the relevant details" do
108
+ subject.add_member(method)
109
+ expect(method.for).to eq subject.name
110
+ expect(method.belongs_to).to be subject
111
+ expect(method.method?).to be true
112
+ expect(method.static?).to be true
113
+ end
114
+
115
+ it "adds the function to the symbol's methods" do
116
+ subject.add_member(method)
117
+ expect(subject.methods).to include method
118
+ end
119
+ end
120
+ end
121
+
122
+ describe "#methods" do
123
+ it "returns an empty array when there are no methods" do
124
+ expect(subject.methods).to be_empty
125
+ end
126
+
127
+ it "returns all of the methods of the class" do
128
+ subject.add_members(method)
129
+ all_methods = subject.methods
130
+ expect(all_methods.length).to be 1
131
+ expect(all_methods).to include method
132
+ end
133
+ end
134
+
135
+ describe "#properties" do
136
+ it "returns an empty array when there are no properties" do
137
+ expect(subject.properties).to be_empty
138
+ end
139
+
140
+ it "returns all of the properties of the symbol" do
141
+ subject.add_members(property)
142
+ all_properties = subject.properties
143
+ expect(all_properties.length).to be 1
144
+ expect(all_properties).to include property
145
+ end
146
+ end
147
+
148
+ describe "#members" do
149
+ it "returns an empty array when there are no members" do
150
+ expect(subject.members).to be_empty
151
+ end
152
+
153
+ it "returns all members, of any type" do
154
+ subject.add_members(method, property)
155
+
156
+ members = subject.members
157
+ expect(members.length).to be 2
158
+ expect(members).to include method
159
+ expect(members).to include property
160
+ end
161
+ end
162
+
163
+ describe "#has_members?" do
164
+ it "returns false when there are no members" do
165
+ expect(subject).not_to have_members
166
+ end
167
+
168
+ it "returns true when there are members" do
169
+ subject.add_members(method, property)
170
+ expect(subject).to have_members
171
+ end
172
+ end
173
+
174
+ describe "#find" do
175
+ it "returns false if the descriptor symbol doesn't match" do
176
+ expect(subject.find("baz")).to be false
177
+ end
178
+
179
+ it "returns the symbol when the symbol name matches and there are no other parts to the descriptor" do
180
+ expect(subject.find(subject.name)).to be subject
181
+ end
182
+
183
+ it "returns false when the symbol name matches but the member does not" do
184
+ expect(subject.find("#{subject.name}.bar")).to be false
185
+ expect(subject.find("#{subject.name}#bar")).to be false
186
+ expect(subject.find("#{subject.name}~bar")).to be false
187
+ end
188
+
189
+ it "returns a method" do
190
+ subject.add_members(method, property)
191
+ expect(subject.find("#{subject.name}.#{method.name}")).to be method
192
+ end
193
+
194
+ it "returns a property" do
195
+ subject.add_members(property, method)
196
+ expect(subject.find("#{subject.name}.#{property.name}")).to be property
197
+ end
198
+ end
199
+ end
200
+
201
+ describe "#summary" do
202
+ before(:each) do
203
+ subject.add_members(Docks::Containers::Variable.new, Docks::Containers::Function.new)
204
+ end
205
+
206
+ let(:summary) { subject.summary }
207
+
208
+ it "preserves the symbol_id, name, properties, and methods" do
209
+ expect(summary).to be_a described_class
210
+ expect(summary.name).to eq subject.name
211
+ expect(summary.symbol_id).to eq subject.symbol_id
212
+ expect(summary.properties).to eq subject.properties.map(&:summary)
213
+ expect(summary.methods).to eq subject.methods.map(&:summary)
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,116 @@
1
+ require "spec_helper"
2
+
3
+ describe Docks::Containers::Variable do
4
+ let(:variable) do
5
+ described_class.new(name: "foo")
6
+ end
7
+
8
+ let(:static_property) do
9
+ described_class.new(name: "bar", static: true, property: true)
10
+ end
11
+
12
+ let(:instance_property) do
13
+ described_class.new(name: "baz", static: false, property: true)
14
+ end
15
+
16
+ let(:factory) do
17
+ Docks::Containers::Factory.new(name: "Foo")
18
+ end
19
+
20
+ before(:each) do
21
+ factory.add_members(instance_property, static_property)
22
+ end
23
+
24
+ describe "#static?" do
25
+ it "returns true for a static method" do
26
+ expect(static_property.static?).to be true
27
+ expect(instance_property.static?).to be false
28
+ end
29
+ end
30
+
31
+ describe "#instance?" do
32
+ it "returns true for an instance method" do
33
+ expect(static_property.instance?).to be false
34
+ expect(instance_property.instance?).to be true
35
+ end
36
+ end
37
+
38
+ describe "#property?" do
39
+ it "is a method when it has a method attribute" do
40
+ expect(static_property.property?).to be true
41
+ expect(variable.property?).to be false
42
+ end
43
+ end
44
+
45
+ describe "#symbol_id" do
46
+ it "returns the default if the variable is not a property" do
47
+ expect(variable.symbol_id).to eq "variable-#{variable.name}"
48
+ end
49
+
50
+ it "indicates it's a property and adds the classlike's name if it is a property" do
51
+ expect(instance_property.symbol_id).to eq "property-#{factory.name}-#{instance_property.name}"
52
+ end
53
+
54
+ it "indicates that it's static if appropriate" do
55
+ expect(static_property.symbol_id).to eq "property-static-#{factory.name}-#{static_property.name}"
56
+ end
57
+ end
58
+
59
+ describe "#to_descriptor" do
60
+ let(:pattern) { Docks::Containers::Pattern.new(name: "foo") }
61
+
62
+ it "returns the super descriptor if not a property" do
63
+ expect(variable.to_descriptor).to eq variable.name
64
+
65
+ pattern.add(:script, variable)
66
+ expect(variable.to_descriptor).to eq "#{pattern.name}::#{variable.name}"
67
+ end
68
+
69
+ it "returns the proper instance property descriptor" do
70
+ pattern.add(:script, factory)
71
+ expect(instance_property.to_descriptor).to eq "#{factory.to_descriptor}##{instance_property.name}"
72
+ end
73
+
74
+ it "returns the proper static property descriptor" do
75
+ pattern.add(:script, factory)
76
+ expect(static_property.to_descriptor).to eq "#{factory.to_descriptor}.#{static_property.name}"
77
+ end
78
+ end
79
+
80
+ describe "#summary" do
81
+ it "preserves the symbol_id, name, static and property status" do
82
+ [instance_property, static_property, variable].each do |var|
83
+ summary = var.summary
84
+
85
+ expect(summary).to be_a described_class
86
+ expect(summary.name).to eq var.name
87
+ expect(summary.symbol_id).to eq var.symbol_id
88
+ expect(summary.property?).to eq var.property?
89
+ expect(summary.static?).to eq var.static?
90
+ end
91
+ end
92
+ end
93
+
94
+ describe "#find" do
95
+ it "finds the variable if it's not a property and the symbol matches" do
96
+ expect(variable.find(variable.name)).to be variable
97
+ expect(variable.find(static_property.name)).to be false
98
+ expect(static_property.find(static_property.name)).to be false
99
+ expect(instance_property.find(instance_property.name)).to be false
100
+ end
101
+
102
+ it "finds the variable if it's a static property and the name matches" do
103
+ expect(variable.find("foo.#{variable.name}")).to be false
104
+ expect(static_property.find("foo.#{static_property.name}")).to be static_property
105
+ expect(static_property.find("foo.#{instance_property.name}")).to be false
106
+ expect(instance_property.find("foo.#{instance_property.name}")).to be false
107
+ end
108
+
109
+ it "finds the variable if it's an instance property and the name matches" do
110
+ expect(variable.find("foo##{variable.name}")).to be false
111
+ expect(static_property.find("foo##{static_property.name}")).to be false
112
+ expect(instance_property.find("foo##{instance_property.name}")).to be instance_property
113
+ expect(static_property.find("foo##{static_property.name}")).to be false
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,52 @@
1
+ require "spec_helper"
2
+
3
+ describe Docks::Containers::Variation do
4
+ subject { Docks::Containers::Variation.new }
5
+
6
+ it "sets appropriate details" do
7
+ expect(subject.active).to be false
8
+ expect(subject.activate_with).to eq []
9
+ expect(subject.precludes).to eq []
10
+ expect(subject.set_by).to eq []
11
+ expect(subject.include_with).to eq []
12
+ expect(subject.demo_type).to eq Docks::Types::Demo::SELECT
13
+ end
14
+
15
+ describe "#has_demo?" do
16
+ it "has a demo only when the demo_type is set to Types::Demo::OWN or Types::Demo::JOINT" do
17
+ expect(subject.has_demo?).to be false
18
+
19
+ subject.demo_type = Docks::Types::Demo::JOINT
20
+ expect(subject.has_demo?).to be true
21
+
22
+ subject.demo_type = Docks::Types::Demo::SELECT
23
+ expect(subject.has_demo?).to be false
24
+
25
+ subject.demo_type = Docks::Types::Demo::OWN
26
+ expect(subject.has_demo?).to be true
27
+
28
+ subject.demo_type = Docks::Types::Demo::NONE
29
+ expect(subject.has_demo?).to be false
30
+
31
+ subject.demo_type = Docks::Types::Demo::HIDDEN
32
+ expect(subject.has_demo?).to be false
33
+ end
34
+ end
35
+
36
+ describe "#find" do
37
+ before(:each) do
38
+ subject.for = "foo"
39
+ subject.name = "foo--bar"
40
+ end
41
+
42
+ it "finds a variation when the name matches the symbol" do
43
+ expect(subject.find(subject.name)).to be subject
44
+ expect(subject.find("foo--baz")).to be false
45
+ end
46
+
47
+ it "finds a variation when any member information matches the variation name and the symbol matches the base class" do
48
+ expect(subject.find("#{subject.for}~#{subject.name}")).to be subject
49
+ expect(subject.find("baz~#{subject.name}")).to be false
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ describe Docks::Containers do
4
+ subject { Docks::Containers }
5
+
6
+ describe ".container_for" do
7
+ it "wraps a parse result in the correct container" do
8
+ subject::TOP_LEVEL_SYMBOLS.each do |type|
9
+ container = subject.constants.map { |const| subject.const_get(const) }.select { |const| const.respond_to?(:type) && const.type == type }.first
10
+ expect(subject.container_for(type)).to be container
11
+ end
12
+ end
13
+
14
+ it "returns the base symbol if no type was passed" do
15
+ expect(subject.container_for).to be Docks::Containers::Symbol
16
+ end
17
+
18
+ it "returns the base symbol for an unrecognized type" do
19
+ expect(subject.container_for("foo")).to be Docks::Containers::Symbol
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,73 @@
1
+ require "spec_helper"
2
+
3
+ describe Docks::Descriptor do
4
+ subject { described_class }
5
+
6
+ let(:symbol) { "CodeBlock" }
7
+ let(:pattern) { "code-block" }
8
+ let(:instance_member) { "toggle" }
9
+ let(:static_member) { "for" }
10
+ let(:local_member) { "CodeCaches" }
11
+
12
+ describe "#initialize" do
13
+ it "returns something that is already a descriptor" do
14
+ descriptor = subject.new(symbol)
15
+ expect(subject.new(descriptor)).to be descriptor
16
+ end
17
+
18
+ it "identifies a symbol name" do
19
+ expect(subject.new(symbol).symbol).to eq symbol
20
+ end
21
+
22
+ it "identifies a pattern instead of a symbol if the pattern assumption option is passed" do
23
+ descriptor = subject.new(pattern, assume: :pattern)
24
+ expect(descriptor.pattern).to eq pattern
25
+ expect(descriptor.symbol).to be nil
26
+ end
27
+
28
+ it "identifies a pattern name" do
29
+ result = subject.new("#{pattern}::#{symbol}")
30
+ expect(result.pattern).to eq Docks.pattern_id(pattern)
31
+ expect(result.symbol).to eq symbol
32
+ end
33
+
34
+ it "identifies an instance member" do
35
+ result = subject.new("#{symbol}##{instance_member}")
36
+ expect(result.symbol).to eq symbol
37
+ expect(result.instance_member).to eq instance_member
38
+ end
39
+
40
+ it "identifies a static member" do
41
+ result = subject.new("#{symbol}.#{static_member}")
42
+ expect(result.symbol).to eq symbol
43
+ expect(result.static_member).to eq static_member
44
+ end
45
+
46
+ it "identifies a local member" do
47
+ result = subject.new("#{symbol}~#{local_member}")
48
+ expect(result.symbol).to eq symbol
49
+ expect(result.local_member).to eq local_member
50
+ end
51
+ end
52
+
53
+ describe "#member?" do
54
+ it "is not a member when it has no member information" do
55
+ expect(subject.new(symbol).member?).to be false
56
+ end
57
+
58
+ it "is a member when it has member information" do
59
+ expect(subject.new("#{symbol}##{instance_member}").member?).to be true
60
+ expect(subject.new("#{symbol}.#{static_member}").member?).to be true
61
+ expect(subject.new("#{symbol}~#{local_member}").member?).to be true
62
+ end
63
+ end
64
+
65
+ describe "member" do
66
+ it "returns any member" do
67
+ expect(subject.new(symbol).member).to be nil
68
+ expect(subject.new("#{symbol}##{instance_member}").member).to eq instance_member
69
+ expect(subject.new("#{symbol}.#{static_member}").member).to eq static_member
70
+ expect(subject.new("#{symbol}~#{local_member}").member).to eq local_member
71
+ end
72
+ end
73
+ end