docks_app 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,20 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::Tags::Type do
|
|
4
|
+
subject { Docks::Tags::Type.instance }
|
|
5
|
+
|
|
6
|
+
it "does not allow multiline content" do
|
|
7
|
+
expect(subject.multiline?).to be false
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "only allows one tag per block" do
|
|
11
|
+
expect(subject.multiple_allowed?).to be false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "#process" do
|
|
15
|
+
it "does not perform any processing" do
|
|
16
|
+
content = "foo"
|
|
17
|
+
expect(subject.process(content)).to eq content
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::Tags::Value do
|
|
4
|
+
subject { Docks::Tags::Value.instance }
|
|
5
|
+
|
|
6
|
+
it "does not allow multiline content" do
|
|
7
|
+
expect(subject.multiline?).to be false
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "only allows one tag per block" do
|
|
11
|
+
expect(subject.multiple_allowed?).to be false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe "#process" do
|
|
15
|
+
it "does not perform any processing" do
|
|
16
|
+
content = "foo"
|
|
17
|
+
expect(subject.process(content)).to eq content
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::Tags::Variant do
|
|
4
|
+
subject { Docks::Tags::Variant.instance }
|
|
5
|
+
|
|
6
|
+
it "allows multiline content" do
|
|
7
|
+
expect(subject.multiline?).to be true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "allows multiple tags per block" do
|
|
11
|
+
expect(subject.multiple_allowed?).to be true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::Tags::Variation do
|
|
4
|
+
subject { described_class.instance }
|
|
5
|
+
|
|
6
|
+
it "can't be be parsed from files" do
|
|
7
|
+
expect(subject.parseable?).to be false
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "post process" do
|
|
11
|
+
before(:each) { Docks::Tags.register_bundled_tags }
|
|
12
|
+
|
|
13
|
+
describe "joining variations to their components" do
|
|
14
|
+
let(:pattern) { Docks::Containers::Pattern.new(name: "foo") }
|
|
15
|
+
let(:subcomponent) { Docks::Containers::Component.new(name: "foo__bar") }
|
|
16
|
+
let(:component) { Docks::Containers::Component.new(name: "foo", subcomponents: [subcomponent]) }
|
|
17
|
+
let(:state) { Docks::Containers::State.new(name: "foo--is-bar") }
|
|
18
|
+
let(:subcomponent_variant) { Docks::Containers::Variant.new(name: "foo__bar--baz") }
|
|
19
|
+
|
|
20
|
+
it "joins orphan variations to their component" do
|
|
21
|
+
pattern.add(:style, [state, component])
|
|
22
|
+
Docks::Process.process(pattern)
|
|
23
|
+
|
|
24
|
+
expect(pattern.style_symbols.length).to be 1
|
|
25
|
+
expect(pattern.components.length).to be 1
|
|
26
|
+
expect(pattern.components.first).to be component
|
|
27
|
+
expect(pattern.components.first.states.length).to be 1
|
|
28
|
+
expect(pattern.components.first.states.first).to be state
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "joins orphan variations to subcomponents" do
|
|
32
|
+
pattern.add(:style, [component, subcomponent_variant])
|
|
33
|
+
Docks::Process.process(pattern)
|
|
34
|
+
|
|
35
|
+
expect(pattern.style_symbols.length).to be 1
|
|
36
|
+
expect(pattern.components.length).to be 1
|
|
37
|
+
|
|
38
|
+
the_component = pattern.components.first
|
|
39
|
+
the_subcomponent = component.subcomponents.first
|
|
40
|
+
|
|
41
|
+
expect(the_component.variants).to be_empty
|
|
42
|
+
expect(the_subcomponent.variants.length).to be 1
|
|
43
|
+
expect(the_subcomponent.variants.first).to be subcomponent_variant
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "creates components for the variation if they don't exist" do
|
|
47
|
+
pattern.add(:style, [subcomponent_variant])
|
|
48
|
+
Docks::Process.process(pattern)
|
|
49
|
+
|
|
50
|
+
expect(pattern.style_symbols.length).to be 1
|
|
51
|
+
expect(pattern.components.length).to be 1
|
|
52
|
+
|
|
53
|
+
component = pattern.find(Docks::NamingConventions::BEM.instance.component(subcomponent_variant.name))
|
|
54
|
+
expect(component.variants.length).to be 1
|
|
55
|
+
expect(component.variants.first).to be subcomponent_variant
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "clean up names" do
|
|
60
|
+
let(:pattern) { Docks::Containers::Pattern.new(name: "foo") }
|
|
61
|
+
let(:variation) { Docks::Containers::State.new(name: "foo--is-bar", activate_with: ["--baz", "foo--fuzz"], precludes: "--qux") }
|
|
62
|
+
let(:bad_name_variation) { Docks::Containers::Variant.new(name: "--baz") }
|
|
63
|
+
|
|
64
|
+
let(:subcomponent) { Docks::Containers::Component.new(name: "foo__bar", variants: [bad_name_variation]) }
|
|
65
|
+
let(:component) { Docks::Containers::Component.new(name: "foo", states: [variation], subcomponents: [subcomponent]) }
|
|
66
|
+
|
|
67
|
+
before(:each) do
|
|
68
|
+
pattern.add(:style, component)
|
|
69
|
+
Docks::Process.process(pattern)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "prepends the names of variations with the base class if necessary" do
|
|
73
|
+
expect(variation.name).to eq "foo--is-bar"
|
|
74
|
+
expect(bad_name_variation.name).to eq "foo__bar--baz"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "prepends the names of active withs and precludes" do
|
|
78
|
+
expect(variation.activate_with.first).to eq "foo--baz"
|
|
79
|
+
expect(variation.activate_with.last).to eq "foo--fuzz"
|
|
80
|
+
expect(variation.precludes.first).to eq "foo--qux"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "mirroring preclusions" do
|
|
85
|
+
let(:state_one) { Docks::Containers::State.new(name: "tab--is-active") }
|
|
86
|
+
let(:state_two) { Docks::Containers::State.new(name: "tab--is-inactive", precludes: [state_one.name]) }
|
|
87
|
+
let(:variant_one) { Docks::Containers::Variant.new(name: "tab--large", precludes: [state_two.name]) }
|
|
88
|
+
let(:subcomponent_variant) { Docks::Containers::Variant.new(name: "tab__text--subdued") }
|
|
89
|
+
let(:subcomponent_state) { Docks::Containers::State.new(name: "tab__text--is-blinking", precludes: [subcomponent_variant.name]) }
|
|
90
|
+
let(:subcomponent) { Docks::Containers::Component.new(name: "tab__text") }
|
|
91
|
+
let(:component) { Docks::Containers::Component.new(name: "tab", subcomponents: [subcomponent]) }
|
|
92
|
+
|
|
93
|
+
let(:pattern) do
|
|
94
|
+
pattern = Docks::Containers::Pattern.new(name: "tab")
|
|
95
|
+
pattern.add(:style, component)
|
|
96
|
+
pattern
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "mirrors a single preclusion to the precluded state/ variant" do
|
|
100
|
+
component.states << state_one
|
|
101
|
+
component.states << state_two
|
|
102
|
+
component.variants << variant_one
|
|
103
|
+
post_process
|
|
104
|
+
|
|
105
|
+
expect(state_one.precludes.length).to be 1
|
|
106
|
+
expect(state_one.precludes).to include state_two.name
|
|
107
|
+
|
|
108
|
+
expect(state_two.precludes.length).to be 2
|
|
109
|
+
expect(state_two.precludes).to include variant_one.name
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "does not mirror a preclusion if the class is already included" do
|
|
113
|
+
state_one.precludes << state_two.name
|
|
114
|
+
component.states << state_one
|
|
115
|
+
component.states << state_two
|
|
116
|
+
post_process
|
|
117
|
+
|
|
118
|
+
expect(state_one.precludes.length).to be 1
|
|
119
|
+
expect(state_one.precludes).to include state_two.name
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "mirrors preclusions to multiple states/ variants" do
|
|
123
|
+
variant_one.precludes << state_one.name
|
|
124
|
+
component.states << state_one
|
|
125
|
+
component.states << state_two
|
|
126
|
+
component.variants << variant_one
|
|
127
|
+
post_process
|
|
128
|
+
|
|
129
|
+
expect(state_one.precludes.length).to be 2
|
|
130
|
+
expect(state_one.precludes).to include variant_one.name
|
|
131
|
+
|
|
132
|
+
expect(state_two.precludes.length).to be 2
|
|
133
|
+
expect(state_one.precludes).to include variant_one.name
|
|
134
|
+
|
|
135
|
+
expect(variant_one.precludes.length).to be 2
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "mirror preclusions in subcomponents" do
|
|
139
|
+
subcomponent.states << subcomponent_state
|
|
140
|
+
subcomponent.variants << subcomponent_variant
|
|
141
|
+
post_process
|
|
142
|
+
|
|
143
|
+
expect(subcomponent_variant.precludes.length).to be 1
|
|
144
|
+
expect(subcomponent_variant.precludes).to include subcomponent_state.name
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
private
|
|
148
|
+
|
|
149
|
+
def post_process
|
|
150
|
+
Docks::Process.process(pattern)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
class Example1 < Docks::Tags::Base
|
|
4
|
+
def initialize
|
|
5
|
+
@name = :name
|
|
6
|
+
@synonyms = [:nom, :nome]
|
|
7
|
+
@multiple_allowed = true
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Example2 < Docks::Tags::Base
|
|
12
|
+
def initialize
|
|
13
|
+
@name = :title
|
|
14
|
+
@synonyms = [:titre]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class Example3 < Docks::Tags::Base
|
|
19
|
+
def initialize
|
|
20
|
+
@name = :group
|
|
21
|
+
@parseable = false
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe Docks::Tags do
|
|
26
|
+
subject { Docks::Tags }
|
|
27
|
+
|
|
28
|
+
let(:example) { Example1.instance }
|
|
29
|
+
|
|
30
|
+
before :each do
|
|
31
|
+
subject.send(:clean)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe ".tag_for" do
|
|
35
|
+
before :each do
|
|
36
|
+
subject.register(Example1)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "returns an instance of the tag class in response to the base tag name" do
|
|
40
|
+
expect(subject.tag_for(example.name)).to be_an Example1
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "returns an instance of the tag class in response to a synonym" do
|
|
44
|
+
example.synonyms.each do |synonym|
|
|
45
|
+
expect(subject.tag_for(synonym)).to be_an Example1
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "returns nil in response to an unregistered tag name" do
|
|
50
|
+
expect(subject.tag_for(:foo)).to be nil
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe ".base_tag_name" do
|
|
55
|
+
before :each do
|
|
56
|
+
subject.register(Example1)
|
|
57
|
+
subject.register(Example2)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "returns the passed name if it is a base tag name" do
|
|
61
|
+
expect(subject.base_tag_name(example.name)).to be example.name
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "returns the base tag name for a synonym" do
|
|
65
|
+
expect(subject.base_tag_name(example.synonyms.first)).to be example.name
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "returns nil if the tag is not registered" do
|
|
69
|
+
expect(subject.base_tag_name(:foo)).to be nil
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "returns the name if the tag class is passed" do
|
|
73
|
+
expect(subject.base_tag_name(example)).to be example.name
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "returns the singularized name if the tag allows multiple" do
|
|
77
|
+
expect(subject.base_tag_name(example)).to be example.name
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "returns nil for a pluralized name with multiples prevented" do
|
|
81
|
+
expect(subject.base_tag_name(Example2.instance.name.to_s.pluralize)).to be nil
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "returns the singularized name of a pluralized synonym" do
|
|
85
|
+
expect(subject.base_tag_name(example.synonyms.first.to_s.pluralize)).to be example.name
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "doesn't return anything for the pluralized name of a synonym for a tag that has no multiples" do
|
|
89
|
+
expect(subject.base_tag_name(Example2.instance.synonyms.first.to_s.pluralize)).to be nil
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
describe ".supported_tags" do
|
|
94
|
+
it "lists all supported tags, including synonyms and plurals" do
|
|
95
|
+
expect(subject.supported_tags).to eq []
|
|
96
|
+
|
|
97
|
+
tags = [Example1, Example2, Example3]
|
|
98
|
+
tags.each { |tag| subject.register(tag) }
|
|
99
|
+
|
|
100
|
+
supported_tags = subject.supported_tags
|
|
101
|
+
|
|
102
|
+
tags.each do |tag|
|
|
103
|
+
tag = tag.instance
|
|
104
|
+
expect(supported_tags).to include tag.name
|
|
105
|
+
expect(supported_tags.include?(tag.name.to_s.pluralize.to_sym)).to be tag.multiple_allowed?
|
|
106
|
+
|
|
107
|
+
tag.synonyms.each do |synonym|
|
|
108
|
+
expect(supported_tags).to include synonym
|
|
109
|
+
expect(supported_tags.include?(synonym.to_s.pluralize.to_sym)).to be tag.multiple_allowed?
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
describe ".supported_parseable_tags" do
|
|
116
|
+
it "lists only tags that are parseable" do
|
|
117
|
+
expect(subject.supported_parseable_tags).to eq []
|
|
118
|
+
|
|
119
|
+
[Example1, Example2, Example3].each { |tag| subject.register(tag) }
|
|
120
|
+
|
|
121
|
+
supported_tags = subject.supported_parseable_tags
|
|
122
|
+
|
|
123
|
+
[Example1, Example2].each do |tag|
|
|
124
|
+
tag = tag.instance
|
|
125
|
+
expect(supported_tags).to include tag.name
|
|
126
|
+
expect(supported_tags.include?(tag.name.to_s.pluralize.to_sym)).to be tag.multiple_allowed?
|
|
127
|
+
|
|
128
|
+
tag.synonyms.each do |synonym|
|
|
129
|
+
expect(supported_tags).to include synonym
|
|
130
|
+
expect(supported_tags.include?(synonym.to_s.pluralize.to_sym)).to be tag.multiple_allowed?
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
tag = Example3.instance
|
|
135
|
+
|
|
136
|
+
expect(supported_tags).not_to include tag.name
|
|
137
|
+
expect(supported_tags).not_to include tag.name.to_s.pluralize.to_sym
|
|
138
|
+
|
|
139
|
+
tag.synonyms.each do |synonym|
|
|
140
|
+
expect(supported_tags).not_to include synonym.name
|
|
141
|
+
expect(supported_tags).not_to include synonym.name.to_s.pluralize.to_sym
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe ".register_bundled_tags" do
|
|
147
|
+
it "registers all bundled tags" do
|
|
148
|
+
subject.register_bundled_tags
|
|
149
|
+
supported_tags = subject.supported_tags
|
|
150
|
+
|
|
151
|
+
bundled = Docks::Tags.constants.select do |const|
|
|
152
|
+
klass = Docks::Tags.const_get(const)
|
|
153
|
+
Class === klass && !(klass.eql?(Docks::Tags::Base))
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
bundled.each do |bundled_tag|
|
|
157
|
+
bundled_tag = Docks::Tags.const_get(bundled_tag).instance
|
|
158
|
+
[bundled_tag.name, bundled_tag.synonyms].flatten.each do |name|
|
|
159
|
+
expect(supported_tags).to include bundled_tag.name
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
describe ".join_synonymous_tags" do
|
|
166
|
+
let(:value) { "foo" }
|
|
167
|
+
let(:example_hash) { Hash.new }
|
|
168
|
+
let(:target_hash) { Hash.new }
|
|
169
|
+
|
|
170
|
+
before :each do
|
|
171
|
+
subject.register(Example1)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "leaves hashes with keys based on the base tag name alone" do
|
|
175
|
+
example_hash[example.name] = value
|
|
176
|
+
expect(subject.join_synonymous_tags(example_hash)).to eq example_hash
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it "renames a synonym hash with its base tag name" do
|
|
180
|
+
example_hash[example.synonyms.first] = value
|
|
181
|
+
target_hash[example.name] = value
|
|
182
|
+
expect(subject.join_synonymous_tags(example_hash)).to eq target_hash
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it "renames a pluralized tag to its base tag name" do
|
|
186
|
+
example_hash[example.name.to_s.pluralize.to_sym] = value
|
|
187
|
+
target_hash[example.name] = value
|
|
188
|
+
expect(subject.join_synonymous_tags(example_hash)).to eq target_hash
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "joins together results of a synonym with results of the base tag name" do
|
|
192
|
+
example_hash[example.name] = [-1]
|
|
193
|
+
example.synonyms.each_with_index do |synonym, index|
|
|
194
|
+
example_hash[synonym] = [index]
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
target_hash[example.name] = (-1...example.synonyms.length).to_a
|
|
198
|
+
expect(subject.join_synonymous_tags(example_hash)).to eq target_hash
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it "removes results for unrecognized tags" do
|
|
202
|
+
example_hash[:foo] = "bar"
|
|
203
|
+
expect(subject.join_synonymous_tags(example_hash)).to eq Hash.new
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
describe ".has_tag?" do
|
|
208
|
+
it "indicates that no tag exists when not previously registered" do
|
|
209
|
+
expect(subject.has_tag?(example.name)).to be false
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "indicates the presence of a tag that has been registered by its name" do
|
|
213
|
+
subject.register(Example1)
|
|
214
|
+
expect(subject.has_tag?(example.name)).to be true
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it "indicates the presence of a tag that has been registered by its class" do
|
|
218
|
+
subject.register(Example1)
|
|
219
|
+
expect(subject.has_tag?(Example1)).to be true
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
describe ".register" do
|
|
224
|
+
it "registers a tag" do
|
|
225
|
+
subject.register(Example1)
|
|
226
|
+
|
|
227
|
+
expect(subject.has_tag?(example.name)).to be true
|
|
228
|
+
expect(subject.supported_tags).to include example.name
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
it "registers synonyms" do
|
|
232
|
+
subject.register(Example1)
|
|
233
|
+
|
|
234
|
+
example.synonyms.each do |synonym|
|
|
235
|
+
expect(subject.has_tag?(synonym)).to be true
|
|
236
|
+
expect(subject.supported_tags).to include synonym
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "registers synonyms to their respective base tag" do
|
|
241
|
+
subject.register(Example1)
|
|
242
|
+
subject.register(Example2)
|
|
243
|
+
|
|
244
|
+
example.synonyms.each do |synonym|
|
|
245
|
+
expect(subject.tag_for(synonym)).to be example
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
example2 = Example2.instance
|
|
249
|
+
example2.synonyms.each do |synonym|
|
|
250
|
+
expect(subject.tag_for(synonym)).to be example2
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
it "allows the tag to setup its post processing" do
|
|
255
|
+
expect(Example1.instance).to receive(:setup_post_processors)
|
|
256
|
+
subject.register(Example1)
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "is aliased to <<" do
|
|
260
|
+
expect(subject).to receive(:register).with Example1
|
|
261
|
+
subject << Example1
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
end
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::Templates do
|
|
4
|
+
subject { Docks::Templates }
|
|
5
|
+
|
|
6
|
+
after :each do
|
|
7
|
+
subject.send(:clean)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe ".register" do
|
|
11
|
+
let(:templates) do
|
|
12
|
+
{ "foo" => "bar", "bar" => "baz" }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "calls the private hash registering method when the first argument is a hash" do
|
|
16
|
+
expect(subject).to receive(:register_from_hash).with(templates)
|
|
17
|
+
subject.register(templates)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "registers each template for a pattern matching the passed key" do
|
|
21
|
+
templates.each do |match, template|
|
|
22
|
+
expect(subject).to receive(:register).with(template, for: Regexp.new(match.to_s))
|
|
23
|
+
end
|
|
24
|
+
subject.send(:register_from_hash, templates)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "registers a template with the fallback or default key as the fallback template" do
|
|
28
|
+
templates["default"] = "default"
|
|
29
|
+
expect(subject).to receive(:fallback=).with(templates["default"])
|
|
30
|
+
expect(subject).not_to receive(:register).with(templates["default"], for: Regexp.new("default"))
|
|
31
|
+
subject.send(:register_from_hash, templates)
|
|
32
|
+
|
|
33
|
+
templates["fallback"] = "default"
|
|
34
|
+
expect(subject).to receive(:fallback=).with(templates["fallback"])
|
|
35
|
+
subject.send(:register_from_hash, templates)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "registers a template with the :demo key as the demo template" do
|
|
39
|
+
templates["demo"] = "my-custom-demo"
|
|
40
|
+
expect(subject).to receive(:demo=).with(templates["demo"])
|
|
41
|
+
expect(subject).not_to receive(:register).with(templates["demo"], for: Regexp.new("demo"))
|
|
42
|
+
subject.send(:register_from_hash, templates)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe ".template_for" do
|
|
47
|
+
context "when no template matches" do
|
|
48
|
+
it "provides the default template when no other template matches" do
|
|
49
|
+
expect(subject.template_for("foo")).to be subject.fallback
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "allows setting a custom default template" do
|
|
53
|
+
template = "custom_default"
|
|
54
|
+
|
|
55
|
+
subject.fallback = template
|
|
56
|
+
expect(subject.template_for("foo").path).to eq template
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "returns a template whose :matches matches the passed ID" do
|
|
61
|
+
template = "custom_template"
|
|
62
|
+
subject.register(template, matches: /foo/)
|
|
63
|
+
expect(subject.template_for("foo").path).to eq template
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "returns a template whose :for matches the passed ID" do
|
|
67
|
+
template = "custom_template"
|
|
68
|
+
subject.register(template, for: /bar/)
|
|
69
|
+
expect(subject.template_for("bar").path).to eq template
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "returns a template matching the name of a passed pattern" do
|
|
73
|
+
template = "custom_template"
|
|
74
|
+
subject.register(template, for: /bar/)
|
|
75
|
+
expect(subject.template_for(Docks::Containers::Pattern.new(name: "bar")).path).to eq template
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "returns the last template matching the passed ID" do
|
|
79
|
+
subject.register("template_1", for: /bar/)
|
|
80
|
+
subject.register("template_2", for: /bar/)
|
|
81
|
+
expect(subject.template_for("bar").path).to eq "template_2"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "throws an error when no template matches the path" do
|
|
85
|
+
expect { subject.search_for_template("fuzz") }.to raise_error Docks::NoTemplateError
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "throws an error with customized messaging for partials, layouts, and normal templates" do
|
|
89
|
+
expect { subject.search_for_template("fuzz") }.to raise_error %r{No template matching}
|
|
90
|
+
expect { subject.search_for_template("fuzz", must_be: :layout) }.to raise_error %r{No layout matching}
|
|
91
|
+
expect { subject.search_for_template("fuzz", must_be: :partial) }.to raise_error %r{No partial matching}
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe ".default_layout=" do
|
|
96
|
+
it "has the correct default layout" do
|
|
97
|
+
expect(subject.fallback.layout).to eq "pattern"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "uses the passed default layout" do
|
|
101
|
+
layout = "my_layout"
|
|
102
|
+
subject.default_layout = layout
|
|
103
|
+
subject.register("no_layout", matches: /no_layout/)
|
|
104
|
+
subject.register("with_layout", matches: /with_layout/, layout: "custom_layout")
|
|
105
|
+
|
|
106
|
+
expect(subject.fallback.layout).to eq layout
|
|
107
|
+
expect(subject.template_for("no_layout").layout).to eq layout
|
|
108
|
+
expect(subject.template_for("with_layout").layout).not_to eq layout
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe ".demo=" do
|
|
113
|
+
it "saves the passed template as the demo template" do
|
|
114
|
+
demo = "custom_demo"
|
|
115
|
+
subject.demo = demo
|
|
116
|
+
expect(subject.demo.path).to eq demo
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "uses the default demo layout when none is passed" do
|
|
120
|
+
demo = "custom_demo"
|
|
121
|
+
subject.demo = demo
|
|
122
|
+
expect(subject.demo.layout).to eq "demo"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "uses the passed demo layout" do
|
|
126
|
+
demo_layout = "custom_demo_layout"
|
|
127
|
+
subject.demo = Docks::Templates::Template.new("custom_demo", layout: demo_layout)
|
|
128
|
+
expect(subject.demo.layout).to eq demo_layout
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe ".search_for_template" do
|
|
133
|
+
it "does nothing when a non-string argument is passed" do
|
|
134
|
+
expect(subject.search_for_template(false)).to be nil
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
describe ".last_template_update" do
|
|
139
|
+
before(:each) do
|
|
140
|
+
Docks.configure_with(root: File.expand_path("../../fixtures/renderers", __FILE__), templates: "templates")
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "returns the date of the most recently modified template" do
|
|
144
|
+
templates = Dir[Docks.config.templates + "**/*.*"]
|
|
145
|
+
FileUtils.touch(templates.first)
|
|
146
|
+
expect(subject.last_template_update).to eq File.mtime(templates.first)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
describe Docks::Templates::Template do
|
|
152
|
+
subject { Docks::Templates::Template }
|
|
153
|
+
|
|
154
|
+
describe "#path" do
|
|
155
|
+
it "uses the passed template as the path" do
|
|
156
|
+
path = "path/to/template"
|
|
157
|
+
expect(subject.new(path).path).to eq path
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
describe "#layout" do
|
|
162
|
+
it "uses the layout from the constructor as the layout" do
|
|
163
|
+
layout = "my_layout"
|
|
164
|
+
expect(subject.new("path", layout: layout).layout).to eq layout
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "uses the default layout when none is provided in the constructor" do
|
|
168
|
+
expect(subject.new("path").layout).to eq Docks::Templates.default_layout
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
describe "#matches?" do
|
|
173
|
+
it "uses the :matches key from the passed option" do
|
|
174
|
+
template = subject.new("path", matches: /foo/)
|
|
175
|
+
expect(template.matches?("foo")).to be true
|
|
176
|
+
expect(template.matches?("bar")).to be false
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it "uses the :for key from the passed option" do
|
|
180
|
+
template = subject.new("path", for: /foo/)
|
|
181
|
+
expect(template.matches?("foo")).to be true
|
|
182
|
+
expect(template.matches?("bar")).to be false
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::Themes do
|
|
4
|
+
subject { described_class }
|
|
5
|
+
let(:theme) { described_class::API }
|
|
6
|
+
|
|
7
|
+
describe ".for" do
|
|
8
|
+
it "gets the theme from a string" do
|
|
9
|
+
expect(described_class.for("API")).to be_a theme
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "gets the theme from a symbol" do
|
|
13
|
+
expect(described_class.for(:API)).to be_a theme
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "gets the theme from a class" do
|
|
17
|
+
expect(described_class.for(theme)).to be_a theme
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "gets the theme from an instance" do
|
|
21
|
+
expect(described_class.for(theme.instance)).to be_a theme
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "sets the theme to be false if it can't be required" do
|
|
25
|
+
expect(described_class.for(:FOO)).to be false
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "doesn't throw an error when it fails" do
|
|
29
|
+
expect { described_class.for(:FOO) }.not_to raise_error
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|