archetype 0.0.1.pre.10 → 0.0.1.pre.11
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.
- checksums.yaml +4 -4
- data/lib/archetype.rb +0 -4
- data/lib/archetype/functions/hash.rb +12 -28
- data/lib/archetype/functions/helpers.rb +13 -46
- data/lib/archetype/functions/styleguide_memoizer.rb +1 -9
- data/lib/archetype/sass_extensions/functions/lists.rb +42 -36
- data/lib/archetype/sass_extensions/functions/locale.rb +16 -32
- data/lib/archetype/sass_extensions/functions/styleguide.rb +39 -121
- data/lib/archetype/sass_extensions/functions/ui.rb +2 -3
- data/lib/archetype/sass_extensions/functions/version.rb +6 -11
- data/lib/archetype/sass_extensions/monkey_patches.rb +1 -1
- data/lib/archetype/version.rb +1 -1
- data/stylesheets/archetype/_base.scss +2 -7
- data/stylesheets/archetype/_config.scss +1 -8
- data/stylesheets/archetype/_hacks.scss +17 -51
- data/stylesheets/archetype/_ui.scss +5 -16
- data/stylesheets/archetype/base/_h5bp.scss +12 -12
- data/stylesheets/archetype/base/_normalize.scss +139 -178
- data/stylesheets/archetype/grid/_grid.scss +13 -13
- data/stylesheets/archetype/styleguide/components/_buttons.scss +0 -1
- data/stylesheets/archetype/util/_debug.scss +4 -4
- data/stylesheets/archetype/util/_lists.scss +1 -1
- data/stylesheets/archetype/util/_misc.scss +1 -1
- data/stylesheets/archetype/util/_rtl.scss +1 -1
- data/stylesheets/archetype/util/_spacing.scss +6 -6
- data/stylesheets/archetype/util/_styles.scss +10 -27
- data/stylesheets/archetype/util/_targeting.scss +1 -1
- data/test/fixtures/stylesheets/archetype/config.rb +0 -2
- data/test/fixtures/stylesheets/archetype/saved/styleguide/buttons.css +2027 -0
- data/test/fixtures/stylesheets/archetype/saved/styleguide/fallback_styles.css +9 -0
- data/test/fixtures/stylesheets/archetype/source/styleguide/buttons.scss +1 -5
- data/test/fixtures/stylesheets/archetype/source/styleguide/fallback_styles.scss +2 -1
- data/test/fixtures/stylesheets/archetype/source/styleguide/nested_styleguides.scss +1 -1
- data/test/fixtures/stylesheets/archetype/source/styleguide/selective_state.scss +1 -1
- data/test/fixtures/stylesheets/archetype/source/ui/glyph_icon.scss +0 -30
- data/test/fixtures/stylesheets/archetype/source/utilities/custom_output_styler.scss +3 -4
- data/test/fixtures/stylesheets/archetype/source/utilities/targeting/target-browser.scss +1 -8
- data/test/helpers/test_case.rb +2 -2
- data/test/integrations/archetype_test.rb +1 -3
- data/test/units/sass_extensions_test.rb +25 -18
- metadata +6 -29
- data/lib/archetype/actions/help.rb +0 -16
- data/lib/archetype/actions/theme.rb +0 -73
- data/lib/archetype/executor.rb +0 -27
- data/test/fixtures/stylesheets/archetype/saved/base.css +0 -349
- data/test/fixtures/stylesheets/archetype/saved/hacks/transparent_focusable.css +0 -4
- data/test/fixtures/stylesheets/archetype/saved/locale.css +0 -23
- data/test/fixtures/stylesheets/archetype/source/base.scss +0 -3
- 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/drop.scss +0 -101
- data/test/fixtures/stylesheets/archetype/source/styleguide/extend.scss +0 -24
- 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/utilities/associative.scss +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 192dd0037d6555124a87aadae4a22c1be1fe080c
|
4
|
+
data.tar.gz: 7cc39be2c7bb42aeb4580baf1481ac2d4a1dcd48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a8a13bf6c81307af54fc6ebbcd0a23c40446d3d3d00f73a695aeef338a08ee1de9521a0a78bc8d3e2eecd73b70118470483ddfa82f9a967de627a637fca8e47
|
7
|
+
data.tar.gz: 648a999357a50954db62eee54078e250ae061d0f3e579a6473b31f8582080a73e04659161dae47032ed43190753bfe29ef7cccdf38a2af5bbceb0e15473b45bc
|
data/lib/archetype.rb
CHANGED
@@ -33,10 +33,6 @@ module Archetype
|
|
33
33
|
Compass::Configuration.add_configuration_property(:memoize, "should the memoizer be used to improve compilation speed") do
|
34
34
|
not (Compass.configuration.environment || :development).to_s.include?('dev')
|
35
35
|
end
|
36
|
-
# testing (for running unit tests)
|
37
|
-
Compass::Configuration.add_configuration_property(:testing, "is this a testing environment") do
|
38
|
-
ENV['CI']
|
39
|
-
end
|
40
36
|
end
|
41
37
|
end
|
42
38
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# :stopdoc:
|
2
2
|
# This module extends the native Ruby Hash class to support deep merging
|
3
3
|
# and comparing the difference between hashes.
|
4
|
-
# This functionality mimics that found in ActiveSupport
|
5
|
-
# @see https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
6
4
|
#
|
7
5
|
module Archetype::Functions::Hash
|
8
6
|
#
|
@@ -13,10 +11,13 @@ module Archetype::Functions::Hash
|
|
13
11
|
# *Returns*:
|
14
12
|
# - {Hash} a new hash containing the contents of other_hash and the contents of hsh, deep merged
|
15
13
|
#
|
16
|
-
def rmerge(other_hash
|
17
|
-
|
14
|
+
def rmerge(other_hash)
|
15
|
+
new_hash = {}
|
16
|
+
merge(other_hash) do |key, oldval, newval|
|
17
|
+
new_hash[key] = oldval.class == self.class ? oldval.rmerge(newval) : newval
|
18
|
+
end
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
#
|
21
22
|
# adds the contents of other_hash to hsh, deep merged
|
22
23
|
#
|
@@ -25,16 +26,10 @@ module Archetype::Functions::Hash
|
|
25
26
|
# *Returns*:
|
26
27
|
# - {Hash} the original hash with the addition of the contents of other_hash
|
27
28
|
#
|
28
|
-
def rmerge!(other_hash
|
29
|
-
other_hash
|
30
|
-
|
31
|
-
if tv.is_a?(Hash) && v.is_a?(Hash)
|
32
|
-
self[k] = tv.rmerge(v, &block)
|
33
|
-
else
|
34
|
-
self[k] = block && tv ? block.call(k, tv, v) : v
|
35
|
-
end
|
29
|
+
def rmerge!(other_hash)
|
30
|
+
merge!(other_hash) do |key, oldval, newval|
|
31
|
+
oldval.class == self.class ? oldval.rmerge!(newval) : newval
|
36
32
|
end
|
37
|
-
return self
|
38
33
|
end
|
39
34
|
|
40
35
|
#
|
@@ -46,7 +41,7 @@ module Archetype::Functions::Hash
|
|
46
41
|
# - {Hash} a representation of the difference between the two hashes
|
47
42
|
#
|
48
43
|
def diff(other_hash)
|
49
|
-
(self.keys + other_hash.keys).uniq.inject(
|
44
|
+
(self.keys + other_hash.keys).uniq.inject({}) do |tmp, key|
|
50
45
|
# special comparison for gradients
|
51
46
|
are_gradients = self[key].is_a?(Compass::SassExtensions::Functions::GradientSupport::LinearGradient) and other_hash[key].is_a?(Compass::SassExtensions::Functions::GradientSupport::LinearGradient)
|
52
47
|
eq_gradients = are_gradients ? (self[key].to_s == other_hash[key].to_s) : true
|
@@ -133,17 +128,6 @@ private
|
|
133
128
|
end
|
134
129
|
end
|
135
130
|
|
136
|
-
|
137
|
-
|
138
|
-
if RUBY_VERSION < '1.9'
|
139
|
-
require 'hashery/ordered_hash'
|
140
|
-
class Hash < Hashery::OrderedHash
|
141
|
-
include Archetype::Functions::Hash
|
142
|
-
end
|
143
|
-
else
|
144
|
-
class Hash < ::Hash
|
145
|
-
include Archetype::Functions::Hash
|
146
|
-
end
|
147
|
-
end
|
131
|
+
class Hash
|
132
|
+
include Archetype::Functions::Hash
|
148
133
|
end
|
149
|
-
|
@@ -24,8 +24,7 @@ private
|
|
24
24
|
def self.hash_to_list(hsh, depth = 0, separator = :comma)
|
25
25
|
if hsh.is_a? Hash
|
26
26
|
list = []
|
27
|
-
hsh.each do |
|
28
|
-
item = [key, item]
|
27
|
+
hsh.each do |item|
|
29
28
|
# if its a hash, convert it to a List
|
30
29
|
if item.is_a? Hash or item.is_a? Array
|
31
30
|
tmp = []
|
@@ -55,56 +54,30 @@ private
|
|
55
54
|
#
|
56
55
|
def self.list_to_hash(list, depth = 0, nest = [], additives = [])
|
57
56
|
list = list.to_a
|
58
|
-
|
59
|
-
hsh = Archetype::Hash.new
|
57
|
+
hsh = {}
|
60
58
|
list.each do |item|
|
61
59
|
item = item.to_a
|
62
|
-
|
63
60
|
# convert the key to a string and strip off quotes
|
64
|
-
key = to_str(item[0]
|
65
|
-
# capture the value
|
61
|
+
key = to_str(item[0]).gsub(/\A"|"\Z/, '')
|
66
62
|
value = item[1]
|
67
|
-
|
68
63
|
if key != 'nil'
|
69
|
-
if is_value(value, :blank)
|
70
|
-
if previous.nil?
|
71
|
-
previous = key
|
72
|
-
next
|
73
|
-
else
|
74
|
-
value = item[0]
|
75
|
-
key = previous
|
76
|
-
previous = nil
|
77
|
-
end
|
78
|
-
elsif not previous.nil?
|
79
|
-
# if we got here, something is wrong with the structure
|
80
|
-
list.shift if to_str(list[0]) == previous # remove the first item if it's the previous key, which is now the parent key
|
81
|
-
list = list[0].to_a # now the remaining items were munged, so split them out
|
82
|
-
hsh = Archetype::Hash.new
|
83
|
-
hsh[previous] = list_to_hash(list, depth - 1, nest, additives)
|
84
|
-
return hsh
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# update the hash if we have a valid key and hash
|
89
|
-
if key != 'nil' and not is_value(value, :blank)
|
90
64
|
# check if if it's a nesting hash
|
91
65
|
nested = nest.include?(key)
|
92
66
|
# if it's nested or we haven't reached out depth, recurse
|
93
67
|
if nested or depth > 0
|
94
68
|
value = list_to_hash(value, nested ? depth + 1 : depth - 1, nest, additives)
|
95
69
|
end
|
96
|
-
|
97
|
-
if
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
70
|
+
# update the hash key
|
71
|
+
if not is_value(value, :blank)
|
72
|
+
if additives.include?(key)
|
73
|
+
hsh[key] ||= []
|
74
|
+
hsh[key].push(value)
|
75
|
+
else
|
76
|
+
hsh[key] = value
|
77
|
+
end
|
102
78
|
end
|
103
79
|
end
|
104
80
|
end
|
105
|
-
|
106
|
-
logger.record(:warning, "one of your data structures is ambiguous, please double check near `#{previous}`") if not previous.nil?
|
107
|
-
|
108
81
|
return hsh
|
109
82
|
end
|
110
83
|
|
@@ -117,12 +90,8 @@ private
|
|
117
90
|
# *Returns*:
|
118
91
|
# - {String} the converted String
|
119
92
|
#
|
120
|
-
def self.to_str(value, separator = ' '
|
121
|
-
|
122
|
-
value = ((value.to_a).each{ |i| i.nil? ? 'nil' : (i.is_a?(String) ? i : i.value) }).join(separator || '')
|
123
|
-
end
|
124
|
-
strip = /\A"|"\Z/ if strip == :quotes
|
125
|
-
return strip.nil? ? value : value.gsub(strip, '')
|
93
|
+
def self.to_str(value, separator = ' ')
|
94
|
+
return value.is_a?(String) ? value : ((value.to_a).each{ |i| i.is_a?(String) ? i : i.value }).join(separator || '')
|
126
95
|
end
|
127
96
|
|
128
97
|
#
|
@@ -140,13 +109,11 @@ private
|
|
140
109
|
when :blank
|
141
110
|
is_it = false
|
142
111
|
value = value.value if value.is_a?(Sass::Script::String)
|
143
|
-
is_it = value.nil?
|
144
112
|
is_it = value.empty? if value.is_a?(String)
|
145
113
|
is_it = value.to_a.empty? if value.is_a?(Sass::Script::List) or value.is_a?(Array)
|
146
114
|
when :nil
|
147
115
|
is_it = false
|
148
116
|
value = value.value if value.is_a?(Sass::Script::String)
|
149
|
-
is_it = value.nil?
|
150
117
|
is_it = value == 'nil' if value.is_a?(String)
|
151
118
|
is_it = to_str(value) == 'nil' if value.is_a?(Sass::Script::List) or value.is_a?(Array)
|
152
119
|
end
|
@@ -50,7 +50,7 @@ private
|
|
50
50
|
end
|
51
51
|
|
52
52
|
#
|
53
|
-
# invalidate the memoizer for the theme
|
53
|
+
# invalidate the entire memoizer for the theme
|
54
54
|
#
|
55
55
|
# *Parameters*:
|
56
56
|
# - <tt>theme</tt> {String} the theme name
|
@@ -58,12 +58,4 @@ private
|
|
58
58
|
def self.clear(theme)
|
59
59
|
@components[theme] = {}
|
60
60
|
end
|
61
|
-
|
62
|
-
|
63
|
-
#
|
64
|
-
# resets the entire memoizer
|
65
|
-
#
|
66
|
-
def self.reset!
|
67
|
-
@components = {}
|
68
|
-
end
|
69
61
|
end
|
@@ -6,7 +6,7 @@ require 'archetype/functions/helpers'
|
|
6
6
|
module Archetype::SassExtensions::Lists
|
7
7
|
#
|
8
8
|
# replace an index in a list
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# *Parameters*:
|
11
11
|
# - <tt>$list</tt> {List} the list to replace from
|
12
12
|
# - <tt>$value</tt> {\*} the value to replace (if nil, it's a removal)
|
@@ -47,8 +47,8 @@ module Archetype::SassExtensions::Lists
|
|
47
47
|
def list_remove(list, idx = false, separator = nil)
|
48
48
|
return list_replace(list, idx, nil, separator)
|
49
49
|
end
|
50
|
-
Sass::Script::Functions.declare :
|
51
|
-
Sass::Script::Functions.declare :
|
50
|
+
Sass::Script::Functions.declare :list_replace, [:list, :idx]
|
51
|
+
Sass::Script::Functions.declare :list_replace, [:list, :idx, :separator]
|
52
52
|
|
53
53
|
#
|
54
54
|
# insert an item into a list
|
@@ -67,9 +67,41 @@ module Archetype::SassExtensions::Lists
|
|
67
67
|
return list if (not idx or idx == Sass::Script::Bool.new(false)) or value.nil?
|
68
68
|
return list_replace(list, idx, value, separator, -1)
|
69
69
|
end
|
70
|
-
Sass::Script::Functions.declare :
|
71
|
-
Sass::Script::Functions.declare :
|
72
|
-
Sass::Script::Functions.declare :
|
70
|
+
Sass::Script::Functions.declare :list_replace, [:list, :idx]
|
71
|
+
Sass::Script::Functions.declare :list_replace, [:list, :idx, :value]
|
72
|
+
Sass::Script::Functions.declare :list_replace, [: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
|
73
105
|
|
74
106
|
#
|
75
107
|
# add values(s) to a list
|
@@ -144,7 +176,7 @@ module Archetype::SassExtensions::Lists
|
|
144
176
|
# - <tt>$haystack</tt> {List} input list
|
145
177
|
# - <tt>$needle</tt> {List} the value(s) to search for
|
146
178
|
# *Returns*:
|
147
|
-
# - {Number|
|
179
|
+
# - {Number|Bool} if an item is found, returns the index, otherwise returns false
|
148
180
|
#
|
149
181
|
def index2(haystack, needle)
|
150
182
|
haystack = haystack.to_a
|
@@ -178,14 +210,14 @@ module Archetype::SassExtensions::Lists
|
|
178
210
|
# *Parameters*:
|
179
211
|
# - <tt>$list</tt> {List} the list to search in
|
180
212
|
# - <tt>$key</tt> {String} the key identifier (name)
|
181
|
-
# - <tt>$strict</tt> {
|
213
|
+
# - <tt>$strict</tt> {Bool} if true, does a strict match against the key
|
182
214
|
# *Returns*:
|
183
215
|
# - {*} the data associated with $key
|
184
216
|
#
|
185
217
|
def associative(list, key, strict = false)
|
186
218
|
separator = list.separator if list.is_a?(Sass::Script::List)
|
187
219
|
list = helpers.list_to_hash(list)
|
188
|
-
item = list[helpers.to_str(key
|
220
|
+
item = list[helpers.to_str(key)]
|
189
221
|
item ||= list.first[1] if not strict
|
190
222
|
return Sass::Script::List.new([], separator) if item.nil?
|
191
223
|
return helpers.hash_to_list(item, 0, separator) if item.is_a?(Array) or item.is_a?(Hash)
|
@@ -211,33 +243,7 @@ module Archetype::SassExtensions::Lists
|
|
211
243
|
list = list.rmerge(extender)
|
212
244
|
return helpers.hash_to_list(list, 0, separator)
|
213
245
|
end
|
214
|
-
Sass::Script::Functions.declare :
|
215
|
-
|
216
|
-
#
|
217
|
-
# given a string of styles, convert it into a key-value pair list
|
218
|
-
#
|
219
|
-
# *Parameters*:
|
220
|
-
# - <tt>$string</tt> {String} the string to convert
|
221
|
-
# *Returns*:
|
222
|
-
# - <tt>$list</tt> {List} the converted list of styles
|
223
|
-
#
|
224
|
-
def _style_string_to_list(string = '')
|
225
|
-
# convert to string and strip all comments
|
226
|
-
string = helpers.to_str(string, ' ').gsub(/\/\*[^\*\/]*\*\//, '')
|
227
|
-
# then split it on each rule
|
228
|
-
tmp = string.split(';')
|
229
|
-
styles = []
|
230
|
-
# and for each rule break it into it's key-value pairs
|
231
|
-
tmp.each do |rule|
|
232
|
-
kvp = []
|
233
|
-
rule.split(':').each do |str|
|
234
|
-
kvp.push Sass::Script::String.new(str)
|
235
|
-
end
|
236
|
-
styles.push Sass::Script::List.new(kvp, :comma)
|
237
|
-
end
|
238
|
-
# the recompose the list
|
239
|
-
return Sass::Script::List.new(styles, :comma)
|
240
|
-
end
|
246
|
+
Sass::Script::Functions.declare :list_extend, [:list, :extender]
|
241
247
|
|
242
248
|
private
|
243
249
|
def helpers
|
@@ -3,36 +3,17 @@
|
|
3
3
|
#
|
4
4
|
module Archetype::SassExtensions::Locale
|
5
5
|
#
|
6
|
-
# get the current locale specified in config
|
6
|
+
# get the current locale specified in config
|
7
7
|
#
|
8
|
-
# *Parameters*:
|
9
|
-
# - <tt>$locales</tt> {List} the list of locales to test
|
10
8
|
# *Returns*:
|
11
|
-
# - {String
|
9
|
+
# - {String} the current locale
|
12
10
|
#
|
13
|
-
def locale
|
14
|
-
|
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))
|
11
|
+
def locale
|
12
|
+
return Sass::Script::String.new(Compass.configuration.locale || 'en_US')
|
32
13
|
end
|
33
14
|
|
34
15
|
#
|
35
|
-
# test a list of locales against the current locale (
|
16
|
+
# test a list of locales against the current locale (supports an alias map)
|
36
17
|
#
|
37
18
|
# *Parameters*:
|
38
19
|
# - <tt>$locales</tt> {List} the list of locales to test
|
@@ -40,9 +21,16 @@ module Archetype::SassExtensions::Locale
|
|
40
21
|
# - {Boolean} is the current locale in the list or not
|
41
22
|
#
|
42
23
|
def lang(locales)
|
43
|
-
|
24
|
+
locales = locales.to_a.collect{|i| i.to_s}
|
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.to_s))
|
44
32
|
end
|
45
|
-
|
33
|
+
|
46
34
|
#
|
47
35
|
# get the current reading direction
|
48
36
|
#
|
@@ -55,9 +43,6 @@ module Archetype::SassExtensions::Locale
|
|
55
43
|
end
|
56
44
|
|
57
45
|
private
|
58
|
-
|
59
|
-
LOCALE_PATTERN = /([a-z]{2})[-_]?([a-z]{2}?)/i
|
60
|
-
|
61
46
|
#
|
62
47
|
# provides an alias mapping for locale names
|
63
48
|
#
|
@@ -67,9 +52,8 @@ private
|
|
67
52
|
# TODO - make this easily extensible
|
68
53
|
def locale_aliases
|
69
54
|
if @locale_aliases.nil?
|
70
|
-
a = {
|
71
|
-
|
72
|
-
}
|
55
|
+
a = {}
|
56
|
+
a['CJK'] = ['ja_JP', 'ko_KR', 'zh_TW', 'zh_CN']
|
73
57
|
@locale_aliases = a
|
74
58
|
end
|
75
59
|
return @locale_aliases
|
@@ -15,13 +15,10 @@ module Archetype::SassExtensions::Styleguide
|
|
15
15
|
DEFAULT = 'default'
|
16
16
|
REGEX = 'regex'
|
17
17
|
SPECIAL = %w(states selectors)
|
18
|
-
DROPALL = %w(all true)
|
19
18
|
# these are unique CSS keys that can be exploited to provide fallback functionality by providing a second value
|
20
19
|
# e.g color: red; color: rgba(255,0,0, 0.8);
|
21
|
-
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
|
22
|
-
|
23
|
-
MULTIMIXINS = %w(target-browser)
|
24
|
-
ADDITIVES = FALLBACKS + [DROP, INHERIT, STYLEGUIDE] + MULTIMIXINS
|
20
|
+
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)
|
21
|
+
ADDITIVES = FALLBACKS + [DROP, INHERIT, STYLEGUIDE]
|
25
22
|
@@archetype_styleguide_mutex = Mutex.new
|
26
23
|
# :startdoc:
|
27
24
|
|
@@ -79,7 +76,7 @@ module Archetype::SassExtensions::Styleguide
|
|
79
76
|
extensions = theme[:extensions]
|
80
77
|
return Sass::Script::Bool.new(false) if component_exists(id, theme, extension, force)
|
81
78
|
extensions.push(extension)
|
82
|
-
components[id] = (components[id] ||=
|
79
|
+
components[id] = (components[id] ||= {}).rmerge(helpers.list_to_hash(data, 1, SPECIAL, ADDITIVES))
|
83
80
|
return Sass::Script::Bool.new(true)
|
84
81
|
end
|
85
82
|
end
|
@@ -101,7 +98,7 @@ module Archetype::SassExtensions::Styleguide
|
|
101
98
|
#
|
102
99
|
def styleguide_component_exists(id, theme = nil, extension = nil, force = false)
|
103
100
|
@@archetype_styleguide_mutex.synchronize do
|
104
|
-
extension = helpers.to_str(extension)
|
101
|
+
extension = helpers.to_str(extension) if not extension.nil?
|
105
102
|
return Sass::Script::Bool.new( component_exists(id, theme, extension, force) )
|
106
103
|
end
|
107
104
|
end
|
@@ -226,34 +223,29 @@ private
|
|
226
223
|
#
|
227
224
|
def extract_styles(id, modifiers, strict = false, theme = nil, context = nil)
|
228
225
|
theme = get_theme(theme)
|
229
|
-
context ||= theme[:components][id] ||
|
226
|
+
context ||= theme[:components][id] || {}
|
230
227
|
modifiers = helpers.to_str(modifiers)
|
231
|
-
return
|
228
|
+
return {} if context.nil? or context.empty?
|
232
229
|
# push on the defaults first
|
233
|
-
out = (strict ? resolve_dependents(id, context[modifiers], theme[:name], context) : context[DEFAULT]) ||
|
230
|
+
out = (strict ? resolve_dependents(id, context[modifiers], theme[:name], context) : context[DEFAULT]) || {}
|
234
231
|
out = out.clone
|
235
232
|
# if it's not strict, find anything that matched
|
236
233
|
if not strict
|
237
234
|
modifiers = modifiers.split
|
238
|
-
context.each do |
|
239
|
-
definition = [key, definition]
|
235
|
+
context.each do |definition|
|
240
236
|
modifier = definition[0]
|
241
237
|
if modifier != DEFAULT
|
242
238
|
match = true
|
243
239
|
modifier = modifier.split
|
244
240
|
if modifier[0] == REGEX
|
245
241
|
# if it's a regex pattern, test if it matches
|
246
|
-
match = modifiers.join(' ') =~ /#{
|
242
|
+
match = modifiers.join(' ') =~ /#{modifiers[1].gsub(/\A"|"\Z/, '')}/i
|
247
243
|
else
|
248
244
|
# otherwise, if the modifier isn't in our list of modifiers, it's not valid and just move on
|
249
245
|
modifier.each { |i| match = false if not modifiers.include?(i) }
|
250
246
|
end
|
251
247
|
# if it matched, process it
|
252
|
-
if match
|
253
|
-
tmp = resolve_dependents(id, definition[1], theme[:name], nil, out)
|
254
|
-
out, tmp = post_resolve_drops(out, tmp)
|
255
|
-
out = out.rmerge(tmp)
|
256
|
-
end
|
248
|
+
out = out.rmerge(resolve_dependents(id, definition[1], theme[:name], nil, out.keys)) if match
|
257
249
|
end
|
258
250
|
end
|
259
251
|
end
|
@@ -261,19 +253,15 @@ private
|
|
261
253
|
# this lets us define special states and elements
|
262
254
|
SPECIAL.each do |special_key|
|
263
255
|
if out.is_a? Hash
|
264
|
-
special = out[special_key]
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
tmp = Archetype::Hash.new
|
269
|
-
special.each { |key, value| tmp[key] = extract_styles(key, key, true, theme[:name], special) }
|
270
|
-
out[special_key] = tmp if not tmp.empty?
|
271
|
-
end
|
256
|
+
special = out[special_key]
|
257
|
+
tmp = {}
|
258
|
+
(special || {}).each { |key, value| tmp[key] = extract_styles(key, key, true, theme[:name], special) }
|
259
|
+
out[special_key] = tmp if not tmp.empty?
|
272
260
|
end
|
273
261
|
end
|
274
262
|
# check for nested styleguides
|
275
263
|
styleguide = out[STYLEGUIDE]
|
276
|
-
if
|
264
|
+
if styleguide and not styleguide.empty?
|
277
265
|
styles = get_styles(styleguide, theme[:name])
|
278
266
|
out.delete(STYLEGUIDE)
|
279
267
|
out = styles.rmerge(out)
|
@@ -281,87 +269,6 @@ private
|
|
281
269
|
return out
|
282
270
|
end
|
283
271
|
|
284
|
-
#
|
285
|
-
# given two objects, resolve the chain of dropped styles
|
286
|
-
# this runs after having already resolved the dropped styles and merged
|
287
|
-
#
|
288
|
-
# *Parameters*:
|
289
|
-
# - <tt>obj</tt> {Hash} the source object
|
290
|
-
# - <tt>merger</tt> {Hash} the object to be merged in
|
291
|
-
# *Returns*:
|
292
|
-
# - {Array.<Hash>} the resulting `obj` and `merger` objects
|
293
|
-
#
|
294
|
-
def post_resolve_drops(obj, merger)
|
295
|
-
return [obj, merger] if obj.nil? or merger.nil?
|
296
|
-
drop = merger[DROP]
|
297
|
-
keys = obj.keys
|
298
|
-
if not drop.nil?
|
299
|
-
drop.to_a.each do |key|
|
300
|
-
key = helpers.to_str(key)
|
301
|
-
obj.delete(key) if not SPECIAL.include?(key)
|
302
|
-
end
|
303
|
-
merger.delete(DROP)
|
304
|
-
else
|
305
|
-
end
|
306
|
-
SPECIAL.each do |special|
|
307
|
-
if obj[special].is_a?(Hash) and merger[special].is_a?(Hash)
|
308
|
-
obj[special], merger[special] = post_resolve_drops(obj[special], merger[special])
|
309
|
-
end
|
310
|
-
end
|
311
|
-
return [obj, merger]
|
312
|
-
end
|
313
|
-
|
314
|
-
#
|
315
|
-
# given two objects, resolve the chain of dropped styles
|
316
|
-
#
|
317
|
-
# *Parameters*:
|
318
|
-
# - <tt>value</tt> {Hash} the source object
|
319
|
-
# - <tt>obj</tt> {Hash} the object to be merged in
|
320
|
-
# - <tt>is_special</tt> {Boolean} whether this is from a SPECIAL branch of a Hash
|
321
|
-
# *Returns*:
|
322
|
-
# - {Array.<Hash>} the resulting value
|
323
|
-
#
|
324
|
-
def resolve_drops(value, obj, is_special = false)
|
325
|
-
return value if not (value.is_a?(Hash) and obj.is_a?(Hash))
|
326
|
-
keys = obj.keys
|
327
|
-
drop = value[DROP]
|
328
|
-
if not drop.nil?
|
329
|
-
tmp = Archetype::Hash.new
|
330
|
-
if DROPALL.include?(helpers.to_str(drop))
|
331
|
-
if not keys.nil?
|
332
|
-
keys.each do |key|
|
333
|
-
if SPECIAL.include?(key)
|
334
|
-
if not (obj[key].nil? or obj[key].empty?)
|
335
|
-
tmp[key] = Archetype::Hash.new
|
336
|
-
tmp[key][DROP] = obj[key].keys
|
337
|
-
end
|
338
|
-
else
|
339
|
-
tmp[key] = 'nil'
|
340
|
-
end
|
341
|
-
end
|
342
|
-
end
|
343
|
-
else
|
344
|
-
drop.to_a.each do |key|
|
345
|
-
key = helpers.to_str(key)
|
346
|
-
if SPECIAL.include?(key)
|
347
|
-
if not (obj[key].nil? or obj[key].empty?)
|
348
|
-
tmp[key] = Archetype::Hash.new
|
349
|
-
tmp[key][DROP] = obj[key].keys
|
350
|
-
end
|
351
|
-
else
|
352
|
-
tmp[key] = 'nil'
|
353
|
-
end
|
354
|
-
end
|
355
|
-
end
|
356
|
-
value.delete(DROP) if not is_special
|
357
|
-
value = tmp.rmerge(value)
|
358
|
-
end
|
359
|
-
value.each do |key|
|
360
|
-
value[key] = resolve_drops(value[key], obj[key], key, SPECIAL.include?(key)) if not value[key].nil?
|
361
|
-
end
|
362
|
-
return value
|
363
|
-
end
|
364
|
-
|
365
272
|
#
|
366
273
|
# resolve any dependent references from the component
|
367
274
|
#
|
@@ -374,19 +281,33 @@ private
|
|
374
281
|
# *Returns*:
|
375
282
|
# - {Hash} a hash of the resolved styles
|
376
283
|
#
|
377
|
-
def resolve_dependents(id, value, theme = nil, context = nil,
|
284
|
+
def resolve_dependents(id, value, theme = nil, context = nil, keys = nil)
|
378
285
|
# we have to create a clone here as the passed in value is volatile and we're performing destructive changes
|
379
286
|
value = value.clone
|
380
287
|
# check that we're dealing with a hash
|
381
288
|
if value.is_a?(Hash)
|
382
289
|
# check for dropped styles
|
383
|
-
|
384
|
-
|
290
|
+
drop = value[DROP]
|
291
|
+
if not drop.nil?
|
292
|
+
tmp = {}
|
293
|
+
if %w(all true).include?(helpers.to_str(drop)) and not keys.nil? and not keys.empty?
|
294
|
+
keys.each do |key|
|
295
|
+
tmp[key] = 'nil'
|
296
|
+
end
|
297
|
+
else
|
298
|
+
drop = drop.to_a
|
299
|
+
drop.each do |key|
|
300
|
+
tmp[helpers.to_str(key)] = 'nil'
|
301
|
+
end
|
302
|
+
end
|
303
|
+
value.delete(DROP)
|
304
|
+
value = tmp.rmerge(value)
|
305
|
+
end
|
385
306
|
# check for inheritance
|
386
307
|
inherit = value[INHERIT]
|
387
|
-
if
|
308
|
+
if inherit and not inherit.empty?
|
388
309
|
# create a temporary object and extract the nested styles
|
389
|
-
tmp =
|
310
|
+
tmp = {}
|
390
311
|
inherit.each { |related| tmp = tmp.rmerge(extract_styles(id, related, true, theme, context)) }
|
391
312
|
# remove the inheritance key and update the styles
|
392
313
|
value.delete(INHERIT)
|
@@ -407,18 +328,14 @@ private
|
|
407
328
|
#
|
408
329
|
def get_theme(theme)
|
409
330
|
theme_name = helpers.to_str(theme || 'archetype')
|
410
|
-
|
331
|
+
@@styleguide_themes ||= {}
|
332
|
+
theme = @@styleguide_themes[theme_name] ||= {}
|
411
333
|
theme[:name] ||= theme_name
|
412
334
|
theme[:components] ||= {}
|
413
335
|
theme[:extensions] ||= []
|
414
336
|
return theme
|
415
337
|
end
|
416
338
|
|
417
|
-
def _get_persisted_theme(theme_name)
|
418
|
-
theme = Thread.current[:styleguide_themes] ||= {}
|
419
|
-
theme[theme_name] ||= {}
|
420
|
-
end
|
421
|
-
|
422
339
|
#
|
423
340
|
# driver method for converting a sentence into a list of styles
|
424
341
|
#
|
@@ -431,8 +348,9 @@ private
|
|
431
348
|
#
|
432
349
|
def get_styles(description, theme = nil, state = 'false')
|
433
350
|
state = helpers.to_str(state)
|
434
|
-
|
435
|
-
|
351
|
+
description = description.to_a
|
352
|
+
styles = {}
|
353
|
+
description.each do |sentence|
|
436
354
|
# get the grammar from the sentence
|
437
355
|
id, modifiers, token = grammar(sentence, theme, state)
|
438
356
|
if id
|