Started improving Glyph integration.
h3rald h3rald@h3rald.com
Wed, 15 Sep 2010 15:54:29 +0200
6 files changed,
75 insertions(+),
101 deletions(-)
M
Rules
→
Rules
@@ -59,14 +59,15 @@ when 'bbcode' then
rep.filter :bbcode layout 'default' when 'glyph' then + require 'glyph' + instance_eval Glyph.file_load("#{Dir.pwd}/lib/glyph.data") pdf_file = Pathname.new "#{Dir.pwd}/output#{item.identifier.gsub(/\/$/, '')}.pdf" unless pdf_file.exist? then # Create the PDF file f = Pathname.new "#{Dir.pwd}/output#{item.identifier.gsub(/\/$/, '')}.glyph" f.parent.mkpath doc = %{ - include[#{f.parent.parent.parent}/lib/data] - h3rald_article[ + h3rald.article[ @identifier[#{item.identifier}] @content[section[#{item.raw_content}]] ]@@ -76,12 +77,7 @@ file_write f, doc
# Now compile the PDF (works if Prince is installed) target = Glyph['document.output'] Glyph['document.output'] = 'pdf' - Glyph['document.author'] = "Fabio Cevasco" - Glyph['output.pdf.generator'] = "prince" Glyph['site.root'] = ".." - Glyph['document.date'] = item[:date].strftime "%A, %d %B %Y" - Glyph['document.title'] = item[:title] - Glyph['document.subtitle'] = "" Glyph.compile f.to_s begin f.unlink
A
content/articles/h3rald-81.glyph
@@ -0,0 +1,24 @@
+----- +:title: H3RALD.com v8.1 Released +:subtitle: Featuring a a brand new newspaper-like design, powered by HTML5 and CSS3 +:type: article +:toc: true +:date: 2010-09-15 14:24:25.052000 +02:00 +:permalink: h3rald-81 +:pdf: true +:tags: +- website +- webdevelopment +:intro: | + Just "over a year ago":/articles/take-back-your-site-with-nanoc I released the 8th version of this web site. + The biggest change then was abandoning the Rails-powered "Typo":http://wiki.github.com/fdv/typo/ blogging + platform in favor of "nanoc":http://nanoc.stoneship.org/, arguably the most versatile static site generator out + there. + + A year later, I am still very happy with nanoc, hence there's no need for another major release. Nonetheless, I + decided to improve the site's overall design and image, making it (hopefully) easier to use and more pleasant to + the eye. +:extended_intro: | + TODO... +----- +$[document.intro]
D
lib/albino.rb
@@ -1,87 +0,0 @@
-## -# Wrapper for the Pygments command line tool, pygmentize. -# -# Pygments: http://pygments.org/ -# -# Assumes pygmentize is in the path. If not, set its location -# with Albino.bin = '/path/to/pygmentize' -# -# Use like so: -# -# @syntaxer = Albino.new('/some/file.rb', :ruby) -# puts @syntaxer.colorize -# -# This'll print out an HTMLized, Ruby-highlighted version -# of '/some/file.rb'. -# -# To use another formatter, pass it as the third argument: -# -# @syntaxer = Albino.new('/some/file.rb', :ruby, :bbcode) -# puts @syntaxer.colorize -# -# You can also use the #colorize class method: -# -# puts Albino.colorize('/some/file.rb', :ruby) -# -# Another also: you get a #to_s, for somewhat nicer use in Rails views. -# -# ... helper file ... -# def highlight(text) -# Albino.new(text, :ruby) -# end -# -# ... view file ... -# <%= highlight text %> -# -# The default lexer is 'text'. You need to specify a lexer yourself; -# because we are using STDIN there is no auto-detect. -# -# To see all lexers and formatters available, run `pygmentize -L`. -# -# Chris Wanstrath // chris@ozmm.org -# GitHub // http://github.com -# -require 'rubygems' -require 'open3' -require 'win32/open3' if RUBY_PLATFORM.match /win32/ - -class Albino - @@bin = 'pygmentize' - - def self.bin=(path) - @@bin = path - end - - def self.colorize(*args) - new(*args).colorize - end - - def initialize(target, lexer = :text, format = :html) - @target = File.exists?(target) ? File.read(target) : target rescue target - @options = { :l => lexer, :f => format, :O => 'encoding=utf-8' } - end - - def execute(command) - output = '' - Open3.popen3(command) do |stdin, stdout, stderr| - stdin.puts @target - stdin.close - output = stdout.read.strip - [stdout, stderr].each { |io| io.close } - end - output - end - - def colorize(options = {}) - html = execute(@@bin + convert_options(options)) - # Work around an RDiscount bug: http://gist.github.com/97682 - html.to_s.sub(%r{</pre></div>\Z}, "</pre>\n</div>") - end - alias_method :to_s, :colorize - - def convert_options(options = {}) - @options.merge(options).inject('') do |string, (flag, value)| - string + " -#{flag} #{value}" - end - end -end
M
lib/data.glyph
→
lib/data.glyph
@@ -1,4 +1,6 @@
-rw:[h3rald_article| +&:[G|Glyph] +rw:[nanoc.item|%[puts Glyph\['nanoc.item'\]\["{{0}}"\]]] +rw:[h3rald.article| article[ @pubdate[$[document.date]] @head[
A
lib/glyph.data
@@ -0,0 +1,35 @@
+Glyph['document.intro'] = RedCloth.new("#{@item[:intro]}\n\n#{@item[:extended_intro]}").to_html +Glyph['document.date'] = @item[:date].strftime "%A, %d %B %Y" +Glyph['document.title'] = @item[:title] +Glyph['document.subtitle'] = @item[:subtitle] +Glyph['document.author'] = "Fabio Cevasco" +Glyph['output.pdf.generator'] = "prince" +Glyph.rewrite "h3rald.article", %{article[ + @pubdate[$[document.date]] + @head[ + style[default.css] + style[pagination.css] + <style> + h1 { + font-size: 24px; + margin: 0.5em auto; + padding: 0.5em auto; + } + .contents { + text-align:justify; + margin-bottom: 2em; + padding-bottom: 2em; + border-bottom: 1px solid #000; + } + </style> + ] + @pre-title[ + =>[http://www.h3rald.com/archives/|image[@width[25%]@height[25%]$[site.root]/images/theme/h3rald.svg]] + ] + @post-title[ + div[em[Originally published on =>[http://www.h3rald.com{{identifier}}|H3RALD.com]]] + toc[] + ] + {{content}} + ] +]}
M
tasks/site.rake
→
tasks/site.rake
@@ -99,12 +99,16 @@ raise RuntimeError, "Name not specified" unless args[:name]
raise RuntimeError, "Article name can only contain letters, numbers and dashes" unless args[:name].match /^[a-zA-Z0-9-]+$/ meta = {} meta[:permalink] = args[:name] - meta[:title] = "" - meta[:tags] = [] + meta[:title] = nil + meta[:subtitle] = nil + meta[:type] = 'article' + meta[:intro] = nil + meta[:extended_intro] = nil + meta[:tags] = nil meta[:date] = Time.now meta[:toc] = true - meta[:type] = 'article' - file = Pathname.new Dir.pwd/"content/articles/#{meta[:permalink]}.textile" + meta[:pdf] = true + file = Pathname.new Dir.pwd/"content/articles/#{meta[:permalink]}.glyph" raise "File '#{file}' already exists!" if file.exist? write_item file, meta, '' end@@ -131,8 +135,8 @@ meta[:github] = args[:name]
meta[:status] = "Active" meta[:version] = "0.1.0" meta[:type] = 'project' - meta[:links] = [{"Documentation" => "http://#{args[:name]}.rubyforge.org"}, - {"Download" => "http://rubyforge.org/projects/#{args[:name]}"}, + meta[:links] = [{"Documentation" => "http://rubydoc.info/gems/#{args[:name]}/#{meta[:version]}/frames"}, + {"Download" => "https://rubygems.org/gems/#{args[:name]}"}, {"Source" => "http://github.com/h3rald/#{args[:name]}/tree/master"}, {"Tracking" => "http://github.com/h3rald/#{args[:name]}/issues"}] contents = %{