Created
January 15, 2014 16:08
-
-
Save bburton/8438992 to your computer and use it in GitHub Desktop.
Better default Rules for nanoc static site compiler (http://nanoc.ws version 3.x) that for the simple cases require little to no configuration. Files that are considered to be pages (based on a list of extensions), are appropriately filtered and routed for some common file types such as Haml, Markdown and Textile. All other text files and binary…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# This is the Compass configuration file for scss and sass file processing. | |
# Compass Configuration Reference: | |
# http://compass-style.org/docs/tutorials/configuration-reference/ | |
# | |
# The compass utility looks for the configuration file in the following | |
# locations: | |
# - config/compass.rb | |
# - .compass/config.rb | |
# - config/compass.config | |
# - config.rb | |
# - src/config.rb | |
# If this file is renamed or moved it must match one of the supported | |
# paths above or the compass command won't find it unless the --config | |
# option is specified. | |
#require 'bundler/setup' | |
# Load Compass plugins | |
#require 'bootstrap-sass' | |
#require 'bourbon' | |
#require 'susy' | |
#require 'zurb-foundation' | |
# | |
# Compass configuration properties | |
# | |
# To view the resolved value of any property below, use: | |
# compass config -p PROPERTY | |
# | |
# http_path - The path to the project when running within the web | |
http_path = "/" | |
# The target directory where the css stylesheets are kept. | |
# Relative to the project_path. | |
css_dir = "output/assets/stylesheets" | |
# The source directory where the sass stylesheets are kept. | |
# Relative to the project_path. | |
sass_dir = "content/assets/stylesheets" | |
# The source directory where the images are kept. | |
# Relative to the project_path. | |
images_dir = "output/assets/images" | |
# The source directory where the javascripts are kept. | |
javascripts_dir = "content/assets/javascripts" | |
# The output style for the compiled css. | |
# :nested - Each CSS rule and property on a separate line, | |
# Rules are indented based on nesting. | |
# :expanded - Each CSS rule and property on a separate line. | |
# :compact - Each CSS rule on a single line | |
# :compressed - Minimum amount of space with almost no whitespace | |
# For more details, on sass output styles, see | |
# http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#output_style | |
##output_style = :compact | |
output_style = if environment == :production then :compact else :expanded end | |
# Indicates whether the compass helper functions should generate | |
# relative urls from the generated css to assets, or absolute urls | |
# using the http path for that asset type. | |
relative_assets = false | |
# Options passed directly to the Sass compiler. | |
# Must be defined in this file to work with compass command. | |
# For more details on the sass options, see | |
# http://sass-lang.com/docs/yardoc/SASS_REFERENCE.md.html#options | |
sass_options = { | |
:syntax => :scss # use SCSS syntax | |
#:full_exception => true, | |
#:line_comments => false, | |
#:trace_selectors => false | |
# The debug_info option generates copious output to support the Firebug | |
# FireSass plugin for Firefox which shows the associated Sass line number. | |
#:debug_info => true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A list of file extensions that nanoc will consider to be textual rather than | |
# binary. If an item with an extension not in this list is found, the file | |
# will be considered as binary. | |
text_extensions: [ 'coffee', 'css', 'erb', 'haml', 'handlebars', 'hb', 'htm', 'html', 'js', 'less', 'markdown', 'md', 'ms', 'mustache', 'php', 'rb', 'sass', 'scss', 'textile', 'txt', 'xhtml', 'xml' ] | |
# A subset of text_extensions that will be mapped to pages with clean, no | |
# extension URI's. Any extension not listed here will retain its extension | |
# on output. | |
page_extensions: [ 'haml', 'htm', 'html', 'markdown', 'md', 'textile', 'xhtml' ] | |
# The path to the directory where all generated files will be written to. This | |
# can be an absolute path starting with a slash, but it can also be path | |
# relative to the site directory. | |
output_dir: output | |
# A list of index filenames, i.e. names of files that will be served by a web | |
# server when a directory is requested. Usually, index files are named | |
# “index.html”, but depending on the web server, this may be something else, | |
# such as “default.htm”. This list is used by nanoc to generate pretty URLs. | |
index_filenames: [ 'index.html' ] | |
# Whether or not to generate a diff of the compiled content when compiling a | |
# site. The diff will contain the differences between the compiled content | |
# before and after the last site compilation. | |
enable_output_diff: false | |
prune: | |
# Whether to automatically remove files not managed by nanoc from the output | |
# directory. For safety reasons, this is turned off by default. | |
auto_prune: false | |
# Which files and directories you want to exclude from pruning. If you version | |
# your output directory, you should probably exclude VCS directories such as | |
# .git, .svn etc. | |
exclude: [ '.git', '.hg', '.svn', 'CVS' ] | |
# The data sources where nanoc loads its data from. This is an array of | |
# hashes; each array element represents a single data source. By default, | |
# there is only a single data source that reads data from the “content/” and | |
# “layout/” directories in the site directory. | |
data_sources: | |
- | |
# The type is the identifier of the data source. By default, this will be | |
# `filesystem_unified`. | |
type: filesystem_unified | |
# The path where items should be mounted (comparable to mount points in | |
# Unix-like systems). This is “/” by default, meaning that items will have | |
# “/” prefixed to their identifiers. If the items root were “/en/” | |
# instead, an item at content/about.html would have an identifier of | |
# “/en/about/” instead of just “/about/”. | |
items_root: / | |
# The path where layouts should be mounted. The layouts root behaves the | |
# same as the items root, but applies to layouts rather than items. | |
layouts_root: / | |
# Whether to allow periods in identifiers. When turned off, everything | |
# past the first period is considered to be the extension, and when | |
# turned on, only the characters past the last period are considered to | |
# be the extension. For example, a file named “content/about.html.erb” | |
# will have the identifier “/about/” when turned off, but when turned on | |
# it will become “/about.html/” instead. | |
allow_periods_in_identifiers: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# This Rules file is an attempt at a near zero configuration for the common | |
# use cases when creating a simple site with nanoc. It's meant to have | |
# better defaults so new users don't have to configure it much if at all. | |
# For the most part, it copies all files from the content folder to the | |
# output folder with the same name. It has the following features: | |
# | |
# * Certain predefined page extensions such as html, haml, md, markdown and | |
# textile are routed to "clean" URI's (see below regarding Item identifiers). | |
# The list of these extensions should be specified in nanoc.yaml: | |
# | |
# page_extensions: [ 'haml', 'htm', 'html', 'markdown', 'md', 'textile', 'xhtml' ] | |
# | |
# All the files matching one of these page extensions are filtered through erb | |
# (except haml) then filtered through one of Haml, Markdown and Textile if | |
# appropriate. Finally, the default layout is applied. | |
# | |
# * All other text files with an extension not found in the page extensions list | |
# and all binary files are routed with the same path and extension on | |
# output as on input. | |
# | |
# * Compass/SASS are much more easily supported just by uncommenting lines | |
# below and adding a config.rb. This Rules file does not need to know | |
# where the .scss or .sass files are located which eliminates the need for | |
# special rules for scss and sass files and keeping paths in sync between | |
# this file and config.rb. The compass config.rb must still be configured | |
# with the correct paths. | |
# | |
# A few helpful tips about the Rules file: | |
# | |
# * The string given to #compile and #route are matching patterns for | |
# identifiers--not for paths. Therefore, you can’t match on extension. | |
# | |
# * The order of rules is important: for each item, only the first matching | |
# rule is applied. | |
# | |
# * Item identifiers start and end with a slash (e.g. “/about/” for the file | |
# “content/about.html”). To select all children, grandchildren, … of an | |
# item, use the pattern “/about/*/”; “/about/*” will also select the parent, | |
# because “*” matches zero or more characters. | |
# Use the compass sass framework for processing scss and sass files. | |
# To use, uncomment these two lines and ensure you have a config.rb for compass. | |
#require 'compass' | |
#Compass.add_project_configuration('config.rb') | |
# From nanoc.yaml, page_extensions | |
page_extensions = @config[:page_extensions] || %w[ haml html markdown md textile ] | |
# Preprocess items before they are compiled and frozen | |
preprocess do | |
end | |
# don't filter SASS partials | |
compile %r{/_.+/$} do | |
nil | |
end | |
compile '*' do | |
if item.binary? | |
# don't filter binary items | |
else | |
if page_extensions.include?(item[:extension]) | |
# for page files, filter and apply a layout | |
filter :erb unless item[:extension].eql?('haml') | |
# filter by extension | |
case item[:extension] | |
when 'md','markdown' then | |
filter :kramdown, :auto_ids => false | |
when 'textile' then | |
filter :redcloth | |
when 'haml' then | |
filter :haml | |
end | |
layout 'default' | |
else | |
# Filter if a scss or sass file | |
filter :sass, Compass.sass_engine_options | |
.merge(:syntax => item[:extension].to_sym) if | |
%w[scss sass].include?item[:extension] | |
end | |
end | |
end | |
# don't route SASS partials | |
route %r{/_.+/$} do | |
nil | |
end | |
route '*' do | |
if item.binary? | |
# Write item with identifier /foo/ to /foo.ext | |
item.identifier.chop + '.' + item[:extension] | |
else | |
if page_extensions.include?(item[:extension]) | |
# Write item with identifier /foo/ to /foo/index.html | |
item.identifier + 'index.html' | |
else | |
# Map extensions if necessary | |
extension = case item[:extension] | |
# Map scss/sass extensions to css | |
when 'scss','sass'; 'css' | |
else item[:extension] | |
end | |
# Write item keeping extension | |
item.identifier.chop + '.' + extension | |
end | |
end | |
end | |
layout '*', :erb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment