-
Notifications
You must be signed in to change notification settings - Fork 93
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
Possible to dynamically inject files depends on the name of file to be injected ? #80
Comments
@joakimbeng what do you think? |
@liuwenchao why don't you just do this: var myTransform = function (filepath, file) {
return file.contents.toString('utf8');
};
gulp.src('target.html')
.pipe(inject(gulp.src('file*.html'), { starttag: '<!--inject:html} -->'), transform: myTransform))
; But please provide an example of how your N.B. If you're trying to inject all the files in different places (one file per tag) in the target file I think |
@joakimbeng yes they're injected in different places. The target.html looks like this: <html>
<head>
<!-- inject:empty:html -->
<script src="/bower_components/webcomponentsjs/webcomponents.min.js"></script>
<link rel="import" href="/bower_components/aha-partial/src/aha-partial.html">
<!-- endinject -->
</head>
<body>
<!-- inject:header:html -->
<aha-partial src="partials/header.html"></aha-partial>
<!-- endinject -->
<div class="container">
<ul class="nav nav-tabs">
<li class="active">
<a href="#tab1" data-toggle="tab">Tab 1</a>
</li>
<li>
<a href="#tab2" data-toggle="tab">Tab 2</a>
</li>
<li>
<a href="#tab3" data-toggle="tab">Tab 3</a>
</li>
<li>
<a href="#tab4" data-toggle="tab">Tab 4</a>
</li>
<li>
<a href="#tab5" data-toggle="tab">Tab 5</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="tab1">
<!-- inject:tab1:html -->
<aha-partial src="partials/tab1.html"></aha-partial>
<!-- endinject -->
</div>
<div class="tab-pane" id="tab2">
<!-- inject:tab2:html -->
<aha-partial src="partials/tab2.html"></aha-partial>
<!-- endinject -->
</div>
<div class="tab-pane" id="tab3">
<!-- inject:tab3:html -->
<aha-partial src="partials/tab3.html"></aha-partial>
<!-- endinject -->
</div>
<div class="tab-pane" id="tab4">
<!-- inject:tab4:html -->
<aha-partial src="partials/tab4.html"></aha-partial>
<!-- endinject -->
</div>
<div class="tab-pane" id="tab5">
<!-- inject:tab5:html -->
<aha-partial src="partials/tab5.html"></aha-partial>
<!-- endinject -->
</div>
</div>
</div>
<!-- inject:footer:html -->
<aha-partial src="partials/footer.html"></aha-partial>
<!-- endinject -->
</body>
</html> The real file is more complicated than this, this is a simplified version. I'm using a custom element in development environment, it's kind of a template engine, I need to use a HTML solution here; and in production environment, it will be replaced by one complete HTML w/o custom element. |
+1 on this. I'm trying to inject minified HTML templates into specific Javascript string variables. |
Actually I would recommend using a real template engine for this... Though I will accept #109 when it has some tests which solves this. |
+1 here as well. Would be great if we could do something like: .pipe(inject(gulp.src(['injects/*.html']), {
starttag: '<!-- inject:{{filename}}:{{ext}} -->',
transform: function (filePath, file) {
return file.contents.toString('utf8')
}
})) |
i found the way to insert template file i need in shortcode)) |
I have found another plugin recently that better suits this need: gulp-file-insert
|
Same here. I really prefer @JustMaier 's way which includes a
|
Although @JustMaier solution is simpler, it is limited to a single file. For large application, you may want to manage by folders or subfolders, or some other way even. |
+1 |
a solution that i've made for my project is this:
but i'm waiting a better solution without create a through pipe like those provided in this thread.... |
I have a huge HTML file, with many files to inject, but it seems not DRY to do this:
Any way to eliminate the duplication? Thanks!
The text was updated successfully, but these errors were encountered: