mirror of
https://github.com/moparisthebest/www.moparscape.org
synced 2024-12-23 16:08:55 -05:00
improved starting point
This commit is contained in:
parent
2b4c5948b3
commit
82d0251da1
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
site
|
63
Rakefile
Normal file
63
Rakefile
Normal file
@ -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
|
@ -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
|
10
config.rb
Normal file
10
config.rb
Normal file
@ -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
|
483
rubypants.rb
Normal file
483
rubypants.rb
Normal file
@ -0,0 +1,483 @@
|
||||
#
|
||||
# = RubyPants - SmartyPants ported to Ruby
|
||||
#
|
||||
# Ported by Christian Neukirchen <mailto:chneukirchen@gmail.com>
|
||||
# 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 (<tt>"</tt> and <tt>'</tt>) into "curly" quote
|
||||
# HTML entities
|
||||
# * Backticks-style quotes (<tt>``like this''</tt>) into "curly" quote
|
||||
# HTML entities
|
||||
# * Dashes (<tt>--</tt> and <tt>---</tt>) into en- and em-dash
|
||||
# entities
|
||||
# * Three consecutive dots (<tt>...</tt> or <tt>. . .</tt>) 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 <tt><pre></tt>,
|
||||
# <tt><code></tt>, <tt><kbd></tt>, <tt><math></tt> or
|
||||
# <tt><script></tt> tag blocks. Typically, these tags are used to
|
||||
# display text where smart quotes and other "smart punctuation" would
|
||||
# not be appropriate, such as source code or example markup.
|
||||
#
|
||||
#
|
||||
# == Backslash Escapes
|
||||
#
|
||||
# If you need to use literal straight quotes (or plain hyphens and
|
||||
# periods), RubyPants accepts the following backslash escape sequences
|
||||
# to force non-smart punctuation. It does so by transforming the
|
||||
# escape sequence into a decimal-encoded HTML entity:
|
||||
#
|
||||
# \\ \" \' \. \- \`
|
||||
#
|
||||
# This is useful, for example, when you want to use straight quotes as
|
||||
# foot and inch marks: 6'2" tall; a 17" iMac. (Use <tt>6\'2\"</tt>
|
||||
# resp. <tt>17\"</tt>.)
|
||||
#
|
||||
#
|
||||
# == Algorithmic Shortcomings
|
||||
#
|
||||
# One situation in which quotes will get curled the wrong way is when
|
||||
# apostrophes are used at the start of leading contractions. For
|
||||
# example:
|
||||
#
|
||||
# 'Twas the night before Christmas.
|
||||
#
|
||||
# In the case above, RubyPants will turn the apostrophe into an
|
||||
# opening single-quote, when in fact it should be a closing one. I
|
||||
# don't think this problem can be solved in the general case--every
|
||||
# word processor I've tried gets this wrong as well. In such cases,
|
||||
# it's best to use the proper HTML entity for closing single-quotes
|
||||
# (``’``) by hand.
|
||||
#
|
||||
#
|
||||
# == Bugs
|
||||
#
|
||||
# To file bug reports or feature requests (except see above) please
|
||||
# send email to: mailto:chneukirchen@gmail.com
|
||||
#
|
||||
# If the bug involves quotes being curled the wrong way, please send
|
||||
# example text to illustrate.
|
||||
#
|
||||
#
|
||||
# == Authors
|
||||
#
|
||||
# John Gruber did all of the hard work of writing this software in
|
||||
# Perl for Movable Type and almost all of this useful documentation.
|
||||
# Chad Miller ported it to Python to use with Pyblosxom.
|
||||
#
|
||||
# Christian Neukirchen provided the Ruby port, as a general-purpose
|
||||
# library that follows the *Cloth api.
|
||||
#
|
||||
#
|
||||
# == Copyright and License
|
||||
#
|
||||
# === SmartyPants license:
|
||||
#
|
||||
# Copyright (c) 2003 John Gruber
|
||||
# (http://daringfireball.net)
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# * Neither the name "SmartyPants" nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this
|
||||
# software without specific prior written permission.
|
||||
#
|
||||
# This software is provided by the copyright holders and contributors
|
||||
# "as is" and any express or implied warranties, including, but not
|
||||
# limited to, the implied warranties of merchantability and fitness
|
||||
# for a particular purpose are disclaimed. In no event shall the
|
||||
# copyright owner or contributors be liable for any direct, indirect,
|
||||
# incidental, special, exemplary, or consequential damages (including,
|
||||
# but not limited to, procurement of substitute goods or services;
|
||||
# loss of use, data, or profits; or business interruption) however
|
||||
# caused and on any theory of liability, whether in contract, strict
|
||||
# liability, or tort (including negligence or otherwise) arising in
|
||||
# any way out of the use of this software, even if advised of the
|
||||
# possibility of such damage.
|
||||
#
|
||||
# === RubyPants license
|
||||
#
|
||||
# RubyPants is a derivative work of SmartyPants and smartypants.py.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
#
|
||||
# This software is provided by the copyright holders and contributors
|
||||
# "as is" and any express or implied warranties, including, but not
|
||||
# limited to, the implied warranties of merchantability and fitness
|
||||
# for a particular purpose are disclaimed. In no event shall the
|
||||
# copyright owner or contributors be liable for any direct, indirect,
|
||||
# incidental, special, exemplary, or consequential damages (including,
|
||||
# but not limited to, procurement of substitute goods or services;
|
||||
# loss of use, data, or profits; or business interruption) however
|
||||
# caused and on any theory of liability, whether in contract, strict
|
||||
# liability, or tort (including negligence or otherwise) arising in
|
||||
# any way out of the use of this software, even if advised of the
|
||||
# possibility of such damage.
|
||||
#
|
||||
#
|
||||
# == Links
|
||||
#
|
||||
# John Gruber:: http://daringfireball.net
|
||||
# SmartyPants:: http://daringfireball.net/projects/smartypants
|
||||
#
|
||||
# Chad Miller:: http://web.chad.org
|
||||
#
|
||||
# Christian Neukirchen:: http://kronavita.de/chris
|
||||
#
|
||||
|
||||
|
||||
class RubyPants < String
|
||||
VERSION = "0.1"
|
||||
|
||||
# Allowed elements in the options array:
|
||||
#
|
||||
# 0 :: do nothing
|
||||
# 1 :: set all
|
||||
# 2 :: set all, using old school en- and em- dash shortcuts
|
||||
# 3 :: set all, using inverted old school en and em- dash shortcuts
|
||||
# -1 :: stupefy (translate HTML entities to their ASCII-counterparts)
|
||||
#
|
||||
# <tt>:quotes</tt> :: quotes
|
||||
# <tt>:backticks</tt> :: backtick quotes (``double'' only)
|
||||
# <tt>:allbackticks</tt> :: backtick quotes (``double'' and `single')
|
||||
# <tt>:dashes</tt> :: dashes
|
||||
# <tt>:oldschool</tt> :: old school dashes
|
||||
# <tt>:inverted</tt> :: inverted old school dashes
|
||||
# <tt>:ellipses</tt> :: ellipses
|
||||
# <tt>:convertquotes</tt> :: convert <tt>"</tt> entities to
|
||||
# <tt>"</tt> for Dreamweaver users
|
||||
# <tt>:stupefy</tt> :: translate SmartyPants HTML entities
|
||||
# to their ASCII counterparts.
|
||||
#
|
||||
def initialize(string, options=[2])
|
||||
super string
|
||||
@options = [*options]
|
||||
end
|
||||
|
||||
# Apply SmartyPants transformations.
|
||||
def to_html
|
||||
do_quotes = do_backticks = do_dashes = do_ellipses = do_stupify = nil
|
||||
convert_quotes = false
|
||||
|
||||
if @options.include? 0
|
||||
# Do nothing.
|
||||
return self
|
||||
elsif @options.include? 1
|
||||
# Do everything, turn all options on.
|
||||
do_quotes = do_backticks = do_ellipses = true
|
||||
do_dashes = :normal
|
||||
elsif @options.include? 2
|
||||
# Do everything, turn all options on, use old school dash shorthand.
|
||||
do_quotes = do_backticks = do_ellipses = true
|
||||
do_dashes = :oldschool
|
||||
elsif @options.include? 3
|
||||
# Do everything, turn all options on, use inverted old school
|
||||
# dash shorthand.
|
||||
do_quotes = do_backticks = do_ellipses = true
|
||||
do_dashes = :inverted
|
||||
elsif @options.include?(-1)
|
||||
do_stupefy = true
|
||||
else
|
||||
do_quotes = @options.include? :quotes
|
||||
do_backticks = @options.include? :backticks
|
||||
do_backticks = :both if @options.include? :allbackticks
|
||||
do_dashes = :normal if @options.include? :dashes
|
||||
do_dashes = :oldschool if @options.include? :oldschool
|
||||
do_dashes = :inverted if @options.include? :inverted
|
||||
do_ellipses = @options.include? :ellipses
|
||||
convert_quotes = @options.include? :convertquotes
|
||||
do_stupefy = @options.include? :stupefy
|
||||
end
|
||||
|
||||
# Parse the HTML
|
||||
tokens = tokenize
|
||||
|
||||
# Keep track of when we're inside <pre> or <code> tags.
|
||||
in_pre = false
|
||||
|
||||
# Here is the result stored in.
|
||||
result = ""
|
||||
|
||||
# This is a cheat, used to get some context for one-character
|
||||
# tokens that consist of just a quote char. What we do is remember
|
||||
# the last character of the previous text token, to use as context
|
||||
# to curl single- character quote tokens correctly.
|
||||
prev_token_last_char = ""
|
||||
|
||||
tokens.each { |token|
|
||||
if token.first == :tag
|
||||
result << token[1]
|
||||
if token[1] =~ %r!<(/?)(?:pre|code|kbd|script|math)[\s>]!
|
||||
in_pre = ($1 != "/") # Opening or closing tag?
|
||||
end
|
||||
else
|
||||
t = token[1]
|
||||
|
||||
# Remember last char of this token before processing.
|
||||
last_char = t[-1]
|
||||
|
||||
unless in_pre
|
||||
t = process_escapes t
|
||||
|
||||
t.gsub!(/"/, '"') if convert_quotes
|
||||
|
||||
if do_dashes
|
||||
t = educate_dashes t if do_dashes == :normal
|
||||
t = educate_dashes_oldschool t if do_dashes == :oldschool
|
||||
t = educate_dashes_inverted t if do_dashes == :inverted
|
||||
end
|
||||
|
||||
t = educate_ellipses t if do_ellipses
|
||||
|
||||
# Note: backticks need to be processed before quotes.
|
||||
if do_backticks
|
||||
t = educate_backticks t
|
||||
t = educate_single_backticks t if do_backticks == :both
|
||||
end
|
||||
|
||||
if do_quotes
|
||||
if t == "'"
|
||||
# Special case: single-character ' token
|
||||
if prev_token_last_char =~ /\S/
|
||||
t = "’"
|
||||
else
|
||||
t = "‘"
|
||||
end
|
||||
elsif t == '"'
|
||||
# Special case: single-character " token
|
||||
if prev_token_last_char =~ /\S/
|
||||
t = "”"
|
||||
else
|
||||
t = "“"
|
||||
end
|
||||
else
|
||||
# Normal case:
|
||||
t = educate_quotes t
|
||||
end
|
||||
end
|
||||
|
||||
t = stupefy_entities t if do_stupefy
|
||||
end
|
||||
|
||||
prev_token_last_char = last_char
|
||||
result << t
|
||||
end
|
||||
}
|
||||
|
||||
# Done
|
||||
result
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Return the string, with after processing the following backslash
|
||||
# escape sequences. This is useful if you want to force a "dumb" quote
|
||||
# or other character to appear.
|
||||
#
|
||||
# Escaped are:
|
||||
# \\ \" \' \. \- \`
|
||||
#
|
||||
def process_escapes(str)
|
||||
str.gsub(/\\\\/, '\').
|
||||
gsub(/\\"/, '"').
|
||||
gsub(/\\'/, ''').
|
||||
gsub(/\\\./, '.').
|
||||
gsub(/\\-/, '-').
|
||||
gsub(/\\`/, '`')
|
||||
end
|
||||
|
||||
# The string, with each instance of "<tt>--</tt>" translated to an
|
||||
# em-dash HTML entity.
|
||||
#
|
||||
def educate_dashes(str)
|
||||
str.gsub(/--/, '—')
|
||||
end
|
||||
|
||||
# The string, with each instance of "<tt>--</tt>" translated to an
|
||||
# en-dash HTML entity, and each "<tt>---</tt>" translated to an
|
||||
# em-dash HTML entity.
|
||||
#
|
||||
def educate_dashes_oldschool(str)
|
||||
str.gsub(/---/, '—').gsub(/--/, '–')
|
||||
end
|
||||
|
||||
# Return the string, with each instance of "<tt>--</tt>" translated
|
||||
# to an em-dash HTML entity, and each "<tt>---</tt>" translated to
|
||||
# an en-dash HTML entity. Two reasons why: First, unlike the en- and
|
||||
# em-dash syntax supported by +educate_dashes_oldschool+, it's
|
||||
# compatible with existing entries written before SmartyPants 1.1,
|
||||
# back when "<tt>--</tt>" was only used for em-dashes. Second,
|
||||
# em-dashes are more common than en-dashes, and so it sort of makes
|
||||
# sense that the shortcut should be shorter to type. (Thanks to
|
||||
# Aaron Swartz for the idea.)
|
||||
#
|
||||
def educate_dashes_inverted(str)
|
||||
str.gsub(/---/, '–').gsub(/--/, '—')
|
||||
end
|
||||
|
||||
# Return the string, with each instance of "<tt>...</tt>" translated
|
||||
# to an ellipsis HTML entity. Also converts the case where there are
|
||||
# spaces between the dots.
|
||||
#
|
||||
def educate_ellipses(str)
|
||||
str.gsub('...', '…').gsub('. . .', '…')
|
||||
end
|
||||
|
||||
# Return the string, with <tt>``backticks''</tt>-style single quotes
|
||||
# translated into HTML curly quote entities.
|
||||
#
|
||||
def educate_backticks(str)
|
||||
str.gsub("``", '“').gsub("''", '”')
|
||||
end
|
||||
|
||||
# Return the string, with <tt>`backticks'</tt>-style single quotes
|
||||
# translated into HTML curly quote entities.
|
||||
#
|
||||
def educate_single_backticks(str)
|
||||
str.gsub("`", '‘').gsub("'", '’')
|
||||
end
|
||||
|
||||
# Return the string, with "educated" curly quote HTML entities.
|
||||
#
|
||||
def educate_quotes(str)
|
||||
punct_class = '[!"#\$\%\'()*+,\-.\/:;<=>?\@\[\\\\\]\^_`{|}~]'
|
||||
|
||||
str = str.dup
|
||||
|
||||
# Special case if the very first character is a quote followed by
|
||||
# punctuation at a non-word-break. Close the quotes by brute
|
||||
# force:
|
||||
str.gsub!(/^'(?=#{punct_class}\B)/, '’')
|
||||
str.gsub!(/^"(?=#{punct_class}\B)/, '”')
|
||||
|
||||
# Special case for double sets of quotes, e.g.:
|
||||
# <p>He said, "'Quoted' words in a larger quote."</p>
|
||||
str.gsub!(/"'(?=\w)/, '“‘')
|
||||
str.gsub!(/'"(?=\w)/, '‘“')
|
||||
|
||||
# Special case for decade abbreviations (the '80s):
|
||||
str.gsub!(/'(?=\d\ds)/, '’')
|
||||
|
||||
close_class = %![^\ \t\r\n\\[\{\(\-]!
|
||||
dec_dashes = '–|—'
|
||||
|
||||
# Get most opening single quotes:
|
||||
str.gsub!(/(\s| |--|&[mn]dash;|#{dec_dashes}|ȁ[34];)'(?=\w)/,
|
||||
'\1‘')
|
||||
# Single closing quotes:
|
||||
str.gsub!(/(#{close_class})'/, '\1’')
|
||||
str.gsub!(/'(\s|s\b|$)/, '’\1')
|
||||
# Any remaining single quotes should be opening ones:
|
||||
str.gsub!(/'/, '‘')
|
||||
|
||||
# Get most opening double quotes:
|
||||
str.gsub!(/(\s| |--|&[mn]dash;|#{dec_dashes}|ȁ[34];)"(?=\w)/,
|
||||
'\1“')
|
||||
# Double closing quotes:
|
||||
str.gsub!(/(#{close_class})"/, '\1”')
|
||||
str.gsub!(/"(\s|s\b|$)/, '”\1')
|
||||
# Any remaining quotes should be opening ones:
|
||||
str.gsub!(/"/, '“')
|
||||
|
||||
str
|
||||
end
|
||||
|
||||
# Return the string, with each SmartyPants HTML entity translated to
|
||||
# its ASCII counterpart.
|
||||
#
|
||||
def stupefy_entities(str)
|
||||
str.
|
||||
gsub(/–/, '-'). # en-dash
|
||||
gsub(/—/, '--'). # em-dash
|
||||
|
||||
gsub(/‘/, "'"). # open single quote
|
||||
gsub(/’/, "'"). # close single quote
|
||||
|
||||
gsub(/“/, '"'). # open double quote
|
||||
gsub(/”/, '"'). # close double quote
|
||||
|
||||
gsub(/…/, '...') # ellipsis
|
||||
end
|
||||
|
||||
# Return an array of the tokens comprising the string. Each token is
|
||||
# either a tag (possibly with nested, tags contained therein, such
|
||||
# as <tt><a href="<MTFoo>"></tt>, or a run of text between
|
||||
# tags. Each element of the array is a two-element array; the first
|
||||
# is either :tag or :text; the second is the actual value.
|
||||
#
|
||||
# Based on the <tt>_tokenize()</tt> subroutine from Brad Choate's
|
||||
# MTRegex plugin. <http://www.bradchoate.com/past/mtregex.php>
|
||||
#
|
||||
# This is actually the easier variant using tag_soup, as used by
|
||||
# Chad Miller in the Python port of SmartyPants.
|
||||
#
|
||||
def tokenize
|
||||
tag_soup = /([^<]*)(<[^>]*>)/
|
||||
|
||||
tokens = []
|
||||
|
||||
prev_end = 0
|
||||
scan(tag_soup) {
|
||||
tokens << [:text, $1] if $1 != ""
|
||||
tokens << [:tag, $2]
|
||||
|
||||
prev_end = $~.end(0)
|
||||
}
|
||||
|
||||
if prev_end < size
|
||||
tokens << [:text, self[prev_end..-1]]
|
||||
end
|
||||
|
||||
tokens
|
||||
end
|
||||
end
|
191
source/_helpers.rb
Normal file
191
source/_helpers.rb
Normal file
@ -0,0 +1,191 @@
|
||||
gem 'activesupport', ">= 2.3.2"
|
||||
require 'active_support'
|
||||
require 'rubypants'
|
||||
|
||||
module Helpers
|
||||
module EscapeHelper
|
||||
HTML_ESCAPE = { '&' => '& ', '>' => '>', '<' => '<', '"' => '"' }
|
||||
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 > 0 & a < 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(" ") + '…'
|
||||
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(" & "," <span class='amp'>&</span> ")
|
||||
end
|
||||
end
|
||||
|
20
source/_layouts/default.haml
Normal file
20
source/_layouts/default.haml
Normal file
@ -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
|
20
source/_layouts/post.haml
Normal file
20
source/_layouts/post.haml
Normal file
@ -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
|
5
source/_posts/2009-10-18-hello-world.markdown
Normal file
5
source/_posts/2009-10-18-hello-world.markdown
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
title: Hello World!
|
||||
---
|
||||
|
||||
How's it going?
|
14
source/archives.haml
Normal file
14
source/archives.haml
Normal file
@ -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")
|
21
source/atom.haml
Normal file
21
source/atom.haml
Normal file
@ -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)))
|
8
source/index.haml
Normal file
8
source/index.haml
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user