aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--_config.yml (renamed from source/_config.yml)6
-rw-r--r--source/_helpers.rb191
-rw-r--r--source/_layouts/default.haml20
-rw-r--r--source/_layouts/post.haml20
-rw-r--r--source/_posts/2009-10-18-hello-world.markdown5
-rw-r--r--source/archives.haml14
-rw-r--r--source/atom.haml21
-rw-r--r--source/index.haml8
8 files changed, 282 insertions, 3 deletions
diff --git a/source/_config.yml b/_config.yml
index b6865c9d..43a64608 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/source/_helpers.rb b/source/_helpers.rb
new file mode 100644
index 00000000..bbff39f0
--- /dev/null
+++ b/source/_helpers.rb
@@ -0,0 +1,191 @@
+gem 'activesupport', ">= 2.3.2"
+require 'active_support'
+require 'rubypants'
+
+module Helpers
+ module EscapeHelper
+ HTML_ESCAPE = { '&' => '&amp; ', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }
+ JSON_ESCAPE = { '&' => '\u0026 ', '>' => '\u003E', '<' => '\u003C' }
+
+ # A utility method for escaping HTML tag characters.
+ # This method is also aliased as <tt>h</tt>.
+ #
+ # In your ERb templates, use this method to escape any unsafe content. For example:
+ # <%=h @person.name %>
+ #
+ # ==== Example:
+ # puts html_escape("is a > 0 & a < 10?")
+ # # => is a &gt; 0 &amp; a &lt; 10?
+ def html_escape(html)
+ html.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
+ end
+ def escape_once(html)
+ html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| HTML_ESCAPE[special] }
+ end
+ alias h escape_once
+
+ # A utility method for escaping HTML entities in JSON strings.
+ # This method is also aliased as <tt>j</tt>.
+ #
+ # In your ERb templates, use this method to escape any HTML entities:
+ # <%=j @person.to_json %>
+ #
+ # ==== Example:
+ # puts json_escape("is a > 0 & a < 10?")
+ # # => is a \u003E 0 \u0026 a \u003C 10?
+ def json_escape(s)
+ s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] }
+ end
+
+ alias j json_escape
+ end
+ include EscapeHelper
+
+ module ParamsHelper
+ def params
+ @params ||= begin
+ q = request.query.dup
+ q.each { |(k,v)| q[k.to_s.intern] = v }
+ q
+ end
+ end
+ end
+ include ParamsHelper
+
+ module TagHelper
+ def content_tag(name, content, html_options={})
+ %{<#{name}#{html_attributes(html_options)}>#{content}</#{name}>}
+ end
+
+ def tag(name, html_options={})
+ %{<#{name}#{html_attributes(html_options)} />}
+ end
+
+ def image_tag(src, html_options = {})
+ tag(:img, html_options.merge({:src=>src}))
+ end
+
+ def javascript_tag(content = nil, html_options = {})
+ content_tag(:script, javascript_cdata_section(content), html_options.merge(:type => "text/javascript"))
+ end
+
+ def link_to(name, href, html_options = {})
+ html_options = html_options.stringify_keys
+ confirm = html_options.delete("confirm")
+ onclick = "if (!confirm('#{html_escape(confirm)}')) return false;" if confirm
+ content_tag(:a, name, html_options.merge(:href => href, :onclick=>onclick))
+ end
+
+ def link_to_function(name, *args, &block)
+ html_options = {}
+ html_options = args.pop if args.last.is_a? Hash
+ function = args[0] || ''
+ onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
+ href = html_options[:href] || '#'
+ content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick))
+ end
+
+ def mail_to(email_address, name = nil, html_options = {})
+ html_options = html_options.stringify_keys
+ encode = html_options.delete("encode").to_s
+ cc, bcc, subject, body = html_options.delete("cc"), html_options.delete("bcc"), html_options.delete("subject"), html_options.delete("body")
+
+ string = ''
+ extras = ''
+ extras << "cc=#{CGI.escape(cc).gsub("+", "%20")}&" unless cc.nil?
+ extras << "bcc=#{CGI.escape(bcc).gsub("+", "%20")}&" unless bcc.nil?
+ extras << "body=#{CGI.escape(body).gsub("+", "%20")}&" unless body.nil?
+ extras << "subject=#{CGI.escape(subject).gsub("+", "%20")}&" unless subject.nil?
+ extras = "?" << extras.gsub!(/&?$/,"") unless extras.empty?
+
+ email_address = email_address.to_s
+
+ email_address_obfuscated = email_address.dup
+ email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.has_key?("replace_at")
+ email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.has_key?("replace_dot")
+
+ if encode == "javascript"
+ "document.write('#{content_tag("a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:"+email_address+extras }))}');".each_byte do |c|
+ string << sprintf("%%%x", c)
+ end
+ "<script type=\"#{Mime::JS}\">eval(decodeURIComponent('#{string}'))</script>"
+ 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)
+ "<![CDATA[#{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(" ") + '&hellip;'
+ 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 + '&hellip;'
+ 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(" & "," <span class='amp'>&</span> ")
+ end
+end
+
diff --git a/source/_layouts/default.haml b/source/_layouts/default.haml
new file mode 100644
index 00000000..43dae4f4
--- /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 00000000..42ccde45
--- /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 00000000..492d50a1
--- /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 00000000..5d78d942
--- /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 00000000..d8cfe040
--- /dev/null
+++ b/source/atom.haml
@@ -0,0 +1,21 @@
+---
+layout: nil
+---
+<?xml version="1.0" encoding="utf-8"?>
+%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 00000000..af77e063
--- /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