Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add extension along with filename in Declare? #10

Open
imran5387 opened this issue Dec 9, 2015 · 1 comment
Open

How to add extension along with filename in Declare? #10

imran5387 opened this issue Dec 9, 2015 · 1 comment

Comments

@imran5387
Copy link

My Gulp FIle is as shown below
var handlebars=require('gulp-handlebars');
var handlebarSrc = config.appBasePath + '/js/templates/*/.hbss',
handlebarDest = config.appBasePath + '/js/libs/iea/core/js/',
handlebarDestFile = config.parentAppName + '.templates.js';

gulp.task('handlebars', function() {
return gulp.src(handlebarSrc)
.pipe(handlebars())
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'templates',
noRedeclare: true, // Avoid duplicate declarations
processName: function(filePath) {
var a= filePath.split("\presentation").pop();
//var a = String(filePath.replace('C:\xampp\htdocs\IEA-Test\presentation', ''));
/////entension was js somehow changing it to hbss below
a = a.replace('.js', ".hbss");
return (a);
}
}))
.pipe(concat(handlebarDestFile))
.pipe(wrap('define(["handlebars","helpers"], function(Handlebars) {<%= contents %>return this["templates"];});'))
.pipe(gulp.dest(handlebarDest));
});

Directory structure ::
js- templates- carousel- defaultView.hbss
js-templates- form- defaultView.hbss
js-templates-searchInput-defaultView.hbss
......................................-defaultView.hbss
... and so on

output template.js file
WHAT I GET
define(["handlebars","helpers"], function(Handlebars) {
this["templates"] = this["templates"] || {};
this["templates"]["lib/js/templates/adaptive-image/defaultView"] = this["templates"]["lib/js/templates/adaptive-image/defaultView"] || {};

/////change needed here
this["templates"]["lib/js/templates/adaptive-image/defaultView"]["hbss"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1;

What I WANT::::

define(["handlebars","helpers"], function(Handlebars) {
this["templates"] = this["templates"] || {};

this["templates"]["lib/js/templates/adaptive-image/defaultView.hbss"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1;

Let me Know what is to be done in gulpfile handlebars to include extension in processName

@xiaomingming
Copy link

+1,i want move grunt-contrib-handlebars to gulp,but gulp-handlebars can't support it.
Well,you can custom it's code:

// Default name processing function should give the filename without extension
var defaultProcessName = function(name) {
    var dirArr = path.dirname(name).split(path.sep);
    return dirArr[dirArr.length - 1] + '/' + path.basename(name, path.extname(name));
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants