@@ -12,7 +12,8 @@ function Import(inputTree, options) {
12
12
this . include = options . include ;
13
13
this . main = options . main ;
14
14
this . themeName = options . themeName || 'ui-base' ;
15
- this . themePrefix = options . themePrefix || 'ui-base' ;
15
+ this . themePrefix = options . themePrefix || 'base' ;
16
+ this . parentTheme = options . parentTheme ;
16
17
}
17
18
18
19
Import . prototype = Object . create ( Filter . prototype ) ;
@@ -53,19 +54,57 @@ Import.prototype.addThemeComponentClasses = function(content) {
53
54
var inputPath = this . inputPaths [ 0 ] ;
54
55
var importFiles = walkSync ( inputPath , { globs : this . include } ) ;
55
56
var themePrefix = this . themePrefix ;
57
+ var parentThemeComponentFiles = this . parentTheme ?
58
+ this . parentTheme . toScssComponentFilesArray ( ) : [ ] ;
56
59
57
- var componentClasses = importFiles . reduce ( function ( string , filePath ) {
58
- var name = path . basename ( filePath ) . replace ( themePrefix + '--' , '' ) . replace ( '.scss' , '' ) ;
60
+ var themeComponents = importFiles . map ( function ( filePath ) {
61
+ return path . basename ( filePath ) . replace ( themePrefix + '--' , '' ) . replace ( '.scss' , '' ) ;
62
+ } ) ;
59
63
60
- return string += ' &--' + name + ' {\n @include ' + name + '($theme);\n }\n\n' ;
61
- } , '' ) ;
64
+ var parentThemeComponents = parentThemeComponentFiles . map ( function ( filePath ) {
65
+ return filePath . replace ( 'components\/' , '' ) . replace ( '.scss' , '' ) ;
66
+ } ) ;
62
67
63
- var themeMixin = '@mixin ' + this . themeName + '($theme...) {\n' +
64
- ' $theme: keywords($theme);\n\n' +
65
- componentClasses +
66
- '}' ;
68
+ var themeClasses = parentThemeComponents . reduce ( function ( array , component ) {
69
+ if ( themeComponents . indexOf ( component ) === - 1 ) {
70
+ var importStatement = ' &--' + component + ' {\n @include ' + component + '($theme);\n }\n' ;
71
+ array = array . concat ( importStatement ) ;
72
+ }
73
+
74
+ return array ;
75
+ } , [ ] ) ;
76
+
77
+ themeClasses = themeComponents . reduce ( function ( array , component ) {
78
+ var importStatement ;
79
+
80
+ if ( themePrefix === 'base' ) {
81
+ importStatement = ' .' + component + ' {\n @include ' + component + '($theme);\n }\n' ;
82
+ } else {
83
+ importStatement = ' &--' + component + ' {\n @include ' + themePrefix + '--' + component + '($theme);\n }\n' ;
84
+ }
85
+
86
+ return array . concat ( importStatement ) ;
87
+ } , themeClasses ) ;
88
+
89
+ var themeMixin = this . buildThemeMixin ( themeClasses ) ;
67
90
68
91
return themeMixin ;
69
92
} ;
70
93
94
+ Import . prototype . buildThemeMixin = function ( themeClasses ) {
95
+ if ( this . themePrefix === 'base' ) {
96
+ return '@mixin ' + this . themeName + '($theme...) {\n' +
97
+ ' $theme: keywords($theme);\n\n' +
98
+ ' @at-root {\n' +
99
+ themeClasses . join ( '\n' ) +
100
+ ' }\n' +
101
+ '}' ;
102
+ } else {
103
+ return '@mixin ' + this . themeName + '($theme...) {\n' +
104
+ ' $theme: keywords($theme);\n\n' +
105
+ themeClasses . join ( '\n' ) +
106
+ '}' ;
107
+ }
108
+ } ;
109
+
71
110
module . exports = Import ;
0 commit comments