archetype 0.0.1.pre.13 → 1.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +97 -24
- data/README.md +11 -5
- data/VERSION +1 -0
- data/lib/archetype.rb +30 -18
- data/lib/archetype/actions/migrate.rb +152 -0
- data/lib/archetype/actions/theme.rb +6 -7
- data/lib/archetype/executor.rb +21 -7
- data/lib/archetype/extensions.rb +57 -0
- data/lib/archetype/functions.rb +2 -3
- data/lib/archetype/functions/css.rb +70 -0
- data/lib/archetype/functions/css/constants.rb +247 -0
- data/lib/archetype/functions/css/helpers.rb +265 -0
- data/lib/archetype/functions/css/routers.rb +28 -0
- data/lib/archetype/functions/css/routers/animation.rb +55 -0
- data/lib/archetype/functions/css/routers/background.rb +38 -0
- data/lib/archetype/functions/css/routers/border.rb +151 -0
- data/lib/archetype/functions/css/routers/list.rb +63 -0
- data/lib/archetype/functions/css/routers/margin_padding.rb +40 -0
- data/lib/archetype/functions/css/routers/outline.rb +56 -0
- data/lib/archetype/functions/css/routers/overflow.rb +11 -0
- data/lib/archetype/functions/css/routers/target.rb +38 -0
- data/lib/archetype/functions/css/routers/transition.rb +48 -0
- data/lib/archetype/functions/css/shorthands.rb +43 -0
- data/lib/archetype/functions/css/shorthands/animation.rb +18 -0
- data/lib/archetype/functions/css/shorthands/background.rb +68 -0
- data/lib/archetype/functions/css/shorthands/border.rb +102 -0
- data/lib/archetype/functions/hash.rb +3 -149
- data/lib/archetype/functions/hash/extend.rb +74 -0
- data/lib/archetype/functions/hash/shim.rb +48 -0
- data/lib/archetype/functions/helpers.rb +231 -22
- data/lib/archetype/functions/styleguide_memoizer.rb +18 -1
- data/lib/archetype/sass_extensions.rb +1 -3
- data/lib/archetype/sass_extensions/functions.rb +15 -1
- data/lib/archetype/sass_extensions/functions/environment.rb +152 -1
- data/lib/archetype/sass_extensions/functions/lists.rb +95 -45
- data/lib/archetype/sass_extensions/functions/locale.rb +107 -28
- data/lib/archetype/sass_extensions/functions/numbers.rb +118 -4
- data/lib/archetype/sass_extensions/functions/strings.rb +53 -0
- data/lib/archetype/sass_extensions/functions/styleguide.rb +43 -375
- data/lib/archetype/sass_extensions/functions/styleguide/components.rb +25 -0
- data/lib/archetype/sass_extensions/functions/styleguide/constants.rb +27 -0
- data/lib/archetype/sass_extensions/functions/styleguide/grammar.rb +80 -0
- data/lib/archetype/sass_extensions/functions/styleguide/helpers.rb +36 -0
- data/lib/archetype/sass_extensions/functions/styleguide/resolve.rb +159 -0
- data/lib/archetype/sass_extensions/functions/styleguide/styles.rb +146 -0
- data/lib/archetype/sass_extensions/functions/styleguide/themes.rb +40 -0
- data/lib/archetype/sass_extensions/functions/ui.rb +7 -57
- data/lib/archetype/sass_extensions/functions/ui/glyphs.rb +118 -0
- data/lib/archetype/sass_extensions/functions/ui/scopes.rb +96 -0
- data/lib/archetype/sass_extensions/functions/util.rb +14 -0
- data/lib/archetype/sass_extensions/functions/util/debug.rb +22 -0
- data/lib/archetype/sass_extensions/functions/util/hacks.rb +44 -0
- data/lib/archetype/sass_extensions/functions/util/images.rb +132 -0
- data/lib/archetype/sass_extensions/functions/util/misc.rb +220 -0
- data/lib/archetype/sass_extensions/functions/util/spacing.rb +83 -0
- data/lib/archetype/sass_extensions/functions/version.rb +12 -17
- data/lib/archetype/version.rb +1 -1
- data/stylesheets/archetype/_config.scss +1 -389
- data/stylesheets/archetype/_core.scss +15 -0
- data/stylesheets/archetype/_hacks.scss +4 -120
- data/stylesheets/archetype/_init.scss +4 -22
- data/stylesheets/archetype/_required.scss +3 -0
- data/stylesheets/archetype/_reset.scss +3 -0
- data/stylesheets/archetype/_styleguide.scss +2 -6
- data/stylesheets/archetype/_ui.scss +2 -358
- data/stylesheets/archetype/_util.scss +3 -10
- data/stylesheets/archetype/config/_core.scss +14 -0
- data/stylesheets/archetype/config/_environment.scss +19 -0
- data/stylesheets/archetype/config/_formatting.scss +63 -0
- data/stylesheets/archetype/config/_glyphs.scss +252 -0
- data/stylesheets/archetype/config/_resets.scss +7 -0
- data/stylesheets/archetype/config/_resolution.scss +3 -0
- data/stylesheets/archetype/config/_spacing.scss +5 -0
- data/stylesheets/archetype/config/_targeting.scss +18 -0
- data/stylesheets/archetype/config/_theme.scss +3 -0
- data/stylesheets/archetype/config/_typography.scss +56 -0
- data/stylesheets/archetype/config/_units.scss +2 -0
- data/stylesheets/archetype/config/_vars.scss +10 -0
- data/stylesheets/archetype/hacks/_core.scss +4 -0
- data/stylesheets/archetype/hacks/_hacks.scss +160 -0
- data/stylesheets/archetype/hacks/_init.scss +2 -0
- data/stylesheets/archetype/styleguide/_core.scss +4 -0
- data/stylesheets/archetype/styleguide/_init.scss +1 -0
- data/stylesheets/archetype/styleguide/_styleguide.scss +41 -18
- data/stylesheets/archetype/ui/_accessibility.scss +41 -0
- data/stylesheets/archetype/ui/_breakpoints.scss +19 -0
- data/stylesheets/archetype/ui/_core.scss +10 -0
- data/stylesheets/archetype/ui/_elements.scss +98 -0
- data/stylesheets/archetype/ui/_glyphs.scss +244 -0
- data/stylesheets/archetype/ui/_init.scss +5 -0
- data/stylesheets/archetype/ui/_layout.scss +37 -0
- data/stylesheets/archetype/ui/_locale.scss +12 -0
- data/stylesheets/archetype/ui/_scopes.scss +42 -0
- data/stylesheets/archetype/util/_core.scss +8 -0
- data/stylesheets/archetype/util/_debug.scss +9 -21
- data/stylesheets/archetype/util/_init.scss +1 -0
- data/stylesheets/archetype/util/_misc.scss +21 -86
- data/stylesheets/archetype/util/_spacing.scss +9 -40
- data/stylesheets/archetype/util/_styles.scss +189 -178
- data/stylesheets/archetype/util/_targeting.scss +51 -68
- data/templates/example/manifest.rb +2 -2
- data/templates/example/screen.scss +0 -1
- data/templates/project/manifest.rb +3 -8
- metadata +93 -263
- data/bin/archetype +0 -3
- data/lib/archetype/sass_extensions/monkey_patches.rb +0 -3
- data/lib/archetype/sass_extensions/monkey_patches/handle_include_loop.rb +0 -13
- data/stylesheets/archetype/_base.scss +0 -54
- data/stylesheets/archetype/_grid.scss +0 -3
- data/stylesheets/archetype/base/_h5bp.scss +0 -307
- data/stylesheets/archetype/base/_hybrid.scss +0 -25
- data/stylesheets/archetype/base/_normalize.scss +0 -634
- data/stylesheets/archetype/base/_reset.scss +0 -72
- data/stylesheets/archetype/grid/_config.scss +0 -14
- data/stylesheets/archetype/grid/_grid.scss +0 -391
- data/stylesheets/archetype/styleguide/_components.scss +0 -25
- data/stylesheets/archetype/styleguide/_helpers.scss +0 -215
- data/stylesheets/archetype/styleguide/_primitives.scss +0 -10
- data/stylesheets/archetype/styleguide/components/_alerts.scss +0 -59
- data/stylesheets/archetype/styleguide/components/_annotations.scss +0 -27
- data/stylesheets/archetype/styleguide/components/_bristol.scss +0 -15
- data/stylesheets/archetype/styleguide/components/_button_groups.scss +0 -47
- data/stylesheets/archetype/styleguide/components/_button_toolbars.scss +0 -17
- data/stylesheets/archetype/styleguide/components/_buttons.scss +0 -339
- data/stylesheets/archetype/styleguide/components/_canvas.scss +0 -15
- data/stylesheets/archetype/styleguide/components/_carets.scss +0 -336
- data/stylesheets/archetype/styleguide/components/_closes.scss +0 -63
- data/stylesheets/archetype/styleguide/components/_container.scss +0 -27
- data/stylesheets/archetype/styleguide/components/_copy.scss +0 -85
- data/stylesheets/archetype/styleguide/components/_flyouts.scss +0 -52
- data/stylesheets/archetype/styleguide/components/_headings.scss +0 -33
- data/stylesheets/archetype/styleguide/components/_headlines.scss +0 -64
- data/stylesheets/archetype/styleguide/components/_hovercards.scss +0 -27
- data/stylesheets/archetype/styleguide/components/_icons.scss +0 -17
- data/stylesheets/archetype/styleguide/components/_identities.scss +0 -34
- data/stylesheets/archetype/styleguide/components/_links.scss +0 -68
- data/stylesheets/archetype/styleguide/components/_loaders.scss +0 -154
- data/stylesheets/archetype/styleguide/components/_menu_items.scss +0 -31
- data/stylesheets/archetype/styleguide/components/_module.scss +0 -15
- data/stylesheets/archetype/styleguide/components/_pullquotes.scss +0 -29
- data/stylesheets/archetype/styleguide/components/_punchcut.scss +0 -18
- data/stylesheets/archetype/styleguide/components/_tooltips.scss +0 -28
- data/stylesheets/archetype/styleguide/primitives/_animations.scss +0 -17
- data/stylesheets/archetype/styleguide/primitives/_dimensions.scss +0 -50
- data/stylesheets/archetype/styleguide/primitives/_glyphs.scss +0 -11
- data/stylesheets/archetype/styleguide/primitives/_misc.scss +0 -8
- data/stylesheets/archetype/styleguide/primitives/_palettes.scss +0 -94
- data/stylesheets/archetype/styleguide/primitives/_shadows.scss +0 -23
- data/stylesheets/archetype/styleguide/primitives/_sprites.scss +0 -46
- data/stylesheets/archetype/styleguide/primitives/_textures.scss +0 -10
- data/stylesheets/archetype/styleguide/primitives/_typography.scss +0 -56
- data/stylesheets/archetype/util/_lists.scss +0 -57
- data/stylesheets/archetype/util/_rtl.scss +0 -279
- data/stylesheets/archetype/util/_units.scss +0 -18
- data/templates/project/screen.scss +0 -1
- data/templates/project/vendor/archetype/animations/loaders/large/large.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/large/large_dark.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/large/large_dark_static.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/large/large_static.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/medium/medium.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/medium/medium_dark.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/medium/medium_dark_static.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/medium/medium_static.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/small/small.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/small/small_dark.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/small/small_dark_static.png +0 -0
- data/templates/project/vendor/archetype/animations/loaders/small/small_static.png +0 -0
- data/templates/project/vendor/archetype/fontawesome-webfont.eot +0 -0
- data/templates/project/vendor/archetype/fontawesome-webfont.svg +0 -255
- data/templates/project/vendor/archetype/fontawesome-webfont.ttf +0 -0
- data/templates/project/vendor/archetype/fontawesome-webfont.woff +0 -0
- data/test/fixtures/stylesheets/archetype/assets/fonts/fontawesome-webfont.eot +0 -0
- data/test/fixtures/stylesheets/archetype/assets/fonts/fontawesome-webfont.svg +0 -255
- data/test/fixtures/stylesheets/archetype/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/test/fixtures/stylesheets/archetype/assets/fonts/fontawesome-webfont.woff +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders-s7889ccc8c1.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/large/large.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/large/large_dark.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/large/large_dark_static.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/large/large_static.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/medium/medium.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/medium/medium_dark.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/medium/medium_dark_static.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/medium/medium_static.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/small/small.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/small/small_dark.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/small/small_dark_static.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/small/small_static.png +0 -0
- data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/sprites/hovercard_tip.png +0 -0
- data/test/fixtures/stylesheets/archetype/config.rb +0 -21
- data/test/fixtures/stylesheets/archetype/source/b.scss +0 -9
- data/test/fixtures/stylesheets/archetype/source/base.scss +0 -3
- data/test/fixtures/stylesheets/archetype/source/hacks/ie_pseudo.scss +0 -13
- data/test/fixtures/stylesheets/archetype/source/hacks/transparent_focusable.scss +0 -5
- data/test/fixtures/stylesheets/archetype/source/locale.scss +0 -43
- data/test/fixtures/stylesheets/archetype/source/styleguide/alerts.scss +0 -21
- data/test/fixtures/stylesheets/archetype/source/styleguide/buttons.scss +0 -18
- data/test/fixtures/stylesheets/archetype/source/styleguide/drop.scss +0 -101
- data/test/fixtures/stylesheets/archetype/source/styleguide/extend.scss +0 -24
- data/test/fixtures/stylesheets/archetype/source/styleguide/fallback_styles.scss +0 -23
- data/test/fixtures/stylesheets/archetype/source/styleguide/invalid_structures.scss +0 -85
- data/test/fixtures/stylesheets/archetype/source/styleguide/multi_value.scss +0 -18
- data/test/fixtures/stylesheets/archetype/source/styleguide/nested_styleguides.scss +0 -40
- data/test/fixtures/stylesheets/archetype/source/styleguide/selective_state.scss +0 -22
- data/test/fixtures/stylesheets/archetype/source/ui/glyph_icon.scss +0 -35
- data/test/fixtures/stylesheets/archetype/source/ui/hide_element.scss +0 -5
- data/test/fixtures/stylesheets/archetype/source/ui/stroke.scss +0 -13
- data/test/fixtures/stylesheets/archetype/source/ui/triangle.scss +0 -13
- data/test/fixtures/stylesheets/archetype/source/utilities/associative.scss +0 -24
- data/test/fixtures/stylesheets/archetype/source/utilities/custom_output_styler.scss +0 -22
- data/test/fixtures/stylesheets/archetype/source/utilities/if-set.scss +0 -16
- data/test/fixtures/stylesheets/archetype/source/utilities/spacing/horizontal-spacing.scss +0 -27
- data/test/fixtures/stylesheets/archetype/source/utilities/spacing/vertical-spacing.scss +0 -27
- data/test/fixtures/stylesheets/archetype/source/utilities/styles/filter.scss +0 -9
- data/test/fixtures/stylesheets/archetype/source/utilities/styles/font-family.scss +0 -9
- data/test/fixtures/stylesheets/archetype/source/utilities/styles/z-index.scss +0 -18
- data/test/fixtures/stylesheets/archetype/source/utilities/targeting/target-browser.scss +0 -77
- data/test/fixtures/stylesheets/archetype/source/utilities/targeting/target-os.scss +0 -42
- data/test/fixtures/stylesheets/archetype/tmp/b.css +0 -14
- data/test/fixtures/stylesheets/archetype/tmp/base.css +0 -349
- data/test/fixtures/stylesheets/archetype/tmp/hacks/ie_pseudo.css +0 -11
- data/test/fixtures/stylesheets/archetype/tmp/hacks/transparent_focusable.css +0 -4
- data/test/fixtures/stylesheets/archetype/tmp/locale.css +0 -23
- data/test/fixtures/stylesheets/archetype/tmp/styleguide/alerts.css +0 -711
- data/test/fixtures/stylesheets/archetype/tmp/styleguide/buttons.css +0 -2119
- data/test/fixtures/stylesheets/archetype/tmp/styleguide/drop.css +0 -63
- data/test/fixtures/stylesheets/archetype/tmp/styleguide/extend.css +0 -11
- data/test/fixtures/stylesheets/archetype/tmp/styleguide/fallback_styles.css +0 -10
- data/test/fixtures/stylesheets/archetype/tmp/styleguide/invalid_structures.css +0 -21
- data/test/fixtures/stylesheets/archetype/tmp/styleguide/multi_value.css +0 -13
- data/test/fixtures/stylesheets/archetype/tmp/styleguide/nested_styleguides.css +0 -28
- data/test/fixtures/stylesheets/archetype/tmp/styleguide/selective_state.css +0 -177
- data/test/fixtures/stylesheets/archetype/tmp/ui/glyph_icon.css +0 -127
- data/test/fixtures/stylesheets/archetype/tmp/ui/hide_element.css +0 -8
- data/test/fixtures/stylesheets/archetype/tmp/ui/stroke.css +0 -17
- data/test/fixtures/stylesheets/archetype/tmp/ui/triangle.css +0 -35
- data/test/fixtures/stylesheets/archetype/tmp/utilities/associative.css +0 -9
- data/test/fixtures/stylesheets/archetype/tmp/utilities/custom_output_styler.css +0 -8
- data/test/fixtures/stylesheets/archetype/tmp/utilities/if-set.css +0 -9
- data/test/fixtures/stylesheets/archetype/tmp/utilities/spacing/horizontal-spacing.css +0 -29
- data/test/fixtures/stylesheets/archetype/tmp/utilities/spacing/vertical-spacing.css +0 -29
- data/test/fixtures/stylesheets/archetype/tmp/utilities/styles/filter.css +0 -11
- data/test/fixtures/stylesheets/archetype/tmp/utilities/styles/font-family.css +0 -16
- data/test/fixtures/stylesheets/archetype/tmp/utilities/styles/z-index.css +0 -15
- data/test/fixtures/stylesheets/archetype/tmp/utilities/targeting/target-browser.css +0 -105
- data/test/fixtures/stylesheets/archetype/tmp/utilities/targeting/target-os.css +0 -55
- data/test/helpers/diff.rb +0 -49
- data/test/helpers/io.rb +0 -36
- data/test/helpers/test_case.rb +0 -62
- data/test/integrations/archetype_test.rb +0 -126
- data/test/test_helper.rb +0 -26
- data/test/units/sass_extensions_test.rb +0 -200
@@ -0,0 +1,25 @@
|
|
1
|
+
module Archetype::SassExtensions::Styleguide
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
#
|
6
|
+
# check whether or not a component (or a component extension) has already been defined
|
7
|
+
#
|
8
|
+
# *Parameters*:
|
9
|
+
# - <tt>id</tt> {String} the component identifier
|
10
|
+
# - <tt>theme</tt> {String} the theme to insert the component into
|
11
|
+
# - <tt>extension</tt> {String} the name of the extension
|
12
|
+
# - <tt>force</tt> {Boolean} if true, forcibly extend the component
|
13
|
+
# *Returns*:
|
14
|
+
# - {Boolean} whether or not the component/extension exists
|
15
|
+
#
|
16
|
+
def component_exists(id, theme = nil, extension = nil, force = false)
|
17
|
+
status = false
|
18
|
+
theme = get_theme(theme) if not theme.is_a? Hash
|
19
|
+
id = helpers.to_str(id)
|
20
|
+
# determine the status of the component
|
21
|
+
status = (extension.nil?) ? (not theme[:components][id].nil?) : theme[:extensions].include?(extension)
|
22
|
+
return (status and not force and Compass.configuration.memoize)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Archetype::SassExtensions::Styleguide
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
# :stopdoc:
|
6
|
+
INHERIT = 'inherit'
|
7
|
+
STYLEGUIDE = 'styleguide'
|
8
|
+
DROP = 'drop'
|
9
|
+
DEFAULT = 'default'
|
10
|
+
REGEX = 'regex'
|
11
|
+
SPECIAL = %w(states selectors)
|
12
|
+
STATES = SPECIAL[0]
|
13
|
+
DROPALL = %w(all true)
|
14
|
+
MESSAGE_PREFIX = "[#{Archetype.name}:{origin}:{phase}] --- `"
|
15
|
+
MESSAGE_SUFFIX = "` ---"
|
16
|
+
# these are unique CSS keys that can be exploited to provide fallback functionality by providing a second value
|
17
|
+
# e.g color: red; color: rgba(255,0,0, 0.8);
|
18
|
+
FALLBACKS = %w(background background-image background-color border border-bottom border-bottom-color border-color border-left border-left-color border-right border-right-color border-top border-top-color clip color layer-background-color outline outline-color white-space extend)
|
19
|
+
# these are mixins that make sense to run multiple times within a block
|
20
|
+
MULTIMIXINS = %w(target-browser)
|
21
|
+
# NOTE: these are no longer used/needed if you're using the map structures
|
22
|
+
ADDITIVES = FALLBACKS + [DROP, INHERIT, STYLEGUIDE] + MULTIMIXINS
|
23
|
+
@@archetype_styleguide_mutex = Mutex.new
|
24
|
+
@@styleguide_themes ||= nil
|
25
|
+
# :startdoc:
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Archetype::SassExtensions::Styleguide
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
#
|
6
|
+
# given a sentence, deconstruct it into it's identifier and verbages
|
7
|
+
#
|
8
|
+
# *Parameters*:
|
9
|
+
# - <tt>sentence</tt> {String|List} the sentence describing the component
|
10
|
+
# - <tt>theme</tt> {String} the theme to use
|
11
|
+
# - <tt>state</tt> {String} the name of a state to return
|
12
|
+
# *Returns*:
|
13
|
+
# - {Array} an array containing the identifer, modifiers, and a token
|
14
|
+
#
|
15
|
+
def grammar(sentence, theme = nil, state = nil)
|
16
|
+
theme = get_theme(theme)
|
17
|
+
components = theme[:components]
|
18
|
+
# get a list of valid ids
|
19
|
+
styleguideIds = components.keys
|
20
|
+
sentence = sentence.split if sentence.is_a? String
|
21
|
+
|
22
|
+
id, modifiers = grammarize(sentence, styleguideIds)
|
23
|
+
|
24
|
+
# if there was no id, return a list of valid IDs for reporting
|
25
|
+
modifiers = styleguideIds if id.nil?
|
26
|
+
# get the list of currenty installed component extensions
|
27
|
+
extensions = theme[:extensions] if not id.nil?
|
28
|
+
# TODO - low - eoneill: make sure we always want to return unique modifiers
|
29
|
+
# i can't think of a case where we wouldn't want to remove dups
|
30
|
+
# maybe in the case where we're looking for strict keys on the lookup?
|
31
|
+
modifiers = modifiers.uniq
|
32
|
+
token = memoizer.tokenize(theme[:name], extensions, id, modifiers, state)
|
33
|
+
return id, modifiers, token
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# given a sentence, convert it to it's internal representation
|
38
|
+
#
|
39
|
+
# *Parameters*:
|
40
|
+
# - <tt>sentence</tt> {Array|List} the sentence describing the component
|
41
|
+
# - <tt>ids</tt> {Array} the list of identifiers
|
42
|
+
# *Returns*:
|
43
|
+
# - {Array} an array containing the identifer and modifiers
|
44
|
+
#
|
45
|
+
def grammarize(sentence, ids = [])
|
46
|
+
sentence = sentence.to_a
|
47
|
+
id = nil
|
48
|
+
modifiers = []
|
49
|
+
if not sentence.empty?
|
50
|
+
prefix = ''
|
51
|
+
order = ''
|
52
|
+
# these define various attributes for modifiers (e.g. `button with a shadow`)
|
53
|
+
extras = %w(on with without)
|
54
|
+
# these are things that are useless to us, so we just leave them out
|
55
|
+
ignore = %w(a an also the this that is was it)
|
56
|
+
# these are our context switches (e.g. `headline in a button`)
|
57
|
+
contexts = %w(in within)
|
58
|
+
sentence.each do |item|
|
59
|
+
item = item.value if not item.is_a?(String)
|
60
|
+
# find the ID
|
61
|
+
if id.nil? and ids.include?(item) and prefix.empty? and order.empty?
|
62
|
+
id = item
|
63
|
+
# if it's a `context`, we need to increase the depth and reset the prefix
|
64
|
+
elsif contexts.include?(item)
|
65
|
+
order = "#{item}-#{order}"
|
66
|
+
prefix = ''
|
67
|
+
# if it's an `extra`, we update the prefix
|
68
|
+
elsif extras.include?(item)
|
69
|
+
prefix = "#{item}-"
|
70
|
+
# finally, check that it's not on the ignore (useless) list. if it is, we just skip over it
|
71
|
+
# (maybe this should be the first thing we check?)
|
72
|
+
elsif not ignore.include?(item)
|
73
|
+
modifiers.push("#{order}#{prefix}#{item}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
return id, modifiers
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Archetype::SassExtensions::Styleguide
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
def memoizer
|
6
|
+
Archetype::Functions::StyleguideMemoizer
|
7
|
+
end
|
8
|
+
|
9
|
+
#
|
10
|
+
# normalize the styleguide definition into a hash representative of the definition
|
11
|
+
#
|
12
|
+
# *Parameters*:
|
13
|
+
# - <tt>definition</tt> {String|List|Hash|Map} the styleguide definition
|
14
|
+
# *Returns*:
|
15
|
+
# - {Hash} the normalized hash representing the styleguide definition
|
16
|
+
#
|
17
|
+
def normalize_styleguide_definition(definition)
|
18
|
+
# if it's not a map, we got a description, which we need to convert
|
19
|
+
definition = get_styles([definition], nil, nil) if not definition.is_a?(Sass::Script::Value::Map)
|
20
|
+
# now convert the map to a hash if needed
|
21
|
+
definition = helpers.data_to_hash(definition) if not definition.is_a?(Hash)
|
22
|
+
definition = resolve_runtime_locale_values(definition)
|
23
|
+
return definition
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.reset!(filename = nil)
|
27
|
+
@@archetype_styleguide_mutex.synchronize do
|
28
|
+
if filename.nil?
|
29
|
+
@@styleguide_themes = {}
|
30
|
+
else
|
31
|
+
(@@styleguide_themes ||= {}).delete(filename.hash)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
module Archetype::SassExtensions::Styleguide
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
#
|
6
|
+
# given two objects, resolve the chain of dropped styles
|
7
|
+
# this runs after having already resolved the dropped styles and merged
|
8
|
+
#
|
9
|
+
# *Parameters*:
|
10
|
+
# - <tt>obj</tt> {Hash} the source object
|
11
|
+
# - <tt>merger</tt> {Hash} the object to be merged in
|
12
|
+
# *Returns*:
|
13
|
+
# - {Array.<Hash>} the resulting `obj` and `merger` objects
|
14
|
+
#
|
15
|
+
def post_resolve_drops(obj, merger)
|
16
|
+
# just return if it's nil
|
17
|
+
return [obj, merger] if helpers.is_value(obj, :nil) or helpers.is_value(merger, :nil)
|
18
|
+
# if it's a Sass::List, this is really an empty hash, so return a new hash
|
19
|
+
return [obj, Archetype::Hash.new] if merger.is_a?(Sass::Script::Value::List)
|
20
|
+
drop = merger[DROP]
|
21
|
+
keys = obj.keys
|
22
|
+
if not drop.nil?
|
23
|
+
drop.to_a.each do |key|
|
24
|
+
key = helpers.to_str(key)
|
25
|
+
obj.delete(key) if not SPECIAL.include?(key)
|
26
|
+
end
|
27
|
+
merger.delete(DROP)
|
28
|
+
end
|
29
|
+
SPECIAL.each do |special|
|
30
|
+
if obj[special].is_a?(Hash) and merger[special].is_a?(Hash)
|
31
|
+
obj[special], merger[special] = post_resolve_drops(obj[special], merger[special])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
return [obj, merger]
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# given two objects, resolve the chain of dropped styles
|
39
|
+
#
|
40
|
+
# *Parameters*:
|
41
|
+
# - <tt>value</tt> {Hash} the source object
|
42
|
+
# - <tt>obj</tt> {Hash} the object to be merged in
|
43
|
+
# - <tt>is_special</tt> {Boolean} whether this is from a SPECIAL branch of a Hash
|
44
|
+
# *Returns*:
|
45
|
+
# - {Array.<Hash>} the resulting value
|
46
|
+
#
|
47
|
+
def resolve_drops(value, obj, is_special = false)
|
48
|
+
return value if not (value.is_a?(Hash) and obj.is_a?(Hash))
|
49
|
+
keys = obj.keys
|
50
|
+
drop = value[DROP]
|
51
|
+
if not drop.nil?
|
52
|
+
tmp = Archetype::Hash.new
|
53
|
+
if DROPALL.include?(helpers.to_str(drop))
|
54
|
+
if not keys.nil?
|
55
|
+
keys.each do |key|
|
56
|
+
special_drop_key(obj, tmp, key)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
else
|
60
|
+
drop.to_a.each do |key|
|
61
|
+
key = helpers.to_str(key)
|
62
|
+
special_drop_key(obj, tmp, key)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
value.delete(DROP) if not is_special
|
66
|
+
value = tmp.rmerge(value)
|
67
|
+
end
|
68
|
+
# suppress warnings from hashery (warning: multiple values for a block parameter (2 for 1))
|
69
|
+
::Sass::Util.silence_warnings do
|
70
|
+
value.each do |key|
|
71
|
+
value[key] = resolve_drops(value[key], obj[key], key, SPECIAL.include?(key)) if not value[key].nil?
|
72
|
+
end
|
73
|
+
end
|
74
|
+
return value
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
#
|
79
|
+
# helper method for resolve_drops
|
80
|
+
#
|
81
|
+
# *Parameters*:
|
82
|
+
# - <tt>obj</tt> {Hash} the object
|
83
|
+
# - <tt>tmp</tt> {Hash} the temporary object
|
84
|
+
# - <tt>key</tt> {String} the key we care about
|
85
|
+
#
|
86
|
+
def special_drop_key(obj, tmp, key)
|
87
|
+
if SPECIAL.include?(key)
|
88
|
+
if not (obj[key].nil? or obj[key].empty?)
|
89
|
+
tmp[key] = Archetype::Hash.new
|
90
|
+
tmp[key][DROP] = obj[key].keys
|
91
|
+
end
|
92
|
+
else
|
93
|
+
tmp[key] = null
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# resolve any dependent references from the component
|
99
|
+
#
|
100
|
+
# *Parameters*:
|
101
|
+
# - <tt>id</tt> {String} the component identifier
|
102
|
+
# - <tt>value</tt> {Hash} the current value
|
103
|
+
# - <tt>theme</tt> {String} the theme to use
|
104
|
+
# - <tt>context</tt> {Hash} the context to work in
|
105
|
+
# - <tt>keys</tt> {Array} list of the external keys
|
106
|
+
# *Returns*:
|
107
|
+
# - {Hash} a hash of the resolved styles
|
108
|
+
#
|
109
|
+
def resolve_dependents(id, value, theme = nil, context = nil, obj = nil)
|
110
|
+
return value if value.nil?
|
111
|
+
# we have to create a clone here as the passed in value is volatile and we're performing destructive changes
|
112
|
+
value = value.clone
|
113
|
+
# check that we're dealing with a hash
|
114
|
+
if value.is_a?(Hash)
|
115
|
+
# check for dropped styles
|
116
|
+
value = resolve_drops(value, obj)
|
117
|
+
|
118
|
+
# check for inheritance
|
119
|
+
inherit = value[INHERIT]
|
120
|
+
if not inherit.nil?
|
121
|
+
if helpers.is_value(inherit, :hashy)
|
122
|
+
inherit = helpers.meta_to_array(inherit)
|
123
|
+
else
|
124
|
+
inherit = [inherit.to_a]
|
125
|
+
end
|
126
|
+
if not inherit.empty?
|
127
|
+
# create a temporary object and extract the nested styles
|
128
|
+
tmp = Archetype::Hash.new
|
129
|
+
inherit.each { |related| tmp = tmp.rmerge(extract_styles(id, related, true, theme, context)) }
|
130
|
+
# remove the inheritance key and update the styles
|
131
|
+
value.delete(INHERIT)
|
132
|
+
inherit = extract_styles(id, inherit, true, theme, context)
|
133
|
+
value = inherit.rmerge(value)
|
134
|
+
value = tmp.rmerge(value)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
# return whatever we got
|
139
|
+
return value
|
140
|
+
end
|
141
|
+
|
142
|
+
#
|
143
|
+
# this helps to resolve any runtime locale values
|
144
|
+
#
|
145
|
+
def resolve_runtime_locale_values(hsh)
|
146
|
+
hsh.each do |key, value|
|
147
|
+
if value.is_a?(Hash)
|
148
|
+
meta = value[helpers::META[:meta]]
|
149
|
+
if meta && (meta.to_h)[helpers::META[:decorators][:runtime_locales]]
|
150
|
+
hsh[key] = get_runtime_locale_value(value)
|
151
|
+
else
|
152
|
+
hsh[key] = resolve_runtime_locale_values(value)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
return hsh
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module Archetype::SassExtensions::Styleguide
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
#
|
6
|
+
# interface for extracting styles in the styleguide references
|
7
|
+
#
|
8
|
+
# *Parameters*:
|
9
|
+
# - <tt>id</tt> {String} the component identifier
|
10
|
+
# - <tt>modifiers</tt> {Array} the component modifiers
|
11
|
+
# - <tt>strict</tt> {Boolean} is it a strict lookup?
|
12
|
+
# - <tt>theme</tt> {String} the theme to use
|
13
|
+
# - <tt>context</tt> {Hash} the context to work in
|
14
|
+
# *Returns*:
|
15
|
+
# - {Hash} a hash of the extracted styles
|
16
|
+
#
|
17
|
+
def extract_styles(id, modifiers, strict = false, theme = nil, context = nil)
|
18
|
+
theme = get_theme(theme)
|
19
|
+
context ||= theme[:components][id] || Archetype::Hash.new
|
20
|
+
modifiers = helpers.to_str(modifiers)
|
21
|
+
return Archetype::Hash.new if helpers.is_value(context, :nil) or context.empty?
|
22
|
+
# push on the defaults first
|
23
|
+
out = (strict ? resolve_dependents(id, context[modifiers], theme[:name], context) : context[DEFAULT]) || Archetype::Hash.new
|
24
|
+
out = out.clone
|
25
|
+
return Archetype::Hash.new if out == null
|
26
|
+
# if it's not strict, find anything that matched
|
27
|
+
if not strict
|
28
|
+
modifiers = modifiers.split
|
29
|
+
context.each do |key, definition|
|
30
|
+
modifier = grammarize(key.split(' '))[1].join(' ')
|
31
|
+
if modifier != DEFAULT
|
32
|
+
match = true
|
33
|
+
modifier = modifier.split
|
34
|
+
if modifier[0] == REGEX
|
35
|
+
# if it's a regex pattern, test if it matches
|
36
|
+
match = modifiers.join(' ') =~ /#{modifier[1].gsub(/\A"|"\Z/, '')}/i
|
37
|
+
else
|
38
|
+
# otherwise, if the modifier isn't in our list of modifiers, it's not valid and just move on
|
39
|
+
modifier.each { |i| match = false if not modifiers.include?(i) }
|
40
|
+
end
|
41
|
+
# if it matched, process it
|
42
|
+
if match
|
43
|
+
tmp = resolve_dependents(id, definition, theme[:name], nil, out)
|
44
|
+
out, tmp = post_resolve_drops(out, tmp)
|
45
|
+
out = out.rmerge(tmp) if not helpers.is_value(tmp, :nil)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
if out.is_a? Hash
|
51
|
+
# recompose the special keys and extract any nested/inherited styles
|
52
|
+
# this lets us define special states and elements
|
53
|
+
SPECIAL.each do |special_key|
|
54
|
+
special = out[special_key] || Archetype::Hash.new
|
55
|
+
if special == null
|
56
|
+
out[special_key] = Archetype::Hash.new
|
57
|
+
else
|
58
|
+
tmp = Archetype::Hash.new
|
59
|
+
special.each { |key, value| tmp[key] = extract_styles(key, key, true, theme[:name], special) }
|
60
|
+
out[special_key] = tmp if not tmp.empty?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# check for nested styleguides
|
65
|
+
styleguide = out[STYLEGUIDE]
|
66
|
+
if not styleguide.nil?
|
67
|
+
if helpers.is_value(styleguide, :hashy)
|
68
|
+
styleguide = helpers.meta_to_array(styleguide)
|
69
|
+
else
|
70
|
+
styleguide = [styleguide]
|
71
|
+
end
|
72
|
+
if not styleguide.empty?
|
73
|
+
styles = get_styles(styleguide, theme[:name])
|
74
|
+
out.delete(STYLEGUIDE)
|
75
|
+
out = styles.rmerge(out)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
return out
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# driver method for converting a sentence into a list of styles
|
84
|
+
#
|
85
|
+
# *Parameters*:
|
86
|
+
# - <tt>description</tt> {String|List|Array} the description of the component
|
87
|
+
# - <tt>theme</tt> {String} the theme to use
|
88
|
+
# - <tt>state</tt> {String} the name of a state to return
|
89
|
+
# *Returns*:
|
90
|
+
# - {Hash} the styles
|
91
|
+
#
|
92
|
+
def get_styles(description, theme = nil, state = nil)
|
93
|
+
styles = Archetype::Hash.new
|
94
|
+
|
95
|
+
all_states = state.nil? || state == null || state == Sass::Script::Value::Bool::FALSE
|
96
|
+
|
97
|
+
# debug message
|
98
|
+
message = []
|
99
|
+
message_extras = []
|
100
|
+
|
101
|
+
# for each description, extract the associated styles
|
102
|
+
description.to_a.each do |sentence|
|
103
|
+
# if we have a hash, it denotes multiple values, so we need to convert this back to an array and recurse
|
104
|
+
return get_styles(helpers.meta_to_array(sentence)) if helpers.is_value(sentence, :hashy)
|
105
|
+
message << sentence
|
106
|
+
# get the grammar from the sentence
|
107
|
+
id, modifiers, token = grammar(sentence, theme, state)
|
108
|
+
if id
|
109
|
+
# check memoizer
|
110
|
+
extracted = memoizer.fetch_or_create(theme, token) do
|
111
|
+
# fetch additional styles
|
112
|
+
extracted = extract_styles(id, modifiers, false, theme)
|
113
|
+
# we can delete anything that had a value of `nil` as we won't be outputting those
|
114
|
+
extracted.delete_if { |k,v| helpers.is_value(v, :nil) }
|
115
|
+
# expose the result to the block
|
116
|
+
extracted
|
117
|
+
end
|
118
|
+
styles = styles.rmerge(extracted)
|
119
|
+
elsif not helpers.is_value(sentence, :nil)
|
120
|
+
msg = modifiers.length > 0 ? "please specify one of: #{modifiers.sort.join(', ')}" : "there are no registered components"
|
121
|
+
helpers.warn("[#{Archetype.name}:styleguide:missing_identifier] `#{helpers.to_str(sentence)}` does not contain an identifier. #{msg}")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
message = message.join(', ')
|
126
|
+
message_extras << "theme: #{theme}" if not theme.nil? and not [environment.var('CONFIG_THEME'), Archetype.name].include?(theme)
|
127
|
+
message_extras << "state: #{state}" if not all_states
|
128
|
+
if not message_extras.empty?
|
129
|
+
message << " (#{message_extras.join(', ')})"
|
130
|
+
end
|
131
|
+
|
132
|
+
# now that we've collected all of our styles, if we requested a single state, merge that state upstream
|
133
|
+
if not (all_states or styles[STATES].nil? or styles[STATES].empty?)
|
134
|
+
state = helpers.to_str(state)
|
135
|
+
state = styles[STATES][state]
|
136
|
+
# remove any nested/special keys
|
137
|
+
SPECIAL.each do |special|
|
138
|
+
styles.delete(special)
|
139
|
+
end
|
140
|
+
styles = styles.merge(state) if not (state.nil? or state.empty?)
|
141
|
+
end
|
142
|
+
|
143
|
+
return helpers.add_meta_message(styles, "#{MESSAGE_PREFIX}#{message}#{MESSAGE_SUFFIX}")
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|