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,467 @@
1
+ require "spec_helper"
2
+
3
+ template_dir = File.expand_path("../../../assets", __FILE__)
4
+ empty_dir = File.expand_path("../../fixtures/build/empty", __FILE__)
5
+ existing_dir = File.expand_path("../../fixtures/build/existing", __FILE__)
6
+
7
+ describe Docks::Builder do
8
+ subject { Docks::Builder }
9
+
10
+ let(:default_options) do
11
+ {
12
+ config_type: "yaml",
13
+ template_language: "erb",
14
+ style_language: "scss",
15
+ script_language: "javascript"
16
+ }
17
+ end
18
+
19
+ after :all do
20
+ FileUtils.rm_rf(empty_dir)
21
+ FileUtils.rm_rf(existing_dir)
22
+ end
23
+
24
+ describe ".setup" do
25
+ let(:assets_dir) { File.join(empty_dir, Docks::ASSETS_DIR) }
26
+ let(:config_dir) { File.expand_path("../../../config", __FILE__) }
27
+
28
+ around do |example|
29
+ original_dir = Dir.pwd
30
+ FileUtils.mkdir_p(empty_dir)
31
+ FileUtils.cd(empty_dir)
32
+
33
+ example.run
34
+
35
+ FileUtils.cd(original_dir)
36
+ FileUtils.rm_rf(empty_dir)
37
+ end
38
+
39
+ it "creates a pattern library assets folder" do
40
+ subject.setup(default_options)
41
+ expect(Dir.exists?(assets_dir)).to be true
42
+ end
43
+
44
+ %w(yaml ruby json).each do |config_type|
45
+ it "creates the mustache-rendered #{config_type} config file to the current directory" do
46
+ default_options[:config_type] = config_type
47
+ original_config = Dir[File.join(config_dir, config_type, "*.*")].first
48
+
49
+ template = subject::Config.new(OpenStruct.new(default_options))
50
+ template.template = File.read(original_config).force_encoding("UTF-8")
51
+ template = template.render.gsub(/ +$/m, "")
52
+
53
+ subject.setup(default_options)
54
+
55
+ config_file = Dir[File.join(empty_dir, "*.*")].first
56
+ config = File.read(config_file).force_encoding("UTF-8")
57
+ expect(config).to eq template
58
+ end
59
+ end
60
+
61
+ it "does not copy the config file if one already exists" do
62
+ file = Dir[File.join(config_dir, "**/*.rb")].first
63
+ copied_file = File.join(empty_dir, File.basename(file))
64
+ FileUtils.cp(file, empty_dir)
65
+ File.open(copied_file, "w") { |file| file.write("# foo") }
66
+
67
+ subject.setup(default_options)
68
+
69
+ expect(File.read(copied_file)).to eq "# foo"
70
+ end
71
+
72
+ it "configures the pattern library with the new config file" do
73
+ expect(Docks).to receive(:configure).with no_args
74
+ subject.setup(default_options)
75
+ end
76
+
77
+ it "still configures the pattern library when there is already a config file" do
78
+ file = Dir[File.join(config_dir, "**/*.rb")].first
79
+ copied_file = File.join(empty_dir, File.basename(file))
80
+ FileUtils.cp(file, empty_dir)
81
+ File.open(copied_file, "w") { |file| file.write("# foo") }
82
+
83
+ expect(Docks).to receive(:configure).with no_args
84
+ subject.setup(default_options)
85
+ end
86
+
87
+ it "calls setup with configured theme" do
88
+ theme = double()
89
+ expect(Docks).to receive(:configure_with) do
90
+ Docks.configure { |config| config.theme = theme }
91
+ end
92
+
93
+ expect(theme).to receive(:setup).with(Docks::Builder)
94
+ subject.setup(default_options)
95
+ end
96
+
97
+ it "sets the theme to false when 'false' is provided" do
98
+ default_options[:theme] = "false"
99
+ subject.setup(default_options)
100
+ expect(Docks.config.theme).to be false
101
+ end
102
+
103
+ it "sets the theme to false when 'none' is provided" do
104
+ default_options[:theme] = "none"
105
+ subject.setup(default_options)
106
+ expect(Docks.config.theme).to be false
107
+ end
108
+
109
+ it "doesn't call configure with the theme if it doesn't exist" do
110
+ default_options[:theme] = "foo"
111
+ expect { subject.setup(default_options) }.not_to raise_error
112
+ end
113
+ end
114
+
115
+ describe ".add_assets" do
116
+ let(:root) { Pathname.new(File.expand_path("../../fixtures/build", __FILE__)) }
117
+
118
+ around do |example|
119
+ FileUtils.rm_rf(root + Docks::ASSETS_DIR)
120
+ Docks.configure { |config| config.root = root }
121
+
122
+ example.run
123
+
124
+ FileUtils.rm_rf(root + Docks::ASSETS_DIR)
125
+ end
126
+
127
+ %w(styles scripts templates).each do |type|
128
+ it "adds #{type} to the #{type} in the pattern library assets and annouces the root-relative location" do
129
+ source_root = root + type
130
+
131
+ destination_root = if type == "templates"
132
+ root + Docks.config.templates
133
+ else
134
+ root + File.join(Docks::ASSETS_DIR, Docks.config.asset_folders.send(type.to_sym))
135
+ end
136
+
137
+ add_assets = Dir[source_root + "**/*.*"]
138
+ allow(Docks::Messenger).to receive(:file).and_call_original
139
+
140
+ subject.add_assets(add_assets, type: type.to_sym, root: source_root)
141
+
142
+ added_assets = Dir[destination_root + "**/*.*"]
143
+ expect(added_assets.count).to be add_assets.count
144
+ added_assets.each do |asset|
145
+ asset = Pathname.new(asset)
146
+ relative_path = asset.relative_path_from(root)
147
+ original_asset = source_root + asset.relative_path_from(destination_root)
148
+ expect(FileUtils.identical?(asset, original_asset)).to be true
149
+ expect(Docks::Messenger).to have_received(:file).with(relative_path, :created)
150
+ end
151
+ end
152
+ end
153
+
154
+ it "updates non-identical assets and does nothing with identical ones" do
155
+ source_root = root + "scripts"
156
+ destination_root = root + File.join(Docks::ASSETS_DIR, Docks.config.asset_folders.scripts)
157
+ add_assets = Dir[source_root + "**/*.*"]
158
+
159
+ subject.add_assets(add_assets, type: :scripts, root: source_root)
160
+ allow(Docks::Messenger).to receive(:file).and_call_original
161
+
162
+ added_assets = Dir[destination_root + "**/*.*"]
163
+ updated = Pathname.new(added_assets.pop)
164
+ original_contents = File.read(add_assets.last)
165
+
166
+ begin
167
+ File.open(add_assets.last, "w") { |file| file.write("#{original_contents} updated") }
168
+
169
+ subject.add_assets(add_assets, type: :scripts, root: source_root)
170
+
171
+ updated_relative_path = updated.relative_path_from(root)
172
+ expect(Docks::Messenger).to have_received(:file).with(updated_relative_path, :updated)
173
+
174
+ added_assets.each do |asset|
175
+ relative_path = Pathname.new(asset).relative_path_from(root)
176
+ expect(Docks::Messenger).not_to have_received(:file).with(relative_path, anything)
177
+ end
178
+ ensure
179
+ File.open(add_assets.last, "w") { |file| file.write(original_contents) }
180
+ end
181
+ end
182
+ end
183
+
184
+ describe ".parse" do
185
+ before :each do
186
+ Docks.configure_with(root: empty_dir, library_assets: "")
187
+ end
188
+
189
+ it "adds the parse function to the top-level Docks namespace" do
190
+ expect(subject).to receive(:parse)
191
+ Docks.parse
192
+ end
193
+
194
+ it "clears the cache if the clear_cache options is passed" do
195
+ expect_any_instance_of(Docks::Cache).to receive(:clear)
196
+ Docks.parse(clear_cache: true)
197
+ end
198
+
199
+ it "passes each group to Parser and the Cache" do
200
+ groups = {
201
+ foo: ["foo.scss", "foo.haml"],
202
+ bar: ["bar.scss", "bar.coffee"]
203
+ }
204
+
205
+ expect(Docks::Grouper).to receive(:group).and_return(groups)
206
+
207
+ groups.each do |id, group|
208
+ expect(Docks::Cache).to receive(:cached?).with(group).and_return(false)
209
+ expect(Docks::Parser).to receive(:parse).with(group).and_return(Docks::Containers::Pattern.new(name: "foo"))
210
+ expect_any_instance_of(Docks::Cache).to receive(:<<)
211
+ end
212
+
213
+ expect_any_instance_of(Docks::Cache).to receive(:dump)
214
+ subject.parse
215
+ end
216
+ end
217
+
218
+ describe ".build" do
219
+ destination = "out"
220
+ dest_dir = File.join(existing_dir, destination)
221
+
222
+ let(:patterns) do
223
+ { "foo" => "bar", "bar" => "baz" }
224
+ end
225
+
226
+ around do |example|
227
+ original_dir = Dir.pwd
228
+ FileUtils.mkdir_p(existing_dir)
229
+ FileUtils.cd(existing_dir)
230
+ Docks::Templates.send(:clean)
231
+ Docks.configure_with(destination: destination, root: existing_dir)
232
+
233
+ default_options[:script_language] = "coffeescript"
234
+ subject.setup(default_options)
235
+
236
+ example.run
237
+
238
+ FileUtils.cd(original_dir)
239
+ FileUtils.rm_rf(existing_dir)
240
+ end
241
+
242
+ it "adds the build function to the top-level Docks namespace" do
243
+ expect(subject).to receive(:build)
244
+ Docks.build
245
+ end
246
+
247
+ it "creates the destination directory" do
248
+ subject.build
249
+ expect(Dir.exists?(File.join(existing_dir, destination))).to be true
250
+ end
251
+
252
+ it "creates the mount_at directory as the base for the pattern library files" do
253
+ mount_at = "pattern-lab"
254
+ Docks.configure { |config| config.mount_at = mount_at }
255
+ subject.build
256
+ expect(Dir.exists?(File.join(existing_dir, destination, mount_at))).to be true
257
+ end
258
+
259
+ it "copies and renames the theme stylesheets to the destination" do
260
+ allow(Docks::Grouper).to receive(:group).and_return(Hash.new)
261
+ subject.build
262
+
263
+ original_stylesheets = Docks.config.theme.styles.map { |file| File.basename(file).sub("pattern-library", "docks") }
264
+ copied_stylesheets = Dir[File.join(Docks.config.destination, Docks.config.asset_folders.styles, "*.css")].map { |file| File.basename(file) }
265
+
266
+ original_stylesheets.each do |stylesheet|
267
+ expect(copied_stylesheets).to include stylesheet
268
+ end
269
+ end
270
+
271
+ it "copies and renames the theme javascripts to the destination" do
272
+ allow(Docks::Grouper).to receive(:group).and_return(Hash.new)
273
+ subject.build
274
+
275
+ original_scripts = Docks.config.theme.scripts.map { |file| File.basename(file).sub("pattern_library", "docks") }
276
+ copied_scripts = Dir[File.join(Docks.config.destination, Docks.config.asset_folders.scripts, "*.js")].map { |file| File.basename(file) }
277
+
278
+ original_scripts.each do |script|
279
+ expect(copied_scripts).to include script
280
+ end
281
+ end
282
+
283
+ it "copies bundled assets only when changed" do
284
+ allow(Docks::Grouper).to receive(:group).and_return(Hash.new)
285
+ subject.build
286
+
287
+ assets = Dir[File.join(Docks.config.destination + "**/*.{css,js}")]
288
+
289
+ first, rest = assets.first, assets[1..-1]
290
+ File.open(first, "a") { |file| file.puts("foo") }
291
+ expect(FileUtils).to receive(:cp).with(anything, first)
292
+ rest.each { |other| expect(FileUtils).not_to receive(:cp).with(anything, other) }
293
+
294
+ subject.build
295
+ end
296
+
297
+ it "copies bundled assets only when a theme is specified" do
298
+ allow(Docks::Grouper).to receive(:group).and_return(Hash.new)
299
+ Docks.configure_with(theme: false)
300
+ expect(FileUtils).not_to receive(:cp)
301
+ subject.build
302
+ end
303
+
304
+ context "when pagination is specified" do
305
+ it "writes a file for each pattern" do
306
+ files = {}
307
+ expect(Docks::Grouper).to receive(:group).and_return(patterns)
308
+
309
+ patterns.each do |id, group|
310
+ expect(Docks::Cache).to receive(:pattern_for?).with(id).and_return true
311
+ expect(Docks::Cache).to receive(:pattern_for).with(id).and_return(OpenStruct.new(name: id))
312
+
313
+ renderer = double(render: group, :ivars= => nil)
314
+ expect(Docks::Renderers::ERB).to receive(:new).and_return(renderer)
315
+ expect(Docks::Helpers).to receive(:add_helpers_to).with(renderer)
316
+ files[id] = { file: File.join(dest_dir, Docks.config.mount_at, id.to_s, "index.html"), content: group }
317
+ end
318
+
319
+ subject.build
320
+
321
+ files.each do |id, details|
322
+ expect(File.exists?(details[:file])).to be true
323
+ expect(File.read(details[:file]).strip).to eq details[:content]
324
+ end
325
+ end
326
+
327
+ # Gross tests, must refactor
328
+ it "only writes a file for each pattern on change" do
329
+ allow(Docks::Grouper).to receive(:group).and_return(patterns)
330
+
331
+ patterns.each do |id, group|
332
+ expect(Docks::Cache).to receive(:pattern_for?).with(id).and_return true
333
+ expect(Docks::Cache).to receive(:pattern_for).with(id).and_return(OpenStruct.new(name: id))
334
+
335
+ renderer = double(render: group, :ivars= => nil)
336
+ expect(Docks::Renderers::ERB).to receive(:new).and_return(renderer)
337
+ expect(Docks::Helpers).to receive(:add_helpers_to).with(renderer)
338
+ end
339
+
340
+ subject.build
341
+
342
+ patterns.each do |id, group|
343
+ expect(Docks::Cache).to receive(:pattern_for?).with(id).and_return true
344
+ expect(Docks::Cache).to receive(:pattern_for).with(id).and_return(OpenStruct.new(name: id))
345
+
346
+ renderer = double(render: group, :ivars= => nil)
347
+ expect(Docks::Renderers::ERB).to receive(:new).and_return(renderer)
348
+ expect(Docks::Helpers).to receive(:add_helpers_to).with(renderer)
349
+ expect(FileUtils).not_to receive(:cp).with(anything, File.join(dest_dir, Docks.config.mount_at, id.to_s, "index.html"))
350
+ end
351
+
352
+ subject.build
353
+ end
354
+
355
+ it "removes patterns that are no longer part of the pattern group" do
356
+ files = {}
357
+ expect(Docks::Grouper).to receive(:group).and_return(patterns)
358
+
359
+ patterns.each do |id, group|
360
+ expect(Docks::Cache).to receive(:pattern_for?).with(id).and_return true
361
+ expect(Docks::Cache).to receive(:pattern_for).with(id).and_return(OpenStruct.new(name: id))
362
+
363
+ renderer = double(render: group, :ivars= => nil)
364
+ expect(Docks::Renderers::ERB).to receive(:new).and_return(renderer)
365
+ expect(Docks::Helpers).to receive(:add_helpers_to).with(renderer)
366
+ files[id] = { file: File.join(dest_dir, Docks.config.mount_at, id.to_s, "index.html"), content: group }
367
+ end
368
+
369
+ subject.build
370
+
371
+ files = {}
372
+ excluded_pattern = patterns.keys.first
373
+ patterns.delete(excluded_pattern)
374
+ expect(Docks::Grouper).to receive(:group).and_return(patterns)
375
+
376
+ patterns.each do |id, group|
377
+ expect(Docks::Cache).to receive(:pattern_for?).with(id).and_return true
378
+ expect(Docks::Cache).to receive(:pattern_for).with(id).and_return(OpenStruct.new(name: id))
379
+
380
+ renderer = double(render: group, :ivars= => nil)
381
+ expect(Docks::Renderers::ERB).to receive(:new).and_return(renderer)
382
+ expect(Docks::Helpers).to receive(:add_helpers_to).with(renderer)
383
+ files[id] = { file: File.join(dest_dir, Docks.config.mount_at, id.to_s, "index.html"), content: group }
384
+ end
385
+
386
+ subject.build
387
+
388
+ files.each do |id, details|
389
+ expect(File.exists?(details[:file])).to be true
390
+ expect(File.read(details[:file]).strip).to eq details[:content]
391
+ end
392
+
393
+ expect(File.exists?(File.join(dest_dir, Docks.config.mount_at, excluded_pattern.to_s, "index.html"))).to be false
394
+ end
395
+
396
+ it "provides the pattern and pattern library to every render call as locals and ivars" do
397
+ pattern_library = Docks::Containers::PatternLibrary.new
398
+
399
+ expect(Docks::Grouper).to receive(:group).and_return(patterns)
400
+ expect(Docks::Cache).to receive(:pattern_library).and_return(pattern_library)
401
+ expect(pattern_library).to receive(:summarize!)
402
+ patterns.each do |id, group|
403
+ pattern = OpenStruct.new(name: id)
404
+
405
+ default_template = Docks::Templates.fallback
406
+ expect(Docks::Templates).to receive(:search_for_template).with(default_template.layout, must_be: :layout).and_return "application.erb"
407
+ expect(Docks::Templates).to receive(:search_for_template).with(default_template.path).and_return "pattern.erb"
408
+ expect(Docks::Cache).to receive(:pattern_for?).with(id).and_return true
409
+ expect(Docks::Cache).to receive(:pattern_for).with(id).and_return(pattern)
410
+
411
+ renderer = double()
412
+ expect(Docks::Renderers::ERB).to receive(:new).and_return(renderer)
413
+ expect(Docks::Helpers).to receive(:add_helpers_to).with(renderer)
414
+ expect(renderer).to receive(:ivars=).with pattern_library: pattern_library, pattern: pattern
415
+ expect(renderer).to receive(:render).with anything, hash_including(locals: { pattern_library: pattern_library, pattern: pattern })
416
+ end
417
+
418
+ subject.build
419
+ end
420
+
421
+ it "doesn't die when there are no cache results matching a pattern" do
422
+ expect(Docks::Grouper).to receive(:group).and_return(patterns)
423
+ patterns.each do |id, group|
424
+ expect { Docks::Cache.pattern_for(id) }.to raise_error(Docks::NoPatternError)
425
+ end
426
+
427
+ subject.build
428
+ end
429
+ end
430
+
431
+ context "when no pagination is specified" do
432
+ before(:each) do
433
+ Docks.configure_with(paginate: false)
434
+ end
435
+
436
+ let(:expected_file) do
437
+ Docks.config.destination + "#{Docks.config.mount_at}/index.html"
438
+ end
439
+
440
+ it "writes the pattern library file" do
441
+ renderer = double(render: "foo", :ivars= => nil)
442
+ expect(Docks::Renderers::ERB).to receive(:new).and_return(renderer)
443
+ expect(Docks::Helpers).to receive(:add_helpers_to).with(renderer)
444
+
445
+ subject.build
446
+
447
+ expect(File.exists?(expected_file)).to be true
448
+ expect(File.read(expected_file)).to eq "foo"
449
+ end
450
+
451
+ it "receives the full pattern library as ivars and locals" do
452
+ pattern_library = Docks::Containers::PatternLibrary.new
453
+ renderer = double(render: "foo", :ivars= => nil)
454
+ locals = { pattern_library: pattern_library, pattern: nil }
455
+
456
+ expect(pattern_library).not_to receive(:summarize!)
457
+ expect(Docks::Cache).to receive(:pattern_library).and_return(pattern_library)
458
+ expect(Docks::Renderers::ERB).to receive(:new).and_return(renderer)
459
+ expect(Docks::Helpers).to receive(:add_helpers_to).with(renderer)
460
+ expect(renderer).to receive(:ivars=).with(locals)
461
+ expect(renderer).to receive(:render).with anything, hash_including(locals: locals)
462
+
463
+ subject.build
464
+ end
465
+ end
466
+ end
467
+ end
@@ -0,0 +1,175 @@
1
+ require "spec_helper"
2
+
3
+ describe Docks::Cache do
4
+ subject { described_class.new }
5
+
6
+ let(:name) { "button" }
7
+
8
+ let(:pattern) do
9
+ pattern = Docks::Containers::Pattern.new(name: name)
10
+ pattern.add(:script, Docks::Containers::Symbol.new(pattern: name.upcase))
11
+ pattern.modified = Date.new
12
+ pattern
13
+ end
14
+
15
+ let(:root) {
16
+ File.expand_path("../../fixtures/cache", __FILE__)
17
+ }
18
+
19
+ let(:cache_file) {
20
+ File.expand_path(name, Docks.config.cache_location)
21
+ }
22
+
23
+ around do |example|
24
+ Docks.configure { |config| config.root = root }
25
+ example.run
26
+ FileUtils.rm_rf(root)
27
+ end
28
+
29
+ describe ".pattern_for" do
30
+ it "sends the cached parse patterns back when it exists" do
31
+ subject << pattern
32
+ subject.dump
33
+ expect(described_class.pattern_for(name)).to eq pattern
34
+ end
35
+
36
+ it "throws an error when no such pattern exists" do
37
+ expect { described_class.pattern_for("foo") }.to raise_error Docks::NoPatternError
38
+ end
39
+ end
40
+
41
+ describe ".cached?" do
42
+ let(:file) { "#{name}.scss" }
43
+
44
+ around do |example|
45
+ File.open(file, "w") { |file| file.write("") }
46
+ example.run
47
+ FileUtils.rm(file)
48
+ end
49
+
50
+ it "is false when there is no cached pattern" do
51
+ expect(described_class.cached?(name)).to be false
52
+ end
53
+
54
+ it "is false when there is a more-recently modified cache file than the newest source file" do
55
+ subject << pattern
56
+ subject.dump
57
+ expect(File).to receive(:mtime).with(Docks.config.cache_location + name).and_return Time.now + 1000
58
+ expect(File).to receive(:mtime).with(file).and_return Time.now
59
+ expect(described_class.cached?(file)).to be true
60
+ end
61
+
62
+ it "is false when there is a more-recently modified source file than the cache" do
63
+ subject << pattern
64
+ subject.dump
65
+ expect(File).to receive(:mtime).with(Docks.config.cache_location + name).and_return Time.now
66
+ expect(File).to receive(:mtime).with(file).and_return Time.now + 1000
67
+ expect(described_class.cached?(file)).to be false
68
+ end
69
+
70
+ it "uses the most recently modified file" do
71
+ file_two ="#{name}-2.scss"
72
+ File.open(file_two, "w") { |file| file.write("") }
73
+ subject << pattern
74
+ subject.dump
75
+
76
+ expect(File).to receive(:mtime).with(Docks.config.cache_location + name).and_return Time.now
77
+ expect(File).to receive(:mtime).with(file).and_return Time.now + 1000
78
+ expect(File).to receive(:mtime).with(file_two).and_return Time.now - 1000
79
+ expect(described_class.cached?([file, file_two])).to be false
80
+
81
+ FileUtils.rm(file_two)
82
+ end
83
+ end
84
+
85
+ describe "#initialize" do
86
+ it "leaves the cache alone when the last cache was on the same version" do
87
+ subject << pattern
88
+ subject.dump
89
+
90
+ expect_any_instance_of(described_class).to_not receive(:clear)
91
+ second_instance = described_class.new
92
+ second_instance << pattern
93
+ second_instance.dump
94
+ end
95
+
96
+ it "clears the cache when a change of version happens" do
97
+ subject << pattern
98
+ subject.dump
99
+
100
+ old_version = Docks.send(:remove_const, :VERSION)
101
+ Docks.const_set(:VERSION, "#{old_version}.1")
102
+
103
+ expect_any_instance_of(described_class).to receive(:clear)
104
+ second_instance = described_class.new
105
+ second_instance << pattern
106
+ second_instance.dump
107
+ end
108
+ end
109
+
110
+ describe "#clear" do
111
+ it "removes all cache files" do
112
+ FileUtils.mkdir_p Docks.config.cache_location
113
+ File.open(cache_file, "w") { |file| file.write("") }
114
+
115
+ expect(Dir[Docks.config.cache_location + "*"]).to_not be_empty
116
+ subject.clear
117
+ expect(Dir[Docks.config.cache_location + "*"]).to be_empty
118
+ end
119
+ end
120
+
121
+ describe "#<<" do
122
+ it "writes the contents of a parse pattern to the corresponding cache file on dump" do
123
+ subject << pattern
124
+ subject.dump
125
+ expect(Marshal::load(File.read(cache_file))).to eq pattern
126
+ end
127
+
128
+ it "doesn't cache a pattern that is invalid" do
129
+ expect(pattern).to receive(:valid?).and_return false
130
+ subject << pattern
131
+ expect(File.exists?(cache_file)).to be false
132
+ subject.dump
133
+ expect(described_class.pattern_library[name]).to be nil
134
+ end
135
+ end
136
+
137
+ describe "#dump" do
138
+ it "collects the sumarized details for each pattern added to the cache" do
139
+ expect_any_instance_of(Docks::Containers::PatternLibrary).to receive(:<<).with(pattern).and_call_original
140
+ subject << pattern
141
+ end
142
+
143
+ it "calls the final processors on the pattern library" do
144
+ expect(Docks::Process).to receive(:process).with an_instance_of(Docks::Containers::PatternLibrary)
145
+ subject.dump
146
+ end
147
+
148
+ it "adds the summarized details to the pattern library" do
149
+ subject << pattern
150
+ subject.dump
151
+ expect(described_class.pattern_library[name]).to eq pattern.summary
152
+ end
153
+
154
+ it "removes any cache patterns that are no longer used" do
155
+ subject << pattern
156
+ subject.dump
157
+
158
+ second_instance = described_class.new
159
+ second_instance.dump
160
+
161
+ expect(File.exists?(cache_file)).to be false
162
+ end
163
+
164
+ it "doesn't remove cache patterns that simply had no updates" do
165
+ subject << pattern
166
+ subject.dump
167
+
168
+ second_instance = described_class.new
169
+ second_instance.no_update(pattern.name)
170
+ second_instance.dump
171
+
172
+ expect(File.exists?(cache_file)).to be true
173
+ end
174
+ end
175
+ end