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,300 @@
1
+ require "set"
2
+ require "tempfile"
3
+ require "mustache"
4
+
5
+ module Docks
6
+ class Builder
7
+ class Config < Mustache
8
+ attr_reader :options
9
+
10
+ def initialize(options)
11
+ @options = options
12
+ end
13
+
14
+ def default_config; @default_config ||= Docks.config end
15
+
16
+ def respond_to?(meth)
17
+ options.respond_to?(meth) || !default_config.instance_variable_get("@#{meth}".to_sym).nil? || super
18
+ end
19
+
20
+ def method_missing(meth)
21
+ if options.respond_to?(meth)
22
+ present(options.send(meth), meth)
23
+ elsif (result = default_config.instance_variable_get("@#{meth}".to_sym))
24
+ present(result, meth)
25
+ else
26
+ super
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def needs_quotes?(string)
33
+ !yaml? || /[:\{\}\[\],&\*#\?\|\-<>=!%@\\]/ =~ string
34
+ end
35
+
36
+ def yaml?
37
+ options.config_type == "yaml"
38
+ end
39
+
40
+ def json?
41
+ options.config_type == "json"
42
+ end
43
+
44
+ def ruby?
45
+ options.config_type == "ruby"
46
+ end
47
+
48
+ def spaces
49
+ yaml? ? "" : " "
50
+ end
51
+
52
+ def present(value, name = nil)
53
+ if value.kind_of?(Class) || (name && [:naming_convention, :theme].include?(name) && !value.kind_of?(String))
54
+ value = value.class.name.demodulize
55
+ end
56
+
57
+ value = case value
58
+ when Hash
59
+ value = "\n#{value.map { |k, v| "#{spaces} #{json? ? present(k) : k}: #{present(v)}" }.join("#{"," unless yaml?}\n")}"
60
+ yaml? ? value : "{#{value}\n#{spaces}}"
61
+ when String
62
+ needs_quotes?(value) ? "\"#{value}\"" : value
63
+ when Array
64
+ if value.empty?
65
+ "[]"
66
+ elsif yaml?
67
+ "\n#{value.map { |v| "#{spaces} - #{present(v)}" }.join("\n")}"
68
+ else
69
+ "[\n#{value.map { |v| "#{spaces} #{present(v)}" }.join(",\n")}\n#{spaces}]"
70
+ end
71
+ when Symbol
72
+ ruby? ? ":#{value}" : present(value.to_s)
73
+ else
74
+ value
75
+ end
76
+
77
+ value
78
+ end
79
+ end
80
+
81
+ def self.parse(options = {})
82
+ cache = Cache.new
83
+ cache.clear if options.fetch(:clear_cache, false)
84
+
85
+ Grouper.group(Docks.config.sources).each do |identifier, group|
86
+ if Cache.cached?(group)
87
+ cache.no_update(identifier)
88
+ else
89
+ cache << Parser.parse(group)
90
+ end
91
+ end
92
+
93
+ cache.dump
94
+ end
95
+
96
+ def self.build
97
+ prepare_destination
98
+ Messenger.file_header("Assets:")
99
+ copy_theme_assets
100
+
101
+ Messenger.file_header("Pages:")
102
+ rendered_patterns = render_pattern_library
103
+ remove_unused_directories(rendered_patterns)
104
+ end
105
+
106
+ def self.setup(options)
107
+ @options = OpenStruct.new(options)
108
+ @assets_dir = File.join(Dir.pwd, Docks::ASSETS_DIR)
109
+ FileUtils.mkdir_p(@assets_dir)
110
+
111
+ if Dir[CONFIG_FILE].empty?
112
+ setup_config
113
+ end
114
+
115
+ Docks.configure
116
+ Docks.config.root = Pathname.pwd
117
+
118
+ return unless Docks.config.theme && Docks.config.theme.respond_to?(:setup)
119
+ Docks.config.theme.setup(self)
120
+ end
121
+
122
+ def self.options; @options end
123
+
124
+ def self.add_assets(assets, options)
125
+ root = /#{Regexp.escape(options.fetch(:root, "").to_s)}\/?/
126
+ copy_to = case options[:type]
127
+ when :styles then Docks.config.root + ASSETS_DIR + Docks.config.asset_folders.styles
128
+ when :scripts then Docks.config.root + ASSETS_DIR + Docks.config.asset_folders.scripts
129
+ when :templates then Docks.config.templates
130
+ end
131
+
132
+ [assets].flatten.each do |asset|
133
+ asset = Pathname.new(asset)
134
+ destination_file = copy_to + asset.to_s.sub(root, "")
135
+ relative_path = destination_file.relative_path_from(Docks.config.root)
136
+ exists = destination_file.exist?
137
+
138
+ next if exists && FileUtils.identical?(asset, destination_file)
139
+
140
+ destination_dir = destination_file.dirname
141
+ FileUtils.mkdir_p(destination_dir)
142
+ FileUtils.cp(asset, destination_dir)
143
+ Messenger.file(relative_path, exists ? :updated : :created)
144
+ end
145
+ end
146
+
147
+ private
148
+
149
+ def self.prepare_destination
150
+ FileUtils.mkdir_p(Docks.config.destination + Docks.config.mount_at)
151
+ end
152
+
153
+ def self.render_pattern_library
154
+ pattern_library = Cache.pattern_library
155
+ pattern_library.summarize! if Docks.config.paginate?
156
+ rendered_patterns = Set.new
157
+
158
+ if Docks.config.paginate?
159
+ Grouper.group(Docks.config.sources).each do |id, _group|
160
+ rendered_patterns << id if render(id, pattern_library)
161
+ end
162
+ else
163
+ rendered_patterns << Docks.config.mount_at if render(nil, pattern_library)
164
+ end
165
+
166
+ rendered_patterns
167
+ end
168
+
169
+ def self.copy_theme_assets
170
+ return unless theme = Docks.config.theme
171
+
172
+ (theme.styles || []).each do |style|
173
+ destination = Docks.config.destination + Docks.config.asset_folders.styles + copied_name_for(style)
174
+ copy_theme_asset_file(style, destination)
175
+ end
176
+
177
+ (theme.scripts || []).each do |script|
178
+ destination = Docks.config.destination + Docks.config.asset_folders.scripts + copied_name_for(script)
179
+ copy_theme_asset_file(script, destination)
180
+ end
181
+ end
182
+
183
+ def self.copy_theme_asset_file(file, destination)
184
+ update = File.exist?(destination)
185
+ return if update && FileUtils.identical?(file, destination)
186
+ FileUtils.mkdir_p(File.dirname(destination)) unless update
187
+ FileUtils.cp(file, destination.to_s)
188
+
189
+ file = destination.to_s
190
+ .gsub(Docks.config.destination.dirname.to_s, "")
191
+ .sub(%r{^\/}, "")
192
+
193
+ Messenger.file(file, update ? :updated : :created)
194
+ end
195
+
196
+ # FIX THIS UP
197
+ def self.copied_name_for(asset)
198
+ File.basename(asset).sub(/pattern[\-_]library/, "docks")
199
+ end
200
+
201
+ def self.render(pattern, pattern_library)
202
+ unless pattern.nil?
203
+ return false unless Cache.pattern_for?(pattern)
204
+ pattern = Cache.pattern_for(pattern)
205
+ end
206
+
207
+ locals = { pattern: pattern, pattern_library: pattern_library }
208
+
209
+ template, layout, renderer = template_details(pattern)
210
+ Helpers.add_helpers_to(renderer)
211
+ renderer.ivars = locals
212
+ Docks.current_renderer = renderer
213
+
214
+ directory = Docks.config.destination + "#{Docks.config.mount_at}#{"/#{pattern.name}" unless pattern.nil?}"
215
+ html_file = directory + "index.html"
216
+ update = File.exist?(html_file)
217
+ Docks.current_render_destination = html_file.dirname
218
+
219
+ file = Tempfile.new(pattern.nil? ? "pattern_library" : pattern.name)
220
+
221
+ begin
222
+ file.write renderer.render template,
223
+ layout: layout,
224
+ locals: locals
225
+
226
+ file.close
227
+ unless update && FileUtils.identical?(html_file, file.path)
228
+ FileUtils.mkdir_p(directory)
229
+ FileUtils.cp_r(file.path, html_file)
230
+ Messenger.file(html_file, update ? :updated : :created)
231
+ end
232
+
233
+ true
234
+ ensure
235
+ file.close
236
+ file.unlink
237
+ end
238
+ end
239
+
240
+ def self.template_details(pattern = nil)
241
+ template = pattern.nil? ? Templates.fallback : Templates.template_for(pattern)
242
+ layout = Templates.search_for_template(template.layout, must_be: :layout)
243
+ template = Templates.search_for_template(template.path)
244
+ renderer = Languages.language_for(template).renderer
245
+
246
+ [template, layout, renderer]
247
+ end
248
+
249
+ def self.remove_unused_directories(rendered_patterns)
250
+ Dir[Docks.config.destination + Docks.config.mount_at + "*/"].each do |pattern_dir|
251
+ next if rendered_patterns.include?(File.basename(pattern_dir))
252
+ deleted_file = Dir[File.join(pattern_dir, "*")].first
253
+ FileUtils.rm_rf(pattern_dir)
254
+ Messenger.file(deleted_file, :deleted)
255
+ end
256
+ end
257
+
258
+ def self.setup_config
259
+ config_folder = File.expand_path("../../../config", __FILE__)
260
+ config_file = Dir[File.join(config_folder, options.config_type, "*")].first
261
+ config_template = Config.new(options)
262
+ config_template.template = File.read(config_file)
263
+ target_file = File.basename(config_file)
264
+
265
+ File.open(target_file, "w") { |file| file.write(config_template.render.gsub(/ +$/m, "")) }
266
+ Messenger.file(target_file, :created)
267
+ end
268
+
269
+ def self.setup_styles(style_ext)
270
+ styles_dir = File.join(@assets_dir, Docks.config.asset_folders.styles)
271
+ FileUtils.mkdir_p(styles_dir)
272
+
273
+ FileUtils.cp_r Dir[File.join(@template_dir, "styles", style_ext, "*")],
274
+ styles_dir
275
+ end
276
+
277
+ def self.setup_scripts(script_language)
278
+ script_dir = File.join(@assets_dir, Docks.config.asset_folders.scripts)
279
+ FileUtils.mkdir_p(script_dir)
280
+
281
+ FileUtils.cp_r Dir[File.join(@template_dir, "scripts", script_language, "*")],
282
+ script_dir
283
+ end
284
+
285
+ def self.setup_templates(template_language)
286
+ markup_dir = File.join(@assets_dir, Docks.config.asset_folders.templates)
287
+ FileUtils.mkdir_p(markup_dir)
288
+ FileUtils.cp_r Dir[File.join(@template_dir, "templates", template_language, "*")],
289
+ markup_dir
290
+ end
291
+ end
292
+
293
+ def self.parse(options = {})
294
+ Builder.parse(options)
295
+ end
296
+
297
+ def self.build
298
+ Builder.build
299
+ end
300
+ end
@@ -0,0 +1,143 @@
1
+ require_relative "languages.rb"
2
+ require_relative "version.rb"
3
+
4
+ module Docks
5
+ class Cache
6
+ DIR = "docks"
7
+ META_FILE = "docks_meta"
8
+ PATTERN_LIBRARY_FILE = "docks_pattern_library"
9
+
10
+ def self.pattern_for?(pattern)
11
+ cache_file = File.join(Docks.config.cache_location, pattern.to_s)
12
+ File.exist?(cache_file)
13
+ end
14
+
15
+ def self.pattern_for(pattern)
16
+ pattern = pattern.to_s
17
+ cache_file = File.join(Docks.config.cache_location, pattern)
18
+
19
+ unless File.exists?(cache_file)
20
+ raise Docks::NoPatternError, "No pattern by the name of '#{pattern}' exists. Make sure you have a script, markup, or style file with that filename that is included in your 'docks_config' source directories."
21
+ end
22
+
23
+ Marshal::load(File.binread(cache_file))
24
+ end
25
+
26
+ def self.pattern_library
27
+ if File.exists?(pattern_library_cache_file)
28
+ Marshal::load(File.binread(pattern_library_cache_file)) || Containers::PatternLibrary.new
29
+ else
30
+ Containers::PatternLibrary.new
31
+ end
32
+ end
33
+
34
+ def self.cached?(group)
35
+ group = Array(group)
36
+ cache_modified = last_modified(Docks.pattern_id(group.first))
37
+ !cache_modified.nil? && cache_modified > most_recent_modified_date(group)
38
+ end
39
+
40
+ private
41
+
42
+ def self.last_modified(pattern)
43
+ cache_file = Docks.config.cache_location + pattern.to_s
44
+ return nil unless File.exist?(cache_file)
45
+ File.mtime(cache_file)
46
+ end
47
+
48
+ def self.most_recent_modified_date(files)
49
+ Array(files).select { |file| File.exist?(file) }
50
+ .map { |file| File.mtime(file) }
51
+ .sort
52
+ .last
53
+ end
54
+
55
+ def self.pattern_library_cache_file
56
+ Docks.config.cache_location + PATTERN_LIBRARY_FILE
57
+ end
58
+
59
+ def self.meta_file
60
+ Docks.config.cache_location + META_FILE
61
+ end
62
+
63
+ public
64
+
65
+ def initialize
66
+ FileUtils.mkdir_p(Docks.config.cache_location)
67
+ @patterns_needing_caches = []
68
+ load_metadata
69
+ load_pattern_library
70
+ end
71
+
72
+ def clear
73
+ FileUtils.rm_rf Dir[Docks.config.cache_location + "*"]
74
+ end
75
+
76
+ def <<(pattern)
77
+ return unless pattern.valid?
78
+
79
+ @patterns_needing_caches << pattern.name
80
+ @pattern_library << pattern
81
+ end
82
+
83
+ # When a pattern exists but did not need to be re-parsed, this needs to
84
+ # be communicated so that we can keep track of what patterns still exist.
85
+ def no_update(pattern)
86
+ @pattern_library << @old_pattern_library[pattern]
87
+ end
88
+
89
+ def dump
90
+ Process.process(@pattern_library)
91
+
92
+ File.open(self.class.pattern_library_cache_file, "wb") do |file|
93
+ file.write Marshal::dump(@pattern_library)
94
+ end
95
+
96
+ File.open(self.class.meta_file, "wb") do |file|
97
+ file.write Marshal::dump(@metadata)
98
+ end
99
+
100
+ @patterns_needing_caches.each do |pattern|
101
+ File.open(Docks.config.cache_location + pattern, "wb") do |file|
102
+ file.write Marshal::dump(@pattern_library[pattern])
103
+ end
104
+ end
105
+
106
+ # Clear out anything that didn't get written to the new cache
107
+ @old_pattern_library.patterns.each do |name, pattern|
108
+ FileUtils.rm_rf(Docks.config.cache_location + name) unless @pattern_library.has_pattern?(name)
109
+ end
110
+ end
111
+
112
+ private
113
+
114
+ def self.load_pattern_cache(&block)
115
+ patterns = {}
116
+
117
+ return unless File.exists?(group_cache_file)
118
+ pattern_cache = Marshal::load(File.binread(group_cache_file))
119
+
120
+ if block_given?
121
+ pattern_cache.each_value(&block)
122
+ end
123
+
124
+ nil
125
+ end
126
+
127
+ def load_metadata
128
+ if File.exists?(self.class.meta_file)
129
+ @metadata = Marshal::load(File.binread(self.class.meta_file)) || Hash.new
130
+ else
131
+ @metadata = Hash.new
132
+ end
133
+
134
+ clear if !@metadata[:version].nil? && @metadata[:version] != VERSION
135
+ @metadata[:version] = VERSION
136
+ end
137
+
138
+ def load_pattern_library
139
+ @old_pattern_library = self.class.pattern_library
140
+ @pattern_library = Containers::PatternLibrary.new
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,65 @@
1
+ require "optparse"
2
+ require "fileutils"
3
+ require "ostruct"
4
+ require_relative "version.rb"
5
+
6
+ module Docks
7
+ class CommandLine
8
+ attr_reader :arguments
9
+
10
+ def initialize(arguments)
11
+ @arguments = arguments
12
+ end
13
+
14
+ def init
15
+ options = {
16
+ config_type: "yaml",
17
+ template_language: "erb",
18
+ script_language: "javascript",
19
+ style_language: "scss"
20
+ }
21
+
22
+ OptionParser.new do |opt|
23
+ opt.banner = "Usage: docks init [options]"
24
+
25
+ opt.on("--config TYPE", %w(yaml json ruby), "The type of config file to generate (yaml, json, or ruby; default is yaml)") { |type| options[:config_type] = type }
26
+ opt.on("--template LANGUAGE", %w(erb haml), "The language of markup templates to generate (erb or haml; default is erb).") { |language| options[:template_language] = language }
27
+ opt.on("--scripts LANGUAGE", %w(javascript coffeescript), "The scripting language to generate helpers for (javascript or coffeescript; default is javascript).") { |language| options[:script_language] = language }
28
+ opt.on("--styles PREPROCESSOR", %w(scss sass less stylus), "The CSS preprocessor to generate style helpers for (scss, sass, stylus or less; default is scss).") { |language| options[:style_language] = language }
29
+ opt.on("--theme THEME", "The theme to to use as a starting point for your pattern library.") { |theme| options[:theme] = theme }
30
+ opt.on_tail("-h", "--help", "Show this message again.") { puts opt; exit }
31
+
32
+ begin
33
+ opt.parse!(arguments)
34
+ rescue => e
35
+ end
36
+
37
+ Builder.setup(options)
38
+ end
39
+ end
40
+
41
+ def run
42
+ return init if arguments[0] == "init"
43
+ config = CONFIG_FILE
44
+ options = {
45
+ clear_cache: false
46
+ }
47
+
48
+ OptionParser.new do |opt|
49
+ opt.on("--config FILE", "Path to the configuration file. If no such file is provided, it will default to a file named 'docks_config' in your current directory.") { |config_file| config = config_file }
50
+ opt.on("--clear-cache", "Discard the cache of previous parse results before running.") { |clear_cache| options[:clear_cache] = clear_cache }
51
+ opt.on_tail("-h", "--help", "Show this message again.") { puts opt; exit }
52
+ opt.on_tail("-v", "--version", "Show the version of docks that's running.") { puts "docks #{Docks::VERSION}"; exit }
53
+
54
+ begin
55
+ opt.parse!(arguments)
56
+ rescue => e
57
+ end
58
+ end
59
+
60
+ Docks.configure_with(config)
61
+ Docks.parse(options)
62
+ Docks.build
63
+ end
64
+ end
65
+ end