diff --git a/index.js b/index.js
index a27afa7..44b5eeb 100644
--- a/index.js
+++ b/index.js
@@ -10,25 +10,31 @@ module.exports = function(file) {
var source = ''
var stream = through(
- function write(buf) {
- source += buf
+ function write(buf) {
+ source += buf
},
function end() {
try {
var component = parseComponentDefinition(source);
var script
- if (component.script) {
- script = [
- 'var component = module',
- component.script
- ]
+ if (component.script || component.imports.length) {
+ script = [ 'var component = module' ]
+ if (component.script) {
+ script.push(component.script)
+ }
if (component.template) {
script.push('component.exports.template = '+toSource(component.template))
}
if (component.css) {
script.push('component.exports.css = '+toSource(component.css))
}
+ if (component.imports.length) {
+ script.push('component.exports.components = {}')
+ component.imports.forEach(function (comp) {
+ script.push('component.exports.components[\'' + comp.name + '\'] = Ractive.extend(require(\'' + comp.href + '\'));')
+ })
+ }
this.queue(script.join('\n\n'))
} else {
script = []
diff --git a/test/simple.js b/test/simple.js
index e952b49..375cc66 100644
--- a/test/simple.js
+++ b/test/simple.js
@@ -36,6 +36,14 @@ test('test2.ract', function(done) {
})
})
+test('test3.ract', function(done) {
+ getTransformedOutput(__dirname+"/test3.ract", function(error, output) {
+ assert.ifError(error);
+ assert.equal(output, fs.readFileSync('test/test3.ract-output', 'utf8'))
+ done()
+ })
+})
+
test('Clock-component.ract', function(done) {
getTransformedOutput(__dirname+"/Clock-component.ract", function(error, output) {
assert.ifError(error)
diff --git a/test/test3.ract b/test/test3.ract
new file mode 100644
index 0000000..858bca3
--- /dev/null
+++ b/test/test3.ract
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/test/test3.ract-output b/test/test3.ract-output
new file mode 100644
index 0000000..8675ba4
--- /dev/null
+++ b/test/test3.ract-output
@@ -0,0 +1,9 @@
+var component = module
+
+component.exports.template = [ ]
+
+component.exports.components = {}
+
+component.exports.components['MyComponent'] = Ractive.extend(require('./component.ract'));
+
+component.exports.components['component'] = Ractive.extend(require('./component.ract'));
\ No newline at end of file