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
@@ -0,0 +1,40 @@
1
+ module Archetype::SassExtensions::Styleguide
2
+
3
+ private
4
+
5
+ #
6
+ # keep a registry of styleguide themes
7
+ #
8
+ # *Parameters*:
9
+ # - <tt>theme</tt> {String} the theme to use
10
+ # *Returns*:
11
+ # - {Hash} the theme
12
+ #
13
+ def get_theme(theme)
14
+ if @@styleguide_themes.nil?
15
+ # bind a callback to file save to cleanup the cache if needed
16
+ Compass.configuration.on_stylesheet_saved do |filename|
17
+ ::Archetype::SassExtensions::Styleguide.reset!(filename) unless Compass.configuration.memoize == :aggressive
18
+ end
19
+ end
20
+ @@styleguide_themes ||= {}
21
+ theme_name = helpers.to_str(theme || environment.var('CONFIG_THEME') || Archetype.name)
22
+ key = nil
23
+ begin
24
+ key = environment.options[:css_filename].hash
25
+ end
26
+ # if we're aggressively memoizing, store everything across the session
27
+ if Compass.configuration.memoize == :aggressive or not key
28
+ styleguide_store = @@styleguide_themes
29
+ #otherwise, just store it per this file instance
30
+ else
31
+ styleguide_store = @@styleguide_themes[key] ||= {}
32
+ end
33
+ theme = styleguide_store[theme_name] ||= {}
34
+ theme[:name] ||= theme_name
35
+ theme[:components] ||= {}
36
+ theme[:extensions] ||= []
37
+ return theme
38
+ end
39
+
40
+ end
@@ -1,60 +1,10 @@
1
- require 'archetype/functions/helpers'
2
- require 'thread'
1
+ module Archetype::SassExtensions::UI; end
3
2
 
4
- #
5
- # This module provides some UI helper methods.
6
- #
7
- module Archetype::SassExtensions::UI
8
- # :stopdoc:
9
- @@archetype_ui_mutex = Mutex.new
10
- # :startdoc:
11
-
12
- #
13
- # generate a unique token
14
- #
15
- # *Parameters*:
16
- # - <tt>$prefix</tt> {String} a string to prefix the UID with, `class` and `id` will generate a unique selector
17
- # *Returns*:
18
- # - {String} the unique string
19
- #
20
- def unique(prefix = '')
21
- prefix = helpers.to_str(prefix, ' ', :quotes)
22
- prefix = '.' if prefix == 'class'
23
- prefix = '#' if prefix == 'id'
24
- suffix = Compass.configuration.testing ? "RANDOM_UID" : "#{Time.now.to_i}-#{rand(36**8).to_s(36)}-#{uid}"
25
- return Sass::Script::String.new("#{prefix}archetype-uid-#{suffix}")
26
- end
27
-
28
- #
29
- # parse a CSS content string and format it for injection into innerHTML
30
- #
31
- # *Parameters*:
32
- # - <tt>$content</tt> {String} the CSS content string
33
- # *Returns*:
34
- # - {String} the processed string
35
- #
36
- def _ie_pseudo_content(content)
37
- content = helpers.to_str(content)
38
- # escape &
39
- content = content.gsub(/\&/, '&amp;')
40
- # convert char codes (and remove single trailing whitespace if present) (e.g. \2079 -> &#x2079;)
41
- content = content.gsub(/\\([\da-zA-Z]{4})\s?/, '&#x\1;')
42
- # escape tags and cleanup quotes
43
- content = content.gsub(/\</, '&lt;').gsub(/\>/, '&gt;')
44
- # cleanup quotes
45
- content = content.gsub(/\A"|"\Z/, '').gsub(/\"/, '\\"')
46
- return Sass::Script::String.new(content)
47
- end
48
-
49
- private
50
- def helpers
51
- @helpers ||= Archetype::Functions::Helpers
52
- end
3
+ %w(glyphs scopes).each do |func|
4
+ require "archetype/sass_extensions/functions/ui/#{func}"
5
+ end
53
6
 
54
- def uid
55
- @@archetype_ui_mutex.synchronize do
56
- @@uid ||= 0
57
- @@uid += 1
58
- end
59
- end
7
+ module Archetype::SassExtensions::UI
8
+ include Archetype::SassExtensions::UI::Glyphs
9
+ include Archetype::SassExtensions::UI::Scopes
60
10
  end
@@ -0,0 +1,118 @@
1
+ module Archetype::SassExtensions::UI::Glyphs
2
+
3
+ #
4
+ # given a set of grid sizes and an individual size, return the closest matching size
5
+ #
6
+ # *Parameters*:
7
+ # - <tt>$grids</tt> {List} the list of grid options
8
+ # - <tt>$size</tt> {Number} the size to find a match for
9
+ # *Returns*:
10
+ # - {Number} the closest matching grid size
11
+ #
12
+ def choose_best_glyph_grid(grids, size)
13
+ return grids if grids == null
14
+
15
+ grids = grids.to_a
16
+
17
+ # perfect match?
18
+ if grids.include?(size)
19
+ return size
20
+ end
21
+
22
+ # otherwise let's find the best match
23
+ # start with assuming the first item is the best
24
+ best = {
25
+ :grid => grids.first,
26
+ :distance => (+1.0/0.0) # similuate Float::INFINITY, but for Ruby 1.8
27
+ }
28
+
29
+ # for each grid option...
30
+ grids.each do |grid|
31
+ # if the units are comparable...
32
+ if unit(grid) == unit(size)
33
+
34
+ tmp_grid = strip_units(grid).value.to_f
35
+ tmp_size = strip_units(size).value.to_f
36
+
37
+ # simple algorithm to compute the distance between the size and grid
38
+ # choose the lesser of the (mod) or (grid - mod)
39
+ # then divide it by grid^(number_of_grid_choices)
40
+ mod = (tmp_size % tmp_grid)
41
+ distance = [mod, tmp_grid - mod].min / tmp_grid**(grids.length)
42
+
43
+ # if it's closer (smaller distance), use it...
44
+ if distance < best[:distance]
45
+ best = {
46
+ :grid => grid,
47
+ :distance => distance
48
+ }
49
+ end
50
+ end
51
+ end
52
+ # return the best match we found
53
+ return best[:grid]
54
+ end
55
+ Sass::Script::Functions.declare :choose_best_glyph_grid, [:grids, :size]
56
+
57
+ #
58
+ # checks if a string looks like it's just a composition of character codes
59
+ #
60
+ # *Parameters*:
61
+ # - <tt>$string</tt> {String} the string to check
62
+ # *Returns*:
63
+ # - {Boolean} whether or not the string looks like a sequence of character codes
64
+ #
65
+ def looks_like_character_code(string)
66
+ string = helpers.to_str(string, ' ', :quotes)
67
+ return bool(string =~ /^(\\([\da-fA-F]{4})\s*)+$/)
68
+ end
69
+ Sass::Script::Functions.declare :looks_like_character_code, [:string]
70
+
71
+
72
+ #
73
+ # registers a glyph library under a given key
74
+ #
75
+ def register_glyph_library(key, library)
76
+ registry = archetype_glyphs_registry
77
+ # if it's already in the registry, just return the current list
78
+ if is_null(registry[key])
79
+ registry = registry.dup
80
+ registry[key] = library
81
+ registry = Sass::Script::Value::Map.new(registry)
82
+ environment.global_env.set_var('CONFIG_GLYPHS_LIBRARIES', registry)
83
+ end
84
+ return key
85
+ end
86
+
87
+ #
88
+ # gets a glyph library as registered under the given key
89
+ #
90
+ def get_glyph_library(key)
91
+ default_key = identifier('default')
92
+ default = archetype_glyphs_registry[default_key] || null
93
+ return default if key == default_key
94
+
95
+ library = archetype_glyphs_registry[key]
96
+ # if the library doesn't exist...
97
+ if helpers.is_null(library)
98
+ # notify the user
99
+ helpers.warn("[archetype:glyph] could not find a glyph library for `#{library}`, using default")
100
+ # and return the default
101
+ return default
102
+ end
103
+ # merge the library with the default
104
+ return map_merge(default, library)
105
+ end
106
+
107
+
108
+ def get_all_glyph_libraries
109
+ return environment.var('CONFIG_GLYPHS_LIBRARIES') || Sass::Script::Value::Map.new
110
+ end
111
+
112
+ private
113
+
114
+ def archetype_glyphs_registry
115
+ registry = environment.var('CONFIG_GLYPHS_LIBRARIES')
116
+ return registry.respond_to?(:to_h) ? registry.to_h : {}
117
+ end
118
+ end
@@ -0,0 +1,96 @@
1
+ module Archetype::SassExtensions::UI::Scopes
2
+
3
+ #
4
+ # registers a breakpoint
5
+ #
6
+ # *Parameters*:
7
+ # - <tt>$key</tt> {String} the key to register it under
8
+ # - <tt>$value</tt> {*} the value to register
9
+ # - <tt>$force</tt> {Boolean} if true, forces any new value into the registry
10
+ # *Returns*:
11
+ # - {Boolean} whether or not the value was registered
12
+ #
13
+ def register_breakpoint(key, value, force = nil)
14
+ # we need a dup as the Hash is frozen
15
+ breakpoints = registered_breakpoints.dup
16
+ force = force.nil? ? false : force.value
17
+ not_registered = breakpoints[key].nil? || is_null(breakpoints[key]).value
18
+ # if there's no key registered...
19
+ if force || not_registered
20
+ # just register the value
21
+ breakpoints[key] = value
22
+ # otherwise, if the current value is different...
23
+ elsif breakpoints[key] != value
24
+ # throw a warning
25
+ helpers.warn("[#{Archetype.name}:breakpoint] a breakpoint for `#{key}` is already set to `#{breakpoints[key]}`, ignoring `#{value}`")
26
+ return bool(false)
27
+ end
28
+ environment.global_env.set_var('CONFIG_BREAKPOINTS', Sass::Script::Value::Map.new(breakpoints))
29
+ return bool(true)
30
+ end
31
+ Sass::Script::Functions.declare :register_breakpoint, [:key, :value]
32
+ Sass::Script::Functions.declare :register_breakpoint, [:key, :value, :force]
33
+
34
+ #
35
+ # retrieves a breakpoint
36
+ #
37
+ # *Parameters*:
38
+ # - <tt>$key</tt> {String} the key to lookup
39
+ # *Returns*:
40
+ # - {*} the registered breakpoint
41
+ #
42
+ def get_breakpoint(key)
43
+ return registered_breakpoints[key] || null
44
+ end
45
+ Sass::Script::Functions.declare :get_breakpoint, [:key]
46
+
47
+ #
48
+ # convert a modifier/element context to a BEM style selector
49
+ #
50
+ # *Parameters*:
51
+ # - <tt>$context</tt> {String} the root selector to scope to
52
+ # - <tt>$element</tt> {String} the element name
53
+ # - <tt>$modifier</tt> {String} the modifier
54
+ # *Returns*:
55
+ # - {String} the BEM formatted selector
56
+ #
57
+ def bem_selector(context = nil, element = nil, modifier = nil)
58
+ element_separator = environment.var('CONFIG_BEM_ELEMENT_SEPARATOR')
59
+ element_separator = element_separator.nil? ? '__' : element_separator.value
60
+
61
+ modifier_separator = environment.var('CONFIG_BEM_MODIFIER_SEPARATOR')
62
+ modifier_separator = modifier_separator.nil? ? '--' : modifier_separator.value
63
+
64
+ context = is_null(context).value ? '' : context.value
65
+ element = is_null(element).value ? nil : element.value
66
+ modifier = is_null(modifier).value ? nil : modifier.value
67
+
68
+ selector = context
69
+
70
+ warning = "[#{Archetype.name}:bem] the current context may produce a non-standard BEM selector for";
71
+
72
+ unless element.nil?
73
+ helpers.warn("#{warning} element `#{element}`: #{context}") if (context.include?(element_separator) || context.include?(modifier_separator))
74
+ selector = "#{selector}#{element_separator}#{element}"
75
+ end
76
+
77
+ unless modifier.nil?
78
+ helpers.warn("#{warning} modifier `#{modifier}`: #{context}") if context.include?(modifier_separator)
79
+ selector = "#{selector}#{modifier_separator}#{modifier}"
80
+ end
81
+
82
+ return identifier(selector)
83
+ end
84
+ Sass::Script::Functions.declare :bem_selector, [:context]
85
+ Sass::Script::Functions.declare :bem_selector, [:context, :element]
86
+ Sass::Script::Functions.declare :bem_selector, [:context, :modifier]
87
+ Sass::Script::Functions.declare :bem_selector, [:context, :element, :modifier]
88
+
89
+ private
90
+
91
+ def registered_breakpoints
92
+ breakpoints = environment.var('CONFIG_BREAKPOINTS')
93
+ breakpoints.respond_to?(:to_h) ? breakpoints.to_h : {}
94
+ end
95
+
96
+ end
@@ -0,0 +1,14 @@
1
+ # :stopdoc:
2
+ module Archetype::SassExtensions::Util; end
3
+
4
+ %w(debug misc images spacing hacks).each do |func|
5
+ require "archetype/sass_extensions/functions/util/#{func}"
6
+ end
7
+
8
+ module Archetype::SassExtensions::Util
9
+ include Archetype::SassExtensions::Util::Misc
10
+ include Archetype::SassExtensions::Util::Images
11
+ include Archetype::SassExtensions::Util::Debug
12
+ include Archetype::SassExtensions::Util::Spacing
13
+ include Archetype::SassExtensions::Util::Hacks
14
+ end
@@ -0,0 +1,22 @@
1
+ module Archetype::SassExtensions::Util::Debug
2
+
3
+ #
4
+ # check if debug is enabled
5
+ #
6
+ # *Parameters*:
7
+ # - <tt>$iff</tt> {Boolean} optional override for `$CONFIG_DEBUG`
8
+ # *Returns*:
9
+ # - {Boolean} whether or not debug is enabled
10
+ #
11
+ def is_debug_enabled(iff = nil)
12
+ # debug is only available in DEBUG environments, so check that first
13
+ return bool(false) unless (environment.var('CONFIG_DEBUG_ENVS') || []).to_a.include?(archetype_env)
14
+ # then check if the debug flag/override is truthy
15
+ # if the param is non-null, then use it
16
+ return iff unless is_null(iff).value
17
+ # otherwise, use `CONFIG_DEBUG`
18
+ return environment.var('CONFIG_DEBUG') || bool(false)
19
+ end
20
+ Sass::Script::Functions.declare :is_debug_enabled, [:iff]
21
+
22
+ end
@@ -0,0 +1,44 @@
1
+ module Archetype::SassExtensions::Util::Hacks
2
+
3
+ #
4
+ # parse a CSS content string and format it for injection into innerHTML
5
+ #
6
+ # *Parameters*:
7
+ # - <tt>$content</tt> {String} the CSS content string
8
+ # *Returns*:
9
+ # - {String} the processed string
10
+ #
11
+ def _ie_pseudo_content(content)
12
+ content = helpers.to_str(content)
13
+ # escape &
14
+ content = content.gsub(/\&/, '&amp;')
15
+ # convert char codes (and remove single trailing whitespace if present) (e.g. \2079 -> &#x2079;)
16
+ content = content.gsub(/\\([\da-fA-F]{4})\s?/, '&#x\1;')
17
+ # escape tags and cleanup quotes
18
+ content = content.gsub(/\</, '&lt;').gsub(/\>/, '&gt;')
19
+ # cleanup quotes
20
+ content = content.gsub(/\A"|"\Z/, '').gsub(/\"/, '\\"')
21
+ return identifier(content)
22
+ end
23
+
24
+ #
25
+ # given a string of styles, convert it into a map
26
+ #
27
+ # *Parameters*:
28
+ # - <tt>$string</tt> {String} the string to convert
29
+ # *Returns*:
30
+ # - {Map} the converted map of styles
31
+ #
32
+ def _style_string_to_map(string = '')
33
+ # convert to string and strip all comments
34
+ string = helpers.to_str(string, ' ').gsub(/\/\*(?!\*\/)*\*\//, '')
35
+ # then split it on each rule and for each rule break it into it's key-value pairs
36
+ styles = string.split(';').map do |rule|
37
+ k, v = rule.split(':')
38
+ [identifier(k), identifier(v)]
39
+ end
40
+ # then recompose the map
41
+ return Sass::Script::Value::Map.new(Sass::Util.to_hash(styles))
42
+ end
43
+
44
+ end
@@ -0,0 +1,132 @@
1
+ module Archetype::SassExtensions::Util::Images
2
+
3
+ #
4
+ # helper to determine if a sprite is already set or sprites are disabled
5
+ #
6
+ # *Parameters*:
7
+ # - <tt>$sprite</tt> {SpriteMap} the sprite map to check against
8
+ # *Returns*:
9
+ # - {Boolean} should the sprite be set
10
+ #
11
+ def _shouldSetSprite(sprite)
12
+ is_sprite = sprite.is_a?(Compass::SassExtensions::Sprites::SpriteMap)
13
+ should_set_sprite = !global_sprites_disabled? && !is_sprite
14
+ return bool(should_set_sprite)
15
+ end
16
+ Sass::Script::Functions.declare :get_collection, [:components, :min]
17
+
18
+ #
19
+ # check that a sprite isn't null or false
20
+ #
21
+ # *Parameters*:
22
+ # - <tt>$map</tt> {SpriteMap} the sprite map to check against
23
+ # *Returns*:
24
+ # - {Boolean} is the sprite set
25
+ #
26
+ def _archetype_check_sprite(map)
27
+ status = !(global_sprites_disabled? && (is_null(map) || !map.value))
28
+ return bool(status)
29
+ end
30
+ Sass::Script::Functions.declare :_archetype_check_sprite, [:map]
31
+
32
+ #
33
+ # wrapper for `sprite`
34
+ #
35
+ # *Parameters*:
36
+ # - <tt>$map</tt> {SpriteMap} the sprite map
37
+ # - <tt>$sprite</tt> {Sprite} the sprite name
38
+ # - <tt>$offset-x</tt> {Number} the horizontal offset of the sprite position
39
+ # - <tt>$offset-y</tt> {Number} the vertical offset of the sprite position
40
+ # *Returns*:
41
+ # - {Sprite} the sprite object or `null`
42
+ #
43
+ def _archetype_sprite(map, sprite, offset_x = number(0), offset_y = number(0))
44
+ return null unless _archetype_check_sprite(map)
45
+ return sprite(map, sprite, offset_x, offset_y)
46
+ end
47
+ Sass::Script::Functions.declare :_archetype_sprite, [:map, :sprite, :offset_x, :offset_y]
48
+
49
+ #
50
+ # wrapper for `sprite-position`
51
+ #
52
+ # *Parameters*:
53
+ # - <tt>$map</tt> {SpriteMap} the sprite map
54
+ # - <tt>$sprite</tt> {Sprite} the sprite name
55
+ # - <tt>$offset-x</tt> {Number} the horizontal offset of the sprite position
56
+ # - <tt>$offset-y</tt> {Number} the vertical offset of the sprite position
57
+ # *Returns*:
58
+ # - {List} the sprite position or `null`
59
+ #
60
+ def _archetype_sprite_position(map, sprite, offset_x = number(0), offset_y = number(0))
61
+ return null unless _archetype_check_sprite(map)
62
+ return sprite_position(map, sprite, offset_x, offset_y)
63
+ end
64
+ Sass::Script::Functions.declare :_archetype_sprite_position, [:map, :sprite, :offset_x, :offset_y]
65
+
66
+ #
67
+ # wrapper for `sprite-url`
68
+ #
69
+ # *Parameters*:
70
+ # - <tt>$map</tt> {SpriteMap} the sprite map
71
+ # *Returns*:
72
+ # - {String} the sprite URL or `null`
73
+ #
74
+ def _archetype_sprite_url(map)
75
+ return null unless _archetype_check_sprite(map)
76
+ return sprite_url(map)
77
+ end
78
+ Sass::Script::Functions.declare :_archetype_sprite_url, [:map]
79
+
80
+ #
81
+ # wrapper for `sprite-file`
82
+ #
83
+ # *Parameters*:
84
+ # - <tt>$map</tt> {SpriteMap} the sprite map
85
+ # - <tt>$sprite</tt> {Sprite} the sprite name
86
+ # *Returns*:
87
+ # - {ImageFile} the image or `null`
88
+ #
89
+ def _archetype_sprite_file(map, sprite)
90
+ return null unless _archetype_check_sprite(map)
91
+ return sprite_file(map, sprite)
92
+ end
93
+ Sass::Script::Functions.declare :_archetype_sprite_file, [:map, :sprite]
94
+
95
+ #
96
+ # wrapper for `image-width`
97
+ #
98
+ # *Parameters*:
99
+ # - <tt>$image</tt> {ImageFile} the image
100
+ # - <tt>$sprite</tt> {Sprite} the sprite name
101
+ # *Returns*:
102
+ # - {Number} the width of the image or `null`
103
+ #
104
+ def _archetype_image_width(image)
105
+ return null if is_null(image).value
106
+ return image_width(image)
107
+ end
108
+ Sass::Script::Functions.declare :_archetype_image_width, [:image]
109
+
110
+ #
111
+ # wrapper for `image-height`
112
+ #
113
+ # *Parameters*:
114
+ # - <tt>$image</tt> {ImageFile} the image
115
+ # - <tt>$sprite</tt> {Sprite} the sprite name
116
+ # *Returns*:
117
+ # - {Number} the height of the image or `null`
118
+ #
119
+ def _archetype_image_height(image)
120
+ return null if is_null(image).value
121
+ return image_height(image)
122
+ end
123
+ Sass::Script::Functions.declare :_archetype_image_height, [:image]
124
+
125
+ private
126
+
127
+ def global_sprites_disabled?
128
+ sprites_disabled = environment.var('CONFIG_DISABLE_STYLEGUIDE_SPRITES')
129
+ return sprites_disabled.respond_to?(:value) ? sprites_disabled.value : false
130
+ end
131
+
132
+ end