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

Error on missing inject tags, Twig support #129

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/inject/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,14 @@ function getNewContent (target, collection, opt) {
var startTag = tags[tag].start;
var endTag = tags[tag].end;

var injectorTagsRegExp = getInjectorTagsRegExp(startTag, endTag);

if (!injectorTagsRegExp.test(contents)) {
throw error('Missing inject tags!');
}

return contents.replace(
getInjectorTagsRegExp(startTag, endTag),
injectorTagsRegExp,
function injector (match, starttag, indent, content, endtag) {
var starttagArray = opt.removeTags ? [] : [starttag];
var endtagArray = opt.removeTags ? [] : [endtag];
Expand Down
10 changes: 9 additions & 1 deletion src/transform/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var extname = require('../extname');
/**
* Constants
*/
var TARGET_TYPES = ['html', 'jade', 'slm', 'jsx', 'haml', 'less'];
var TARGET_TYPES = ['html', 'jade', 'slm', 'jsx', 'haml', 'less', 'twig'];
var IMAGES = ['jpeg', 'jpg', 'png', 'gif'];
var DEFAULT_TARGET = TARGET_TYPES[0];

Expand Down Expand Up @@ -140,6 +140,14 @@ transform.less.less = function(filepath){

transform.less.css = transform.less.less;

transform.twig.css = function (filepath) {
return '<link rel="stylesheet" href="{{ asset("' + filepath + '") }}"' + end();
};

transform.twig.js = function (filepath) {
return '<script src="{{ asset("' + filepath + '") }}"></script>';
};

/**
* Transformations for jsx is like html
* but always with self closing tags, invalid jsx otherwise
Expand Down