From 7262578c819497d36692df52831350b0f850428a Mon Sep 17 00:00:00 2001 From: hacksalot Date: Mon, 5 Feb 2018 23:43:38 -0500 Subject: [PATCH] feat: allow standalone FRESH themes to inherit --- dist/core/fresh-theme.js | 12 ++++++++---- src/core/fresh-theme.coffee | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/dist/core/fresh-theme.js b/dist/core/fresh-theme.js index 7570333..8d15622 100644 --- a/dist/core/fresh-theme.js +++ b/dist/core/fresh-theme.js @@ -62,10 +62,14 @@ Definition of the FRESHTheme class. if (this.inherits) { cached = {}; _.each(this.inherits, function(th, key) { - var d, themePath, themesFolder; - themesFolder = require.resolve('fresh-themes'); - d = parsePath(themeFolder).dirname; - themePath = PATH.join(d, th); + var d, themePath, themesObj; + themesObj = require('fresh-themes'); + if (_.has(themesObj.themes, th)) { + themePath = PATH.join(parsePath(require.resolve('fresh-themes')).dirname, '/themes/', th); + } else { + d = parsePath(th).dirname; + themePath = PATH.join(d, th); + } cached[th] = cached[th] || new FRESHTheme().open(themePath); return formatsHash[key] = cached[th].getFormat(key); }); diff --git a/src/core/fresh-theme.coffee b/src/core/fresh-theme.coffee index 48e0b78..6e4432b 100644 --- a/src/core/fresh-theme.coffee +++ b/src/core/fresh-theme.coffee @@ -59,9 +59,23 @@ class FRESHTheme if @inherits cached = { } _.each @inherits, (th, key) -> - themesFolder = require.resolve 'fresh-themes' - d = parsePath( themeFolder ).dirname - themePath = PATH.join d, th + # First, see if this is one of the predefined FRESH themes. There are + # only a handful of these, but they may change over time, so we need to + # query the official source of truth: the fresh-themes repository, which + # mounts the themes conveniently by name to the module object, and which + # is embedded locally inside the HackMyResume installation. + # TODO: merge this code with + themesObj = require 'fresh-themes' + if _.has themesObj.themes, th + themePath = PATH.join( + parsePath( require.resolve('fresh-themes') ).dirname, + '/themes/', + th + ) + else + d = parsePath( th ).dirname + themePath = PATH.join d, th + cached[ th ] = cached[th] || new FRESHTheme().open( themePath ) formatsHash[ key ] = cached[ th ].getFormat( key )