Skip to content

Commit fb3ddce

Browse files
authored
Merge pull request #515 from SassDoc/hotfix/scoped-packages
Add support for scoped theme packages
2 parents 00bfe0c + 30561f8 commit fb3ddce

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/environment.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,20 @@ export default class Environment extends EventEmitter {
198198
return this.defaultTheme()
199199
}
200200

201-
if (this.theme.indexOf('/') === -1) {
201+
const hasSlash = this.theme.includes('/')
202+
const isScoped = this.theme.startsWith('@') && hasSlash
203+
204+
// We assume it's a full scoped package name.
205+
if (isScoped) {
206+
return this.tryTheme(this.theme)
207+
}
208+
209+
// We assume it's a theme name shorthand.
210+
if (!hasSlash) {
202211
return this.tryTheme(`sassdoc-theme-${this.theme}`)
203212
}
204213

214+
// We assume it's a path to a local theme.
205215
let theme = this.resolve(this.theme, this.themeCwd)
206216
this.themeName = this.theme
207217
this.displayTheme = path.relative(process.cwd(), theme)

test/env/environment.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,31 @@ describe('#environment', function () {
213213
})
214214
})
215215

216+
/**
217+
* A scoped package is passed as theme.
218+
*/
219+
describe('#theme-scoped', function () {
220+
beforeEach(function () {
221+
env.load({ theme: '@test/sassdoc-theme-test' })
222+
env.postProcess()
223+
env.data = []
224+
mkdirp.sync('.sassdoc')
225+
return env.theme('.sassdoc', env)
226+
})
227+
228+
it('should warn and render the default theme', function () {
229+
assert.notEqual(-1, warnings[0].indexOf('Theme `@test/sassdoc-theme-test` not found'))
230+
assert.notEqual(-1, warnings[1].indexOf('Falling back to default theme'))
231+
assert.ok(env.themeName === 'default')
232+
assert.ok(fs.existsSync('.sassdoc/index.html'))
233+
assert.ok(fs.existsSync('.sassdoc/assets'))
234+
})
235+
236+
after(function (done) {
237+
rimraf('.sassdoc', done)
238+
})
239+
})
240+
216241
/**
217242
* ensureEnvironment
218243
*/

0 commit comments

Comments
 (0)