Skip to content

Instantly share code, notes, and snippets.

@johana-star
Created December 26, 2011 22:22
Show Gist options
  • Save johana-star/1522214 to your computer and use it in GitHub Desktop.
Save johana-star/1522214 to your computer and use it in GitHub Desktop.
Hungry Academy application part 2

This is part two of my application to Hungry Academy. Part one lives at: http://www.youtube.com/watch?v=-Ze-dcVY05k

Recently I made a pull request to improve Octopress' pullquote plugin.

The improvement happened in pullquote.rb and _typography.scss. These files allow users to create pullquotes as demonstrated in the documentation. Pullquotes are by default right-aligned. I wanted to be able to use pullquotes with either left or right alignment. I worked to modify existing code to allow left aligning pullquotes.

I added a condition which assigns a very simple regular expression to the existing initialization which assigns a variable to "left" if the liquid tag contains the word "left", and "right" otherwise. The plugin creates an html tag with alignment indicated in the class.

Then, I edited the Sass to interpret the new class to float left and mirror the margins of its right-aligned counterpart.

If I had it to do again, I would have made my initial pull request a little later when I had sufficiently cleaned up my code. This pull request taught me a number of things, including how to actually make a pull request, a little bit of how regular expressions work in Ruby, and how to read and modify Sass. I wrote about this project in my blog post My First Three Pull Requests.

As this is not my original work, please review the diffs on my pull request.

# Normally kept in Octopress' .themes/classic/sass/base/ directory.
$blockquote: $type-border !default;
$mono: Menlo, Monaco, "Andale Mono", "lucida console", "Courier New", monospace;
// Fonts
.heading {
font-family: "PT Serif", "Georgia", "Helvetica Neue", Arial, sans-serif;
}
.sans { font-family: "PT Sans", "Helvetica Neue", Arial, sans-serif; }
.serif { font-family: "PT Serif", Georgia, Times, "Times New Roman", serif; }
.mono { font-family: $mono; }
body > header h1 {
font-size: 2.2em;
@extend .heading;
font-weight: normal;
line-height: 1.2em;
margin-bottom: 0.6667em;
}
body {
line-height: 1.5em;
color: $text-color;
@extend .serif;
}
h1 {
font-size: 2.2em;
line-height: 1.2em;
}
@media only screen and (min-width: 992px) {
body { font-size: 1.15em; }
h1 { font-size: 2.6em; line-height: 1.2em; }
}
#{headings()}{
@extend .heading;
text-rendering: optimizelegibility;
margin-bottom: 1em;
font-weight: bold;
}
h2, section h1 {
font-size: 1.5em;
}
h3, section h2, section section h1 {
font-size: 1.3em;
}
h4, section h3, section section h2, section section section h1 {
font-size: 1em;
}
h5, section h4, section section h3 {
font-size: .9em;
}
h6, section h5, section section h4, section section section h3 {
font-size: .8em;
}
p, blockquote, ul, ol { margin-bottom: 1.5em; }
ul { list-style-type: disc;
ul { list-style-type: circle;
ul { list-style-type: square; }}}
ol { list-style-type: decimal;
ol { list-style-type: lower-alpha;
ol { list-style-type: lower-roman; }}}
ul, ol { &, ul, ol { margin-left: 1.3em; }}
strong { font-weight: bold; }
em { font-style: italic; }
sup, sub { font-size: 0.8em; position: relative; display: inline-block; }
sup { top: -.5em; }
sub { bottom: -.5em; }
q { font-style: italic;
&:before { content: "\201C"; }
&:after { content: "\201D"; }
}
em, dfn { font-style: italic; }
strong, dfn { font-weight: bold; }
del, s { text-decoration: line-through; }
abbr, acronym { border-bottom: 1px dotted; cursor: help; }
pre, code, tt { @extend .mono; }
sub, sup { line-height: 0; }
hr { margin-bottom: 0.2em; }
small { font-size: .8em; }
big { font-size: 1.2em; }
blockquote {
$bq-margin: 1.2em;
font-style: italic;
position: relative;
font-size: 1.2em;
line-height: 1.5em;
padding-left: 1em;
border-left: 4px solid rgba($text-color-light, .5);
cite {
font-style: italic;
a { color: $text-color-light !important; word-wrap: break-word; }
&:before { content: '\2014'; padding:{right: .3em; left: .3em;} color: $text-color-light; }
}
@media only screen and (min-width: 992px) {
padding-left: 1.5em;
border-left-width: 4px;
}
}
.pullquote-right:before, .pullquote-left:before {
/* Reset metrics. */
padding: 0;
border: none;
/* Content */
content: attr(data-pullquote);
/* Pull out to the right, modular scale based margins. */
float: right;
width: 45%;
margin: .5em 0 1em 1.5em;
/* Baseline correction */
position: relative;
top: 7px;
font-size: 1.4em;
line-height: 1.45em;
}
.pullquote-left:before {
/* Make left pullquotes align properly. */
float: left;
margin: .5em 1.5em 1em 0;
}
/* @extend this to force long lines of continuous text to wrap */
.force-wrap {
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
white-space: pre-wrap;
word-wrap: break-word;
}
# Normally kept in Octopress' plugins directory.
#
# Author: Brandon Mathis
# Based on the semantic pullquote technique by Maykel Loomans at http://miekd.com/articles/pull-quotes-with-html5-and-css/
#
# Outputs a span with a data-pullquote attribute set from the marked pullquote. Example:
#
# {% pullquote %}
# When writing longform posts, I find it helpful to include pullquotes, which help those scanning a post discern whether or not a post is helpful.
# It is important to note, {" pullquotes are merely visual in presentation and should not appear twice in the text. "} That is why it is prefered
# to use a CSS only technique for styling pullquotes.
# {% endpullquote %}
# ...will output...
# <p>
# <span data-pullquote="pullquotes are merely visual in presentation and should not appear twice in the text.">
# When writing longform posts, I find it helpful to include pullquotes, which help those scanning a post discern whether or not a post is helpful.
# It is important to note, pullquotes are merely visual in presentation and should not appear twice in the text. This is why a CSS only approach # for styling pullquotes is prefered.
# </span>
# </p>
#
# Strand's modification adds the ability to call this plugin with {% pullquote left %} which duplicates the current behavior of the pullquote plugin, with a left float and appropriate margins.
# Note: this version of the plugin now creates pullquotes with the class of pullquote-right by default
module Jekyll
class PullquoteTag < Liquid::Block
def initialize(tag_name, markup, tokens)
markup =~ /left/i ? @align = "left" : @align = "right"
super
end
def render(context)
output = super
if output.join =~ /\{"\s*(.+)\s*"\}/
@quote = $1
"<span class='pullquote-#{@align}' data-pullquote='#{@quote}'>#{output.join.gsub(/\{"\s*|\s*"\}/, '')}</span>"
else
return "Surround your pullquote like this {\" text to be quoted \"}"
end
end
end
end
Liquid::Template.register_tag('pullquote', Jekyll::PullquoteTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment