docks_app 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.editorconfig +8 -0
- data/.gitignore +22 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +3 -0
- data/bin/docks +5 -0
- data/config/json/docks_config.json +71 -0
- data/config/ruby/docks_config.rb +127 -0
- data/config/yaml/docks_config.yml +70 -0
- data/docks.gemspec +38 -0
- data/lib/docks/build.rb +300 -0
- data/lib/docks/cache.rb +143 -0
- data/lib/docks/command_line.rb +65 -0
- data/lib/docks/configuration.rb +217 -0
- data/lib/docks/containers/base_container.rb +103 -0
- data/lib/docks/containers/class_container.rb +39 -0
- data/lib/docks/containers/component_container.rb +92 -0
- data/lib/docks/containers/demo_container.rb +105 -0
- data/lib/docks/containers/factory_container.rb +12 -0
- data/lib/docks/containers/function_container.rb +46 -0
- data/lib/docks/containers/mixin_container.rb +19 -0
- data/lib/docks/containers/pattern_container.rb +168 -0
- data/lib/docks/containers/pattern_library_container.rb +77 -0
- data/lib/docks/containers/state_container.rb +9 -0
- data/lib/docks/containers/symbol_container.rb +77 -0
- data/lib/docks/containers/variable_container.rb +47 -0
- data/lib/docks/containers/variant_container.rb +9 -0
- data/lib/docks/containers/variation_container.rb +38 -0
- data/lib/docks/containers.rb +25 -0
- data/lib/docks/descriptor.rb +60 -0
- data/lib/docks/errors.rb +5 -0
- data/lib/docks/group.rb +66 -0
- data/lib/docks/helpers/github_helper.rb +29 -0
- data/lib/docks/helpers/path_helper.rb +94 -0
- data/lib/docks/helpers/render_helper.rb +87 -0
- data/lib/docks/helpers.rb +19 -0
- data/lib/docks/languages/base_language.rb +17 -0
- data/lib/docks/languages/coffeescript_language.rb +30 -0
- data/lib/docks/languages/common_types/markup_language.rb +71 -0
- data/lib/docks/languages/css_language.rb +13 -0
- data/lib/docks/languages/erb_language.rb +21 -0
- data/lib/docks/languages/haml_language.rb +21 -0
- data/lib/docks/languages/html_language.rb +10 -0
- data/lib/docks/languages/javascript_language.rb +42 -0
- data/lib/docks/languages/json_language.rb +18 -0
- data/lib/docks/languages/less_language.rb +33 -0
- data/lib/docks/languages/markdown_language.rb +10 -0
- data/lib/docks/languages/sass_language.rb +36 -0
- data/lib/docks/languages/slim_language.rb +21 -0
- data/lib/docks/languages/stylus_language.rb +26 -0
- data/lib/docks/languages/yaml_language.rb +18 -0
- data/lib/docks/languages.rb +103 -0
- data/lib/docks/markdown.rb +18 -0
- data/lib/docks/messenger.rb +69 -0
- data/lib/docks/naming_conventions/base_naming_convention.rb +9 -0
- data/lib/docks/naming_conventions/bem_naming_convention.rb +45 -0
- data/lib/docks/naming_conventions/suit_naming_convention.rb +45 -0
- data/lib/docks/naming_conventions.rb +21 -0
- data/lib/docks/ostruct.rb +17 -0
- data/lib/docks/parser.rb +86 -0
- data/lib/docks/parsers/base_parser.rb +128 -0
- data/lib/docks/parsers/coffeescript_parser.rb +30 -0
- data/lib/docks/parsers/css_parser.rb +27 -0
- data/lib/docks/parsers/javascript_parser.rb +30 -0
- data/lib/docks/parsers/less_parser.rb +22 -0
- data/lib/docks/parsers/sass_parser.rb +31 -0
- data/lib/docks/parsers/stylus_parser.rb +28 -0
- data/lib/docks/process.rb +60 -0
- data/lib/docks/processors.rb +416 -0
- data/lib/docks/renderers/base_renderer.rb +64 -0
- data/lib/docks/renderers/common_features/capturable.rb +69 -0
- data/lib/docks/renderers/common_features/helperable.rb +23 -0
- data/lib/docks/renderers/erb_renderer.rb +68 -0
- data/lib/docks/renderers/haml_renderer.rb +37 -0
- data/lib/docks/renderers/slim_renderer.rb +33 -0
- data/lib/docks/symbol_sources/base_symbol_source.rb +12 -0
- data/lib/docks/symbol_sources/jquery_symbol_source.rb +17 -0
- data/lib/docks/symbol_sources/mdn_symbol_source.rb +35 -0
- data/lib/docks/symbol_sources/sass_symbol_source.rb +27 -0
- data/lib/docks/symbol_sources.rb +28 -0
- data/lib/docks/tags/access_tag.rb +27 -0
- data/lib/docks/tags/activate_with_tag.rb +17 -0
- data/lib/docks/tags/active_tag.rb +14 -0
- data/lib/docks/tags/alias_tag.rb +17 -0
- data/lib/docks/tags/author_tag.rb +19 -0
- data/lib/docks/tags/base_tag.rb +52 -0
- data/lib/docks/tags/beta_tag.rb +26 -0
- data/lib/docks/tags/class_tag.rb +16 -0
- data/lib/docks/tags/compatibility_tag.rb +19 -0
- data/lib/docks/tags/demo_type_tag.rb +14 -0
- data/lib/docks/tags/deprecated_tag.rb +26 -0
- data/lib/docks/tags/description_tag.rb +99 -0
- data/lib/docks/tags/example_tag.rb +20 -0
- data/lib/docks/tags/factory_tag.rb +16 -0
- data/lib/docks/tags/for_tag.rb +23 -0
- data/lib/docks/tags/group_tag.rb +10 -0
- data/lib/docks/tags/helper_tag.rb +13 -0
- data/lib/docks/tags/include_with_tag.rb +57 -0
- data/lib/docks/tags/javascript_action_tag.rb +10 -0
- data/lib/docks/tags/link_tag.rb +18 -0
- data/lib/docks/tags/markup_tag.rb +106 -0
- data/lib/docks/tags/member_tag.rb +37 -0
- data/lib/docks/tags/method_tag.rb +18 -0
- data/lib/docks/tags/name_tag.rb +10 -0
- data/lib/docks/tags/object_tag.rb +15 -0
- data/lib/docks/tags/param_tag.rb +94 -0
- data/lib/docks/tags/pattern_tag.rb +21 -0
- data/lib/docks/tags/preclude_tag.rb +17 -0
- data/lib/docks/tags/private_tag.rb +15 -0
- data/lib/docks/tags/property_tag.rb +18 -0
- data/lib/docks/tags/public_tag.rb +15 -0
- data/lib/docks/tags/require_tag.rb +47 -0
- data/lib/docks/tags/returns_tag.rb +31 -0
- data/lib/docks/tags/set_by_tag.rb +18 -0
- data/lib/docks/tags/signature_tag.rb +35 -0
- data/lib/docks/tags/since_tag.rb +26 -0
- data/lib/docks/tags/source_tag.rb +12 -0
- data/lib/docks/tags/state_tag.rb +21 -0
- data/lib/docks/tags/static_tag.rb +14 -0
- data/lib/docks/tags/subcomponent_tag.rb +68 -0
- data/lib/docks/tags/subtitle_tag.rb +11 -0
- data/lib/docks/tags/symbol_type_tag.rb +10 -0
- data/lib/docks/tags/throws_tag.rb +30 -0
- data/lib/docks/tags/title_tag.rb +10 -0
- data/lib/docks/tags/type_tag.rb +10 -0
- data/lib/docks/tags/value_tag.rb +10 -0
- data/lib/docks/tags/variant_tag.rb +21 -0
- data/lib/docks/tags/variation_tag.rb +136 -0
- data/lib/docks/tags.rb +103 -0
- data/lib/docks/templates.rb +122 -0
- data/lib/docks/themes.rb +19 -0
- data/lib/docks/types.rb +26 -0
- data/lib/docks/version.rb +3 -0
- data/lib/docks.rb +37 -0
- data/spec/fixtures/build/scripts/bar/bar_2.js +1 -0
- data/spec/fixtures/build/scripts/bar.js +1 -0
- data/spec/fixtures/build/styles/foo/foo-2.css +1 -0
- data/spec/fixtures/build/styles/foo.css +1 -0
- data/spec/fixtures/build/templates/baz/baz_2.erb +1 -0
- data/spec/fixtures/build/templates/baz.erb +1 -0
- data/spec/fixtures/grouper/components/button/button.coffee +0 -0
- data/spec/fixtures/grouper/components/button/button.haml +0 -0
- data/spec/fixtures/grouper/components/button/button.scss +0 -0
- data/spec/fixtures/grouper/components/checkbox/_checkbox.haml +0 -0
- data/spec/fixtures/grouper/components/checkbox/_checkbox.scss +0 -0
- data/spec/fixtures/grouper/components/checkbox/checkbox.coffee +0 -0
- data/spec/fixtures/grouper/components/form/form.coffee +0 -0
- data/spec/fixtures/grouper/components/form/form.m +0 -0
- data/spec/fixtures/grouper/components/form/form.scss +0 -0
- data/spec/fixtures/grouper/components/next-expanding-textarea/_next-expanding-textarea.scss +0 -0
- data/spec/fixtures/grouper/components/next-expanding-textarea/_next_expanding_textarea.coffee +0 -0
- data/spec/fixtures/grouper/components/next-expanding-textarea/next-expanding-textarea.haml +0 -0
- data/spec/fixtures/grouper/components/next-tab/next-tab.coffee +0 -0
- data/spec/fixtures/grouper/components/next-tab/next-tab.haml +0 -0
- data/spec/fixtures/grouper/components/next-tab/next-tab.scss +0 -0
- data/spec/fixtures/grouper/components/segmented control/segmented control.coffee +0 -0
- data/spec/fixtures/grouper/components/segmented control/segmented control.haml +0 -0
- data/spec/fixtures/grouper/components/segmented control/segmented control.min.html +0 -0
- data/spec/fixtures/grouper/components/segmented control/segmented control.scss +0 -0
- data/spec/fixtures/grouper/markup/list-view.haml +0 -0
- data/spec/fixtures/grouper/markup/resizable/resizable.haml +0 -0
- data/spec/fixtures/grouper/markup/toggle.haml +0 -0
- data/spec/fixtures/grouper/scripts/resizable/resizable.coffee +0 -0
- data/spec/fixtures/grouper/scripts/toggle.coffee +0 -0
- data/spec/fixtures/grouper/style/_list-view.scss +0 -0
- data/spec/fixtures/grouper/style/_toggle.scss +0 -0
- data/spec/fixtures/languages/stub.json +3 -0
- data/spec/fixtures/languages/stub.yml +2 -0
- data/spec/fixtures/parsers/coffeescript_parser_fixture_basic.coffee +20 -0
- data/spec/fixtures/parsers/coffeescript_parser_fixture_complex.coffee +80 -0
- data/spec/fixtures/parsers/css_parser_fixture_basic.css +44 -0
- data/spec/fixtures/parsers/css_parser_fixture_complex.css +120 -0
- data/spec/fixtures/parsers/javascript_parser_fixture_basic.js +27 -0
- data/spec/fixtures/parsers/javascript_parser_fixture_complex.js +85 -0
- data/spec/fixtures/parsers/sass_parser_fixture_basic.scss +39 -0
- data/spec/fixtures/parsers/sass_parser_fixture_complex.scss +149 -0
- data/spec/fixtures/parsers/stylus_parser_fixture_basic.styl +34 -0
- data/spec/fixtures/parsers/stylus_parser_fixture_complex.styl +113 -0
- data/spec/fixtures/processors/join_with_smart_line_breaks/code_blocks.txt +10 -0
- data/spec/fixtures/processors/join_with_smart_line_breaks/headings.txt +15 -0
- data/spec/fixtures/processors/join_with_smart_line_breaks/lists.txt +21 -0
- data/spec/fixtures/processors/join_with_smart_line_breaks/lists_with_nesting.txt +13 -0
- data/spec/fixtures/processors/join_with_smart_line_breaks/multiple_paragraphs.txt +11 -0
- data/spec/fixtures/renderers/helpers.rb +37 -0
- data/spec/fixtures/renderers/html_output.html +7 -0
- data/spec/fixtures/renderers/templates/layouts/application.html.erb +0 -0
- data/spec/fixtures/renderers/templates/layouts/more/subdirectory.html.erb +0 -0
- data/spec/fixtures/renderers/templates/partials/_leading_underscore.html.erb +1 -0
- data/spec/fixtures/renderers/templates/partials/more/_subdirectory.html.erb +1 -0
- data/spec/fixtures/renderers/templates/partials/partial.html.erb +0 -0
- data/spec/fixtures/renderers/templates/partials/template.html.erb +1 -0
- data/spec/fixtures/renderers/templates/template.html.erb +1 -0
- data/spec/fixtures/tags/description/button.md +24 -0
- data/spec/fixtures/tags/description/class.md +27 -0
- data/spec/fixtures/tags/description/component.md +23 -0
- data/spec/fixtures/tags/description/function.md +30 -0
- data/spec/lib/build_spec.rb +467 -0
- data/spec/lib/cache_spec.rb +175 -0
- data/spec/lib/command_line_spec.rb +77 -0
- data/spec/lib/configuration_spec.rb +180 -0
- data/spec/lib/containers/base_container_spec.rb +214 -0
- data/spec/lib/containers/class_container_spec.rb +209 -0
- data/spec/lib/containers/component_container_spec.rb +158 -0
- data/spec/lib/containers/demo_container_spec.rb +113 -0
- data/spec/lib/containers/function_container_spec.rb +116 -0
- data/spec/lib/containers/mixin_container_spec.rb +4 -0
- data/spec/lib/containers/pattern_container_spec.rb +291 -0
- data/spec/lib/containers/pattern_library_container_spec.rb +130 -0
- data/spec/lib/containers/symbol_container_spec.rb +216 -0
- data/spec/lib/containers/variable_container_spec.rb +116 -0
- data/spec/lib/containers/variation_container_spec.rb +52 -0
- data/spec/lib/containers_spec.rb +22 -0
- data/spec/lib/descriptor_spec.rb +73 -0
- data/spec/lib/group_spec.rb +151 -0
- data/spec/lib/helpers/path_helper_spec.rb +202 -0
- data/spec/lib/helpers/render_helper_spec.rb +159 -0
- data/spec/lib/helpers_spec.rb +35 -0
- data/spec/lib/languages/base_language_spec.rb +32 -0
- data/spec/lib/languages/coffeescript_language_spec.rb +52 -0
- data/spec/lib/languages/css_language_spec.rb +13 -0
- data/spec/lib/languages/erb_language_spec.rb +33 -0
- data/spec/lib/languages/haml_language_spec.rb +32 -0
- data/spec/lib/languages/javascript_language_spec.rb +54 -0
- data/spec/lib/languages/json_language_spec.rb +24 -0
- data/spec/lib/languages/less_language_spec.rb +39 -0
- data/spec/lib/languages/markup_language_spec.rb +95 -0
- data/spec/lib/languages/sass_language_spec.rb +53 -0
- data/spec/lib/languages/slim_language_spec.rb +32 -0
- data/spec/lib/languages/stylus_language_spec.rb +34 -0
- data/spec/lib/languages/yaml_language_spec.rb +24 -0
- data/spec/lib/languages_spec.rb +127 -0
- data/spec/lib/markdown_spec.rb +63 -0
- data/spec/lib/messenger_spec.rb +1 -0
- data/spec/lib/naming_conventions/bem_naming_convention_spec.rb +112 -0
- data/spec/lib/naming_conventions/suit_naming_convention_spec.rb +107 -0
- data/spec/lib/naming_conventions_spec.rb +28 -0
- data/spec/lib/ostruct_spec.rb +15 -0
- data/spec/lib/parser_spec.rb +93 -0
- data/spec/lib/parsers/base_parser_spec.rb +128 -0
- data/spec/lib/parsers/coffeescript_parser_spec.rb +184 -0
- data/spec/lib/parsers/css_parser_spec.rb +136 -0
- data/spec/lib/parsers/javascript_parser_spec.rb +216 -0
- data/spec/lib/parsers/less_parser_spec.rb +111 -0
- data/spec/lib/parsers/sass_parser_spec.rb +233 -0
- data/spec/lib/parsers/stylus_parser_spec.rb +212 -0
- data/spec/lib/process_spec.rb +96 -0
- data/spec/lib/processors_spec.rb +555 -0
- data/spec/lib/renderers/base_renderer_spec.rb +122 -0
- data/spec/lib/renderers/common_features/helperable_spec.rb +30 -0
- data/spec/lib/renderers/erb_renderer_spec.rb +119 -0
- data/spec/lib/renderers/haml_renderer_spec.rb +103 -0
- data/spec/lib/renderers/slim_renderer_spec.rb +103 -0
- data/spec/lib/symbol_sources/jquery_symbol_source_spec.rb +25 -0
- data/spec/lib/symbol_sources/mdn_symbol_source_spec.rb +40 -0
- data/spec/lib/symbol_sources/sass_symbol_source_spec.rb +39 -0
- data/spec/lib/symbol_sources_spec.rb +19 -0
- data/spec/lib/tags/access_tag_spec.rb +32 -0
- data/spec/lib/tags/activate_with_tag_spec.rb +31 -0
- data/spec/lib/tags/active_tag_spec.rb +24 -0
- data/spec/lib/tags/alias_tag_spec.rb +31 -0
- data/spec/lib/tags/author_tag_spec.rb +172 -0
- data/spec/lib/tags/base_tag_spec.rb +21 -0
- data/spec/lib/tags/beta_tag_spec.rb +52 -0
- data/spec/lib/tags/class_tag_spec.rb +29 -0
- data/spec/lib/tags/compatibility_tag_spec.rb +159 -0
- data/spec/lib/tags/demo_type_tag_spec.rb +24 -0
- data/spec/lib/tags/deprecated_tag_spec.rb +50 -0
- data/spec/lib/tags/description_tag_spec.rb +242 -0
- data/spec/lib/tags/example_tag_spec.rb +37 -0
- data/spec/lib/tags/factory_tag_spec.rb +29 -0
- data/spec/lib/tags/for_tag_spec.rb +45 -0
- data/spec/lib/tags/group_tag_spec.rb +20 -0
- data/spec/lib/tags/helper_tag_spec.rb +22 -0
- data/spec/lib/tags/include_with_tag_spec.rb +74 -0
- data/spec/lib/tags/javascript_action_tag_spec.rb +20 -0
- data/spec/lib/tags/link_tag_spec.rb +49 -0
- data/spec/lib/tags/markup_tag_spec.rb +255 -0
- data/spec/lib/tags/member_tag_spec.rb +167 -0
- data/spec/lib/tags/method_tag_spec.rb +27 -0
- data/spec/lib/tags/name_tag_spec.rb +20 -0
- data/spec/lib/tags/object_tag_spec.rb +24 -0
- data/spec/lib/tags/param_tag_spec.rb +261 -0
- data/spec/lib/tags/pattern_tag_spec.rb +49 -0
- data/spec/lib/tags/preclude_tag_spec.rb +31 -0
- data/spec/lib/tags/private_tag_spec.rb +31 -0
- data/spec/lib/tags/property_tag_spec.rb +27 -0
- data/spec/lib/tags/public_tag_spec.rb +29 -0
- data/spec/lib/tags/require_tag_spec.rb +133 -0
- data/spec/lib/tags/returns_tag_spec.rb +85 -0
- data/spec/lib/tags/set_by_tag_spec.rb +92 -0
- data/spec/lib/tags/signature_tag_spec.rb +125 -0
- data/spec/lib/tags/since_tag_spec.rb +48 -0
- data/spec/lib/tags/state_tag_spec.rb +199 -0
- data/spec/lib/tags/static_tag_spec.rb +27 -0
- data/spec/lib/tags/subcomponent_tag_spec.rb +78 -0
- data/spec/lib/tags/subtitle_tag_spec.rb +13 -0
- data/spec/lib/tags/symbol_type_tag_spec.rb +20 -0
- data/spec/lib/tags/throws_tag_spec.rb +49 -0
- data/spec/lib/tags/title_tag_spec.rb +20 -0
- data/spec/lib/tags/type_tag_spec.rb +20 -0
- data/spec/lib/tags/value_tag_spec.rb +20 -0
- data/spec/lib/tags/variant_tag_spec.rb +13 -0
- data/spec/lib/tags/variation_tag_spec.rb +154 -0
- data/spec/lib/tags_spec.rb +264 -0
- data/spec/lib/templates_spec.rb +185 -0
- data/spec/lib/themes_spec.rb +32 -0
- data/spec/spec_helper.rb +34 -0
- data/tasks/rspec.rake +7 -0
- data/tasks/rubocop.rake +8 -0
- metadata +740 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Docks::Parsers::CSS do
|
4
|
+
subject { Docks::Parsers::CSS.instance }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Docks::Tags.register_bundled_tags
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:basic_fixture) { File.join(File.dirname(__FILE__), "..", "..", "fixtures", "parsers", "css_parser_fixture_basic.css") }
|
11
|
+
let(:complex_fixture) { File.join(File.dirname(__FILE__), "..", "..", "fixtures", "parsers", "css_parser_fixture_complex.css") }
|
12
|
+
|
13
|
+
describe "#parse" do
|
14
|
+
let(:basic_parsed_symbols) { subject.parse(basic_fixture) }
|
15
|
+
let(:complex_parsed_symbols) { subject.parse(complex_fixture) }
|
16
|
+
|
17
|
+
it "captures the correct number of documentation blocks" do
|
18
|
+
expect(basic_parsed_symbols.length).to be 2
|
19
|
+
expect(complex_parsed_symbols.length).to be 6
|
20
|
+
end
|
21
|
+
|
22
|
+
it "captures the pattern comment block when one exists" do
|
23
|
+
expect(basic_parsed_symbols.first[:pattern]).to be nil
|
24
|
+
expect(complex_parsed_symbols.first[:pattern]).to_not be nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "captures the pattern comment block when it is written using the page synonym" do
|
28
|
+
complex_parsed_symbols = subject.parse(File.read(complex_fixture).sub("@pattern", "@page"))
|
29
|
+
expect(complex_parsed_symbols.first[:page]).to_not be nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it "adds line number for the first line following all other comment blocks" do
|
33
|
+
expected_line_numbers = [10, 30]
|
34
|
+
basic_parsed_symbols.each_with_index do |symbol, index|
|
35
|
+
expect(symbol.source.line_number).to be expected_line_numbers[index]
|
36
|
+
end
|
37
|
+
|
38
|
+
expected_line_numbers = [1, 21, 34, 48, 82, 99]
|
39
|
+
complex_parsed_symbols.each_with_index do |symbol, index|
|
40
|
+
expect(symbol.source.line_number).to be expected_line_numbers[index]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#symbol_block_extractor" do
|
46
|
+
it "provides the first non-comment line as the second capture group" do
|
47
|
+
[
|
48
|
+
".button {",
|
49
|
+
"#button {",
|
50
|
+
"[button] {",
|
51
|
+
"body {",
|
52
|
+
"@media(print) {"
|
53
|
+
].each do |non_comment|
|
54
|
+
match = " /**\n * Description\n */\n\n #{non_comment}".match(subject.symbol_block_extractor)
|
55
|
+
expect(match[:first_line]).to eq non_comment
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#comment_line_pattern" do
|
61
|
+
let(:basic_comment) { "This is a comment" }
|
62
|
+
let(:complex_comment) { "* This comment has some extra comment-like symbols/characters *" }
|
63
|
+
|
64
|
+
it "spits back out comments without any leading comment symbols" do
|
65
|
+
expect(basic_comment.gsub(subject.comment_line_pattern, "")).to eq basic_comment
|
66
|
+
end
|
67
|
+
|
68
|
+
it "strips line comments" do
|
69
|
+
expect("* #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
|
70
|
+
end
|
71
|
+
|
72
|
+
it "strips line comments with leading whitespace" do
|
73
|
+
expect(" * #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
|
74
|
+
end
|
75
|
+
|
76
|
+
it "strips line complex comments" do
|
77
|
+
expect("* #{complex_comment}".gsub(subject.comment_line_pattern, "")).to eq complex_comment
|
78
|
+
end
|
79
|
+
|
80
|
+
it "leaves empty lines intact" do
|
81
|
+
content = "* Foo\n*\n* 1. Bar\n\n* 2. Baz"
|
82
|
+
expect(content.gsub(subject.comment_line_pattern, "")).to eq "Foo\n\n1. Bar\n\n2. Baz"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#symbol_details_from_first_line" do
|
87
|
+
|
88
|
+
describe "states" do
|
89
|
+
it "identifies a state as a class starting with `.is-`" do
|
90
|
+
target_name = "is-active"
|
91
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
|
92
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
93
|
+
expect(name).to eq target_name
|
94
|
+
end
|
95
|
+
|
96
|
+
it "identifies a state as a class containing `--is-`" do
|
97
|
+
target_name = "tab-list__tab--is-active"
|
98
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
|
99
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
100
|
+
expect(name).to eq target_name
|
101
|
+
end
|
102
|
+
|
103
|
+
it "identifies a state as a class starting with `.js-`" do
|
104
|
+
target_name = "js-active"
|
105
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
|
106
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
107
|
+
expect(name).to eq target_name
|
108
|
+
end
|
109
|
+
|
110
|
+
it "identifies a state as a class containing `--js-`" do
|
111
|
+
target_name = "tab-list__tab--js-active"
|
112
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
|
113
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
114
|
+
expect(name).to eq target_name
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "variants" do
|
119
|
+
it "identifies a variant as a class containing `--`" do
|
120
|
+
target_name = "tab-list__tab--large"
|
121
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
|
122
|
+
expect(type).to eq Docks::Types::Symbol::VARIANT
|
123
|
+
expect(name).to eq target_name
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "component" do
|
128
|
+
it "identifies a component as any class not matching state/ variant" do
|
129
|
+
target_name = "tab-list__tab"
|
130
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} { flex: 1 1 0; }").values
|
131
|
+
expect(type).to eq Docks::Types::Symbol::COMPONENT
|
132
|
+
expect(name).to eq target_name
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Docks::Parsers::JavaScript do
|
4
|
+
subject { Docks::Parsers::JavaScript.instance }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Docks::Tags.register_bundled_tags
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:basic_fixture) { File.join(File.dirname(__FILE__), "..", "..", "fixtures", "parsers", "javascript_parser_fixture_basic.js") }
|
11
|
+
let(:complex_fixture) { File.join(File.dirname(__FILE__), "..", "..", "fixtures", "parsers", "javascript_parser_fixture_complex.js") }
|
12
|
+
|
13
|
+
describe "#parse" do
|
14
|
+
let(:basic_parsed_symbols) { subject.parse(basic_fixture) }
|
15
|
+
let(:complex_parsed_symbols) { subject.parse(complex_fixture) }
|
16
|
+
|
17
|
+
it "captures the correct number of documentation blocks" do
|
18
|
+
expect(basic_parsed_symbols.length).to eq 2
|
19
|
+
expect(complex_parsed_symbols.length).to eq 6
|
20
|
+
end
|
21
|
+
|
22
|
+
it "captures the pattern comment block when one exists" do
|
23
|
+
expect(basic_parsed_symbols.first[:pattern]).to be nil
|
24
|
+
expect(complex_parsed_symbols.first[:pattern]).to_not be nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "captures the pattern comment block when it is written using the page synonym" do
|
28
|
+
complex_parsed_symbols = subject.parse(File.read(complex_fixture).sub("@pattern", "@page"))
|
29
|
+
expect(complex_parsed_symbols.first[:page]).to_not be nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it "adds line number for the first line following all other comment blocks" do
|
33
|
+
expected_line_numbers = [10, 26]
|
34
|
+
basic_parsed_symbols.each_with_index do |symbol, index|
|
35
|
+
expect(symbol.source.line_number).to be expected_line_numbers[index]
|
36
|
+
end
|
37
|
+
|
38
|
+
expected_line_numbers = [2, 16, 39, 45, 54, 77]
|
39
|
+
complex_parsed_symbols.each_with_index do |symbol, index|
|
40
|
+
expect(symbol.source.line_number).to be expected_line_numbers[index]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#symbol_block_extractor" do
|
46
|
+
it "provides the first non-comment line as the second capture group" do
|
47
|
+
[
|
48
|
+
"_foo = 'bar'",
|
49
|
+
"$node = $(this)",
|
50
|
+
"bar = 'baz'"
|
51
|
+
].each do |non_comment|
|
52
|
+
match = " //*\n // Description\n\n #{non_comment}".match(subject.symbol_block_extractor)
|
53
|
+
expect(match[:first_line]).to eq non_comment
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#comment_line_pattern" do
|
59
|
+
let(:basic_comment) { "This is a comment" }
|
60
|
+
let(:complex_comment) { "# This comment has ##some extra comment-like symbols/characters #" }
|
61
|
+
|
62
|
+
context "when using line comments" do
|
63
|
+
it "strips line comments" do
|
64
|
+
expect("// #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
|
65
|
+
end
|
66
|
+
|
67
|
+
it "strips line comments with leading whitespace" do
|
68
|
+
expect(" // #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
|
69
|
+
end
|
70
|
+
|
71
|
+
it "strips line complex comments" do
|
72
|
+
expect("// #{complex_comment}".gsub(subject.comment_line_pattern, "")).to eq complex_comment
|
73
|
+
end
|
74
|
+
|
75
|
+
it "leaves empty lines intact" do
|
76
|
+
content = "// Foo\n//\n// 1. Bar\n\n// 2. Baz"
|
77
|
+
expect(content.gsub(subject.comment_line_pattern, "")).to eq "Foo\n\n1. Bar\n\n2. Baz"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when using block commments" do
|
82
|
+
it "strips line comments" do
|
83
|
+
expect("* #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
|
84
|
+
end
|
85
|
+
|
86
|
+
it "strips line comments with leading whitespace" do
|
87
|
+
expect(" * #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
|
88
|
+
end
|
89
|
+
|
90
|
+
it "strips line complex comments" do
|
91
|
+
expect("* #{complex_comment}".gsub(subject.comment_line_pattern, "")).to eq complex_comment
|
92
|
+
end
|
93
|
+
|
94
|
+
it "leaves empty lines intact" do
|
95
|
+
content = "* Foo\n*\n* 1. Bar\n\n* 2. Baz"
|
96
|
+
expect(content.gsub(subject.comment_line_pattern, "")).to eq "Foo\n\n1. Bar\n\n2. Baz"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#symbol_details_from_first_line" do
|
102
|
+
describe "functions" do
|
103
|
+
it "identifies a function literal" do
|
104
|
+
target_name = "activateTab"
|
105
|
+
name, type = subject.symbol_details_from_first_line("function #{target_name}($tab) { $tab.activate() }").values
|
106
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
107
|
+
expect(name).to eq target_name
|
108
|
+
end
|
109
|
+
|
110
|
+
it "identifies a function variable" do
|
111
|
+
target_name = "activateTab"
|
112
|
+
name, type = subject.symbol_details_from_first_line("var #{target_name} = function($tab) { $tab.activate() }").values
|
113
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
114
|
+
expect(name).to eq target_name
|
115
|
+
end
|
116
|
+
|
117
|
+
it "identifies an arrow function" do
|
118
|
+
target_name = "activateTab"
|
119
|
+
name, type = subject.symbol_details_from_first_line("var #{target_name} = ($tab) => { $tab.activate() }").values
|
120
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
121
|
+
expect(name).to eq target_name
|
122
|
+
end
|
123
|
+
|
124
|
+
it "identifies a function declared in an object literal" do
|
125
|
+
target_name = "activateTab"
|
126
|
+
|
127
|
+
[" #{target_name} : function($tab) { $tab.activate() }",
|
128
|
+
" #{target_name}: function($tab) { $tab.activate() }"].each do |example|
|
129
|
+
name, type = subject.symbol_details_from_first_line(example).values
|
130
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
131
|
+
expect(name).to eq target_name
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it "identifies a function declared using dot notation" do
|
136
|
+
target_name = "activateTab"
|
137
|
+
|
138
|
+
name, type = subject.symbol_details_from_first_line(" foo.#{target_name} = function($tab) { $tab.activate() }").values
|
139
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
140
|
+
expect(name).to eq target_name
|
141
|
+
|
142
|
+
name, type = subject.symbol_details_from_first_line(" foo.bar.#{target_name} = function($tab) { $tab.activate() }").values
|
143
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
144
|
+
expect(name).to eq target_name
|
145
|
+
|
146
|
+
name, type = subject.symbol_details_from_first_line(" foo['bar'].#{target_name} = function($tab) { $tab.activate() }").values
|
147
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
148
|
+
expect(name).to eq target_name
|
149
|
+
end
|
150
|
+
|
151
|
+
it "identifies a function declared using bracket notation" do
|
152
|
+
target_name = "activateTab"
|
153
|
+
|
154
|
+
name, type = subject.symbol_details_from_first_line(" foo['#{target_name}'] = function($tab) { $tab.activate() }").values
|
155
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
156
|
+
expect(name).to eq target_name
|
157
|
+
|
158
|
+
name, type = subject.symbol_details_from_first_line(" foo[\"#{target_name}\"] = function($tab) { $tab.activate() }").values
|
159
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
160
|
+
expect(name).to eq target_name
|
161
|
+
|
162
|
+
name, type = subject.symbol_details_from_first_line(" foo['bar']['#{target_name}'] = function($tab) { $tab.activate() }").values
|
163
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
164
|
+
expect(name).to eq target_name
|
165
|
+
|
166
|
+
name, type = subject.symbol_details_from_first_line(" foo.bar['#{target_name}'] = function($tab) { $tab.activate() }").values
|
167
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
168
|
+
expect(name).to eq target_name
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "variables" do
|
173
|
+
it "identifies a variable" do
|
174
|
+
target_name = "newTab"
|
175
|
+
|
176
|
+
[
|
177
|
+
"var #{target_name} = @newTab()",
|
178
|
+
"const #{target_name} = @newTab()",
|
179
|
+
"#{target_name} = @newTab()"
|
180
|
+
].each do |example|
|
181
|
+
name, type = subject.symbol_details_from_first_line(example).values
|
182
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
183
|
+
expect(name).to eq target_name
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
it "identifies a variable declared in an object literal" do
|
188
|
+
target_name = "val"
|
189
|
+
name, type = subject.symbol_details_from_first_line(" #{target_name} : (2 * 3) / 4").values
|
190
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
191
|
+
expect(name).to eq target_name
|
192
|
+
end
|
193
|
+
|
194
|
+
it "identifies a variable that is declared without assignment" do
|
195
|
+
target_name = "val"
|
196
|
+
name, type = subject.symbol_details_from_first_line("var #{target_name}").values
|
197
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
198
|
+
expect(name).to eq target_name
|
199
|
+
end
|
200
|
+
|
201
|
+
it "identifies the first variable in a comma-separated list without assignment" do
|
202
|
+
target_name = "val"
|
203
|
+
name, type = subject.symbol_details_from_first_line("var #{target_name}, foo, bar , baz").values
|
204
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
205
|
+
expect(name).to eq target_name
|
206
|
+
end
|
207
|
+
|
208
|
+
it "identifies the first variable in a comma-separated list with assignment" do
|
209
|
+
target_name = "val"
|
210
|
+
name, type = subject.symbol_details_from_first_line("#{target_name}, foo, bar , baz = 'qux'").values
|
211
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
212
|
+
expect(name).to eq target_name
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Docks::Parsers::Less do
|
4
|
+
subject { Docks::Parsers::Less.instance }
|
5
|
+
|
6
|
+
describe "#symbol_details_from_first_line" do
|
7
|
+
it "identifies a mixin" do
|
8
|
+
target_name = "full-size"
|
9
|
+
name, type = subject.symbol_details_from_first_line(" .#{target_name}($height, $width) {").values
|
10
|
+
expect(type).to eq Docks::Types::Symbol::MIXIN
|
11
|
+
expect(name).to eq target_name
|
12
|
+
end
|
13
|
+
|
14
|
+
it "identifies a variable" do
|
15
|
+
target_name = "message-width"
|
16
|
+
name, type = subject.symbol_details_from_first_line(" @#{target_name}: 40rem;").values
|
17
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
18
|
+
expect(name).to eq "@#{target_name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "states" do
|
22
|
+
it "identifies a state as a class starting with `is-`" do
|
23
|
+
target_name = "is-active"
|
24
|
+
name, type = subject.symbol_details_from_first_line("#{target_name} {").values
|
25
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
26
|
+
expect(name).to eq target_name
|
27
|
+
end
|
28
|
+
|
29
|
+
it "identifies a state as a class starting with `&.is-`" do
|
30
|
+
target_name = "is-active"
|
31
|
+
name, type = subject.symbol_details_from_first_line("&.#{target_name} {").values
|
32
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
33
|
+
expect(name).to eq target_name
|
34
|
+
end
|
35
|
+
|
36
|
+
it "identifies a state as a class containing `--is-`" do
|
37
|
+
target_name = "tab-list__tab--is-active"
|
38
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
|
39
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
40
|
+
expect(name).to eq target_name
|
41
|
+
end
|
42
|
+
|
43
|
+
it "identifies a state as a class starting with `&--is-`" do
|
44
|
+
target_name = "--is-active"
|
45
|
+
name, type = subject.symbol_details_from_first_line("&#{target_name} {").values
|
46
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
47
|
+
expect(name).to eq target_name
|
48
|
+
end
|
49
|
+
|
50
|
+
it "identifies a state as a class starting with `js-`" do
|
51
|
+
target_name = "js-active"
|
52
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
|
53
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
54
|
+
expect(name).to eq target_name
|
55
|
+
end
|
56
|
+
|
57
|
+
it "identifies a state as a class starting with `&.js-`" do
|
58
|
+
target_name = "js-active"
|
59
|
+
name, type = subject.symbol_details_from_first_line("&.#{target_name} {").values
|
60
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
61
|
+
expect(name).to eq target_name
|
62
|
+
end
|
63
|
+
|
64
|
+
it "identifies a state as a class containing `--js-`" do
|
65
|
+
target_name = "tab-list__tab--js-active"
|
66
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
|
67
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
68
|
+
expect(name).to eq target_name
|
69
|
+
end
|
70
|
+
|
71
|
+
it "identifies a state as a class starting with `&--js-`" do
|
72
|
+
target_name = "--js-active"
|
73
|
+
name, type = subject.symbol_details_from_first_line("&#{target_name} {").values
|
74
|
+
expect(type).to eq Docks::Types::Symbol::STATE
|
75
|
+
expect(name).to eq target_name
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "variants" do
|
80
|
+
it "identifies a variant as a class containing `--`" do
|
81
|
+
target_name = "tab-list__tab--large"
|
82
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} {").values
|
83
|
+
expect(type).to eq Docks::Types::Symbol::VARIANT
|
84
|
+
expect(name).to eq target_name
|
85
|
+
end
|
86
|
+
|
87
|
+
it "identifies a variant as a class starting with `&--`" do
|
88
|
+
target_name = "--large"
|
89
|
+
name, type = subject.symbol_details_from_first_line("&#{target_name} {").values
|
90
|
+
expect(type).to eq Docks::Types::Symbol::VARIANT
|
91
|
+
expect(name).to eq target_name
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "component" do
|
96
|
+
it "identifies a component as any class not matching state/ variant" do
|
97
|
+
target_name = "tab-list__tab"
|
98
|
+
name, type = subject.symbol_details_from_first_line(".#{target_name} { flex: 1 1 0; }").values
|
99
|
+
expect(type).to eq Docks::Types::Symbol::COMPONENT
|
100
|
+
expect(name).to eq target_name
|
101
|
+
end
|
102
|
+
|
103
|
+
it "identifies a component as a class starting with `&__`" do
|
104
|
+
target_name = "__tab"
|
105
|
+
name, type = subject.symbol_details_from_first_line("&#{target_name} { flex: 1 1 0; }").values
|
106
|
+
expect(type).to eq Docks::Types::Symbol::COMPONENT
|
107
|
+
expect(name).to eq target_name
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|