Question

I'm using nanoc to generate an static site.

Recently I added Bower to manage front end dependencies.

When I add Bootstrap via Bower I place the package in /assets/bower/

The Bootstrap package contains multiple files, including:

bootstrap/js/tests/vendor/qunit.css
bootstrap/js/tests/vendor/qunit.js

My Rules file has these rules:

route '/assets/*' do
  extension = item[:extension]
  if extension == 'coffee'
    extension = 'js'
  end
  item.identifier.chop + '.' + extension
end

compile '*', :rep => :spec do
  if !item[:spec_files].nil? && !item.binary?
    filter :erb
    layout 'spec'
  end
end

route '*', :rep => :spec do
  if !item[:spec_files].nil? && !item.binary?
     '/specs' + @item.identifier[0..-2] + '.html'
  end
end

compile '*' do
  if !item.binary?
    filter :erb
    layout_name = item[:layout] || 'default'
    layout layout_name
  end
end

route '*' do
  if item.binary?
     item.identifier.chop + '.' + item[:extension]
  else
     item.identifier[0..-2] + '.html'
  end
end

When running nanoc I get the following error:

 RuntimeError: Found 2 content files for
 content/assets/bower/bootstrap/js/tests/vendor/qunit; expected 0 or 1

I tried adding 2 new 'empty' rules for the /assets/bower/ folder but still getting the error.

route '/assets/bower/*' do
end

compile '/assets/bower/*' do      
end

Any suggestions?

Later edit:

Looks like nanoc supports a static datasource that also takes in consideration the file extension.

https://github.com/nanoc/nanoc-site/blob/master/content/docs/troubleshooting.md

Still not sure if I can use both data sources in parallel.

Was it helpful?

Solution

Unfortunately, you can't have two files in the same directory with the same name before the last extension. For nanoc 4.0 it'll be rewritten to change that.

You can definitely have multiple data sources used at once, but that means you can't apply filters to the qunit files, only redirect the output.

Do you explicitly have to be able to organise files the same as Bower installs them? It might be a better idea to split them up into scripts and styles if you can, anyway - you'll almost certainly be filtering based on filetype, anyway, and that means in Rules you can just go

compile '/whatever-path/scripts/' do
    filter :concatenate
    filter :uglify_js
end

rather than

compile '/whatever-path/ do
  case item[:extension]
  when 'js'
    filter :uglify_js
  when 'scss'
    filter :sass
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top