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,103 @@
1
+ require "set"
2
+
3
+ module Docks
4
+ module Types
5
+ module Languages
6
+ MARKUP = :markup
7
+ SCRIPT = :script
8
+ STYLE = :style
9
+ STUB = :stub
10
+ DESCRIPTION = :description
11
+ end
12
+ end
13
+
14
+ module Languages
15
+ def self.language_for(file)
16
+ language = @languages[extension_for_file(file)]
17
+ language.nil? ? nil : language.instance
18
+ end
19
+
20
+ def self.register_bundled_languages
21
+ bundled_languages.each { |language| register(language) }
22
+ end
23
+
24
+ def self.register(language)
25
+ Array(language.extensions).each do |extension|
26
+ @extensions[language.type].add(extension)
27
+ @languages[extension] = language
28
+ end
29
+
30
+ Array(language.symbol_sources).each do |source|
31
+ SymbolSources.register(source)
32
+ end
33
+ end
34
+
35
+ def self.<<(language)
36
+ register(language)
37
+ end
38
+
39
+ def self.extensions
40
+ @extensions.values.inject([]) { |all, all_of_type| all.concat(all_of_type.to_a) }
41
+ end
42
+
43
+ Docks::Types::Languages.constants.each do |const|
44
+ type = Docks::Types::Languages.const_get(const)
45
+ define_singleton_method("#{type}_extensions") { @extensions[type].to_a }
46
+ end
47
+
48
+ def self.most_common_markup_language
49
+ markup_files = Grouper.source_files_of_type(Types::Languages::MARKUP)
50
+ return if markup_files.empty?
51
+ most_common = markup_files.map { |file| extension_for_file(file) }.group_by { |ext| ext }.values.max_by(&:size).first
52
+ language_for(most_common)
53
+ end
54
+
55
+ def self.file_type(file)
56
+ extension = extension_for_file(file)
57
+ type = nil
58
+
59
+ @extensions.each do |extensions_type, the_extensions|
60
+ if the_extensions.include?(extension)
61
+ type = extensions_type
62
+ break
63
+ end
64
+ end
65
+
66
+ type
67
+ end
68
+
69
+ def self.supported_file?(file)
70
+ extensions.include?(extension_for_file(file))
71
+ end
72
+
73
+ def self.extension_for_file(file)
74
+ file.to_s.split(".").last
75
+ end
76
+
77
+ private
78
+
79
+ def self.bundled_languages
80
+ if @bundled_languages.nil?
81
+ bundled = constants.select do |const|
82
+ klass = const_get(const)
83
+ Class === klass && !(klass.eql?(Base))
84
+ end
85
+
86
+ @bundled_languages = bundled.map { |const| const_get(const) }
87
+ end
88
+
89
+ @bundled_languages
90
+ end
91
+
92
+ def self.clean
93
+ @languages = Hash.new
94
+ @bundled_languages = nil
95
+ @extensions = Types::Languages.constants.inject(Hash.new) do |exts, const|
96
+ exts[Types::Languages.const_get(const)] = Set.new
97
+ exts
98
+ end
99
+ end
100
+
101
+ clean
102
+ end
103
+ end
@@ -0,0 +1,18 @@
1
+ require "redcarpet"
2
+
3
+ module Docks
4
+ module Markdown
5
+ class Renderer < Redcarpet::Render::HTML
6
+ def block_code(code, language)
7
+ return nil unless language
8
+ "<fenced_code_block #{"data-has-demo='true'" unless (language =~ /demo/).nil?} data-language='#{language.sub(/_?demo/, "")}'>#{code}</fenced_code_block>"
9
+ end
10
+
11
+ def link(href, title, content)
12
+ href = "@link #{content.gsub(/<[^>]*>/, "").strip}" if href.strip == "@link"
13
+ content = "<span>#{content}</span>" unless content.strip.start_with?("<")
14
+ "<a href=\"#{href}\"#{" title=\"#{title}\"" unless title.nil?}>#{content}</a>"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,69 @@
1
+ module Docks
2
+ module Messenger
3
+ @@quiet = false
4
+ @@header = nil
5
+
6
+ def self.quiet
7
+ @@quiet = true
8
+ self
9
+ end
10
+
11
+ def self.show
12
+ @@quiet = false
13
+ self
14
+ end
15
+
16
+ def self.puts(message); puts message end
17
+ def self.warn(message); puts yellow("Warning: #{message}") end
18
+ def self.error(message); puts red("Error: #{message}") end
19
+ def self.succeed(message); puts green(message) end
20
+
21
+ def self.created(*files)
22
+ puts 'Created the following files and directories:'
23
+ created_files files
24
+ end
25
+
26
+ def self.created_files(*files)
27
+ files.flatten.each do |file|
28
+ puts " #{file}"
29
+ if File.directory? file
30
+ created_files Dir["#{file}/*"]
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.file(file, action = :updated)
36
+ unless @@header.nil?
37
+ puts "\n#{@@header}"
38
+ puts "-" * @@header.length
39
+ @@header = nil
40
+ end
41
+
42
+ file = file.to_s.sub((Docks.config.root || Pathname.pwd).to_s, "").sub(/^\//, "")
43
+
44
+ case action
45
+ when :updated then puts "Updated #{file}"
46
+ when :created then puts green("Created #{file}")
47
+ when :deleted then puts red("Deleted #{file}")
48
+ end
49
+ end
50
+
51
+ def self.file_header(header)
52
+ @@header = header
53
+ end
54
+
55
+ def self.puts(str)
56
+ return if @@quiet
57
+ super(str)
58
+ end
59
+
60
+ def self.colorize(color, str)
61
+ "\e[#{color}m#{str}\e[0m"
62
+ end
63
+
64
+ def self.yellow(str); colorize(33, str) end
65
+ def self.red(str); colorize(31, str) end
66
+ def self.green(str); colorize(32, str) end
67
+ end
68
+ end
69
+
@@ -0,0 +1,9 @@
1
+ require "singleton"
2
+
3
+ module Docks
4
+ module NamingConventions
5
+ class Base
6
+ include Singleton
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ require_relative "base_naming_convention.rb"
2
+
3
+ module Docks
4
+ module NamingConventions
5
+ class BEM < Base
6
+ STATEFUL_WORDS = %w(is)
7
+
8
+ def base_component(component_name)
9
+ component_name.split("--").first.split("__").first
10
+ end
11
+
12
+ def base_component?(component_name)
13
+ component_name == base_component(component_name)
14
+ end
15
+
16
+ def component(component_name)
17
+ component_name.gsub(/--[^_]*/, "")
18
+ end
19
+
20
+ def parent_component(component_name)
21
+ component_name = component(component_name)
22
+ component_name.sub(/__[^_]*$/, "")
23
+ end
24
+
25
+ def clean_variation_name(variation_name, component_name)
26
+ return variation_name if disconnected_state?(variation_name)
27
+ variation_name = variation_name.sub(Regexp.new("^(?:#{component_name})?(?:--)?"), "")
28
+ "#{component_name}--#{variation_name}"
29
+ end
30
+
31
+ def state?(state_name)
32
+ state_name = state_name.split("--").last
33
+ STATEFUL_WORDS.any? { |word| state_name.start_with?(word) }
34
+ end
35
+
36
+ def variant?(variant_name)
37
+ variant_name.split("--").length > 1 && !state?(variant_name)
38
+ end
39
+
40
+ def disconnected_state?(state_name)
41
+ state?(state_name) && !state_name.include?("--")
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ require_relative "base_naming_convention.rb"
2
+
3
+ module Docks
4
+ module NamingConventions
5
+ class SUIT < Base
6
+ STATEFUL_WORDS = %w(is)
7
+
8
+ def base_component(component_name)
9
+ component_name.split("-").first
10
+ end
11
+
12
+ def base_component?(component_name)
13
+ component_name == base_component(component_name)
14
+ end
15
+
16
+ def component(component_name)
17
+ component_name.gsub(/--[^\-]*/, "")
18
+ end
19
+
20
+ def parent_component(component_name)
21
+ component_name = component(component_name)
22
+ component_name.sub(/-[^\-]*$/, "")
23
+ end
24
+
25
+ def clean_variation_name(variation_name, component_name)
26
+ return variation_name if disconnected_state?(variation_name)
27
+ variation_name = variation_name.sub(Regexp.new("^(?:#{component_name})?(?:--)?"), "")
28
+ "#{component_name}--#{variation_name}"
29
+ end
30
+
31
+ def state?(state_name)
32
+ state_name = state_name.split("--").last
33
+ STATEFUL_WORDS.any? { |word| state_name.start_with?(word) }
34
+ end
35
+
36
+ def variant?(variant_name)
37
+ variant_name.split("--").length > 1 && !state?(variant_name)
38
+ end
39
+
40
+ def disconnected_state?(state_name)
41
+ state?(state_name) && !state_name.include?("--")
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ Dir[File.expand_path("../naming_conventions/*.rb", __FILE__)].each do |convention|
2
+ require convention
3
+ end
4
+
5
+ module Docks
6
+ module NamingConventions
7
+ def self.for(convention)
8
+ if [String, ::Symbol].include?(convention.class)
9
+ convention = convention.to_sym
10
+ begin
11
+ convention = const_get(convention).instance
12
+ rescue NameError
13
+ end
14
+ else
15
+ convention = convention.instance if convention.kind_of?(Class)
16
+ end
17
+
18
+ convention.kind_of?(Base) ? convention : nil
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ require "ostruct"
2
+
3
+ module Docks
4
+ class OpenStruct < ::OpenStruct
5
+ def to_json(options = nil)
6
+ @table.to_json(options)
7
+ end
8
+
9
+ def as_json(options = nil)
10
+ @table.as_json(options)
11
+ end
12
+
13
+ def each(&block)
14
+ @table.each(&block)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,86 @@
1
+ module Docks
2
+ class Parser
3
+ def self.parse(files)
4
+ files = Array(files).select { |file| File.exists?(file) }
5
+
6
+ pattern = Containers::Pattern.new(name: Docks.pattern_id(files.first))
7
+ pattern.files = files
8
+ pattern.modified = files.map { |file| File.mtime(file) }.max
9
+
10
+ files.each do |file|
11
+ next unless parseable?(file)
12
+ pattern.add(Languages.file_type(file), parse_file(file))
13
+ end
14
+
15
+ Process.process(pattern)
16
+ pattern
17
+ end
18
+
19
+ def self.register(parser, options)
20
+ match = options.delete(:for) || options.delete(:match)
21
+ @custom_parsers.push(parser: parser, for: match)
22
+ end
23
+
24
+ def self.parse_block(content, language)
25
+ store_current_details("foo.#{language}") do
26
+ symbol = Docks.current_parser.parse_comment_block(content)
27
+ Process.process(symbol)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def self.parseable?(file)
34
+ File.exists?(file) && Languages.supported_file?(file) && !parser_for(file).nil?
35
+ end
36
+
37
+ def self.parser_for(file)
38
+ parser = @custom_parsers.reverse_each.find { |custom_parser| custom_parser[:for] =~ file }
39
+
40
+ if parser.nil?
41
+ language = Languages.language_for(file)
42
+ language.nil? ? nil : language.parser
43
+ else
44
+ parser[:parser].instance
45
+ end
46
+ end
47
+
48
+ def self.parse_file(file)
49
+ store_current_details(file) do
50
+ symbols = Docks.current_parser.parse(file)
51
+ symbols.map { |symbol| Process.process(symbol) }
52
+ end
53
+ end
54
+
55
+ def self.store_current_details(file)
56
+ Docks.current_file = file
57
+ Docks.current_parser = parser_for(file)
58
+ Docks.current_language = Languages.language_for(file)
59
+ Docks.current_pattern = Docks.pattern_id(file)
60
+
61
+ symbol = yield
62
+
63
+ Docks.current_file = nil
64
+ Docks.current_parser = nil
65
+ Docks.current_language = nil
66
+ Docks.current_pattern = nil
67
+
68
+ symbol
69
+ end
70
+
71
+ def self.clean
72
+ @custom_parsers = []
73
+ end
74
+
75
+ clean
76
+ end
77
+
78
+ def self.current_file; @current_file end
79
+ def self.current_file=(file); @current_file = file end
80
+ def self.current_language; @current_language end
81
+ def self.current_language=(language); @current_language = language end
82
+ def self.current_parser; @current_parser end
83
+ def self.current_parser=(parser); @current_parser = parser end
84
+ def self.current_pattern; @current_pattern end
85
+ def self.current_pattern=(pattern); @current_pattern = pattern.to_s end
86
+ end
@@ -0,0 +1,128 @@
1
+ module Docks
2
+ module Parsers
3
+ class Base
4
+ include Singleton
5
+
6
+ attr_accessor :comment_pattern,
7
+ :comment_line_pattern,
8
+ :pattern_block_extractor,
9
+ :symbol_block_extractor
10
+
11
+ def initialize
12
+ @comment_pattern = /#/
13
+ setup_regexes
14
+ end
15
+
16
+ def parse(file)
17
+ symbols = []
18
+ file_contents, file_given = if File.exists?(file)
19
+ [File.read(file).gsub(/\r\n?/, "\n"), true]
20
+ else
21
+ [file, false]
22
+ end
23
+
24
+ # Get rid of the page block and, in the process, add the page block
25
+ # to the set of parse results.
26
+ lines_from_pattern_block = 0
27
+ file_contents.sub!(@pattern_block_extractor) do |page_comment_block|
28
+ start_line_number = $`.lines.count + 1
29
+ lines_from_pattern_block = page_comment_block.lines.count
30
+ page_comment_block.sub!(/#{@comment_pattern}\*\s*/, '')
31
+
32
+ index = page_comment_block.index(/^\s*(?:#{@first_non_code_line_pattern}|#{@comment_pattern}\*$)/m)
33
+ parseable_block, replacement = page_comment_block, ""
34
+
35
+ if index
36
+ index -= 1
37
+ parseable_block = page_comment_block[0...index]
38
+ replacement = page_comment_block[index..-1]
39
+ lines_from_pattern_block -= replacement.lines.count
40
+ end
41
+
42
+ symbol = parse_comment_block(parseable_block)
43
+ symbol.source = OpenStruct.new(file: file, language_code: Languages.extension_for_file(file), line_number: start_line_number) if file_given
44
+ symbols << symbol
45
+
46
+ replacement
47
+ end
48
+
49
+ # Scan through each symbols comment block and add it to the list of parsed symbols.
50
+ last_match_position = 0
51
+ while (match = file_contents.match(@symbol_block_extractor, last_match_position))
52
+ symbol_details = symbol_details_from_first_line(match[:first_line])
53
+ symbol = Containers.container_for(symbol_details[:symbol_type]).new(symbol_details)
54
+ parse_comment_block(match[:comments], symbol)
55
+
56
+ symbol.source = OpenStruct.new(file: file, language_code: Languages.extension_for_file(file), line_number: lines_from_pattern_block + match.pre_match.lines.count + match[0].lines.count) if file_given
57
+ symbols << symbol
58
+
59
+ last_match_position = match.offset(0).last
60
+ end
61
+
62
+ symbols
63
+ end
64
+
65
+ def parse_comment_block(comment_block, symbol = Containers::Symbol.new)
66
+ if @tag_pattern.nil?
67
+ supported_tags = Tags.supported_parseable_tags.sort! { |a, b| b.length <=> a.length }
68
+ @tag_pattern = /(?:\s*@(?<tag>#{supported_tags.join("|")}) ?)?(?<text>.*)/
69
+ end
70
+
71
+ last_tag = nil
72
+
73
+ comment_block.sub(/#{@comment_pattern}\*\s*/, '').gsub(@comment_line_pattern, "").strip.split("\n").each do |comment_line|
74
+ line_details = comment_line.match(@tag_pattern)
75
+ next if line_details.nil? || line_details[:text].nil?
76
+
77
+ tag, text = line_details[:tag], line_details[:text]
78
+
79
+ if tag.nil?
80
+ if last_tag.nil?
81
+ # No tag and no previous tag — must be description
82
+ symbol[Tags::Description] ||= []
83
+ symbol[Tags::Description] << text
84
+ else
85
+ # No tag, but has a previous tag — bundle with last tag. As discussed below,
86
+ # multiple_allowed tags will be represented by an array of arrays, so append
87
+ # this line to the last array within the main array. Otherwise, just append
88
+ # the text to the main array.
89
+ (symbol[last_tag].first.kind_of?(Array) ? symbol[last_tag].last : symbol[last_tag]) << text
90
+ end
91
+ else
92
+ # New tag declaration
93
+ tag = tag.to_sym
94
+ tag_handler = Tags.tag_for(tag)
95
+ multiline = tag_handler.multiline?
96
+ last_tag = multiline ? tag : nil
97
+
98
+ # If multiple tags are allowed, each one (the tag declaration, plus the following lines)
99
+ # should be in an array inside the main array for that tag. Otherwise, the array
100
+ # for the tag should only contain strings. If only one of that tag is available per tag,
101
+ # overwrite the existing content. Non-multiline comments are always as minimally-Array-ed
102
+ # as possible (if only one is allowed per file, the tag value will be the line. Otherwise,
103
+ # it is added to a single-dimensional array).
104
+ if tag_handler.multiple_allowed?
105
+ symbol[tag] ||= []
106
+ symbol[tag] << (multiline ? [text] : text)
107
+ else
108
+ symbol[tag] = multiline ? [text] : text
109
+ end
110
+ end
111
+ end
112
+
113
+ symbol
114
+ end
115
+
116
+ protected
117
+
118
+ def setup_regexes
119
+ return if @comment_pattern.nil?
120
+
121
+ @first_non_code_line_pattern ||= /\w/
122
+ @pattern_block_extractor ||= /^ *#{@comment_pattern}\*(.*?@(?:page|pattern).*?)^\s*#{@comment_pattern}\*/m
123
+ @symbol_block_extractor ||= /^ *#{@comment_pattern}\*(?<comments>.*?)^[^#{@comment_pattern}]*?(?<first_line>#{@first_non_code_line_pattern}[^\n]*)/m
124
+ @comment_line_pattern ||= /^ *#{@comment_pattern} ?/m
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "base_parser.rb"
2
+
3
+ module Docks
4
+ module Parsers
5
+ class CoffeeScript < Base
6
+ def initialize
7
+ @comment_pattern = /#/
8
+ @first_non_code_line_pattern = /[\w\$]/
9
+ setup_regexes
10
+ end
11
+
12
+ def symbol_details_from_first_line(first_code_line)
13
+ first_code_line.strip!
14
+
15
+ type = case first_code_line
16
+ when /^class/ then Docks::Types::Symbol::CLASS
17
+ when /^.*?[\-\=]\>/ then Docks::Types::Symbol::FUNCTION
18
+ else Docks::Types::Symbol::VARIABLE
19
+ end
20
+
21
+ clean_first_line = first_code_line.split(/[=:,]/).first.gsub(/class\s+/, "").split(".").last.strip
22
+ bracket_check = clean_first_line.split(/['"]/)
23
+
24
+ name = bracket_check.length > 1 ? bracket_check[-2] : clean_first_line
25
+
26
+ { name: name, symbol_type: type }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ require_relative "base_parser.rb"
2
+
3
+ module Docks
4
+ module Parsers
5
+ class CSS < Base
6
+
7
+ def initialize
8
+ @comment_pattern = /(?:\/\*|\*\/?)/
9
+ @first_non_code_line_pattern = /[\.#\w\[@]/
10
+ setup_regexes
11
+ end
12
+
13
+ def symbol_details_from_first_line(first_code_line)
14
+ first_code_line.strip!
15
+
16
+ type = case first_code_line
17
+ when /(\.|\-\-)?(?:is|js)\-/ then Docks::Types::Symbol::STATE
18
+ when /\-\-(?:[a-zA-Z][\-_]?)*/ then Docks::Types::Symbol::VARIANT
19
+ else Docks::Types::Symbol::COMPONENT
20
+ end
21
+
22
+ name = first_code_line.match(/^\s*[\.#]([^\s\:\.#]*)/).captures.first
23
+ { name: name, symbol_type: type }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "base_parser.rb"
2
+
3
+ module Docks
4
+ module Parsers
5
+ class JavaScript < Base
6
+ def initialize
7
+ @comment_pattern = /(?:\/\/|\/\*|\*\/?)/
8
+ @first_non_code_line_pattern = /[\w\$]/
9
+ setup_regexes
10
+ end
11
+
12
+ def symbol_details_from_first_line(first_code_line)
13
+ first_code_line.strip!
14
+
15
+ type = case first_code_line
16
+ when /^class/ then Docks::Types::Symbol::CLASS
17
+ when /(?:function|=>)/ then Docks::Types::Symbol::FUNCTION
18
+ else Docks::Types::Symbol::VARIABLE
19
+ end
20
+
21
+ clean_first_line = first_code_line.split(/[=:,\(]/).first.split(/[\.\s]/).last.strip
22
+ bracket_check = clean_first_line.split(/['"]/)
23
+
24
+ name = bracket_check.length > 1 ? bracket_check[-2] : clean_first_line
25
+
26
+ { name: name, symbol_type: type }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ require_relative "sass_parser.rb"
2
+
3
+ module Docks
4
+ module Parsers
5
+ class Less < Sass
6
+ def symbol_details_from_first_line(first_code_line)
7
+ first_code_line.strip!
8
+
9
+ type = case first_code_line
10
+ when /^.[^\(]*\(/ then Docks::Types::Symbol::MIXIN
11
+ when /^@/ then Docks::Types::Symbol::VARIABLE
12
+ when /(\.|\-\-)?(?:is|js)\-/ then Docks::Types::Symbol::STATE
13
+ when /\-\-(?:[a-zA-Z][\-_]?)*/ then Docks::Types::Symbol::VARIANT
14
+ else Docks::Types::Symbol::COMPONENT
15
+ end
16
+
17
+ name = first_code_line.match(/^\s*&?[\.#]?\s*(@?[^\s\(\:]*)/).captures.first
18
+ { name: name, symbol_type: type }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "base_parser.rb"
2
+
3
+ module Docks
4
+ module Parsers
5
+ class Sass < Base
6
+
7
+ def initialize
8
+ @comment_pattern = /(?:\/\/|\/\*|\*\/?)/
9
+ @first_non_code_line_pattern = /[\$=+\.#\w\[&@]/
10
+ setup_regexes
11
+ end
12
+
13
+ def symbol_details_from_first_line(first_code_line)
14
+ first_code_line = first_code_line.strip
15
+
16
+ type = case first_code_line
17
+ when /^@function/ then Docks::Types::Symbol::FUNCTION
18
+ when /^@mixin/, /^=/ then Docks::Types::Symbol::MIXIN
19
+ when /^%/ then Docks::Types::Symbol::PLACEHOLDER
20
+ when /^\$/ then Docks::Types::Symbol::VARIABLE
21
+ when /(\.|\-\-)?(?:is|js)\-/ then Docks::Types::Symbol::STATE
22
+ when /\-\-(?:[a-zA-Z][\-_]?)*/ then Docks::Types::Symbol::VARIANT
23
+ else Docks::Types::Symbol::COMPONENT
24
+ end
25
+
26
+ name = first_code_line.match(/^=?@?(?:(?:function|mixin)\s*)?&?[\.#]?\s*([\$%]?[^\s\(\:]*)/).captures.first
27
+ { name: name, symbol_type: type }
28
+ end
29
+ end
30
+ end
31
+ end