Upgrated to Nanoc 3.
jump to
@@ -0,0 +1,51 @@
+#!/usr/bin/env ruby + +"a-look-at-drupal.bbcode +boolean-search.bbcode +cakephp.bbcode +from-firefox-to-deer-park.bbcode +google-earth.bbcode +ie-lovers-guide-to-firefox.bbcode +ma.gnolia.bbcode +next-generation-dvds.bbcode +pagerank.bbcode +perfect-browser.bbcode +pre-review-of-ie7.bbcode +project-gutenberg.bbcode +project-windstone.bbcode +quick-overview-of-sqlite.bbcode +server-packages.bbcode +slax.bbcode +sqlyog5-review.bbcode +web-promotion.bbcode +what-is-ajax.bbcode +log-jan-2009.bluecloth +the-rails-way-review.bluecloth".split(/\n/).each do |s| + f, ident, fil = s.match(/(.+)\.(.+)$/).to_a + compile "/articles/#{ident}" do + rep.filter fil.to_sym + layout 'default' + end +end + +compile /archives/ do + rep.filter :erb + layout 'default' +end + +compile /\/(home|projects|about)/ do + rep.filter :erb + rep.filter :redcloth + layout 'default' +end + +compile '*' do + rep.filter :redcloth + layout 'default' +end + +route '*' do + item.identifier + 'index.html' +end + +layout '*', :erb
@@ -1,6 +0,0 @@
-# Built-in -extension: dat -binary: true -filters: [] - -# Custom
@@ -1,3 +1,6 @@
-output_dir: "output" -data_source: "filesystem_combined" -router: "default" +--- +data_sources: +- items_root: / + layouts_root: / + type: filesystem_combined +output_dir: output
@@ -75,7 +75,7 @@
And so on. Anyhow... I followed the tutorial and yes, it was a nice read. CakePHP borrowed a lot from Rails but not everything. Inevitably Ruby's syntax is less verbose and looks very very clean: -<pre><code> +<% highlight :ruby do %> class RecipeController < ApplicationController scaffold :recipe@@ -88,11 +88,11 @@ @recipe = Recipe.find(@params["id"])
@categories = Category.find_all end end -</code></pre> +<% end %> While CakePHP's, simply because it uses PHP and not Ruby, looks less pretty: -<pre><code> +<% highlight :php do %> class RecipesController extends AppController { var $scaffold;@@ -109,7 +109,7 @@ $this->set('categories', $this->Category->findAll());
} } -</code></pre> +<% end %> CakePHP Development Team did a great job translating some of Rails functionalities into PHP, and the while CakePHP's syntax is *much* cleaner if compared to PHP's standard spaghetti-code approach, Ruby just looks much more clear, sorry. _Imagine a world without funny unnecessary brackets, pointless semicolons and where everything just looks better_: that's Ruby.@@ -119,7 +119,7 @@ One thing I liked about Rails which has not been ported in Cake (yet) is a somehow smarter way of scaffolding. While the Ruby code above actually works, the CakePHP's edit method doesn't, or better, it does but not as expected: when you remove @var $scaffold@ the scaffold is just plain gone, and you have to code everything yourself, while in Ruby you can leave the scaffold and then develop methods one by one, and still be able to use scaffolded methods if you didn't define the custom ones.
The other thing I noticed about RoR is that it definitely handles errors better! This is probably another language issue. I basically forgot to set a category for the recipes, and when executing my custom list of recipes I got a very, very well structured error page showing something like: -<pre><code> +<% highlight :ruby do %> NoMethodError in Recipe#index Showing app/views/recipe/index.rhtml where line #18 raised:@@ -129,13 +129,13 @@ The error occured while evaluating nil.name
Extracted source (around line #18): -15: <% @recipes.each do |recipe| %> +15: <% @recipes.each do |recipe| %> 16: <tr> -17: <td><%= link_to recipe.title, :action => "show", :id => recipe.id %></td> -18: <td><%= recipe.category.name %></td> -19: <td><%= recipe.date %></td> +17: <td><%= link_to recipe.title, :action => "show", :id => recipe.id %></td> +18: <td><%= recipe.category.name %></td> +19: <td><%= recipe.date %></td> 20: </tr> -21: <% end %> -</code></pre> +21: <% end %> +<% end %> I took a screenshot of the page, because it was too nice: "check it out":http://base--/img/pictures/rails_error.jpg. This error page really tells you what's wrong, and even prints the lines of code around the error! It also lets the developer check the full backtrace and every sort of information... Can we have this in CakePHP please? I actually started to develop something like this, but seemed quite hard to do in PHP.
@@ -13,7 +13,6 @@ all_articles = latest_articles
latest = latest_articles 5 popular = popular_articles 5 %> -h2. Welcome This is Fabio Cevasco's web site, featuring <%= all_articles.length %> "articles":/archives/ and <%= 5 %> open source "projects":/projects/. Fabio is a full-time technical writer working in Genoa, Italy. In his free time, he enjoys writing (surprise, surprise), reading about technology and programming a little bit in Ruby and other languages.
@@ -2,7 +2,7 @@ -----
filter: erb ----- <div id="comments"> - <%= render 'legacy_comments' if @page.comments && @page.comments.length > 0 %> + <%= render 'legacy_comments' if @item[:comments] && @item[:comments].length > 0 %> <script> var idcomments_acct = '7a8e41c4b06641909304090b010e8009'; var idcomments_post_id;
@@ -5,7 +5,7 @@ <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> - <title><%= @page.title %> - H3RALD</title> + <title><%= @item[:title] %> - H3RALD</title> <link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.h3rald.com/rss" /> <link rel="alternate" type="application/atom+xml" title="ATOM" href="http://www.h3rald.com/atom" /> <meta name="author" content="Fabio Cevasco" />@@ -79,23 +79,10 @@ <!-- CONTAINER START -->
<div id="container"> <!-- CONTENT START --> <div id="content" class="clearfix"> - <% if @page.permalink == 'home' then %> - <div id="slider"> - <div class="scroll"> - <div class="scrollContainer"> - <%= @page.content %> - <% else %> <div id="article-content"> - <h2><%= @page.title %></h2> - <%= @page.content %> + <h2><%= @item[:title] %></h2> + <%= yield %> </div> - <% end %> - - <% if @page.permalink == 'home' then %> - </div><!-- .scrollContainer --> - </div><!-- .scroll --> - </div><!-- #slider --> - <% end %> </div> <!-- CONTENT END --> </div>@@ -108,7 +95,7 @@ <div id="share">
<a class="a2a_dd" href="http://www.addtoany.com/share_save"><img src="http://static.addtoany.com/buttons/share_save_120_16.gif" width="120" height="16" alt="Share/Save/Bookmark"/></a><script type="text/javascript">a2a_linkname=document.title;a2a_linkurl=location.href;a2a_onclick=1;a2a_prioritize=["delicious","stumbleupon","friendfeed","twitter","dzone","digg","reddit","slashdot","facebook","newsvine","sphere","ping"];</script><script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script> <a class="a2a_dd" href="http://www.addtoany.com/subscribe?linkname=&linkurl=http%3A%2F%2Fwww.h3rald.com%2Frss%2F"><img src="http://static.addtoany.com/buttons/subscribe_120_16.gif" width="120" height="16" alt="Subscribe"/></a><script type="text/javascript">a2a_linkname=document.title;a2a_linkurl="http://www.h3rald.com/rss/";a2a_onclick=1;</script><script type="text/javascript" src="http://static.addtoany.com/menu/feed.js"></script> </div> - <% if @page.type == 'article' then %> + <% if @item[:type] == 'article' then %> <%= render 'comments' %> <% else %> <%= render 'services' %>
@@ -7,7 +7,7 @@ <h3>Legacy Comments</h3>
<p> <em>These comments were imported automatically from an old version of this web site. Scroll <a href="#idc-container-parent">down</a> for the newest stuff.</em> </p> - <% @page.comments.each do |c| %> + <% @item[:comments].each do |c| %> <div id="comment-<%=c[:id]%>" class="legacy-comment"> <div class="lc-header"><%= (c[:url].empty?) ? c[:author] : %{<a href="#{c[:url]}">#{c[:author]}</a>} %></div> <div class="lc-body">
@@ -1,10 +1,10 @@
require 'rubygems' require 'bb-ruby' -class BbcodeFilter < Nanoc::Filter +class BbcodeFilter < Nanoc3::Filter identifier :bbcode - def run(content) + def run(content, args) content.bbcode_to_html end
@@ -1,10 +1,12 @@
-module Nanoc::Helpers::Tagging +require 'redcloth' + +module Nanoc3::Helpers::Tagging def site_tags ts = {} - @pages.each do |p| - next unless p.tags - p.tags.each do |t| + @items.each do |p| + next unless p[:tags] + p[:tags].each do |t| if ts[t] ts[t] = ts[t]+1 else@@ -25,16 +27,16 @@ end
end -module Nanoc::Helpers::Site +module Nanoc3::Helpers::Site def latest_articles(max=nil) - total = @site.pages.select{|p| p.attributes[:date] && p.attributes[:type] == 'article'}.sort{|a, b| a.attributes[:date] <=> b.attributes[:date]}.reverse + total = @site.items.select{|p| p.attributes[:date] && p.attributes[:type] == 'article'}.sort{|a, b| a.attributes[:date] <=> b.attributes[:date]}.reverse max ||= total.length total[0..max-1] end def popular_articles(max=nil) - total = @site.pages.select{|p| p.attributes[:date] && p.attributes[:type] == 'article' && p.attributes[:popular]}.sort{|a, b| a.attributes[:date] <=> b.attributes[:date]}.reverse + total = @site.items.select{|p| p.attributes[:date] && p.attributes[:type] == 'article' && p.attributes[:popular]}.sort{|a, b| a.attributes[:date] <=> b.attributes[:date]}.reverse max ||= total.length total[0..max-1] end@@ -67,5 +69,6 @@ end
end -include Nanoc::Helpers::Tagging -include Nanoc::Helpers::Site +include Nanoc3::Helpers::Tagging +include Nanoc3::Helpers::Site +include Nanoc3::Helpers::Rendering
@@ -1,7 +1,7 @@
# Monkey patch Nanoc::Helpers::Filtering -module Nanoc::Helpers::Filtering +module Nanoc3::Helpers::Filtering def highlight(syntax, &block) # Seamlessly ripped off from the filter method...@@ -19,4 +19,4 @@ end
end -include Nanoc::Helpers::Filtering +include Nanoc3::Helpers::Filtering
@@ -1,10 +0,0 @@
-# Built-in -layout: default -extension: html -filters_pre: ['redcloth'] -skip_output: false -filters_post: [] -custom_path: -filename: index - -# Custom
@@ -2,7 +2,7 @@ require 'rubygems'
require 'extlib' require 'pathname' require 'fileutils' -require 'nanoc' +require 'nanoc3' module SiteUtils@@ -16,7 +16,7 @@ meta[:permalink] = name
pl = (count == 1) ? ' is' : 's are' contents = %{\n#{count} item#{pl} tagged with _#{name}_: -<% @site.pages.select{|p| p.attributes[:tags] && p.attributes[:tags].include?('#{name}')}.sort{|a,b| a.attributes[:date] <=> b.attributes[:date]}.reverse.each do |pg| +<% @site.items.select{|p| p.attributes[:tags] && p.attributes[:tags].include?('#{name}')}.sort{|a,b| a.attributes[:date] <=> b.attributes[:date]}.reverse.each do |pg| %>* <span class="<%= pg.attributes[:type] %>_link"> <a href="/articles/<%= pg.attributes[:permalink] %>/"><%= pg.attributes[:title] %></a></span> <% end %> }@@ -65,25 +65,25 @@ (output/'data').mkpath
end task :update => [:copy_resources] do - system "nanoc co" + system "nanoc3 co" end task :run => [:copy_resources] do - system "nanoc aco" + system "nanoc3 aco" end task :rebuild => [:clear_output, :update] do end task :tags do - site = Nanoc::Site.new(YAML.load_file('config.yaml')) + site = Nanoc3::Site.new('.') site.load_data dir = Pathname(Dir.pwd)/'content/tags' dir.rmtree if dir.exist? dir.mkpath tags = {} # Collect tag and page data - site.pages.each do |p| + site.items.each do |p| next unless p.attributes[:tags] p.attributes[:tags].each do |t| if tags[t]@@ -100,7 +100,7 @@ end
end task :archives do - site = Nanoc::Site.new(YAML.load_file('config.yaml')) + site = Nanoc3::Site.new(YAML.load_file('config.yaml')) site.load_data dir = Pathname(Dir.pwd)/'content/archives' dir.rmtree if dir.exist?
@@ -12,6 +12,7 @@ require 'iconv'
module TypoUtils + # Ignored by Nanoc 3 def get_filter(db, fid) filter = db[:text_filters].where("id = ?", fid).get(:name).downcase # Multiple filters are not handled (e.g. markdown smartypants)
@@ -1,14 +0,0 @@
------ -permalink: article -filters_pre: -- redcloth -title: New article! -date: -type: page -toc: true -tags: [] ------ - -h2. Title - -...
@@ -1,12 +0,0 @@
------ -permalink: page -filters_pre: -- redcloth -title: New page! -date: -type: page ------ - -h2. Title - -...