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.
Files changed (253) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +97 -24
  3. data/README.md +11 -5
  4. data/VERSION +1 -0
  5. data/lib/archetype.rb +30 -18
  6. data/lib/archetype/actions/migrate.rb +152 -0
  7. data/lib/archetype/actions/theme.rb +6 -7
  8. data/lib/archetype/executor.rb +21 -7
  9. data/lib/archetype/extensions.rb +57 -0
  10. data/lib/archetype/functions.rb +2 -3
  11. data/lib/archetype/functions/css.rb +70 -0
  12. data/lib/archetype/functions/css/constants.rb +247 -0
  13. data/lib/archetype/functions/css/helpers.rb +265 -0
  14. data/lib/archetype/functions/css/routers.rb +28 -0
  15. data/lib/archetype/functions/css/routers/animation.rb +55 -0
  16. data/lib/archetype/functions/css/routers/background.rb +38 -0
  17. data/lib/archetype/functions/css/routers/border.rb +151 -0
  18. data/lib/archetype/functions/css/routers/list.rb +63 -0
  19. data/lib/archetype/functions/css/routers/margin_padding.rb +40 -0
  20. data/lib/archetype/functions/css/routers/outline.rb +56 -0
  21. data/lib/archetype/functions/css/routers/overflow.rb +11 -0
  22. data/lib/archetype/functions/css/routers/target.rb +38 -0
  23. data/lib/archetype/functions/css/routers/transition.rb +48 -0
  24. data/lib/archetype/functions/css/shorthands.rb +43 -0
  25. data/lib/archetype/functions/css/shorthands/animation.rb +18 -0
  26. data/lib/archetype/functions/css/shorthands/background.rb +68 -0
  27. data/lib/archetype/functions/css/shorthands/border.rb +102 -0
  28. data/lib/archetype/functions/hash.rb +3 -149
  29. data/lib/archetype/functions/hash/extend.rb +74 -0
  30. data/lib/archetype/functions/hash/shim.rb +48 -0
  31. data/lib/archetype/functions/helpers.rb +231 -22
  32. data/lib/archetype/functions/styleguide_memoizer.rb +18 -1
  33. data/lib/archetype/sass_extensions.rb +1 -3
  34. data/lib/archetype/sass_extensions/functions.rb +15 -1
  35. data/lib/archetype/sass_extensions/functions/environment.rb +152 -1
  36. data/lib/archetype/sass_extensions/functions/lists.rb +95 -45
  37. data/lib/archetype/sass_extensions/functions/locale.rb +107 -28
  38. data/lib/archetype/sass_extensions/functions/numbers.rb +118 -4
  39. data/lib/archetype/sass_extensions/functions/strings.rb +53 -0
  40. data/lib/archetype/sass_extensions/functions/styleguide.rb +43 -375
  41. data/lib/archetype/sass_extensions/functions/styleguide/components.rb +25 -0
  42. data/lib/archetype/sass_extensions/functions/styleguide/constants.rb +27 -0
  43. data/lib/archetype/sass_extensions/functions/styleguide/grammar.rb +80 -0
  44. data/lib/archetype/sass_extensions/functions/styleguide/helpers.rb +36 -0
  45. data/lib/archetype/sass_extensions/functions/styleguide/resolve.rb +159 -0
  46. data/lib/archetype/sass_extensions/functions/styleguide/styles.rb +146 -0
  47. data/lib/archetype/sass_extensions/functions/styleguide/themes.rb +40 -0
  48. data/lib/archetype/sass_extensions/functions/ui.rb +7 -57
  49. data/lib/archetype/sass_extensions/functions/ui/glyphs.rb +118 -0
  50. data/lib/archetype/sass_extensions/functions/ui/scopes.rb +96 -0
  51. data/lib/archetype/sass_extensions/functions/util.rb +14 -0
  52. data/lib/archetype/sass_extensions/functions/util/debug.rb +22 -0
  53. data/lib/archetype/sass_extensions/functions/util/hacks.rb +44 -0
  54. data/lib/archetype/sass_extensions/functions/util/images.rb +132 -0
  55. data/lib/archetype/sass_extensions/functions/util/misc.rb +220 -0
  56. data/lib/archetype/sass_extensions/functions/util/spacing.rb +83 -0
  57. data/lib/archetype/sass_extensions/functions/version.rb +12 -17
  58. data/lib/archetype/version.rb +1 -1
  59. data/stylesheets/archetype/_config.scss +1 -389
  60. data/stylesheets/archetype/_core.scss +15 -0
  61. data/stylesheets/archetype/_hacks.scss +4 -120
  62. data/stylesheets/archetype/_init.scss +4 -22
  63. data/stylesheets/archetype/_required.scss +3 -0
  64. data/stylesheets/archetype/_reset.scss +3 -0
  65. data/stylesheets/archetype/_styleguide.scss +2 -6
  66. data/stylesheets/archetype/_ui.scss +2 -358
  67. data/stylesheets/archetype/_util.scss +3 -10
  68. data/stylesheets/archetype/config/_core.scss +14 -0
  69. data/stylesheets/archetype/config/_environment.scss +19 -0
  70. data/stylesheets/archetype/config/_formatting.scss +63 -0
  71. data/stylesheets/archetype/config/_glyphs.scss +252 -0
  72. data/stylesheets/archetype/config/_resets.scss +7 -0
  73. data/stylesheets/archetype/config/_resolution.scss +3 -0
  74. data/stylesheets/archetype/config/_spacing.scss +5 -0
  75. data/stylesheets/archetype/config/_targeting.scss +18 -0
  76. data/stylesheets/archetype/config/_theme.scss +3 -0
  77. data/stylesheets/archetype/config/_typography.scss +56 -0
  78. data/stylesheets/archetype/config/_units.scss +2 -0
  79. data/stylesheets/archetype/config/_vars.scss +10 -0
  80. data/stylesheets/archetype/hacks/_core.scss +4 -0
  81. data/stylesheets/archetype/hacks/_hacks.scss +160 -0
  82. data/stylesheets/archetype/hacks/_init.scss +2 -0
  83. data/stylesheets/archetype/styleguide/_core.scss +4 -0
  84. data/stylesheets/archetype/styleguide/_init.scss +1 -0
  85. data/stylesheets/archetype/styleguide/_styleguide.scss +41 -18
  86. data/stylesheets/archetype/ui/_accessibility.scss +41 -0
  87. data/stylesheets/archetype/ui/_breakpoints.scss +19 -0
  88. data/stylesheets/archetype/ui/_core.scss +10 -0
  89. data/stylesheets/archetype/ui/_elements.scss +98 -0
  90. data/stylesheets/archetype/ui/_glyphs.scss +244 -0
  91. data/stylesheets/archetype/ui/_init.scss +5 -0
  92. data/stylesheets/archetype/ui/_layout.scss +37 -0
  93. data/stylesheets/archetype/ui/_locale.scss +12 -0
  94. data/stylesheets/archetype/ui/_scopes.scss +42 -0
  95. data/stylesheets/archetype/util/_core.scss +8 -0
  96. data/stylesheets/archetype/util/_debug.scss +9 -21
  97. data/stylesheets/archetype/util/_init.scss +1 -0
  98. data/stylesheets/archetype/util/_misc.scss +21 -86
  99. data/stylesheets/archetype/util/_spacing.scss +9 -40
  100. data/stylesheets/archetype/util/_styles.scss +189 -178
  101. data/stylesheets/archetype/util/_targeting.scss +51 -68
  102. data/templates/example/manifest.rb +2 -2
  103. data/templates/example/screen.scss +0 -1
  104. data/templates/project/manifest.rb +3 -8
  105. metadata +93 -263
  106. data/bin/archetype +0 -3
  107. data/lib/archetype/sass_extensions/monkey_patches.rb +0 -3
  108. data/lib/archetype/sass_extensions/monkey_patches/handle_include_loop.rb +0 -13
  109. data/stylesheets/archetype/_base.scss +0 -54
  110. data/stylesheets/archetype/_grid.scss +0 -3
  111. data/stylesheets/archetype/base/_h5bp.scss +0 -307
  112. data/stylesheets/archetype/base/_hybrid.scss +0 -25
  113. data/stylesheets/archetype/base/_normalize.scss +0 -634
  114. data/stylesheets/archetype/base/_reset.scss +0 -72
  115. data/stylesheets/archetype/grid/_config.scss +0 -14
  116. data/stylesheets/archetype/grid/_grid.scss +0 -391
  117. data/stylesheets/archetype/styleguide/_components.scss +0 -25
  118. data/stylesheets/archetype/styleguide/_helpers.scss +0 -215
  119. data/stylesheets/archetype/styleguide/_primitives.scss +0 -10
  120. data/stylesheets/archetype/styleguide/components/_alerts.scss +0 -59
  121. data/stylesheets/archetype/styleguide/components/_annotations.scss +0 -27
  122. data/stylesheets/archetype/styleguide/components/_bristol.scss +0 -15
  123. data/stylesheets/archetype/styleguide/components/_button_groups.scss +0 -47
  124. data/stylesheets/archetype/styleguide/components/_button_toolbars.scss +0 -17
  125. data/stylesheets/archetype/styleguide/components/_buttons.scss +0 -339
  126. data/stylesheets/archetype/styleguide/components/_canvas.scss +0 -15
  127. data/stylesheets/archetype/styleguide/components/_carets.scss +0 -336
  128. data/stylesheets/archetype/styleguide/components/_closes.scss +0 -63
  129. data/stylesheets/archetype/styleguide/components/_container.scss +0 -27
  130. data/stylesheets/archetype/styleguide/components/_copy.scss +0 -85
  131. data/stylesheets/archetype/styleguide/components/_flyouts.scss +0 -52
  132. data/stylesheets/archetype/styleguide/components/_headings.scss +0 -33
  133. data/stylesheets/archetype/styleguide/components/_headlines.scss +0 -64
  134. data/stylesheets/archetype/styleguide/components/_hovercards.scss +0 -27
  135. data/stylesheets/archetype/styleguide/components/_icons.scss +0 -17
  136. data/stylesheets/archetype/styleguide/components/_identities.scss +0 -34
  137. data/stylesheets/archetype/styleguide/components/_links.scss +0 -68
  138. data/stylesheets/archetype/styleguide/components/_loaders.scss +0 -154
  139. data/stylesheets/archetype/styleguide/components/_menu_items.scss +0 -31
  140. data/stylesheets/archetype/styleguide/components/_module.scss +0 -15
  141. data/stylesheets/archetype/styleguide/components/_pullquotes.scss +0 -29
  142. data/stylesheets/archetype/styleguide/components/_punchcut.scss +0 -18
  143. data/stylesheets/archetype/styleguide/components/_tooltips.scss +0 -28
  144. data/stylesheets/archetype/styleguide/primitives/_animations.scss +0 -17
  145. data/stylesheets/archetype/styleguide/primitives/_dimensions.scss +0 -50
  146. data/stylesheets/archetype/styleguide/primitives/_glyphs.scss +0 -11
  147. data/stylesheets/archetype/styleguide/primitives/_misc.scss +0 -8
  148. data/stylesheets/archetype/styleguide/primitives/_palettes.scss +0 -94
  149. data/stylesheets/archetype/styleguide/primitives/_shadows.scss +0 -23
  150. data/stylesheets/archetype/styleguide/primitives/_sprites.scss +0 -46
  151. data/stylesheets/archetype/styleguide/primitives/_textures.scss +0 -10
  152. data/stylesheets/archetype/styleguide/primitives/_typography.scss +0 -56
  153. data/stylesheets/archetype/util/_lists.scss +0 -57
  154. data/stylesheets/archetype/util/_rtl.scss +0 -279
  155. data/stylesheets/archetype/util/_units.scss +0 -18
  156. data/templates/project/screen.scss +0 -1
  157. data/templates/project/vendor/archetype/animations/loaders/large/large.png +0 -0
  158. data/templates/project/vendor/archetype/animations/loaders/large/large_dark.png +0 -0
  159. data/templates/project/vendor/archetype/animations/loaders/large/large_dark_static.png +0 -0
  160. data/templates/project/vendor/archetype/animations/loaders/large/large_static.png +0 -0
  161. data/templates/project/vendor/archetype/animations/loaders/medium/medium.png +0 -0
  162. data/templates/project/vendor/archetype/animations/loaders/medium/medium_dark.png +0 -0
  163. data/templates/project/vendor/archetype/animations/loaders/medium/medium_dark_static.png +0 -0
  164. data/templates/project/vendor/archetype/animations/loaders/medium/medium_static.png +0 -0
  165. data/templates/project/vendor/archetype/animations/loaders/small/small.png +0 -0
  166. data/templates/project/vendor/archetype/animations/loaders/small/small_dark.png +0 -0
  167. data/templates/project/vendor/archetype/animations/loaders/small/small_dark_static.png +0 -0
  168. data/templates/project/vendor/archetype/animations/loaders/small/small_static.png +0 -0
  169. data/templates/project/vendor/archetype/fontawesome-webfont.eot +0 -0
  170. data/templates/project/vendor/archetype/fontawesome-webfont.svg +0 -255
  171. data/templates/project/vendor/archetype/fontawesome-webfont.ttf +0 -0
  172. data/templates/project/vendor/archetype/fontawesome-webfont.woff +0 -0
  173. data/test/fixtures/stylesheets/archetype/assets/fonts/fontawesome-webfont.eot +0 -0
  174. data/test/fixtures/stylesheets/archetype/assets/fonts/fontawesome-webfont.svg +0 -255
  175. data/test/fixtures/stylesheets/archetype/assets/fonts/fontawesome-webfont.ttf +0 -0
  176. data/test/fixtures/stylesheets/archetype/assets/fonts/fontawesome-webfont.woff +0 -0
  177. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders-s7889ccc8c1.png +0 -0
  178. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/large/large.png +0 -0
  179. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/large/large_dark.png +0 -0
  180. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/large/large_dark_static.png +0 -0
  181. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/large/large_static.png +0 -0
  182. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/medium/medium.png +0 -0
  183. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/medium/medium_dark.png +0 -0
  184. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/medium/medium_dark_static.png +0 -0
  185. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/medium/medium_static.png +0 -0
  186. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/small/small.png +0 -0
  187. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/small/small_dark.png +0 -0
  188. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/small/small_dark_static.png +0 -0
  189. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/animations/loaders/small/small_static.png +0 -0
  190. data/test/fixtures/stylesheets/archetype/assets/images/vendor/archetype/sprites/hovercard_tip.png +0 -0
  191. data/test/fixtures/stylesheets/archetype/config.rb +0 -21
  192. data/test/fixtures/stylesheets/archetype/source/b.scss +0 -9
  193. data/test/fixtures/stylesheets/archetype/source/base.scss +0 -3
  194. data/test/fixtures/stylesheets/archetype/source/hacks/ie_pseudo.scss +0 -13
  195. data/test/fixtures/stylesheets/archetype/source/hacks/transparent_focusable.scss +0 -5
  196. data/test/fixtures/stylesheets/archetype/source/locale.scss +0 -43
  197. data/test/fixtures/stylesheets/archetype/source/styleguide/alerts.scss +0 -21
  198. data/test/fixtures/stylesheets/archetype/source/styleguide/buttons.scss +0 -18
  199. data/test/fixtures/stylesheets/archetype/source/styleguide/drop.scss +0 -101
  200. data/test/fixtures/stylesheets/archetype/source/styleguide/extend.scss +0 -24
  201. data/test/fixtures/stylesheets/archetype/source/styleguide/fallback_styles.scss +0 -23
  202. data/test/fixtures/stylesheets/archetype/source/styleguide/invalid_structures.scss +0 -85
  203. data/test/fixtures/stylesheets/archetype/source/styleguide/multi_value.scss +0 -18
  204. data/test/fixtures/stylesheets/archetype/source/styleguide/nested_styleguides.scss +0 -40
  205. data/test/fixtures/stylesheets/archetype/source/styleguide/selective_state.scss +0 -22
  206. data/test/fixtures/stylesheets/archetype/source/ui/glyph_icon.scss +0 -35
  207. data/test/fixtures/stylesheets/archetype/source/ui/hide_element.scss +0 -5
  208. data/test/fixtures/stylesheets/archetype/source/ui/stroke.scss +0 -13
  209. data/test/fixtures/stylesheets/archetype/source/ui/triangle.scss +0 -13
  210. data/test/fixtures/stylesheets/archetype/source/utilities/associative.scss +0 -24
  211. data/test/fixtures/stylesheets/archetype/source/utilities/custom_output_styler.scss +0 -22
  212. data/test/fixtures/stylesheets/archetype/source/utilities/if-set.scss +0 -16
  213. data/test/fixtures/stylesheets/archetype/source/utilities/spacing/horizontal-spacing.scss +0 -27
  214. data/test/fixtures/stylesheets/archetype/source/utilities/spacing/vertical-spacing.scss +0 -27
  215. data/test/fixtures/stylesheets/archetype/source/utilities/styles/filter.scss +0 -9
  216. data/test/fixtures/stylesheets/archetype/source/utilities/styles/font-family.scss +0 -9
  217. data/test/fixtures/stylesheets/archetype/source/utilities/styles/z-index.scss +0 -18
  218. data/test/fixtures/stylesheets/archetype/source/utilities/targeting/target-browser.scss +0 -77
  219. data/test/fixtures/stylesheets/archetype/source/utilities/targeting/target-os.scss +0 -42
  220. data/test/fixtures/stylesheets/archetype/tmp/b.css +0 -14
  221. data/test/fixtures/stylesheets/archetype/tmp/base.css +0 -349
  222. data/test/fixtures/stylesheets/archetype/tmp/hacks/ie_pseudo.css +0 -11
  223. data/test/fixtures/stylesheets/archetype/tmp/hacks/transparent_focusable.css +0 -4
  224. data/test/fixtures/stylesheets/archetype/tmp/locale.css +0 -23
  225. data/test/fixtures/stylesheets/archetype/tmp/styleguide/alerts.css +0 -711
  226. data/test/fixtures/stylesheets/archetype/tmp/styleguide/buttons.css +0 -2119
  227. data/test/fixtures/stylesheets/archetype/tmp/styleguide/drop.css +0 -63
  228. data/test/fixtures/stylesheets/archetype/tmp/styleguide/extend.css +0 -11
  229. data/test/fixtures/stylesheets/archetype/tmp/styleguide/fallback_styles.css +0 -10
  230. data/test/fixtures/stylesheets/archetype/tmp/styleguide/invalid_structures.css +0 -21
  231. data/test/fixtures/stylesheets/archetype/tmp/styleguide/multi_value.css +0 -13
  232. data/test/fixtures/stylesheets/archetype/tmp/styleguide/nested_styleguides.css +0 -28
  233. data/test/fixtures/stylesheets/archetype/tmp/styleguide/selective_state.css +0 -177
  234. data/test/fixtures/stylesheets/archetype/tmp/ui/glyph_icon.css +0 -127
  235. data/test/fixtures/stylesheets/archetype/tmp/ui/hide_element.css +0 -8
  236. data/test/fixtures/stylesheets/archetype/tmp/ui/stroke.css +0 -17
  237. data/test/fixtures/stylesheets/archetype/tmp/ui/triangle.css +0 -35
  238. data/test/fixtures/stylesheets/archetype/tmp/utilities/associative.css +0 -9
  239. data/test/fixtures/stylesheets/archetype/tmp/utilities/custom_output_styler.css +0 -8
  240. data/test/fixtures/stylesheets/archetype/tmp/utilities/if-set.css +0 -9
  241. data/test/fixtures/stylesheets/archetype/tmp/utilities/spacing/horizontal-spacing.css +0 -29
  242. data/test/fixtures/stylesheets/archetype/tmp/utilities/spacing/vertical-spacing.css +0 -29
  243. data/test/fixtures/stylesheets/archetype/tmp/utilities/styles/filter.css +0 -11
  244. data/test/fixtures/stylesheets/archetype/tmp/utilities/styles/font-family.css +0 -16
  245. data/test/fixtures/stylesheets/archetype/tmp/utilities/styles/z-index.css +0 -15
  246. data/test/fixtures/stylesheets/archetype/tmp/utilities/targeting/target-browser.css +0 -105
  247. data/test/fixtures/stylesheets/archetype/tmp/utilities/targeting/target-os.css +0 -55
  248. data/test/helpers/diff.rb +0 -49
  249. data/test/helpers/io.rb +0 -36
  250. data/test/helpers/test_case.rb +0 -62
  251. data/test/integrations/archetype_test.rb +0 -126
  252. data/test/test_helper.rb +0 -26
  253. data/test/units/sass_extensions_test.rb +0 -200
@@ -20,7 +20,7 @@ private
20
20
  #
21
21
  def self.tokenize(theme, extensions, id, modifiers, state)
22
22
  return nil if extensions.nil? or id.nil?
23
- return "#{id}::#{(modifiers.to_a.sort + extensions).join('$')}::#{state}"
23
+ return "#{id}::#{(modifiers.to_a.sort + extensions).join('$')}::#{state}".hash
24
24
  end
25
25
 
26
26
  #
@@ -49,6 +49,23 @@ private
49
49
  return (@components[theme] ||= {})[token]
50
50
  end
51
51
 
52
+ #
53
+ # fetch a value from the memoizer if available, otherwise execute the block and create it
54
+ #
55
+ # *Parameters*:
56
+ # - <tt>theme</tt> {String} the theme name
57
+ # - <tt>token</tt> {Fixnum} the token to lookup
58
+ # *Returns*:
59
+ # - <tt>value</tt> {Hash} the value from the memoizer
60
+ #
61
+ def self.fetch_or_create(theme, token)
62
+ fetched = self.fetch(theme, token)
63
+ return fetched if fetched
64
+ fetched = yield if block_given?
65
+ self.add(theme, token, fetched)
66
+ return fetched
67
+ end
68
+
52
69
  #
53
70
  # invalidate the memoizer for the theme
54
71
  #
@@ -1,7 +1,5 @@
1
1
  # :stopdoc:
2
2
  # This module exposes the available methods to Sass
3
- module Archetype::SassExtensions
4
- end
3
+ module Archetype::SassExtensions; end
5
4
 
6
5
  require 'archetype/sass_extensions/functions'
7
- require 'archetype/sass_extensions/monkey_patches'
@@ -1,14 +1,28 @@
1
- %w(lists styleguide ui locale numbers version environment).each do |func|
1
+ # leverage Sass::Script::Value::Helpers
2
+ require 'sass/script/value/helpers'
3
+
4
+ %w(lists strings styleguide ui locale numbers version environment util).each do |func|
2
5
  require "archetype/sass_extensions/functions/#{func}"
3
6
  end
4
7
 
5
8
  # :stopdoc:
6
9
  module Sass::Script::Functions
10
+ include Archetype::SassExtensions::Util
7
11
  include Archetype::SassExtensions::Lists
12
+ include Archetype::SassExtensions::Strings
8
13
  include Archetype::SassExtensions::Styleguide
9
14
  include Archetype::SassExtensions::UI
10
15
  include Archetype::SassExtensions::Locale
11
16
  include Archetype::SassExtensions::Numbers
12
17
  include Archetype::SassExtensions::Version
13
18
  include Archetype::SassExtensions::Environment
19
+
20
+ private
21
+ # shortcut to Archetype::Functions::Helpers
22
+ def helpers
23
+ Archetype::Functions::Helpers
24
+ end
25
+
26
+ # include the Sass::Script::Value::Helpers in the context for all included modules
27
+ include Sass::Script::Value::Helpers
14
28
  end
@@ -9,6 +9,157 @@ module Archetype::SassExtensions::Environment
9
9
  # - {String} the current environment the compiler is running in
10
10
  #
11
11
  def archetype_env
12
- return Sass::Script::String.new((Compass.configuration.environment || :development).to_s)
12
+ return identifier((Compass.configuration.environment || :development).to_s)
13
13
  end
14
+
15
+ #
16
+ # namespaces a string
17
+ #
18
+ # *Parameters*:
19
+ # - <tt>$string</tt> {String} the string to namespace
20
+ # *Returns*:
21
+ # - {String} the namespaced string
22
+ #
23
+ def archetype_namespace(string)
24
+ namespace = environment.var('CONFIG_NAMESPACE')
25
+ return string if is_null(namespace).value
26
+ return identifier(namespace.value + '_' + string.value)
27
+ end
28
+
29
+ #
30
+ # gets the value of the given key from the `meta` config map
31
+ #
32
+ # *Parameters*:
33
+ # - <tt>$key</tt> {String} the key to lookup
34
+ # *Returns*:
35
+ # - {*} the value from the meta map
36
+ #
37
+ def archetype_meta(key)
38
+ # if `$CONFIG_META` is set, use it, otherwise, use the one set on the configuration object
39
+ meta = environment.var('CONFIG_META') || Compass.configuration.archetype_meta || {}
40
+ # convert it to a hash
41
+ meta = helpers.map_to_hash(meta)
42
+ # fetch the value for the key
43
+ value = meta[key.value]
44
+ # if we got nothing...
45
+ if value.nil?
46
+ # return `null`
47
+ return null
48
+ # if it's a Sass::Script value...
49
+ elsif value.is_a?(Sass::Script::Value::Base)
50
+ # just return it
51
+ return value
52
+ # otherwise...
53
+ else
54
+ # convert it to a Sass::Script::String
55
+ return identifier(helpers.to_str(value))
56
+ end
57
+ end
58
+
59
+ #
60
+ # registers an Archetype module as active
61
+ #
62
+ # *Parameters*:
63
+ # - <tt>$name</tt> {String} the module name
64
+ # *Returns*:
65
+ # - {List} the list of current registered modules
66
+ #
67
+ def register_archetype_module(name)
68
+ registry = archetype_modules_registry
69
+ # if it's already in the registry, just return the current list
70
+ return list(registry, :comma) if archetype_modules_registry.include?(name)
71
+ # update the registry with the module name
72
+ registry = list(registry.dup.push(name), :comma)
73
+ environment.global_env.set_var('ARCHETYPE_MODULES_REGISTRY', registry)
74
+ # return the registry
75
+ return registry
76
+ end
77
+
78
+ #
79
+ # checks to see if a required module is loaded or not
80
+ # if not, throws an error
81
+ #
82
+ # *Parameters*:
83
+ # - <tt>$name</tt> {String} the module name
84
+ # *Returns*:
85
+ # - {Boolean} whether or not all the modules are registered
86
+ #
87
+ def require_archetype_modules(*names)
88
+ return check_archetype_modules(names, true)
89
+ end
90
+ alias_method :require_archetype_module, :require_archetype_modules
91
+
92
+ #
93
+ # checks whether or not a module has been registered
94
+ #
95
+ # *Parameters*:
96
+ # - <tt>$name</tt> {String} the module name
97
+ # *Returns*:
98
+ # - {Boolean} whether or not all the modules are registered
99
+ #
100
+ def has_archetype_modules(*names)
101
+ return check_archetype_modules(names, false)
102
+ end
103
+ alias_method :has_archetype_module, :has_archetype_modules
104
+
105
+ #
106
+ # sets the intialization state of Archetype
107
+ #
108
+ # *Parameters*
109
+ # - <tt>$state</tt> {*} the state to set
110
+ # *Returns*:
111
+ # - {*} the state that was just set
112
+ #
113
+ def init_archetype(state = identifier('done'))
114
+ environment.global_env.set_var('ARCHETYPE_INIT', state)
115
+ return state
116
+ end
117
+
118
+ #
119
+ # sets the intialization state of Archetype to `skip`
120
+ #
121
+ # *Returns*:
122
+ # - {String} the state `skip` that was just set
123
+ #
124
+ def skip_archetype_init
125
+ init_archetype(identifier('skip'))
126
+ end
127
+
128
+ #
129
+ # sets the intialization state of Archetype to `null`
130
+ #
131
+ # *Returns*:
132
+ # - {Null} the state `null` that was just set
133
+ #
134
+ def force_archetype_init
135
+ init_archetype(null)
136
+ end
137
+
138
+ #
139
+ # gets Archetype's current initialization state
140
+ #
141
+ # *Returns*:
142
+ # - {*} Archetype's current initialization state
143
+ #
144
+ def archetype_init_state
145
+ return environment.var('ARCHETYPE_INIT') || null
146
+ end
147
+
148
+ private
149
+
150
+ def check_archetype_modules(names, warn = false)
151
+ missing = []
152
+ names.each do |name|
153
+ missing << name unless archetype_modules_registry.include?(name)
154
+ end
155
+ if missing.count > 0 and warn
156
+ helpers.logger.record(:error, "[archetype:module:missing] the required module#{missing.count > 1 ? 's are' : ' is'} missing: #{helpers.to_str(missing)}")
157
+ end
158
+ return bool(missing.count == 0)
159
+ end
160
+
161
+ def archetype_modules_registry
162
+ (environment.var('ARCHETYPE_MODULES_REGISTRY') || []).to_a
163
+ end
164
+
14
165
  end
@@ -1,7 +1,5 @@
1
- require 'archetype/functions/helpers'
2
-
3
1
  #
4
- # This module provides a set of Sass functions for working with Sass::List
2
+ # This module provides a set of Sass functions for working with Sass::Script::Value::List
5
3
  #
6
4
  module Archetype::SassExtensions::Lists
7
5
  #
@@ -17,18 +15,19 @@ module Archetype::SassExtensions::Lists
17
15
  #
18
16
  def list_replace(list, idx = false, value = nil, separator = nil)
19
17
  # 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')
18
+ return list if (!idx || is_null(idx).value || idx.value == false)
19
+ separator ||= list.separator if list.is_a?(Sass::Script::Value::List)
24
20
  # cast and zero-index $idx
25
21
  idx = (idx.value) - 1
26
22
  # cast list to a ruby array
27
- list = list.to_a
23
+ list = list.to_a.dup
28
24
  # 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)
25
+ if value.nil? or value == null
26
+ list.delete_at(idx)
27
+ else
28
+ list[idx] = value
29
+ end
30
+ return Sass::Script::Value::List.new(list, separator)
32
31
  end
33
32
  Sass::Script::Functions.declare :list_replace, [:list, :idx]
34
33
  Sass::Script::Functions.declare :list_replace, [:list, :idx, :value]
@@ -75,7 +74,7 @@ module Archetype::SassExtensions::Lists
75
74
  # add values(s) to a list
76
75
  #
77
76
  # *Parameters*:
78
- # - <tt>$list</tt> {List} the list operate on
77
+ # - <tt>$list</tt> {List} the list operate to on
79
78
  # - <tt>$values</tt> {List|Number|String} the value(s) to add to the list
80
79
  # *Returns*:
81
80
  # - {List} the final list
@@ -83,12 +82,13 @@ module Archetype::SassExtensions::Lists
83
82
  def list_add(list, values)
84
83
  return list_math(list, values, :plus)
85
84
  end
85
+ Sass::Script::Functions.declare :list_add, [:list, :values]
86
86
 
87
87
  #
88
88
  # subtract values(s) from a list
89
89
  #
90
90
  # *Parameters*:
91
- # - <tt>$list</tt> {List} the list operate on
91
+ # - <tt>$list</tt> {List} the list operate to on
92
92
  # - <tt>$values</tt> {List|Number|String} the value(s) to subtract from the list
93
93
  # *Returns*:
94
94
  # - {List} the final list
@@ -96,12 +96,13 @@ module Archetype::SassExtensions::Lists
96
96
  def list_subtract(list, values)
97
97
  return list_math(list, values, :minus)
98
98
  end
99
+ Sass::Script::Functions.declare :list_subtract, [:list, :values]
99
100
 
100
101
  #
101
102
  # multiply values(s) into a list
102
103
  #
103
104
  # *Parameters*:
104
- # - <tt>$list</tt> {List} the list operate on
105
+ # - <tt>$list</tt> {List} the list operate to on
105
106
  # - <tt>$values</tt> {List|Number|String} the value(s) to multiply into the list
106
107
  # *Returns*:
107
108
  # - {List} the final list
@@ -109,12 +110,13 @@ module Archetype::SassExtensions::Lists
109
110
  def list_multiply(list, values)
110
111
  return list_math(list, values, :times)
111
112
  end
113
+ Sass::Script::Functions.declare :list_multiply, [:list, :values]
112
114
 
113
115
  #
114
116
  # divide values(s) into a list
115
117
  #
116
118
  # *Parameters*:
117
- # - <tt>$list</tt> {List} the list operate on
119
+ # - <tt>$list</tt> {List} the list operate to on
118
120
  # - <tt>$values</tt> {List|Number|String} the value(s) to divide into the list
119
121
  # *Returns*:
120
122
  # - {List} the final list
@@ -122,12 +124,13 @@ module Archetype::SassExtensions::Lists
122
124
  def list_divide(list, values)
123
125
  return list_math(list, values, :div)
124
126
  end
127
+ Sass::Script::Functions.declare :list_divide, [:list, :values]
125
128
 
126
129
  #
127
130
  # list modulus value(s)
128
131
  #
129
132
  # *Parameters*:
130
- # - <tt>$list</tt> {List} the list operate on
133
+ # - <tt>$list</tt> {List} the list to operate on
131
134
  # - <tt>$values</tt> {List|Number|String} the value(s) to modulus into the list
132
135
  # *Returns*:
133
136
  # - {List} the final list
@@ -135,6 +138,23 @@ module Archetype::SassExtensions::Lists
135
138
  def list_mod(list, values)
136
139
  return list_math(list, values, :mod)
137
140
  end
141
+ Sass::Script::Functions.declare :list_mod, [:list, :values]
142
+
143
+ #
144
+ # joins a list into a string with the separator given
145
+ #
146
+ # *Parameters*:
147
+ # - <tt>$list</tt> {List} the list operate to on
148
+ # - <tt>$separator</tt> {String} the separator to insert between each item
149
+ # *Returns*:
150
+ # - {String} string conversions of all list item joined into one string
151
+ #
152
+ def list_join(list, separator = ', ')
153
+ list = list.to_a
154
+ separator = (separator.respond_to?(:value) ? separator.value : separator).to_s
155
+ return identifier(list.join(separator))
156
+ end
157
+ Sass::Script::Functions.declare :list_join, [:list, :separator]
138
158
 
139
159
  #
140
160
  # find if any set of values is in a list
@@ -151,11 +171,12 @@ module Archetype::SassExtensions::Lists
151
171
  needle = needle.to_a
152
172
  index = haystack.index(haystack.detect { |i| needle.include?(i) })
153
173
  if index
154
- return Sass::Script::Number.new(index + 1)
174
+ return number(index + 1)
155
175
  else
156
176
  return Sass::Script::Bool.new(false)
157
177
  end
158
178
  end
179
+ Sass::Script::Functions.declare :index2, [:haystack, :needle]
159
180
 
160
181
  #
161
182
  # treats a list cyclically (never out of bounds, just wraps around)
@@ -167,10 +188,12 @@ module Archetype::SassExtensions::Lists
167
188
  # - {*} the nth item in the List
168
189
  #
169
190
  def nth_cyclic(list, n = 1)
170
- n = n.to_i if n.is_a?(Sass::Script::Number)
191
+ n = n.to_i if n.is_a?(Sass::Script::Value::Number)
171
192
  list = list.to_a
172
193
  return list[(n - 1) % list.size]
173
194
  end
195
+ Sass::Script::Functions.declare :nth_cyclic, [:list]
196
+ Sass::Script::Functions.declare :nth_cyclic, [:list, :n]
174
197
 
175
198
  #
176
199
  # find a key within a nested list of ordered pairs
@@ -183,11 +206,11 @@ module Archetype::SassExtensions::Lists
183
206
  # - {*} the data associated with $key
184
207
  #
185
208
  def associative(list, key, strict = false)
186
- separator = list.separator if list.is_a?(Sass::Script::List)
209
+ separator = list.separator if list.is_a?(Sass::Script::Value::List)
187
210
  list = helpers.list_to_hash(list)
188
211
  item = list[helpers.to_str(key, ' ' , :quotes)]
189
212
  item ||= list.first[1] if not strict
190
- return Sass::Script::List.new([], separator) if item.nil?
213
+ return Sass::Script::Value::List.new([], separator) if item.nil?
191
214
  return helpers.hash_to_list(item, 0, separator) if item.is_a?(Array) or item.is_a?(Hash)
192
215
  # no conversion needed, so just return
193
216
  return item
@@ -205,7 +228,7 @@ module Archetype::SassExtensions::Lists
205
228
  # - <tt>$list</tt> {List} the extended list
206
229
  #
207
230
  def associative_merge(list, extender, kwargs = {})
208
- separator = list.separator if list.is_a?(Sass::Script::List)
231
+ separator = list.separator if list.is_a?(Sass::Script::Value::List)
209
232
  list = helpers.list_to_hash(list)
210
233
  extender = helpers.list_to_hash(extender)
211
234
  list = list.rmerge(extender)
@@ -213,6 +236,47 @@ module Archetype::SassExtensions::Lists
213
236
  end
214
237
  Sass::Script::Functions.declare :associative_merge, [:list, :extender]
215
238
 
239
+ #
240
+ # map collection items to conform to a well defined collection
241
+ # this is primarily used to convert shorthand notations into symmetrical longhand notations
242
+ #
243
+ # *Parameters*:
244
+ # - <tt>$list</tt> {List} input list
245
+ # - <tt>$components</tt> {List} list of components
246
+ # - <tt>$min</tt> {List} the minimum length of the collection
247
+ # *Returns*:
248
+ # - {List} formatted collection
249
+ #
250
+ def get_collection(list = bool(false), components = [], min = number(1))
251
+ list = list.value ? list.to_a : components.to_a
252
+ while(list.length < min.value)
253
+ list = list.concat(list)
254
+ end
255
+ return list(list, :space)
256
+ end
257
+ Sass::Script::Functions.declare :get_collection, [:list]
258
+ Sass::Script::Functions.declare :get_collection, [:components]
259
+ Sass::Script::Functions.declare :get_collection, [:list, :min]
260
+ Sass::Script::Functions.declare :get_collection, [:components, :min]
261
+ Sass::Script::Functions.declare :get_collection, [:list, :components, :min]
262
+
263
+ # Returns a list object from a value that was passed.
264
+ # This can be used to unpack a space separated list that got turned
265
+ # into a string by sass before it was passed to a mixin.
266
+ # this is shamelessly stolen from Compass :)
267
+ #
268
+ # *Parameters*:
269
+ # - <tt>$arg</tt> {*} the item to cast to a list
270
+ # *Returns*:
271
+ # - <tt>$list</tt> {List} the item as a list
272
+ #
273
+ def _archetype_list(arg)
274
+ # if it's already a list, just return it
275
+ return arg if arg.is_a?(Sass::Script::Value::List)
276
+ # otherwise, we'll try to cast it
277
+ return list(arg, :space)
278
+ end
279
+
216
280
  #
217
281
  # given a string of styles, convert it into a key-value pair list
218
282
  #
@@ -231,48 +295,34 @@ module Archetype::SassExtensions::Lists
231
295
  tmp.each do |rule|
232
296
  kvp = []
233
297
  rule.split(':').each do |str|
234
- kvp.push Sass::Script::String.new(str)
298
+ kvp.push identifier(str)
235
299
  end
236
- styles.push Sass::Script::List.new(kvp, :comma)
300
+ styles.push Sass::Script::Value::List.new(kvp, :comma)
237
301
  end
238
- # the recompose the list
239
- return Sass::Script::List.new(styles, :comma)
302
+ # then recompose the list
303
+ return Sass::Script::Value::List.new(styles, :comma)
240
304
  end
241
305
 
242
306
  private
243
- def helpers
244
- @helpers ||= Archetype::Functions::Helpers
245
- end
246
307
 
247
308
  #
248
309
  # perform math operations on a list
249
310
  #
250
311
  # *Parameters*:
251
- # - <tt>list</tt> {Sass::List} the list operate on
252
- # - <tt>values</tt> {Sass::List|Sass::Number|Sass::String} the value(s) perform with
312
+ # - <tt>list</tt> {Sass::Script::Value::List} the list operate to on
313
+ # - <tt>values</tt> {Sass::Script::Value::List|Sass::Script::Value::Number|Sass::Script::Value::String} the value(s) perform with
253
314
  # - <tt>method</tt> {Symbol} the method to perform [:plus|:minus|:times|:div|:mod]
254
315
  # *Returns*:
255
- # - {Sass::List} the final list
316
+ # - {Sass::Script::Value::List} the final list
256
317
  #
257
318
  def list_math(list, values, method = :plus)
258
- separator = list.separator if list.is_a?(Sass::Script::List)
319
+ separator = list.separator if list.is_a?(Sass::Script::Value::List)
259
320
  values = values.to_a
260
321
  list = list.to_a
261
322
  values.fill(values[0], 0..(list.size - 1)) if values.size < list.size
262
323
  list = [list, values].transpose.map do |x|
263
- case method
264
- when :plus
265
- x[0].plus(x[1])
266
- when :minus
267
- x[0].minus(x[1])
268
- when :times
269
- x[0].times(x[1])
270
- when :div
271
- x[0].div(x[1])
272
- when :mod
273
- x[0].mod(x[1])
274
- end
324
+ x[0].method(method).call(x[1])
275
325
  end
276
- return Sass::Script::List.new(list, separator)
326
+ return Sass::Script::Value::List.new(list, separator)
277
327
  end
278
328
  end