archetype 0.0.1.pre.1 → 0.0.1.pre.3.00dfd9a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +88 -0
- data/LICENSE +16 -0
- data/README.md +87 -1
- data/VERSION.yml +6 -0
- data/lib/README.rdoc +4 -0
- data/lib/archetype.rb +45 -0
- data/lib/archetype/functions.rb +9 -0
- data/lib/archetype/functions/hash.rb +149 -0
- data/lib/archetype/functions/helpers.rb +125 -0
- data/lib/archetype/functions/styleguide_memoizer.rb +61 -0
- data/lib/archetype/sass_extensions.rb +6 -0
- data/lib/archetype/sass_extensions/functions.rb +14 -0
- data/lib/archetype/sass_extensions/functions/environment.rb +14 -0
- data/lib/archetype/sass_extensions/functions/lists.rb +284 -0
- data/lib/archetype/sass_extensions/functions/locale.rb +77 -0
- data/lib/archetype/sass_extensions/functions/numbers.rb +19 -0
- data/lib/archetype/sass_extensions/functions/styleguide.rb +406 -0
- data/lib/archetype/sass_extensions/functions/ui.rb +59 -0
- data/lib/archetype/sass_extensions/functions/version.rb +95 -0
- data/lib/archetype/version.rb +75 -0
- data/stylesheets/_archetype.scss +2 -0
- data/stylesheets/archetype/_base.scss +46 -0
- data/stylesheets/archetype/_config.scss +366 -0
- data/stylesheets/archetype/_grid.scss +3 -0
- data/stylesheets/archetype/_hacks.scss +72 -0
- data/stylesheets/archetype/_init.scss +23 -0
- data/stylesheets/archetype/_styleguide.scss +6 -0
- data/stylesheets/archetype/_ui.scss +326 -0
- data/stylesheets/archetype/_util.scss +12 -0
- data/stylesheets/archetype/base/_h5bp.scss +307 -0
- data/stylesheets/archetype/base/_hybrid.scss +25 -0
- data/stylesheets/archetype/base/_normalize.scss +595 -0
- data/stylesheets/archetype/base/_reset.scss +72 -0
- data/stylesheets/archetype/grid/_config.scss +14 -0
- data/stylesheets/archetype/grid/_grid.scss +391 -0
- data/stylesheets/archetype/styleguide/_components.scss +25 -0
- data/stylesheets/archetype/styleguide/_helpers.scss +215 -0
- data/stylesheets/archetype/styleguide/_primitives.scss +10 -0
- data/stylesheets/archetype/styleguide/_styleguide.scss +41 -0
- data/stylesheets/archetype/styleguide/components/_alerts.scss +59 -0
- data/stylesheets/archetype/styleguide/components/_annotations.scss +27 -0
- data/stylesheets/archetype/styleguide/components/_bristol.scss +15 -0
- data/stylesheets/archetype/styleguide/components/_button_groups.scss +47 -0
- data/stylesheets/archetype/styleguide/components/_button_toolbars.scss +17 -0
- data/stylesheets/archetype/styleguide/components/_buttons.scss +338 -0
- data/stylesheets/archetype/styleguide/components/_canvas.scss +15 -0
- data/stylesheets/archetype/styleguide/components/_carets.scss +336 -0
- data/stylesheets/archetype/styleguide/components/_closes.scss +63 -0
- data/stylesheets/archetype/styleguide/components/_container.scss +27 -0
- data/stylesheets/archetype/styleguide/components/_copy.scss +85 -0
- data/stylesheets/archetype/styleguide/components/_flyouts.scss +52 -0
- data/stylesheets/archetype/styleguide/components/_headings.scss +33 -0
- data/stylesheets/archetype/styleguide/components/_headlines.scss +63 -0
- data/stylesheets/archetype/styleguide/components/_hovercards.scss +27 -0
- data/stylesheets/archetype/styleguide/components/_icons.scss +17 -0
- data/stylesheets/archetype/styleguide/components/_identities.scss +34 -0
- data/stylesheets/archetype/styleguide/components/_links.scss +66 -0
- data/stylesheets/archetype/styleguide/components/_loaders.scss +154 -0
- data/stylesheets/archetype/styleguide/components/_menu_items.scss +31 -0
- data/stylesheets/archetype/styleguide/components/_module.scss +15 -0
- data/stylesheets/archetype/styleguide/components/_pullquotes.scss +29 -0
- data/stylesheets/archetype/styleguide/components/_punchcut.scss +18 -0
- data/stylesheets/archetype/styleguide/components/_tooltips.scss +28 -0
- data/stylesheets/archetype/styleguide/primitives/_animations.scss +17 -0
- data/stylesheets/archetype/styleguide/primitives/_dimensions.scss +50 -0
- data/stylesheets/archetype/styleguide/primitives/_glyphs.scss +11 -0
- data/stylesheets/archetype/styleguide/primitives/_misc.scss +8 -0
- data/stylesheets/archetype/styleguide/primitives/_palettes.scss +94 -0
- data/stylesheets/archetype/styleguide/primitives/_shadows.scss +23 -0
- data/stylesheets/archetype/styleguide/primitives/_sprites.scss +46 -0
- data/stylesheets/archetype/styleguide/primitives/_textures.scss +10 -0
- data/stylesheets/archetype/styleguide/primitives/_typography.scss +56 -0
- data/stylesheets/archetype/util/_debug.scss +40 -0
- data/stylesheets/archetype/util/_lists.scss +57 -0
- data/stylesheets/archetype/util/_misc.scss +108 -0
- data/stylesheets/archetype/util/_rtl.scss +279 -0
- data/stylesheets/archetype/util/_spacing.scss +78 -0
- data/stylesheets/archetype/util/_styles.scss +466 -0
- data/stylesheets/archetype/util/_targeting.scss +210 -0
- data/stylesheets/archetype/util/_units.scss +18 -0
- data/templates/example/index.html +40 -0
- data/templates/example/manifest.rb +13 -0
- data/templates/example/screen.scss +99 -0
- data/templates/example/vendor/archetype/animations/loaders/large/large.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/large/large_dark.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/large/large_dark_static.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/large/large_static.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/medium/medium.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/medium/medium_dark.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/medium/medium_dark_static.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/medium/medium_static.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/small/small.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/small/small_dark.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/small/small_dark_static.png +0 -0
- data/templates/example/vendor/archetype/animations/loaders/small/small_static.png +0 -0
- data/templates/example/vendor/archetype/fontawesome-webfont.eot +0 -0
- data/templates/example/vendor/archetype/fontawesome-webfont.svg +255 -0
- data/templates/example/vendor/archetype/fontawesome-webfont.ttf +0 -0
- data/templates/example/vendor/archetype/fontawesome-webfont.woff +0 -0
- data/templates/project/manifest.rb +9 -0
- data/templates/project/screen.scss +1 -0
- 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 +255 -0
- 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 +255 -0
- 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/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 +19 -0
- data/test/fixtures/stylesheets/archetype/expected/b.css +14 -0
- data/test/fixtures/stylesheets/archetype/expected/base.css +349 -0
- data/test/fixtures/stylesheets/archetype/expected/hacks/ie_pseudo.css +11 -0
- data/test/fixtures/stylesheets/archetype/expected/locale.css +23 -0
- data/test/fixtures/stylesheets/archetype/expected/styleguide/buttons.css +2091 -0
- data/test/fixtures/stylesheets/archetype/expected/styleguide/fallback_styles.css +9 -0
- data/test/fixtures/stylesheets/archetype/expected/styleguide/nested_styleguides.css +24 -0
- data/test/fixtures/stylesheets/archetype/expected/styleguide/selective_state.css +174 -0
- data/test/fixtures/stylesheets/archetype/expected/ui/glyph_icon.css +37 -0
- data/test/fixtures/stylesheets/archetype/expected/ui/hide_element.css +8 -0
- data/test/fixtures/stylesheets/archetype/expected/ui/stroke.css +17 -0
- data/test/fixtures/stylesheets/archetype/expected/ui/triangle.css +35 -0
- data/test/fixtures/stylesheets/archetype/expected/utilities/associative.css +9 -0
- data/test/fixtures/stylesheets/archetype/expected/utilities/if-set.css +9 -0
- data/test/fixtures/stylesheets/archetype/expected/utilities/spacing/horizontal-spacing.css +29 -0
- data/test/fixtures/stylesheets/archetype/expected/utilities/spacing/vertical-spacing.css +29 -0
- data/test/fixtures/stylesheets/archetype/expected/utilities/styles/filter.css +11 -0
- data/test/fixtures/stylesheets/archetype/expected/utilities/styles/font-family.css +16 -0
- data/test/fixtures/stylesheets/archetype/expected/utilities/styles/z-index.css +15 -0
- data/test/fixtures/stylesheets/archetype/expected/utilities/targeting/target-browser.css +100 -0
- data/test/fixtures/stylesheets/archetype/expected/utilities/targeting/target-os.css +55 -0
- data/test/fixtures/stylesheets/archetype/source/b.scss +9 -0
- data/test/fixtures/stylesheets/archetype/source/base.scss +3 -0
- data/test/fixtures/stylesheets/archetype/source/hacks/ie_pseudo.scss +13 -0
- data/test/fixtures/stylesheets/archetype/source/locale.scss +43 -0
- data/test/fixtures/stylesheets/archetype/source/styleguide/buttons.scss +18 -0
- data/test/fixtures/stylesheets/archetype/source/styleguide/fallback_styles.scss +22 -0
- data/test/fixtures/stylesheets/archetype/source/styleguide/nested_styleguides.scss +40 -0
- data/test/fixtures/stylesheets/archetype/source/styleguide/selective_state.scss +22 -0
- data/test/fixtures/stylesheets/archetype/source/ui/glyph_icon.scss +13 -0
- data/test/fixtures/stylesheets/archetype/source/ui/hide_element.scss +5 -0
- data/test/fixtures/stylesheets/archetype/source/ui/stroke.scss +13 -0
- data/test/fixtures/stylesheets/archetype/source/ui/triangle.scss +13 -0
- data/test/fixtures/stylesheets/archetype/source/utilities/associative.scss +24 -0
- data/test/fixtures/stylesheets/archetype/source/utilities/if-set.scss +16 -0
- data/test/fixtures/stylesheets/archetype/source/utilities/spacing/horizontal-spacing.scss +27 -0
- data/test/fixtures/stylesheets/archetype/source/utilities/spacing/vertical-spacing.scss +27 -0
- data/test/fixtures/stylesheets/archetype/source/utilities/styles/filter.scss +9 -0
- data/test/fixtures/stylesheets/archetype/source/utilities/styles/font-family.scss +9 -0
- data/test/fixtures/stylesheets/archetype/source/utilities/styles/z-index.scss +18 -0
- data/test/fixtures/stylesheets/archetype/source/utilities/targeting/target-browser.scss +70 -0
- data/test/fixtures/stylesheets/archetype/source/utilities/targeting/target-os.scss +42 -0
- data/test/helpers/diff.rb +49 -0
- data/test/helpers/io.rb +36 -0
- data/test/helpers/test_case.rb +62 -0
- data/test/integrations/archetype_test.rb +126 -0
- data/test/test_helper.rb +26 -0
- data/test/units/sass_extensions_test.rb +207 -0
- metadata +303 -15
@@ -0,0 +1,61 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
# This module implements a memoizer for caching styleguide() invocations.
|
3
|
+
#
|
4
|
+
module Archetype::Functions::StyleguideMemoizer
|
5
|
+
private
|
6
|
+
# memoized store for components we've already computed
|
7
|
+
@components ||= {}
|
8
|
+
|
9
|
+
#
|
10
|
+
# get the token for a styleguide reference given the current state of the theme
|
11
|
+
#
|
12
|
+
# *Parameters*:
|
13
|
+
# - <tt>theme</tt> {String} the theme name
|
14
|
+
# - <tt>extensions</tt> {Array} the list of currently installed extensions
|
15
|
+
# - <tt>id</tt> {String} the component identifier
|
16
|
+
# - <tt>modifiers</tt> {Array} the list of modifiers
|
17
|
+
# - <tt>state</tt> {String} the name of the state
|
18
|
+
# *Returns*:
|
19
|
+
# - {Fixnum} whether or not the value is nil/blank
|
20
|
+
#
|
21
|
+
def self.tokenize(theme, extensions, id, modifiers, state)
|
22
|
+
return nil if extensions.nil? or id.nil?
|
23
|
+
return "#{id}::#{(modifiers.to_a.sort + extensions).join('$')}::#{state}".hash
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# add a value to the memoizer given a token
|
28
|
+
#
|
29
|
+
# *Parameters*:
|
30
|
+
# - <tt>theme</tt> {String} the theme name
|
31
|
+
# - <tt>token</tt> {Fixnum} the token to register
|
32
|
+
# - <tt>value</tt> {Hash} the value to store
|
33
|
+
#
|
34
|
+
def self.add(theme, token, value)
|
35
|
+
(@components[theme] ||= {})[token] = value if Compass.configuration.memoize
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# fetch a value from the memoizer given a token
|
40
|
+
#
|
41
|
+
# *Parameters*:
|
42
|
+
# - <tt>theme</tt> {String} the theme name
|
43
|
+
# - <tt>token</tt> {Fixnum} the token to lookup
|
44
|
+
# *Returns*:
|
45
|
+
# - <tt>value</tt> {Hash} the value from the memoizer
|
46
|
+
#
|
47
|
+
def self.fetch(theme, token)
|
48
|
+
return false if token.nil?
|
49
|
+
return (@components[theme] ||= {})[token]
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# invalidate the entire memoizer for the theme
|
54
|
+
#
|
55
|
+
# *Parameters*:
|
56
|
+
# - <tt>theme</tt> {String} the theme name
|
57
|
+
#
|
58
|
+
def self.clear(theme)
|
59
|
+
@components[theme] = {}
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
%w(lists styleguide ui locale numbers version environment).each do |func|
|
2
|
+
require "archetype/sass_extensions/functions/#{func}"
|
3
|
+
end
|
4
|
+
|
5
|
+
# :stopdoc:
|
6
|
+
module Sass::Script::Functions
|
7
|
+
include Archetype::SassExtensions::Lists
|
8
|
+
include Archetype::SassExtensions::Styleguide
|
9
|
+
include Archetype::SassExtensions::UI
|
10
|
+
include Archetype::SassExtensions::Locale
|
11
|
+
include Archetype::SassExtensions::Numbers
|
12
|
+
include Archetype::SassExtensions::Version
|
13
|
+
include Archetype::SassExtensions::Environment
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#
|
2
|
+
# Archetype environment
|
3
|
+
#
|
4
|
+
module Archetype::SassExtensions::Environment
|
5
|
+
#
|
6
|
+
# get the current environment (this is similar to compass_env)
|
7
|
+
#
|
8
|
+
# *Returns*:
|
9
|
+
# - {String} the current environment the compiler is running in
|
10
|
+
#
|
11
|
+
def archetype_env
|
12
|
+
return Sass::Script::String.new((Compass.configuration.environment || :development).to_s)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,284 @@
|
|
1
|
+
require 'archetype/functions/helpers'
|
2
|
+
|
3
|
+
#
|
4
|
+
# This module provides a set of Sass functions for working with Sass::List
|
5
|
+
#
|
6
|
+
module Archetype::SassExtensions::Lists
|
7
|
+
#
|
8
|
+
# replace an index in a list
|
9
|
+
#
|
10
|
+
# *Parameters*:
|
11
|
+
# - <tt>$list</tt> {List} the list to replace from
|
12
|
+
# - <tt>$value</tt> {\*} the value to replace (if nil, it's a removal)
|
13
|
+
# - <tt>$idx</tt> {Number} the index to replace
|
14
|
+
# - <tt>$separator</tt> {String} the separator to use [auto|comma|space]
|
15
|
+
# *Returns*:
|
16
|
+
# - {List} the list with replaced index
|
17
|
+
#
|
18
|
+
def list_replace(list, idx = false, value = nil, separator = nil)
|
19
|
+
# return early if the index is invalid (no operation)
|
20
|
+
return list if (not idx or idx == Sass::Script::Bool.new(false))
|
21
|
+
separator ||= list.separator if list.is_a?(Sass::Script::List)
|
22
|
+
# if $value is `nil`, make sure we can use it
|
23
|
+
value = nil if value == Sass::Script::String.new('nil')
|
24
|
+
# cast and zero-index $idx
|
25
|
+
idx = (idx.value) - 1
|
26
|
+
# cast list to a ruby array
|
27
|
+
list = list.to_a
|
28
|
+
# remove or replace the given value
|
29
|
+
list.delete_at(idx) if value.nil?
|
30
|
+
list[idx,1] = value if not value.nil?
|
31
|
+
return Sass::Script::List.new(list, separator)
|
32
|
+
end
|
33
|
+
Sass::Script::Functions.declare :list_replace, [:list, :idx]
|
34
|
+
Sass::Script::Functions.declare :list_replace, [:list, :idx, :value]
|
35
|
+
Sass::Script::Functions.declare :list_replace, [:list, :idx, :value, :separator]
|
36
|
+
|
37
|
+
#
|
38
|
+
# remove an index from a list
|
39
|
+
#
|
40
|
+
# *Parameters*:
|
41
|
+
# - <tt>$list</tt> {List} the list to remove from
|
42
|
+
# - <tt>$idx</tt> {Number} the index to remove
|
43
|
+
# - <tt>$separator</tt> {String} the separator to use [auto|comma|space]
|
44
|
+
# *Returns*:
|
45
|
+
# - {List} the list with removed index
|
46
|
+
#
|
47
|
+
def list_remove(list, idx = false, separator = nil)
|
48
|
+
return list_replace(list, idx, nil, separator)
|
49
|
+
end
|
50
|
+
Sass::Script::Functions.declare :list_remove, [:list, :idx]
|
51
|
+
Sass::Script::Functions.declare :list_remove, [:list, :idx, :separator]
|
52
|
+
|
53
|
+
#
|
54
|
+
# insert an item into a list
|
55
|
+
#
|
56
|
+
# *Parameters*:
|
57
|
+
# - <tt>$list</tt> {List} the list to insert into
|
58
|
+
# - <tt>$idx</tt> {Number} the index to insert at
|
59
|
+
# - <tt>$value</tt> {\*} the value to insert
|
60
|
+
# - <tt>$separator</tt> {String} the separator to use [auto|comma|space]
|
61
|
+
# *Returns*:
|
62
|
+
# - {List} the list with inserted value
|
63
|
+
#
|
64
|
+
def list_insert(list, idx = false, value = nil, separator = nil)
|
65
|
+
value = nil if value == Sass::Script::String.new('nil')
|
66
|
+
# return early if the index is invalid (no operation) or $value is `nil`
|
67
|
+
return list if (not idx or idx == Sass::Script::Bool.new(false)) or value.nil?
|
68
|
+
return list_replace(list, idx, value, separator, -1)
|
69
|
+
end
|
70
|
+
Sass::Script::Functions.declare :list_insert, [:list, :idx]
|
71
|
+
Sass::Script::Functions.declare :list_insert, [:list, :idx, :value]
|
72
|
+
Sass::Script::Functions.declare :list_insert, [:list, :idx, :value, :separator]
|
73
|
+
|
74
|
+
#
|
75
|
+
# sort a list
|
76
|
+
#
|
77
|
+
# *Parameters*:
|
78
|
+
# - <tt>$list</tt> {List} the list to sort
|
79
|
+
# - <tt>$reverse</tt> {Boolean} sort the list in reverse order
|
80
|
+
# *Returns*:
|
81
|
+
# - {List} the sorted list
|
82
|
+
#
|
83
|
+
# TODO - this is failing, fix this
|
84
|
+
#def list_sort(list, reverse = false)
|
85
|
+
# separator = list.separator if list.is_a?(Sass::Script::List)
|
86
|
+
# list = list.to_a.sort
|
87
|
+
# list = list.reverse if (reverse == Sass::Script::Bool.new(true))
|
88
|
+
# return Sass::Script::List.new(list, separator)
|
89
|
+
#end
|
90
|
+
|
91
|
+
#
|
92
|
+
# reverse order a list
|
93
|
+
#
|
94
|
+
# *Parameters*:
|
95
|
+
# - <tt>$list</tt> {List} the list to reverse
|
96
|
+
# *Returns*:
|
97
|
+
# - {List} the reversed list
|
98
|
+
#
|
99
|
+
# TODO - this is failing, fix this
|
100
|
+
#def list_reverse(list)
|
101
|
+
# separator = list.separator if list.is_a?(Sass::Script::List)
|
102
|
+
# list = list.to_a.reverse
|
103
|
+
# return Sass::Script::List.new(list, separator)
|
104
|
+
#end
|
105
|
+
|
106
|
+
#
|
107
|
+
# add values(s) to a list
|
108
|
+
#
|
109
|
+
# *Parameters*:
|
110
|
+
# - <tt>$list</tt> {List} the list operate on
|
111
|
+
# - <tt>$values</tt> {List|Number|String} the value(s) to add to the list
|
112
|
+
# *Returns*:
|
113
|
+
# - {List} the final list
|
114
|
+
#
|
115
|
+
def list_add(list, values)
|
116
|
+
return list_math(list, values, :plus)
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# subtract values(s) from a list
|
121
|
+
#
|
122
|
+
# *Parameters*:
|
123
|
+
# - <tt>$list</tt> {List} the list operate on
|
124
|
+
# - <tt>$values</tt> {List|Number|String} the value(s) to subtract from the list
|
125
|
+
# *Returns*:
|
126
|
+
# - {List} the final list
|
127
|
+
#
|
128
|
+
def list_subtract(list, values)
|
129
|
+
return list_math(list, values, :minus)
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# multiply values(s) into a list
|
134
|
+
#
|
135
|
+
# *Parameters*:
|
136
|
+
# - <tt>$list</tt> {List} the list operate on
|
137
|
+
# - <tt>$values</tt> {List|Number|String} the value(s) to multiply into the list
|
138
|
+
# *Returns*:
|
139
|
+
# - {List} the final list
|
140
|
+
#
|
141
|
+
def list_multiply(list, values)
|
142
|
+
return list_math(list, values, :times)
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# divide values(s) into a list
|
147
|
+
#
|
148
|
+
# *Parameters*:
|
149
|
+
# - <tt>$list</tt> {List} the list operate on
|
150
|
+
# - <tt>$values</tt> {List|Number|String} the value(s) to divide into the list
|
151
|
+
# *Returns*:
|
152
|
+
# - {List} the final list
|
153
|
+
#
|
154
|
+
def list_divide(list, values)
|
155
|
+
return list_math(list, values, :div)
|
156
|
+
end
|
157
|
+
|
158
|
+
#
|
159
|
+
# list modulus value(s)
|
160
|
+
#
|
161
|
+
# *Parameters*:
|
162
|
+
# - <tt>$list</tt> {List} the list operate on
|
163
|
+
# - <tt>$values</tt> {List|Number|String} the value(s) to modulus into the list
|
164
|
+
# *Returns*:
|
165
|
+
# - {List} the final list
|
166
|
+
#
|
167
|
+
def list_mod(list, values)
|
168
|
+
return list_math(list, values, :mod)
|
169
|
+
end
|
170
|
+
|
171
|
+
#
|
172
|
+
# find if any set of values is in a list
|
173
|
+
# this is similar to `index()`, but allows $values to contain multiple values to test against
|
174
|
+
#
|
175
|
+
# *Parameters*:
|
176
|
+
# - <tt>$haystack</tt> {List} input list
|
177
|
+
# - <tt>$needle</tt> {List} the value(s) to search for
|
178
|
+
# *Returns*:
|
179
|
+
# - {Number|Bool} if an item is found, returns the index, otherwise returns false
|
180
|
+
#
|
181
|
+
def index2(haystack, needle)
|
182
|
+
haystack = haystack.to_a
|
183
|
+
needle = needle.to_a
|
184
|
+
index = haystack.index(haystack.detect { |i| needle.include?(i) })
|
185
|
+
if index
|
186
|
+
return Sass::Script::Number.new(index + 1)
|
187
|
+
else
|
188
|
+
return Sass::Script::Bool.new(false)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
#
|
193
|
+
# treats a list cyclically (never out of bounds, just wraps around)
|
194
|
+
#
|
195
|
+
# *Parameters*:
|
196
|
+
# - <tt>$list</tt> {List} the list
|
197
|
+
# - <tt>$idx</tt> {Number} the index
|
198
|
+
# *Returns*:
|
199
|
+
# - {*} the nth item in the List
|
200
|
+
#
|
201
|
+
def nth_cyclic(list, n = 1)
|
202
|
+
n = n.to_i if n.is_a?(Sass::Script::Number)
|
203
|
+
list = list.to_a
|
204
|
+
return list[(n - 1) % list.size]
|
205
|
+
end
|
206
|
+
|
207
|
+
#
|
208
|
+
# find a key within a nested list of ordered pairs
|
209
|
+
#
|
210
|
+
# *Parameters*:
|
211
|
+
# - <tt>$list</tt> {List} the list to search in
|
212
|
+
# - <tt>$key</tt> {String} the key identifier (name)
|
213
|
+
# - <tt>$strict</tt> {Bool} if true, does a strict match against the key
|
214
|
+
# *Returns*:
|
215
|
+
# - {*} the data associated with $key
|
216
|
+
#
|
217
|
+
def associative(list, key, strict = false)
|
218
|
+
separator = list.separator if list.is_a?(Sass::Script::List)
|
219
|
+
list = helpers.list_to_hash(list)
|
220
|
+
item = list[helpers.to_str(key, ' ' , :quotes)]
|
221
|
+
item ||= list.first[1] if not strict
|
222
|
+
return Sass::Script::List.new([], separator) if item.nil?
|
223
|
+
return helpers.hash_to_list(item, 0, separator) if item.is_a?(Array) or item.is_a?(Hash)
|
224
|
+
# no conversion needed, so just return
|
225
|
+
return item
|
226
|
+
end
|
227
|
+
Sass::Script::Functions.declare :associative, [:list, :key]
|
228
|
+
Sass::Script::Functions.declare :associative, [:list, :key, :strict]
|
229
|
+
|
230
|
+
#
|
231
|
+
# extend a key-value paired list with another
|
232
|
+
#
|
233
|
+
# *Parameters*:
|
234
|
+
# - <tt>$list</tt> {List} the list to extend to
|
235
|
+
# - <tt>$extender</tt> {List} the list to extend with
|
236
|
+
# *Returns*:
|
237
|
+
# - <tt>$list</tt> {List} the extended list
|
238
|
+
#
|
239
|
+
def associative_merge(list, extender, kwargs = {})
|
240
|
+
separator = list.separator if list.is_a?(Sass::Script::List)
|
241
|
+
list = helpers.list_to_hash(list)
|
242
|
+
extender = helpers.list_to_hash(extender)
|
243
|
+
list = list.rmerge(extender)
|
244
|
+
return helpers.hash_to_list(list, 0, separator)
|
245
|
+
end
|
246
|
+
Sass::Script::Functions.declare :associative_merge, [:list, :extender]
|
247
|
+
|
248
|
+
private
|
249
|
+
def helpers
|
250
|
+
@helpers ||= Archetype::Functions::Helpers
|
251
|
+
end
|
252
|
+
|
253
|
+
#
|
254
|
+
# perform math operations on a list
|
255
|
+
#
|
256
|
+
# *Parameters*:
|
257
|
+
# - <tt>list</tt> {Sass::List} the list operate on
|
258
|
+
# - <tt>values</tt> {Sass::List|Sass::Number|Sass::String} the value(s) perform with
|
259
|
+
# - <tt>method</tt> {Symbol} the method to perform [:plus|:minus|:times|:div|:mod]
|
260
|
+
# *Returns*:
|
261
|
+
# - {Sass::List} the final list
|
262
|
+
#
|
263
|
+
def list_math(list, values, method = :plus)
|
264
|
+
separator = list.separator if list.is_a?(Sass::Script::List)
|
265
|
+
values = values.to_a
|
266
|
+
list = list.to_a
|
267
|
+
values.fill(values[0], 0..(list.size - 1)) if values.size < list.size
|
268
|
+
list = [list, values].transpose.map do |x|
|
269
|
+
case method
|
270
|
+
when :plus
|
271
|
+
x[0].plus(x[1])
|
272
|
+
when :minus
|
273
|
+
x[0].minus(x[1])
|
274
|
+
when :times
|
275
|
+
x[0].times(x[1])
|
276
|
+
when :div
|
277
|
+
x[0].div(x[1])
|
278
|
+
when :mod
|
279
|
+
x[0].mod(x[1])
|
280
|
+
end
|
281
|
+
end
|
282
|
+
return Sass::Script::List.new(list, separator)
|
283
|
+
end
|
284
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# This module provides an interface for localization.
|
3
|
+
#
|
4
|
+
module Archetype::SassExtensions::Locale
|
5
|
+
#
|
6
|
+
# get the current locale specified in config or test a list of locales against the current locale
|
7
|
+
#
|
8
|
+
# *Parameters*:
|
9
|
+
# - <tt>$locales</tt> {List} the list of locales to test
|
10
|
+
# *Returns*:
|
11
|
+
# - {String|Boolean} the current locale or whether or not the current locale is in the test set
|
12
|
+
#
|
13
|
+
def locale(locales = nil)
|
14
|
+
locale = (Compass.configuration.locale || 'en_US').to_s
|
15
|
+
# if the locales are nil, just return the current locale
|
16
|
+
return Sass::Script::String.new(locale) if locales.nil?
|
17
|
+
locales = locales.to_a.collect{|i| i.to_s}
|
18
|
+
# add wild card support for language or territory
|
19
|
+
match = locale.match(LOCALE_PATTERN)
|
20
|
+
# language with wildcard territory
|
21
|
+
language = match[1] + '_'
|
22
|
+
# territory with wildcard language
|
23
|
+
territory = '_' + match[2]
|
24
|
+
# for each item, look it up in the alias list
|
25
|
+
locales.each do |key|
|
26
|
+
if a = locale_aliases[key]
|
27
|
+
locales.delete(key)
|
28
|
+
locales.concat(a)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
return Sass::Script::Bool.new(locales.include?(locale) || locales.include?(language) || locales.include?(territory))
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# test a list of locales against the current locale (this is now just an alias for locales(), for back-compat)
|
36
|
+
#
|
37
|
+
# *Parameters*:
|
38
|
+
# - <tt>$locales</tt> {List} the list of locales to test
|
39
|
+
# *Returns*:
|
40
|
+
# - {Boolean} is the current locale in the list or not
|
41
|
+
#
|
42
|
+
def lang(locales)
|
43
|
+
return locale(locales)
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# get the current reading direction
|
48
|
+
#
|
49
|
+
# *Returns*:
|
50
|
+
# - {String} is the current reading direction [ltr|rtl]
|
51
|
+
#
|
52
|
+
def reading_direction
|
53
|
+
direction = Compass.configuration.reading || 'ltr'
|
54
|
+
return Sass::Script::String.new(direction == 'rlt' ? 'rtl' : 'ltr')
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
LOCALE_PATTERN = /([a-z]{2})[-_]?([a-z]{2}?)/i
|
60
|
+
|
61
|
+
#
|
62
|
+
# provides an alias mapping for locale names
|
63
|
+
#
|
64
|
+
# *Returns*:
|
65
|
+
# - {Hash} a hash of aliases
|
66
|
+
#
|
67
|
+
# TODO - make this easily extensible
|
68
|
+
def locale_aliases
|
69
|
+
if @locale_aliases.nil?
|
70
|
+
a = {
|
71
|
+
'CJK' => ['ja_JP', 'ko_KR', 'zh_TW', 'zh_CN']
|
72
|
+
}
|
73
|
+
@locale_aliases = a
|
74
|
+
end
|
75
|
+
return @locale_aliases
|
76
|
+
end
|
77
|
+
end
|