Nesta CMSNestatag:nestacms.com,2009:/A Ruby CMS. Built with Sinatra.2023-03-23T19:00:00+00:00Nesta 0.14.0 is out (it's a big one)tag:nestacms.com,2023-03-23:/blog/version-0-14-0<p>Nesta 0.14.0 is out, and it brings the first significant new feature in almost a decade!</p>
<ul>
<li><p>Nesta can now be <strong>used as a Static Site Generator</strong>.</p>
<p>This means that you can now join the cool kids and deploy Nesta to a host of JAMstack-focused hosting services like Netlify, GitHub Pages, AWS Amplify, Cloudflare (and many more).</p></li>
<li><p>This release also includes a <strong>new library for converting Sass</strong> to CSS. This might require some minor code changes if you've got stylesheets written in Sass (see below for details).</p></li>
<li><p>Setting config via environment variables is no longer supported directly, but can be achieved by reading the environment within <code>config.yml</code>. See the <a href="https://github.com/gma/nesta/blob/v0.14.0/CHANGES">CHANGES file</a> for tips on how to do that.</p></li>
<li><p>Support for several (long since deprecated) features have been removed:</p>
<ul>
<li>The <code>local_stylesheet?</code> helper method has been removed (deprecated in 0.9.1)</li>
<li>The <code>breadcrumb_label</code> helper method has been removed (deprecated in 0.9.3)</li>
<li>Plugins are no longer read from the <code>./plugins</code> directory (deprecated in 0.9.10)</li>
</ul>
</li>
<li><p>There have been a bunch of internal improvements to the code, which shouldn't affect you. See the <a href="https://github.com/gma/nesta/blob/v0.14.0/CHANGES">CHANGES file</a> for full details.</p></li>
</ul>
<h2>Upgrading</h2>
<p>To install the new version edit your site's <code>Gemfile</code> and <strong>remove the version number</strong> (if it has one) from the end of the line, then run:</p>
<pre><code>$ bundle update nesta
</code></pre>
<p>You should now be able to start up the site locally with <code>mr-sparkle</code>, and test it:</p>
<pre><code>$ bundle exec mr-sparkle
</code></pre>
<p>If you have any weird errors when you start your server it could be a result of there being some fairly old gems installed. Update the entire <code>bundle</code> and try again:</p>
<pre><code>$ bundle update
$ bundle exec mr-sparkle
</code></pre>
<h3>Updating your code</h3>
<p>Sass and SCSS files are now rendered with Dart Sass (the main implementation of Sass). We had been using the (now deprecated) libsass library.</p>
<p>Sass has changed a bit since libsass was current, so you may need to make some small changes to your stylesheets. See the Sass <a href="https://sass-lang.com/documentation/breaking-changes">Breaking Changes</a> docs for full details of what's changed.</p>
<p>If that seems like a lot to read, you can do what I did to see if you've got any work to do:</p>
<ul>
<li>Fire up a local copy of your site (e.g. <code>bundle exec mr-sparkle</code>) and visit a few pages.</li>
<li>If Sass thinks you've got some work to do it'll print deprecation warnings in the server logs, including links to pages documenting any changes you need to make. Easy!</li>
</ul>
<h2>Building a static site</h2>
<p>There's a new command to build your sites, and a couple of new settings in <code>config.yml</code> to help you configure your build.</p>
<p>I'll be writing more expansive docs on this, but if you'd like to try it, these tips should get you going:</p>
<pre><code>$ cd mysite.com
$ bundle exec nesta build # builds in ./dist by default
</code></pre>
<p>If you'd like to build the output in another directory, specify it on the command line:</p>
<pre><code>$ bundle exec nesta build _site # builds in ./_site
</code></pre>
<p>Checkout the bottom of the <a href="https://github.com/gma/nesta/blob/v0.14.0/templates/config/config.yml">default config file</a> for an example of how to use the new config settings.</p>
<p>I've not written docs on deploying to any static site hosting services yet, but if you fancy giving Netlify a shot (which is easy, and free) you can configure it by adding a <code>netlify.toml</code> file to your project. It should contain the following lines:</p>
<pre><code class="toml">[build]
 command = "bundle exec nesta build"
 publish = "dist"
</code></pre>
<p>You'll also want a <code>.ruby-version</code> to tell Netlify what version of Ruby you'd like them to use. At the time of writing, Ruby 3.2.1 is the latest release.</p>
<pre><code>$ cat .ruby-version
3.2.1
</code></pre>
<p>If you then give Netlify access to your Git repository, it should be able to build and deploy your site! Let me know how you get on...</p>
2023-03-23T19:00:00+00:002023-03-23T19:00:00+00:00Nesta 0.13.0 releasedtag:nestacms.com,2022-09-28:/blog/version-0-13-0<p>Nesta 0.13.0 has been released, with updates to dependencies that were required to support Ruby 3.x and later.</p>
<p>We've also pinned the version of Haml that Nesta uses to the 5.x series, given the release of the backwards-incompatible 6.x branch. See the <a href="https://github.com/haml/haml/blob/main/CHANGELOG.md#600">Haml changelog</a> for details on that.</p>
<p>Nesta's internals have had a few tweaks and improvements, but they don't affect how Nesta works.</p>
<p>You can find the full list of updates in the <a href="https://github.com/gma/nesta/blob/v0.13.0/CHANGES">CHANGES file</a>.</p>
<h2>Upgrading</h2>
<p>To install the new version edit your site's <code>Gemfile</code> and <strong>remove the version number</strong> (if it has one) from the end of the line, then run:</p>
<pre><code>$ bundle update nesta
</code></pre>
<p>You should now be able to start up the site locally with <code>mr-sparkle</code>, and test it:</p>
<pre><code>$ bundle exec mr-sparkle
</code></pre>
<p>If you have any weird errors when you start your server it could be a result of there being some fairly old gems installed. Update the entire <code>bundle</code> and try again:</p>
<pre><code>$ bundle update
$ bundle exec mr-sparkle
</code></pre>
<h3>Updating your code</h3>
<p>This new version of Nesta is backwards compatible, and doesn't require you to make any changes to your sites.</p>
<p>However, if you've added Ruby code (e.g. in your site's <code>app.rb</code> file) that references Ruby code in some of Nesta's dependencies, you may need to make some changes to support any API changes made by those libraries (e.g. Sinatra, Rack or Sass). You'll know if this applies to you!</p>
2022-09-28T14:30:00+00:002022-09-28T14:30:00+00:00Nesta 0.12.0 releasedtag:nestacms.com,2020-06-30:/blog/version-0-12-0<p>You can find the full list of updates in the <a href="https://github.com/gma/nesta/blob/v0.12.0/CHANGES">CHANGES file</a>.</p>
<h2>Upgrading</h2>
<p>To install the new version edit your site's <code>Gemfile</code> and <strong>remove the version number</strong> (if it has one) from the end of the line, then run:</p>
<pre><code>$ bundle update nesta
</code></pre>
<p>You should now be able to start up the site locally with <code>mr-sparkle</code>, and test it:</p>
<pre><code>$ bundle exec mr-sparkle
</code></pre>
<p>If you have any weird errors when you start your server it could be a result of there being some fairly old gems installed. Update the entire <code>bundle</code> and try again:</p>
<pre><code>$ bundle update
$ bundle exec mr-sparkle
</code></pre>
<h3>Updating your code</h3>
<p>This new version of Nesta is backwards compatible, and doesn't require you to make any changes to your sites.</p>
<p>However, if you've added Ruby code (e.g. in your site's <code>app.rb</code> file) that references Ruby code in some of Nesta's dependencies, you may need to make some changes to support any API changes made by those libraries (e.g. Sinatra, Rack or Sass).</p>
<h2>What's new?</h2>
<ul>
<li><p>Upgrade to Sinatra 2 and Rack 2, fixing <a href="https://github.com/advisories/GHSA-j6w9-fv6q-3q52">CVE-2020-8184</a> (reported by Brad Weslake). (Graham Ashton)</p></li>
<li><p>Replace the deprecated sass gem with sassc. (Brad Weslake)</p></li>
<li><p>Port the test suite from RSpec and Webrat to Minitest and Capybara. (Graham Ashton)</p></li>
<li><p>Silence deprecation warnings produced under Ruby 2.7. (Graham Ashton)</p></li>
<li><p>Stop running the test suite under Ruby 2.3 and 2.4, both of which have reached end-of-life. (Graham Ashton)</p></li>
</ul>
<p>All dependencies have been updated, which has also fixed several CVEs in the <code>nokogiri</code> gem.</p>
2020-06-30T17:00:00+00:002020-06-30T17:00:00+00:00Nesta 0.11.0 releasedtag:nestacms.com,2015-03-16:/blog/version-0-11-0<p>You can find the full list of updates in the <a href="https://github.com/gma/nesta/blob/v0.11.0/CHANGES">CHANGES file</a>.</p>
<p>Thanks to all who've contributed to this release, particularly Jordan Owens who worked his way through a bunch of outstanding bugs late last year.</p>
<h2>Upgrading</h2>
<p>To install the new version edit your site's <code>Gemfile</code> and <strong>remove the version number</strong> (if it has one) from the end of the line, then run:</p>
<pre><code>$ bundle update nesta
</code></pre>
<p>You should now be able to start up the site locally with <code>mr-sparkle</code>, and test it:</p>
<pre><code>$ bundle exec mr-sparkle
</code></pre>
<p>If you have any weird errors when you start your server it could be a result of there being some fairly old gems installed. Update the entire <code>bundle</code> and try again:</p>
<pre><code>$ bundle update
$ bundle exec mr-sparkle
</code></pre>
<h3>Updating your code</h3>
<p>There are no changes to make to your sites.</p>
<h2>What's new?</h2>
<p>These notes are pulled straight out of the <a href="https://github.com/gma/nesta/blob/v0.11.0/CHANGES">CHANGES file</a>.</p>
<ul>
<li><p>Allow Haml pages to use the built-in Markdown filter again, by
including the haml-contrib gem.
(Jordan Owens)</p></li>
<li><p>When building the breadcrumb (e.g. "Home > Category > Page") for a
page whose URL is at the top level of a site, include a page's first
category in the breadcrumb.
See <a href="https://github.com/gma/nesta/issues/147">https://github.com/gma/nesta/issues/147</a> for an example.
(Jordan Owens)</p></li>
<li><p>Print an error message when one of Nesta's command line tools calls
an external process (e.g. <code>git</code>), but the command doesn't return
successfully. (Graham Ashton)</p></li>
<li><p>When the menu.txt pointed to a page that didn't exist, Nesta would
silently stop generating the menu, and links to pages further down
the file would be ignored. This is now fixed; the missing page is
ignored and the rest of the menu is generated. (Jordan Owens)</p></li>
<li><p>Nesta previously expected all Markdown files to be named with a
<code>.mdown</code> extension. The (commonly used) <code>.md</code> extension is now
supported as well. (Phillip Miller)</p></li>
<li><p>The Google Analytics JavaScript code has been updated to their
Universal Analytics version. (Graham Ashton)</p></li>
<li><p>Relax restrictions on how Nesta can be configured. Previously Nesta
would only read if <code>config.yml</code> file if there weren't any environment
variables set. This restriction is historic, and unhelpful.
See <a href="https://github.com/gma/nesta/commit/bac50974">https://github.com/gma/nesta/commit/bac50974</a> for details.
(Glenn Gillen)</p></li>
<li><p>Plugins are distributed as gems. We've previously relied upon Bundler
to generate plugin gems for us, but when Bundler changed the format
of its generated gems they no longer worked with Nesta. Nesta now
generates gems from scratch (from a template), which removes our
dependency on a third party tool.
(Jordan Owens, Glenn Gillen, Graham Ashton)</p></li>
<li><p>Support for Ruby 2.2. (Graham Ashton)</p></li>
</ul>
2015-03-16T17:30:00+00:002015-03-16T17:30:00+00:00Nesta 0.10.0 releasedtag:nestacms.com,2014-04-29:/blog/version-0-10-0<p>It's been a while since the last release of Nesta, and this version has plenty of new features. The most obvious change is the default theme; it has a responsive design and a new font (you can see it in action on the <a href="http://nesta-demo.herokuapp.com">demo site</a>).</p>
<p>Other notable changes include:</p>
<ul>
<li>Support for Ruby 2.x. Support for Ruby 1.8.x has been dropped.</li>
<li>It's faster, especially on larger sites.</li>
<li>You can define your own config keys in <code>config.yml</code>.</li>
<li><code>shotgun</code> has been replaced by Micah Chalmer's superb Unicorn launcher as the recommended approach to running Nesta on your local computer.</li>
<li>There's some new metadata for you to play with.</li>
</ul>
<h2>Upgrading</h2>
<p>To install the new version edit your site's <code>Gemfile</code> and <strong>remove the version number</strong> (if it has one) from the end of the line, then run:</p>
<pre><code>$ bundle update nesta
</code></pre>
<p>Depending on when you created your site, you might find that <code>shotgun</code>
is listed in your <code>Gemfile</code>. If you do, I recommend you change it to
<code>mr-sparkle</code>, then run:</p>
<pre><code>$ bundle install
</code></pre>
<p>We're now using Haml 4.x. If your site has any pages written in Haml that use the <code>:textile</code> or <code>:maruku</code> inline filters you'll also need to add <code>haml-contrib</code> to your Gemfile:</p>
<pre><code>$ echo "gem 'haml-contrib'" >> Gemfile
$ bundle install
</code></pre>
<p>If you have any weird errors when you start your server it could be a result of there being some fairly old gems installed. Update the entire <code>bundle</code> and try again:</p>
<pre><code>$ bundle update
$ bundle exec mr-sparkle
</code></pre>
<h3>Updating your code</h3>
<p>The <code>url</code> helper (introduced in 0.9.13) has been renamed to <code>path_to</code>.</p>
<p>If your project (or theme) contains any templates that use the <code>url</code> helper method you'll need to change replace all calls to it with the <code>path_to</code> helper. By default it returns a path to a page, but will give you a URL if you really need one (see the <a href="http://rubydoc.info/gems/nesta/0.10.0/Nesta/View/Helpers:path_to">API docs</a> for more).</p>
<p>That should cover it, but I recommend you have a skim through the list of changes (below) to familiarise yourself with what's new.</p>
<h2>What's new?</h2>
<ul>
<li><p>Upgraded the default theme to a responsive design, using Google's Roboto Slab web font. (Graham Ashton)</p></li>
<li><p>Reduced the amount of I/O required to load a page with some judicious in memory caching of filenames. Expect a speed boost! (Graham Ashton)</p></li>
<li><p>Added 'Link text' metadata. When working out how to link to your pages from the automatically generated menus and breadcrumbs, Nesta uses the page's heading. It still does, but if you want to use different words when linking to the page in breadcrumbs or in the menu you can by defining the "Link text" metadata. (Micah Chalmer)</p>
<p>NOTE: Some existing sites may have pages that don't define a heading. Those sites will not work with Nesta 0.10.0 until they've been upgraded; either add an h1 level heading at the top of your pages (preferred) or define the 'Link text' metadata. If you don't want h1 headings to appear at the top of your web pages, hide them with CSS (this is the best approach for accessibility), or define the "Link text" metadata.</p></li>
<li><p>The text used in the 'Read more' link is now configurable in config.yml. The config key is called <code>read_more</code>. (Pete Gadomski)</p>
<p>See the config.yml template (on GitHub) for more details. <a href="https://github.com/gma/nesta/blob/master/templates/config/config.yml">https://github.com/gma/nesta/blob/master/templates/config/config.yml</a></p></li>
<li><p>Added the skip-sitemap flag, to prevent a page from being listed in the XML sitemap. Add <code>Flags: skip-sitemap</code> to the top of your page to enable it. Draft pages have also been removed from the sitemap. (Suggested by Joshua Mervine, implemented by Graham Ashton)</p></li>
<li><p>Added support for user-defined config settings in config.yml. If you've ever wanted to add config settings to config.yml and then access them from within your <code>app.rb</code> file or templates, this is for you.</p>
<p>There's a new <code>Nesta::Config.fetch</code> method for reading these settings. It can also read settings from the environment, looking for variables whose names are prefixed with "NESTA_". For example, the value in the <code>NESTA_MY_SETTING</code> variable can be returned by calling <code>Nesta::Config.fetch(:my_setting)</code>.</p>
<p>If the setting you're trying to read isn't defined a NotDefined exception (a subclass of KeyError) will be raised. Similarly to Ruby's Hash#fetch method, you can avoid the exception by specifying a second argument (such as nil) that will be returned if the setting isn't defined.</p>
<p>(Sean Redmond, Graham Ashton)</p></li>
<li><p>The built-in file caching (where Nesta could write generated HTML for rendered pages to disk) has been removed. If you'd like to cache pages to disk, use the sinatra-cache gem.</p>
<p>See <a href="http://nestacms.com/docs/deployment/page-caching">http://nestacms.com/docs/deployment/page-caching</a> for more details, and instructions for installing and testing sintra-cache.</p>
<p>(Graham Ashton)</p></li>
<li><p>The nesta script's theme:create command now copies default templates into a new theme. (Jake Rayson)</p></li>
<li><p>Added the --zsh-completion option to the nesta command, which outputs code that will configure command line completion in Zsh for the nesta command. (Wynn Netherland)</p></li>
<li><p>Page titles no longer include the heading from the parent page. Behaviour was a little inconsistent, and it's arguably not a great feature in the first place. Since the Title metadata appeared you can ovverride the page title to something more useful if you need to too. (Graham Ashton)</p></li>
<li><p>When commenting via Disqus is configured, comments appeared on every page in earlier versions of Nesta. From now on only pages with a date set (i.e. articles) will display the comment form by default. If you've copied the comments.haml template into your <code>./views</code> folder (or into a theme) you'll need to modify it slightly. See the <code>if</code> statement in the latest version.</p>
<p>If you'd actually like comments to appear on every page of your site, redefine the <code>Page#receives_comments?</code> method in your <code>app.rb</code> file, so that it returns <code>true</code>.</p>
<p>(Graham Ashton)</p></li>
<li><p>Breadcrumbs include Microdata for use by search engines. See: <a href="http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417">http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417</a> (Sean Schofield)</p></li>
<li><p>The menu and breadcrumb helper methods can now generate HTML that identifies the current page. When viewing a page that appears in the menu, its menu item will have the class "current". To change the name of the class, override the <code>Nesta::Navigation::current_menu_item_class</code> method.</p>
<p>The current page doesn't have a class applied by default. If you want to add a class to style it, override the <code>current_breadcrumb_class</code> method (also in the <code>Nesta::Navigation</code> module), returning a string.</p>
<p>(Pete Gadomski)</p></li>
<li><p>Version 0.9.13 used Sinatra's <code>url</code> helper method to generate links to pages on the site. When these pages were cached by proxy servers the hostname in the URL could be set incorrectly, as it would be determined from the HTTP headers (see issue #103 for more details).</p>
<p>The solution was to link to pages on the current site using an absolute path, rather than a full URL. The <code>path_to</code> helper was added,
and used in place of Sinatra's <code>url</code> helper method.</p>
<p>(Micah Chalmer)</p></li>
<li><p>Updated the test suite from RSpec 1.3 to RSpec 2. (Wynn Netherland, Graham Ashton)</p></li>
<li><p>Support for Ruby 1.8 has been dropped. Ruby 1.9.3 or above is recommended.</p></li>
<li><p>There were also plenty of small bug fixes that didn't make it into this list. See GitHub for the full list of commits. <a href="https://github.com/gma/nesta/compare/v0.9.13...v0.10.0">https://github.com/gma/nesta/compare/v0.9.13...v0.10.0</a></p></li>
</ul>
2014-04-29T13:00:00+00:002014-04-29T13:00:00+00:00Make a page that lists old articlestag:nestacms.com,2013-06-03:/docs/recipes/adding-links-to-archived-posts<p>Out of the box, Nesta doesn't provide a page that lists all your old
blog posts. It is however, easy to add one.</p>
<p>This recipe will walk you through how to add a page to your site at
/archives that lists all your blog posts, organised by the year in which
they were written.</p>
<h2>A dash of Ruby</h2>
<p>If you don't already have one, create a file called <code>app.rb</code> in your
project's directory, and paste the following code into it (if you do
have one, just add the code that follows to your <code>app.rb</code> file).</p>
<pre><code>module Nesta
 class App
 helpers do
 def list_articles(articles)
 haml_tag :ol do
 articles.each do |article|
 haml_tag :li do
 haml_tag :a, article.heading, :href => path_to(article.abspath)
 end
 end
 end
 end

 def article_years
 articles = Page.find_articles
 last, first = articles[0].date.year, articles[-1].date.year
 (first..last).to_a.reverse
 end

 def archive_by_year
 article_years.each do |year|
 haml_tag :li do
 haml_tag :a, :id => "#{year}"
 haml_tag :h2, year
 haml_tag :ol do
 articles = Page.find_articles.select { |a| a.date.year == year }
 list_articles(articles)
 end
 end
 end
 end
 end
 end
end
</code></pre>
<h2>Creating an /archives page</h2>
<p>We've just defined a new Ruby method called <code>archive_by_year</code> that we can
call from within a page to insert a list of all the articles on the
site. Let's create a new file called <code>content/pages/archives.haml</code> and
add the following Haml to it:</p>
<pre><code>%h1 Archives

%p
 Here's the full list of all the posts on the blog. I hope you enjoy
 browsing through them...

%ol.archive
 - archive_by_year
</code></pre>
<p>In case you haven't used it, Haml is a clean and simple way of writing HTML.
Nesta will convert Haml to HTML for you when the page is served. Any
line in a Haml file that starts with a hyphen will be treated as Ruby,
so our <code>archive_by_year</code> method is run and the HTML it produces is
inserted inside an <ol> tag.</p>
<p>Before we load the page, let's just add a bit of CSS to style our list
of articles. You can style it however you like, but I tend to use
something simple like this:</p>
<pre><code>ol.archive {
 list-style: none;
}

ol.archive ol {
 list-style: disc;
}
</code></pre>
<p>If you've written your own styles for your site you'll no doubt know
which file to add those styles to. If you're using the standard theme
you'll be able to add it to a file called <code>views/local.scss</code> and it'll
be loaded automatically.</p>
<p>If you fire up a local web server (e.g. with <code>mr-sparkle</code>) you should be
able to see a list of all your blog posts at /archives.</p>
<h2>Adding navigation links</h2>
<p>To make it easier for people to browse your archives you could add a few
links to the sidebar. I'm assuming you're using the standard theme here;
you may need to adapt the code that follows so that it works with your
site's design, but you'll get the idea.</p>
<p>First, create a template that will render a list of links to the years
in which we've published articles. Put this Haml in <code>views/years.haml</code>:</p>
<pre><code>%nav.archive
 %h1 Articles by year
 %ol
 - article_years.each do |year|
 %li
 %a{ :href => "/archives##{year}" }= year
</code></pre>
<p>Let's style it with this CSS (add it to <code>local.scss</code> again, or wherever
you put your CSS for styling the /archives page):</p>
<pre><code>nav.archive ol {
 list-style: none;
}
</code></pre>
<p>Now you just need to render the <code>years.haml</code> template in a suitable
place in your sidebar. If you're using a theme that has a <code>sidebar.haml</code>
template you can copy the <code>sidebar.haml</code> file to your <code>views</code> folder,
and edit it so it looks something like this:</p>
<pre><code>#sidebar
 = haml :categories, :layout => false
 = haml :years, :layout => false
</code></pre>
<p>If you're not sure where to find a sidebar.haml file, these commands may
help (run them from within your site's folder):</p>
<pre><code>$ ls `bundle show nesta`/views
$ mkdir -p views
$ cp `bundle show nesta`/views/sidebar.haml views
</code></pre>
2013-06-03T00:00:00+00:002013-06-03T00:00:00+00:00Nesta 0.9.13 releasedtag:nestacms.com,2012-03-04:/blog/version-0-9-13<p>Version 0.9.13 has been released. New features include support for Erb
templates (in the views folder only, not for pages) and a <code>nesta edit</code>
command that makes it easier to edit your site. Etag support is enabled
in new projects.There have also been a few internal API tweaks to
support the plugins that are starting to spring up. Two view helper
methods (<code>url_for</code> and <code>base_url</code>) have been removed.</p>
<p>There have been a few contributors to this release (thanks all). Max
Sadrieh has been particularly helpful by digging through the list of
outstanding issues, submitting patches, and generally getting stuck in. :-)</p>
<h2>Upgrading</h2>
<p>If your project (or theme) contains any templates that use the <code>url_for</code>
or <code>base_url</code> helpers, you'll need to replace them with a call to the
<code>url</code> helper from Sinatra. It's automatically available to you within
your templates, and takes a path. For example:</p>
<pre><code>%a{ :href => url(page.path) }= page.heading
</code></pre>
<p>If you've copied the <code>atom.haml</code> or <code>sitemap.haml</code> files from the
default set into your <code>views</code> folder, they'll need updating (if you
haven't actually changed them just delete them, and Nesta will find them
in the gem itself).</p>
<h2>The changes</h2>
<p>Here's the <a href="https://github.com/gma/nesta/blob/v0.13.0/CHANGES">CHANGES</a> file with the full list of updates:</p>
<ul>
<li><p>The nesta script has a new command; edit. You can pass it the path
to a file within your <code>content/pages</code> folder and it will open the file
in your default editor (as set by the <code>EDITOR</code> environment variable).</p></li>
<li><p>The nesta script has a new option; <code>--bash-completion</code>. Run nesta
with this option and it will print some Bash that will configure
command line completion for the nesta command.</p>
<p>You can type <code>nesta edit <TAB></code> and Bash will complete the names of
the files in your <code>content/pages</code> directory. :-)</p>
<p>Installation instructions at the top of the Bash script.</p></li>
<li><p>Nesta can now be mounted cleanly at a path, rather than at a site's
root, and assets and links will be served correctly.
(Max Sadrieh, Graham Ashton)</p></li>
<li><p>The default <code>config.ru</code> file that is generated when you create a new
project now enables Etag HTTP headers. (Max Sadrieh)</p></li>
<li><p>Two helper methods have been removed; <code>url_for</code> and <code>base_url</code>. Use
Sinatra's <code>url</code> helper instead. They would have been deprecated rather
than removed, but if you try and load Nesta's helpers in a Rails app
<code>url_for</code> breaks Rails's rendering. (Max Sadrieh, Graham Ashton)</p></li>
<li><p>The <code>current_item?</code> helper has been created in <code>Nesta::Navigation</code>.
You can override it to implement your own logic for determining
whether or not a menu item rendered by the menu helpers are
considered to be "current". (Chad Ostrowski)</p></li>
<li><p>The <code>Page</code> class has a new method; <code>body_markup</code>. It can be
overridden by a plugin, and is used by the foldable plugin. (Micah
Chalmer)</p></li>
<li><p>The <code>FileModel</code> class has a new method; <code>parse_metadata</code>. It can be
overriden by plugins that implement an alternate metadata syntax.
Used by the yaml-metadata plugin.</p></li>
<li><p>Erb templates in your <code>./views</code> folder, or in a theme's folder, will
now be found when you call Sinatra's erb helper method.</p></li>
<li><p><code>config.yml</code> can now contain Erb (and therefore inline Ruby), which
will be interpreted when loaded. (Glenn Gillen)</p></li>
<li><p>Extended the <code>nesta</code> command to support new commands that could (for
example) be added by a plugin. The class to be instantiated within
the <code>Nesta::Commands</code> module is determined from the command line
argument (e.g. <code>nesta plugin:create</code> will instantiate the class
called <code>Nesta::Commands::Plugin::Create</code>).</p></li>
<li><p>Bug fix: Don't crash if a page's metadata only contains the key, with
no corresponding value. You could argue this wasn't a bug, but the
error message was difficult to trace. See #77.</p></li>
<li><p>Bug fix: Summaries on Haml pages were not marked up as paragraphs.
See #75.</p></li>
</ul>
<p>I really hope I haven't forgotten anybody. Let me know if I have and
I'll update the post/CHANGES file...</p>
2012-03-04T00:00:00+00:002012-03-04T00:00:00+00:00Setting up rack-codehighlightertag:nestacms.com,2012-02-27:/docs/recipes/syntax-highlighting-with-rack-codehighlighter<p>If you write about software, you can make code look more attractive by
adding syntax highlighting to your pages. Nesta is a Sinatra app (and is
therefore built on top of Rack), which makes it easy to setup syntax
highlighting with the <code>rack-codehighlighter</code> gem.</p>
<h2>Installing the gem</h2>
<p>Before you can highlight any code, you've got a decision to make. There
are several highlighting libraries available to you</p>
<p>Add the <code>rack-codehighlighter</code> gem and your preferred highlighting
library (I'm using <code>coderay</code> in this example) to your <code>Gemfile</code> and run
bundle:</p>
<pre><code>$ echo 'gem "coderay"' >> Gemfile
$ echo 'gem "rack-codehighlighter", :require => "rack/codehighlighter"' >> Gemfile
$ bundle
</code></pre>
<p>Now edit your project's <code>config.ru</code> file, as outlined in the
rack-codehighlighter <a href="https://github.com/wbzyl/rack-codehighlighter/blob/master/README.md">README</a> file. Because I'm using coderay the
bottom of my <code>config.ru</code> file now looks like this:</p>
<pre><code>use Rack::Codehighlighter, :coderay,
 :element => "pre>code", :markdown => true

run Nesta::App
</code></pre>
<p>The <code>:element</code> and <code>:markdown</code> options that I've set in this example
work well if your content is written in Markdown; if you're using
Textile you'll want to tweak the setting (see the <a href="https://github.com/wbzyl/rack-codehighlighter/blob/master/README.md">README</a>).</p>
<p>Now start your app up in development mode, add a block of source code to
one of your web pages, and tell the highlighter what syntax it is.
Something like this should do it:</p>
<pre><code>:::ruby
def hello
 puts "Hi!"
end
</code></pre>
<p>Reload the page. If <code>:::ruby</code> has been removed from the HTML then the
highlighter is working -- if you look at the source you'll see that your
code has been wrapped in span tags.</p>
<p>Now you need some CSS to make it look pretty.</p>
<h2>Adding some colour</h2>
<p>If you've decided to use Ultraviolet it looks as though you can choose a
theme and tell Rack::Codehighlighter to deal with it for you. I haven't
investigated that yet -- see the <a href="https://github.com/wbzyl/rack-codehighlighter/blob/master/README.md">README</a> for notes on Ultraviolet.</p>
<h3>CSS styles for Coderay</h3>
<p>If you're using Coderay you'll need to provide your own CSS. I'm too
lazy for that, but luckily some kind souls have shared their CSS with
the rest of us. I like the <a href="https://github.com/pie4dan/CodeRay-GitHub-Theme">GitHub styles</a> and the <a href="http://railscasts.com/episodes/207-syntax-highlighting">RailsCasts
colours</a>.</p>
<p><em>Update:</em> Since I first wrote this article, <code>coderay</code> appears to have
updated the CSS class names that it uses to highlight code, and those
themes don't work any more. If you'd like to use them, make sure that
you tell Bundler to load an earlier version of <code>coderay</code> (I'm using
0.9.8 successfully, and I'm not sure when the CSS class names were
changed).</p>
<h4>If you're using a Nesta theme...</h4>
<p>Themes load their CSS from their own <code>views</code> folder (e.g.
<code>themes/slate/views</code>), but if you put a stylesheet in your site's
<code>views</code> folder Nesta will load that instead.</p>
<p>So we're going to pull a neat trick, and get Sass to include our
stylesheet at the end of the theme's default CSS. Start by making a copy
of the theme's Sass file:</p>
<pre><code>$ mkdir -p views
$ cp themes/slate/views/master.sass views/
</code></pre>
<p>Now get your Coderay CSS and store it in a <code>.scss</code> file:</p>
<pre><code>$ curl https://raw.github.com/pie4dan/CodeRay-GitHub-Theme/master/coderay.css \ 
 > views/coderay-github.scss
</code></pre>
<p>Finally, get Sass to import the styles into the main stylesheet:</p>
<pre><code>$ echo '@import "coderay-github"' >> views/master.sass
</code></pre>
<p>You should be all set. Try reloading your page and see if your code is
in colour.</p>
<h4>If you've designed your own site...</h4>
<p>Download the source for one and put it in <code>public/css</code>:</p>
<pre><code>$ mkdir -p public/css
$ curl https://raw.github.com/pie4dan/CodeRay-GitHub-Theme/master/coderay.css \ 
 > public/css/coderay-github.css
</code></pre>
<p>Edit your layout template and load the CSS with a <link> tag. You
should be good to go...</p>
<h2>Resources</h2>
<ul>
<li>The <a href="https://github.com/wbzyl/rack-codehighlighter">rack-codehighlighter gem</a></li>
<li><a href="http://railscasts.com/episodes/207-syntax-highlighting">RailsCasts episode 207</a> from Ryan Bates</li>
</ul>
2012-02-27T00:00:00+00:002012-02-27T00:00:00+00:00Refresh the browser when you save a filetag:nestacms.com,2012-02-15:/docs/recipes/automatically-reload-pages-as-you-write<p>Most of the pages on a Nesta site are written in a text editor, using Markdown or Textile. You don't get to see what your words look like on a web page until you save the file to disk and reload your browser. Wouldn't it be nice if your browser automatically reloaded pages as you saved them? When designing a theme, what if changes to HTML and CSS were reloaded immediately?</p>
<p>With the <a href="https://github.com/mockko/livereload">livereload</a> and <a href="https://github.com/guard/guard">Guard</a> projects, it's fairly easy to setup.</p>
<p><strong>Note:</strong> Since I wrote this article, <a href="http://livereload.com">Livereload 2</a> has been released. It looks as though that's an even easier way to reload your pages, but I haven't had a chance to try it with Nesta yet. These instructions are for Livereload 1.</p>
<h2>Installing guard</h2>
<p>Guard is distributed as a Ruby gem. We actually want the <code>guard-livereload</code> gem (which will pull in <code>guard</code> itself) so we'll add that to our <code>Gemfile</code>. We're going to add the <code>rb-readline</code> gem too, as it gives Guard a nice interactive prompt:</p>
<pre><code>$ cat >> Gemfile
group :development do
 gem 'guard-livereload'
 gem 'rb-readline'
end
</code></pre>
<p>Now re-build your bundle to install the extra gems...</p>
<pre><code>$ bundle
</code></pre>
<p>That's Guard installed.</p>
<h2>Installing the browser plugin</h2>
<p>Head over to the <a href="https://github.com/mockko/livereload/blob/master/README-old.md">plugin instructions</a> and download and install the browser plugin.</p>
<h2>Setting up your Guardfile</h2>
<p>Now we just need to create a <code>Guardfile</code> that will tell Guard what we want it to do. You can create the default config file like this:</p>
<pre><code>$ guard init livereload
</code></pre>
<p>If you have a look at the <code>Guardfile</code> you'll see a few <code>watch</code> commands that specify paths to files that you'd find in a Rails app. Nesta keeps things in different places to Rails, so we'll be changing the contents of that file.</p>
<p>Mine looks like this:</p>
<pre><code>$ cat > Guardfile
guard 'livereload' do
 watch(%r{content/pages(/.+)\.(mdown|textile|haml)}) { |match| match[1] }
 watch(%r{public(/.+\.(jpe?g|js|png))}) { |match| match[1] }
 watch(%r{views/.+\.haml})
 watch(%r{views/(.+)\.s[ac]ss}) do |match|
 if match[1] =~ /(mixins|variables)/
 ["/css/master.css", "/css/layout.css"]
 else
 "/css/#{match[1]}.css"
 end
 end
end
</code></pre>
<p>I won't go into too much detail about what's going on there; I think you'll do better by studying the code than you would at reading my attempt to explain it. The only thing I want to point out is that I usually have Sass files called <code>views/mixins.sass</code> and <code>views/variables.sass</code>. Those two files are never served to the browser; they're just included into <code>master.sass</code> and <code>layout.sass</code>. That's why when they change, Guard tells the browser to reload <code>master.css</code> and <code>layout.css</code>.</p>
<p>When you're happy with your config, run Guard like this:</p>
<pre><code>$ guard
</code></pre>
<p>If you make some changes to <code>Guardfile</code> while <code>guard</code> is running you can prompt Guard to reload its config by typing "reload" at Guard's prompt.</p>
<h2>Try it out</h2>
<p>Run <code>guard</code> in one terminal window, and your local web server in another. Visit a web page, then right click in the browser window and select "Enable Livereload".</p>
<p>Any changes that you make to your content, HTML or CSS should now cause your browser to automatically reload.</p>
<p>If you want to see what else Guard can do, Ryan Bates has recorded a <a href="http://railscasts.com/episodes/264-guard">Railscast on Guard</a> (livereload is introduced after 6 minutes and 20 seconds).</p>
2012-02-15T00:00:00+00:002012-02-15T00:00:00+00:00Running a blog in a larger sitetag:nestacms.com,2012-02-01:/docs/design/blog-within-larger-site<p>We start by customising the default templates and applying a different
layout to blog articles. We then move the blog to a new URL, freeing up
your site's home page for different content.</p>
<h2>Copying the default templates</h2>
<p>The default theme that comes with Nesta uses HTML5 markup, and WAI-ARIA
roles for accessibility. As such, they make a good starting point for
anybody wanting to implement a custom design.</p>
<p>To copy all the templates (other than those for the Atom feed and
sitemap, which you won't need to modify), run these two commands:</p>
<pre><code>$ cd mysite.com
$ mkdir -p views
$ cp $(bundle show nesta)/views/* ./views
$ rm views/feed.haml views/sitemap.haml
</code></pre>
<p><strong>Note:</strong> You'll need to substitute Nesta's current version number into
the command.</p>
<p>You can now edit the templates in your local <code>views</code> folder, which will
be used instead of the templates that ship with Nesta.</p>
<h2>Switching from Sass to Scss</h2>
<p>Some people prefer the original CSS syntax to Sass's rather neat nested
syntax. As a result the Sass developers created the Scss format, which
supports pure CSS (with the clever bits from Sass thrown in).</p>
<p>If you'd rather work with Scss than Sass, you can convert the default
<code>.sass</code> files, like so:</p>
<pre><code>$ cd views
$ for f in *.sass; do sass-convert $f $(basename $f).scss; done
</code></pre>
<p>You'll also need to make sure that requests for CSS files are handled by
Sinatra's <code>scss</code> method, rather than the <code>sass</code> method. You can achieve
this by adding a route to <code>app.rb</code>.</p>
<p>Open (or create, if it doesn't exist) the <code>app.rb</code> file in your
project's top level directory (e.g. <code>mysite.com</code>). Then add the
following code (if you find that <code>Nesta::App</code> already exists in
<code>app.rb</code>, just add the <code>get</code> block inside it):</p>
<pre><code>module Nesta
 class App
 get '/css/:sheet.css' do
 content_type 'text/css', :charset => 'utf-8'
 scss(params[:sheet].to_sym)
 end
 end
end
</code></pre>
<h2>Using a different template for blog posts</h2>
<p>In the default theme the <code>page.haml</code> template is used to render every
page on the site, but you can use a different template for some pages if
you prefer. If you only want to allow comments on your blog articles you
could remove the comments markup from <code>page.haml</code> and create an
<code>article.haml</code> template (that includes the relevant markup) specifically
for your blog posts.</p>
<p>Start by creating a template for displaying blog posts:</p>
<pre><code>$ cp views/page.haml views/article.haml
</code></pre>
<p>Now edit <code>page.haml</code>, removing the comments template.</p>
<p>You can use <code>article.haml</code> by by adding a line like this to the top of
each blog article:</p>
<pre><code>Template: article
</code></pre>
<p>See the coverage of "Template" in the <a href="https://nestacms.com/docs/creating-content/metadata-reference">metadata reference</a> for more
details.</p>
<h2>Moving the blog to /blog</h2>
<p>If you'd like to list your recent blog articles at the URL /blog, rather
than on your site's home page, all you need to do is to create a page in
<code>content/pages/blog/index.haml</code> that contains this code:</p>
<pre><code>%section.articles= article_summaries(latest_articles)
</code></pre>
<p>It will create a <code><section/></code> HTML tag with a class of <code>articles</code>
(which is only there as it's useful for applying CSS styles), and will
then use the <code>article_summaries</code> helper method to list the latest
articles in an <code><ol/></code> tag.</p>
<p>If you haven't changed it, you can probably just copy the default
<code>index.haml</code> template into <code>content/pages/blog/</code>:</p>
<pre><code>$ mkdir -p content/pages/blog
$ cp content/pages/index.haml content/pages/blog/
</code></pre>
<h3>Thoughts on blog post URLs</h3>
<p>If your site includes breadcrumb navigation to show your visitors where
they are, it can be a good idea to make sure that your articles are
children of the blog page. If you put them inside the
<code>content/pages/blog</code> folder then this will work automatically.</p>
<p>It is by no means the only way to do it though; I often place articles
(such as this one) inside the folder containing other pages in the
article's main category, rather than dropping content inside the <code>blog</code>
folder (it has never felt like a particularly useful part of the URL to
me).</p>
<h2>Universal IE6 stylesheet</h2>
<p>Nesta's default layout includes Andy Clarke's Universal IE6 stylesheets
to make sure that the content is available to visitors who are have to
use IE6, while freeing developers up to use progressive CSS.</p>
<p>If you'd rather not use it, edit <code>views/layout.haml</code> and remove the line
that references <code>universal-ie6-css</code>.</p>
2012-02-01T13:30:00+00:002012-02-01T13:30:00+00:00