Static (binary?) assets [images, css] in output/ => messy .gitignore

79 views
Skip to first unread message

"Peter Valdemar Mørch (Google Groups)"

unread,
Dec 9, 2009, 7:37:36 PM12/9/09
to na...@googlegroups.com
As I understand it, because nanoc 3.0.X doesn't have binary assets, it
is recommended to put things like images directly in the output/
directory. So output/ is actually a mixture of real source files and
output generated from sources in content/.

Is that correct? Is that the best-practice until 3.1?

This confuses me:

* The name of the folder is "output", but really it contains output and
source mixed together.

* Because of that, a .gitignore file (or svn:ignore or .cvsignore) is
going to be a mess: It will have to contain separate lines for all the
generated output. Or rely on wildcards or something like that. Would be
nice to have all of output/ in .gitignore and be done with it.

* I'd like to keep e.g. images in directories with the pages that use
them. I now need to maintain similar trees in content/ and in output/
manually.

* "rake clean" removes generated files, but not the directories around
them making it harder to find actual source files in output/. (Yeah, I
guess "find output -type f" would do it) But it would be nice to be able
to "rm -rf output; nanoc3 compile" and be done with it.

So I just want to be sure I'm not missing something trivial... :-)

Peter
--
Peter Valdemar M�rch
http://www.morch.com

h3raLd

unread,
Dec 10, 2009, 3:50:49 AM12/10/09
to nanoc
I believe you are correct. However, personally I prefer to keep images
& co. in a separate directory ("resources"), and then I use custom
rake tasks to sync to output (calling nanoc3 co as well) and cleaning.
See: http://github.com/h3rald/h3rald/blob/master/tasks/site.rake

On Dec 10, 1:37 am, "Peter Valdemar Mørch (Google Groups)"
> Peter Valdemar M rchhttp://www.morch.com

Eric Sunshine

unread,
Dec 10, 2009, 3:54:35 AM12/10/09
to na...@googlegroups.com
Peter Valdemar M�rch (Google Groups) wrote:
> As I understand it, because nanoc 3.0.X doesn't have binary assets, it
> is recommended to put things like images directly in the output/
> directory. So output/ is actually a mixture of real source files and
> output generated from sources in content/.
> Is that correct? Is that the best-practice until 3.1?

I also look forward to binary (generic) asset handling in 3.1. In the
meantime, though, you can define Rake tasks to copy non-content assets
to the output folder.

http://projects.stoneship.org/trac/nanoc/wiki/Tips/CopyingAssetsIntelligently

> * Because of that, a .gitignore file (or svn:ignore or .cvsignore) is
> going to be a mess: It will have to contain separate lines for all the
> generated output. Or rely on wildcards or something like that. Would be
> nice to have all of output/ in .gitignore and be done with it.

In practice, all or nearly all generated output of nanoc 3.0 is HTML, so
it typically is very easy to craft an appropriate .gitignore,
svn:ignore, .cvsignore. My output/.gitignore contains just two lines,
one of which is "*.html" (and the other also a wildcard for a custom
type of generated output).

> * I'd like to keep e.g. images in directories with the pages that use
> them. I now need to maintain similar trees in content/ and in output/
> manually.
> * "rake clean" removes generated files, but not the directories around
> them making it harder to find actual source files in output/. (Yeah, I
> guess "find output -type f" would do it) But it would be nice to be able
> to "rm -rf output; nanoc3 compile" and be done with it.
> So I just want to be sure I'm not missing something trivial... :-)

There is a good mailing list thread talking about the planned binary
asset handling for 3.1:

http://groups.google.com/group/nanoc/browse_thread/thread/89d14f138883108e

Also, a couple wiki pages related to your comments:

http://projects.stoneship.org/trac/nanoc/wiki/Development/3.1
http://projects.stoneship.org/trac/nanoc/wiki/Development/3.1/BinaryAssets

-- ES

Alexander Mankuta

unread,
Dec 10, 2009, 4:04:06 AM12/10/09
to na...@googlegroups.com
I keep everything in content dir of my site.

content
  assets
    fonts
    images
    styles

And use this rules to make nanoc3 copy those files to output dir.

### Compilation #####################################################

compile '/assets/styles/*' do
  filter :sass, {
    :load_paths => [File.expand_path('content/assets/styles')],
    :full_exception => true,
    :line_numbers => true
  }
end

compile '/assets/*' do
  # do nothing
end

### Routing #########################################################

route '/assets/styles/*' do
  item.identifier.gsub(/\/$/, '') + '.css'
end

route '/assets/fonts/eot/*' do
  item.identifier.gsub('/eot/', '/').gsub(/\/$/, '') + '.eot'
end

route '/assets/fonts/otf/*' do
  item.identifier.gsub('/otf/', '/').gsub(/\/$/, '') + '.otf'
end

route '/assets/fonts/ttf/*' do
  item.identifier.gsub('/ttf/', '/').gsub(/\/$/, '') + '.ttf'
end

route '/assets/*' do
  dir = File.join('content', item.identifier)
  base = File.basename(dir)
  regexp = /^#{base}\.(?!yaml)(.*)/

  file_name = Dir.entries(dir).sort.find do |d|
    d.match(regexp)
  end

  if file_name
    ext = file_name.match(regexp)[1]
    File.join(File.dirname(item.identifier), "#{base}.#{ext}")
  else
    nil
  end
end


On Thu, Dec 10, 2009 at 10:54 AM, Eric Sunshine <suns...@sunshineco.com> wrote:

--
You received this message because you are subscribed to the nanoc discusssion group.

To post to this group, send email to na...@googlegroups.com
To unsubscribe from this group, send email to nanoc+un...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/nanoc

Denis Defreyne

unread,
Dec 10, 2009, 8:01:31 AM12/10/09
to na...@googlegroups.com
On 10 Dec 2009, at 01:37, Peter Valdemar Mørch (Google Groups) wrote:

> As I understand it, because nanoc 3.0.X doesn't have binary assets, it
> is recommended to put things like images directly in the output/
> directory. So output/ is actually a mixture of real source files and
> output generated from sources in content/.
>
> Is that correct? Is that the best-practice until 3.1?

Hi,

I don’t consider this to be the best practice, but it is probaby the easiest way to keep binary assets around.

The best practice is to keep assets in a separate directory, and copy the files over when the site is compiled. This technique is described on the <http://projects.stoneship.org/trac/nanoc/wiki/Tips/CopyingAssetsIntelligently> page on the wiki. This is the technique I use on the Stoneship and nanoc web sites.

For the nanoc web site, whose source you can find at <http://projects.stoneship.org/hg/sites-nanoc>, I implemented a custom "clean" task that deletes static files copied from assets/ as well as normal files generated by nanoc. You can find this rake task at <http://projects.stoneship.org/hg/sites-nanoc/file/716425754f63/tasks/clean.rake>. This task is useful for making binary asset handling easier in nanoc 3.0, but will not be necessary for nanoc 3.1.

> * The name of the folder is "output", but really it contains output and source mixed together.

This is something that has annoyed me as well, and it’s on the todo list for 3.1. There’s a high-priority ticket for it on the nanoc issue tracker: <http://projects.stoneship.org/trac/nanoc/ticket/32>.

When using the copy-assets technique, though, you *can* treat the output directory as a build directory that can be emptied without the risk of losing data.

> * Because of that, a .gitignore file (or svn:ignore or .cvsignore) is
> going to be a mess: It will have to contain separate lines for all the
> generated output. Or rely on wildcards or something like that. Would be
> nice to have all of output/ in .gitignore and be done with it.

The entire output directory can be put into the .gitignore file when using the asset copying technique.

> * I'd like to keep e.g. images in directories with the pages that use
> them. I now need to maintain similar trees in content/ and in output/
> manually.

One of the goals of nanoc 3.1 is to keep the binary files in content/ as well, eliminating the need for a separate tree. Images that belong to a certain page can therefore be put close to the page itself, for example.

> * "rake clean" removes generated files, but not the directories around
> them making it harder to find actual source files in output/. (Yeah, I
> guess "find output -type f" would do it) But it would be nice to be able
> to "rm -rf output; nanoc3 compile" and be done with it.

"rake clean" is fairly naïve: it fetches the names of all files generated by nanoc and removes them. Empty directories will not be removed, but this is probably a useful feature that is fairly easy to add.

In 3.1, a "rake clean" task will probably be able to simply remove all files in output/ (with the appropriate safety checks to make sure no files are accidentally deleted).

Hope this helps,

--
Denis Defreyne
denis.d...@stoneship.org

tenable

unread,
Dec 15, 2009, 1:41:56 AM12/15/09
to nanoc
> * "rake clean" removes generated files, but not the directories around
> them making it harder to find actual source files in output/. (Yeah, I
> guess "find output -type f" would do it) But it would be nice to be able
> to "rm -rf output; nanoc3 compile" and be done with it.

I keep my assets in the output for now and use this:

task :clean do
compiled_items = Dir['output/*'].reject { |assets| assets =~ /css|
images|graphics|javascript/ }
compiled_items.each { |item| FileUtils.rm_r item }
end

> * Because of that, a .gitignore file (or svn:ignore or .cvsignore) is
> going to be a mess: It will have to contain separate lines for all the
> generated output. Or rely on wildcards or something like that. Would be
> nice to have all of output/ in .gitignore and be done with it.

And for committing to Git, I use a rake task:

task :commit => :clean do
system "git commit -a"
end
Reply all
Reply to author
Forward
0 new messages