@@ -2,12 +2,23 @@ React = require 'react'
2
2
objectAssign = require (' object-assign' )
3
3
VerticalRhythm = require ' compass-vertical-rhythm'
4
4
ms = require ' modularscale'
5
- isArray = require ' is-array'
6
5
isObject = require ' isobject'
7
6
copy = require ' shallow-copy'
8
7
9
8
createStyles = require (' ./utils/createStyles' )
10
9
10
+ createStylesString = (options ) ->
11
+ # Create styles for base theme + each subtheme.
12
+ vr = VerticalRhythm (options)
13
+ styles = createStyles (vr, options)
14
+
15
+ if options .subThemes ? and isObject (options .subThemes )
16
+ for name, theme of options .subThemes
17
+ vr = VerticalRhythm (theme)
18
+ styles += createStyles (vr, theme, name, options)
19
+
20
+ return styles
21
+
11
22
module .exports = test = (options ) ->
12
23
defaults =
13
24
baseFontSize : ' 18px'
@@ -39,32 +50,22 @@ module.exports = test = (options) ->
39
50
for name, theme of options .subThemes
40
51
options .subThemes [name] = objectAssign (copy (options), theme, rhythmUnit : ' px' )
41
52
42
- unless isArray options .modularScales
43
- options .modularScales = [options .modularScales ]
44
-
45
- # Create styles for base theme + each subtheme.
46
53
vr = VerticalRhythm (options)
47
- styles = createStyles (vr, options)
48
-
49
- if options .subThemes ? and isObject (options .subThemes )
50
- for name, theme of options .subThemes
51
- vr = VerticalRhythm (theme)
52
- styles += createStyles (vr, theme, name, options)
53
54
54
55
return {
55
56
options : options
56
- GoogleFont : require (' ./components/GoogleFont' )(options)
57
- TypographyStyle : require (' ./components/TypographyStyle' )(styles )
57
+ GoogleFont : -> require (' ./components/GoogleFont' )(options)
58
+ TypographyStyle : -> require (' ./components/TypographyStyle' )(-> createStylesString (options) )
58
59
rhythm : vr .rhythm
59
- styles : styles
60
+ createStyles : -> createStylesString (options)
60
61
fontSizeToPx : vr .adjustFontSizeTo
61
62
fontSizeToMS : (scaler ) ->
62
63
baseFont = options .baseFontSize .slice (0 , - 2 )
63
64
newFontSize = ms (scaler, options .modularScales [0 ]) * baseFont + " px"
64
65
vr .adjustFontSizeTo (newFontSize)
65
66
injectStyles : ->
66
67
node = document .createElement (' style' )
67
- node .innerHTML = styles
68
+ node .innerHTML = createStylesString ()
68
69
document .head .appendChild (node)
69
70
}
70
71
@@ -74,4 +75,4 @@ module.exports = test = (options) ->
74
75
# blog:
75
76
# baseFontSize: '18px'
76
77
# bodyFontFamily: 'Open Sans'
77
- # }).styles
78
+ # }).createStyles()
0 commit comments