Skip to content

Commit

Permalink
Improve default Rules for new sites
Browse files Browse the repository at this point in the history
* Better handling of non-root pages
* Commented-out Markdown rule
  • Loading branch information
denisdefreyne committed May 22, 2015
1 parent 8dc4450 commit d4bbdae
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/nanoc/base/source_data/site.rb
Expand Up @@ -33,7 +33,7 @@ class Site
# that lacks some options, the default value will be taken from
# `DEFAULT_CONFIG`.
DEFAULT_CONFIG = {
text_extensions: %w( css erb haml htm html js less markdown md php rb sass scss txt xhtml xml coffee hb handlebars mustache ms slim ).sort,
text_extensions: %w( css erb haml htm html js less markdown md php rb sass scss txt xhtml xml coffee hb handlebars mustache ms slim rdoc ).sort,
lib_dirs: %w( lib ),
commands_dirs: %w( commands ),
output_dir: 'output',
Expand Down
65 changes: 33 additions & 32 deletions lib/nanoc/cli/commands/create-site.rb
Expand Up @@ -107,13 +107,29 @@ def array_to_yaml(array)
#!/usr/bin/env ruby
compile '/**/*.html' do
filter :erb
layout '/default.*'
end
# This is an example rule that matches Markdown (.md) files, and filters them
# using the :kramdown filter. It is commented out by default, because kramdown
# is not bundled with nanoc or Ruby.
#
#compile '/**/*.md' do
# filter :kramdown
# layout '/default.*'
#end
compile '/**/*' do
end
route '/**/*.{html,md}' do
if item.identifier =~ '/index.*'
'/index.html'
else
item.identifier.without_ext + '/index.html'
end
end
route '/**/*' do
item.identifier.to_s
end
Expand All @@ -122,6 +138,10 @@ def array_to_yaml(array)
EOS

DEFAULT_ITEM = <<EOS unless defined? DEFAULT_ITEM
---
title: Home
---
<h1>A Brand New nanoc Site</h1>
<p>You’ve just created a new nanoc site. The page you are looking at right now is the home page for your site. To get started, consider replacing this default homepage with your own customized homepage. Some pointers on how to do so:</p>
Expand Down Expand Up @@ -305,41 +325,22 @@ def run
FileUtils.mkdir_p('lib')
FileUtils.mkdir_p('output')

# Config
File.open('nanoc.yaml', 'w') { |io| io.write(DEFAULT_CONFIG) }
Nanoc::Int::NotificationCenter.post(:file_created, 'nanoc.yaml')

# Rules
File.open('Rules', 'w') do |io|
io.write DEFAULT_RULES
end
Nanoc::Int::NotificationCenter.post(:file_created, 'Rules')

# Home page
File.open('content/index.html', 'w') do |io|
io << '---' << "\n"
io << 'title: Home' << "\n"
io << '---' << "\n"
io << "\n"
io << DEFAULT_ITEM
end
Nanoc::Int::NotificationCenter.post(:file_created, 'content/index.html')

# Style sheet
File.open('content/stylesheet.css', 'w') do |io|
io << DEFAULT_STYLESHEET
end
Nanoc::Int::NotificationCenter.post(:file_created, 'content/stylesheet.css')

# Layout
File.open('layouts/default.html', 'w') do |io|
io << DEFAULT_LAYOUT
end
Nanoc::Int::NotificationCenter.post(:file_created, 'layouts/default.html')
write('nanoc.yaml', DEFAULT_CONFIG)
write('Rules', DEFAULT_RULES)
write('content/index.html', DEFAULT_ITEM)
write('content/stylesheet.css', DEFAULT_STYLESHEET)
write('layouts/default.html', DEFAULT_LAYOUT)
end

puts "Created a blank nanoc site at '#{path}'. Enjoy!"
end

private

def write(filename, content)
File.write(filename, content)
Nanoc::Int::NotificationCenter.post(:file_created, filename)
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/base/test_site.rb
Expand Up @@ -203,8 +203,8 @@ def test_setup_child_parent_links
qux = site.items.find { |i| i.identifier == '/parent/bar/qux/' }

assert_equal Set.new([parent, style]), Set.new(root.children)
assert_equal Set.new([foo, bar]), Set.new(parent.children)
assert_equal Set.new([qux]), Set.new(bar.children)
assert_equal Set.new([foo, bar]), Set.new(parent.children)
assert_equal Set.new([qux]), Set.new(bar.children)

assert_equal nil, root.parent
assert_equal root, parent.parent
Expand Down
13 changes: 13 additions & 0 deletions test/cli/commands/test_create_site.rb
Expand Up @@ -50,6 +50,19 @@ def test_can_compile_site_in_nonempty_directory
end
end

def test_compiled_site_output
FileUtils.mkdir('foo')
FileUtils.touch(File.join('foo', 'SomeFile.txt'))
Nanoc::CLI.run %w( create_site foo --force )

FileUtils.cd('foo') do
site = Nanoc::Int::Site.new('.')
site.compile

assert File.file?('output/index.html')
end
end

def test_default_encoding
unless defined?(Encoding)
skip 'No Encoding class'
Expand Down

0 comments on commit d4bbdae

Please sign in to comment.