From 82d0251da120186c27791b7c073aa103d73c2b31 Mon Sep 17 00:00:00 2001 From: B Mathis Date: Sun, 18 Oct 2009 19:07:36 -0500 Subject: [PATCH] improved starting point --- .gitignore | 1 + Rakefile | 63 +++ source/_config.yml => _config.yml | 6 +- config.rb | 10 + rubypants.rb | 483 ++++++++++++++++++ source/_helpers.rb | 191 +++++++ source/_layouts/default.haml | 20 + source/_layouts/post.haml | 20 + source/_posts/2009-10-18-hello-world.markdown | 5 + source/archives.haml | 14 + source/atom.haml | 21 + source/index.haml | 8 + 12 files changed, 839 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 Rakefile rename source/_config.yml => _config.yml (64%) create mode 100644 config.rb create mode 100644 rubypants.rb create mode 100644 source/_helpers.rb create mode 100644 source/_layouts/default.haml create mode 100644 source/_layouts/post.haml create mode 100644 source/_posts/2009-10-18-hello-world.markdown create mode 100644 source/archives.haml create mode 100644 source/atom.haml create mode 100644 source/index.haml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d97e100 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +site \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..75f89b9 --- /dev/null +++ b/Rakefile @@ -0,0 +1,63 @@ +require 'active_support' + +def ok_failed(condition) + if (condition) + puts "OK" + else + puts "FAILED" + end +end + +port = "4000" +site = "site" + +desc "list tasks" +task :default do + puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:default]]).to_sentence}" + puts "(type rake -T for more detail)\n\n" +end + +desc "remove files in output directory" +task :clean do + puts "Removing output..." + Dir["#{site}/*"].each { |f| rm_rf(f) } +end + +desc "generate website in output directory" +task :generate => :clean do + puts "Generating website..." + system "compass" + system "jekyll" + Dir["#{site}/stylesheets/*.sass"].each { |f| rm_rf(f) } + system "mv #{site}/atom.html #{site}/blog/atom.xml" +end + +desc "generate and deploy website" +task :deploy => :generate do + print "Deploying website..." + ok_failed system("rsync -avz --delete #{site}/ user@host.com:~/document_root/") +end + +desc "start up an instance of serve on the output files" +task :start_serve => :stop_serve do + cd "#{site}" do + print "Starting serve..." + ok_failed system("serve #{port} > /dev/null 2>&1 &") + end +end + +desc "stop all instances of serve" +task :stop_serve do + pid = `ps auxw | awk '/bin\\/serve\\ #{port}/ { print $2 }'`.strip + if pid.empty? + puts "Serve is not running" + else + print "Stoping serve..." + ok_failed system("kill -9 #{pid}") + end +end + +desc "preview the site in a web browser" +multitask :preview => [:generate, :start_serve] do + system "open http://localhost:#{port}" +end \ No newline at end of file diff --git a/source/_config.yml b/_config.yml similarity index 64% rename from source/_config.yml rename to _config.yml index b6865c9..43a6460 100644 --- a/source/_config.yml +++ b/_config.yml @@ -1,9 +1,9 @@ -source: . -destination: ../site +source: source +destination: site markdown: rdiscount pygments: true permalink: /blog/:year/:month/:day/:title -url: +url: http://yoursite.com multiviews: true sass: false haml: true diff --git a/config.rb b/config.rb new file mode 100644 index 0000000..8fcaa80 --- /dev/null +++ b/config.rb @@ -0,0 +1,10 @@ +# Require any additional compass plugins here. +project_type = :stand_alone +# Set this to the root of your project when deployed: +http_path = "/" +css_dir = "_site/stylesheets" +sass_dir = "_source/stylesheets" +images_dir = "images" + +# To enable relative paths to assets via compass helper functions. Uncomment: +# relative_assets = true diff --git a/rubypants.rb b/rubypants.rb new file mode 100644 index 0000000..6897228 --- /dev/null +++ b/rubypants.rb @@ -0,0 +1,483 @@ +# +# = RubyPants - SmartyPants ported to Ruby +# +# Ported by Christian Neukirchen +# Copyright (C) 2004 Christian Neukirchen +# +# Incooporates ideas, comments and documentation by Chad Miller +# Copyright (C) 2004 Chad Miller +# +# Original SmartyPants by John Gruber +# Copyright (C) 2003 John Gruber +# + +# +# = RubyPants - SmartyPants ported to Ruby +# +# == Synopsis +# +# RubyPants is a Ruby port of the smart-quotes library SmartyPants. +# +# The original "SmartyPants" is a free web publishing plug-in for +# Movable Type, Blosxom, and BBEdit that easily translates plain ASCII +# punctuation characters into "smart" typographic punctuation HTML +# entities. +# +# +# == Description +# +# RubyPants can perform the following transformations: +# +# * Straight quotes (" and ') into "curly" quote +# HTML entities +# * Backticks-style quotes (``like this'') into "curly" quote +# HTML entities +# * Dashes (-- and ---) into en- and em-dash +# entities +# * Three consecutive dots (... or . . .) into an +# ellipsis entity +# +# This means you can write, edit, and save your posts using plain old +# ASCII straight quotes, plain dashes, and plain dots, but your +# published posts (and final HTML output) will appear with smart +# quotes, em-dashes, and proper ellipses. +# +# RubyPants does not modify characters within
,
+# , ,  or
+# "
+      elsif encode == "hex"
+        email_address_encoded = ''
+        email_address_obfuscated.each_byte do |c|
+          email_address_encoded << sprintf("&#%d;", c)
+        end
+        
+        protocol = 'mailto:'
+        protocol.each_byte { |c| string << sprintf("&#%d;", c) }
+        
+        email_address.each_byte do |c|
+          char = c.chr
+          string << (char =~ /\w/ ? sprintf("%%%x", c) : char)
+        end
+        content_tag "a", name || email_address_encoded, html_options.merge({ "href" => "#{string}#{extras}" })
+      else
+        content_tag "a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:#{email_address}#{extras}" })
+      end
+    end
+    
+    private
+    
+      def cdata_section(content)
+        ""
+      end
+      
+      def javascript_cdata_section(content) #:nodoc:
+        "\n//#{cdata_section("\n#{content}\n//")}\n"
+      end
+      
+      def html_attributes(options)
+        unless options.blank?
+          attrs = []
+          options.each_pair do |key, value|
+            if value == true
+              attrs << %(#{key}="#{key}") if value
+            else
+              attrs << %(#{key}="#{value}") unless value.nil?
+            end
+          end
+          " #{attrs.sort * ' '}" unless attrs.empty?
+        end
+      end
+  end
+  include TagHelper
+  
+  # My added helpers
+  
+  def shorten_words (string, word_limit = 25)
+    words = string.split(/\s/)
+    if words.size >= word_limit
+      words[0,(word_limit-1)].join(" ") + '…'
+    else 
+      string
+    end
+  end
+  
+  def shorten (string, char_limit = 55)
+    chars = string.scan(/.{1,1}/)
+    if chars.size >= char_limit
+      chars[0,(char_limit-1)].join + '…'
+    else
+      "blah2"
+    end
+  end
+  
+  def absolute_url(input)
+    input.gsub(/(href|src)(\s*=\s*)(["'])(\/.*?)\3/) { $1 + $2 + $3 + "http://brandonmathis.com" + $4 + $3 }
+  end
+  
+  def full_url(input)
+    'http://brandonmathis.com'+input
+  end
+  def rp(input)
+    RubyPants.new(input).to_html
+  end
+  def style_amp(input)
+    input.gsub(" & "," & ")
+  end
+end
+
diff --git a/source/_layouts/default.haml b/source/_layouts/default.haml
new file mode 100644
index 0000000..43dae4f
--- /dev/null
+++ b/source/_layouts/default.haml
@@ -0,0 +1,20 @@
+!!! 1.1 Transitional
+%html(xmlns="http://www.w3.org/1999/xhtml" xml:lang="en")
+  %head
+    %title= page.title
+    - if page.respond_to? :description
+      %meta{:name=>"description", :content=>page.description}/
+    - if page.respond_to? :keywords
+      %meta{:name=>"keywords", :content=>page.keywords}/
+  %body
+    #header
+      .page_width
+        %a.title(href="/")Blog
+        %ul#header_nav.nav
+          %li.alpha
+            %a(href="/") Home
+    #page
+      .page_width
+        = content
+    #footer
+      .page_width Footer
\ No newline at end of file
diff --git a/source/_layouts/post.haml b/source/_layouts/post.haml
new file mode 100644
index 0000000..42ccde4
--- /dev/null
+++ b/source/_layouts/post.haml
@@ -0,0 +1,20 @@
+!!! 1.1 Transitional
+%html(xmlns="http://www.w3.org/1999/xhtml" xml:lang="en")
+  %head
+    %title= page.title
+    - if page.respond_to? :description
+      %meta{:name=>"description", :content=>page.description}/
+    - if page.respond_to? :keywords
+      %meta{:name=>"keywords", :content=>page.keywords}/
+  %body
+    #header
+      .page_width
+        %a.title(href="/")Page Title
+        %ul#header_nav.nav
+          %li.alpha
+            %a(href="/") Home
+    #page
+      .page_width
+        = content
+    #footer
+      .page_width Footer
\ No newline at end of file
diff --git a/source/_posts/2009-10-18-hello-world.markdown b/source/_posts/2009-10-18-hello-world.markdown
new file mode 100644
index 0000000..492d50a
--- /dev/null
+++ b/source/_posts/2009-10-18-hello-world.markdown
@@ -0,0 +1,5 @@
+---
+title: Hello World!
+---
+
+How's it going?
\ No newline at end of file
diff --git a/source/archives.haml b/source/archives.haml
new file mode 100644
index 0000000..5d78d94
--- /dev/null
+++ b/source/archives.haml
@@ -0,0 +1,14 @@
+---
+layout: default
+title: Blog Archives
+---
+%h2 Blog Archives
+
+- posts = site.posts.group_by { |p| p.date.strftime("%Y") }
+- posts.keys.each do |year|
+  %h3= year
+  %ul
+    - posts[year].each do |post|
+      %li(class="#{(post.data['link'] ? "link" : nil )}")
+        = link_to(post.title, post.url)
+        %span.pubdate= post.date.strftime("%d %b, %Y")
\ No newline at end of file
diff --git a/source/atom.haml b/source/atom.haml
new file mode 100644
index 0000000..d8cfe04
--- /dev/null
+++ b/source/atom.haml
@@ -0,0 +1,21 @@
+---
+layout: nil
+---
+
+%feed(xmlns="http://www.w3.org/2005/Atom")
+  %title Your Name - Your Site
+  %link(href="yoursite.com/atom.xml" rel="self")
+  %link(href="yoursite.com")
+  %updated= Time.now.xmlschema
+  %id http://yoursite.com/
+  %author
+    %name Your Name
+    %email user[at]domain.com
+  - site.posts[0..14].each do |post|
+    %entry
+      %title= rp(post.title)
+      %link(href="#{full_url(post.url)}")
+      %updated=post.date.xmlschema
+      %id= full_url(post.id)
+      %content(type="html")
+        = h(absolute_url(rp(post.content)))
\ No newline at end of file
diff --git a/source/index.haml b/source/index.haml
new file mode 100644
index 0000000..af77e06
--- /dev/null
+++ b/source/index.haml
@@ -0,0 +1,8 @@
+---
+layout: basic/default
+title: Blog
+---
+.blog
+  - site.posts.sort_by(&:date).reverse[0..9].each_with_index do |post,index|
+    %h2= link_to(post.title, post.url, {:class=>"title"})
+    .article= post.content
\ No newline at end of file