Skip to content

Commit

Permalink
1.3.14 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis-CI committed Dec 12, 2020
1 parent ca82cb1 commit b2579d6
Show file tree
Hide file tree
Showing 17 changed files with 8,796 additions and 8,764 deletions.
31 changes: 20 additions & 11 deletions bin/ractive.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ const opts = {
base: process.cwd()
};

function readFile(name) {
return Promise.resolve(fs.readFileSync(path.resolve(opts.base, name), { encoding: 'utf8' }));
function mkReadFile(file) {
const base = path.isAbsolute(file)
? path.dirname(file)
: path.join(opts.base, path.dirname(file));
return function readFile(name) {
return Promise.resolve(
fs.readFileSync(path.isAbsolute(name) ? name : path.join(base, name), { encoding: 'utf8' })
);
};
}

function dirIndexOrFile(name) {
Expand Down Expand Up @@ -76,14 +83,16 @@ const commands = {
util
.readToString(fs.createReadStream(path.join(opts.directory, f)))
.then(string => {
return component.build(string, opts, readFile).then(string => {
const file = path.join(
opts.output,
f.replace(ext, opts.outputExtension || '.js')
);
util.mkdirp(path.dirname(file));
util.writeToStream(fs.createWriteStream(file), string);
});
return component
.build(string, opts, mkReadFile(path.join(opts.directory, f)))
.then(string => {
const file = path.join(
opts.output,
f.replace(ext, opts.outputExtension || '.js')
);
util.mkdirp(path.dirname(file));
util.writeToStream(fs.createWriteStream(file), string);
});
})
.then(step, err => {
console.error(err && typeof err === 'object' ? err.stack : err);
Expand All @@ -98,7 +107,7 @@ const commands = {
.readToString(opts.input)
.then(string => {
return component
.build(string, opts, readFile)
.build(string, opts, mkReadFile(''))
.then(string => util.writeToStream(opts.output, string));
})
.then(null, err => {
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ractive",
"description": "Next-generation DOM manipulation",
"version": "1.2.10",
"version": "1.3.14",
"homepage": "https://ractive.js.org",
"license": "MIT",
"main": "ractive.js",
Expand Down
26 changes: 24 additions & 2 deletions lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function build(string, opts, readFile) {

const promises = [];

// walk the template finding any script, style, or link tags to process them as appropriate
// walk the template finding any script, style, template, or link tags to process them as appropriate
let i = tpl.t.length;
while (i--) {
const item = tpl.t[i];
Expand Down Expand Up @@ -112,7 +112,12 @@ function build(string, opts, readFile) {
} else if (item.e === 'template') {
const id = getAttr('id', item) || getAttr('name', item);
if (id) {
partials[id] = item.f ? item.f[0] : '';
const src = getAttr('src', item);
if (src) {
promises.push(readFile(src).then(str => !partials[id] && (partials[id] = str)));
} else {
partials[id] = item.f ? item.f[0] : '';
}
}

i = drop(i, tpl.t);
Expand Down Expand Up @@ -163,6 +168,23 @@ function build(string, opts, readFile) {

const t = Ractive.parse(partials[k], opts);

// extract any styles
i = t.t.length;
while (i--) {
if (t.e === 'style') {
const item = t.e[i];
const rel = getAttr('rel', item);

if (rel === 'ractive') {
style.unshift({ type: 'tpl', body: item.f[0] });
} else {
style.unshift({ type: 'css', body: item.f[0] || '' });
}

i = drop(i, tpl.t);
}
}

// copy any expressions
if (t.e) {
if (!tpl.e) tpl.e = {};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ractive",
"description": "Next-generation DOM manipulation",
"version": "1.2.10",
"version": "1.3.14",
"homepage": "https://ractive.js.org",
"license": "MIT",
"main": "ractive.js",
Expand Down
Loading

0 comments on commit b2579d6

Please sign in to comment.