Add some more fancy syntax highlighting
This commit is contained in:
parent
49786246fd
commit
8d4966dc6c
|
@ -1,6 +1,8 @@
|
|||
tag_page_layout: tag_page
|
||||
tag_page_dir: tag
|
||||
paginate: 10
|
||||
pygments: true
|
||||
markdown: rdiscount
|
||||
lsi: false
|
||||
url: http://unethicalblogger.com
|
||||
exclude: ['README.markdown', 'drupal.rb', 'sync.sh', 'Makefile']
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
http://edward.oconnor.cx the typography just looks too good to not use :D -->
|
||||
<link rel="stylesheet" href="/stylesheets/typography.css" type="text/css" />
|
||||
<link rel="stylesheet" href="/stylesheets/color-dark-on-light.css" type="text/css" />
|
||||
<link rel="stylesheet" href="/stylesheets/monokai.css" type="text/css" />
|
||||
|
||||
|
||||
{% for css in page.css %}
|
||||
|
|
|
@ -26,9 +26,11 @@ magic ActiveRecord developers seem to love, this post is more about the latter.
|
|||
In general, JOINs involve two tables, JOINing together the tables typically for
|
||||
a nested query of some form or fashion. For an example, let's use this make believe query:
|
||||
|
||||
{% highlight sql %}
|
||||
SELECT `guests`.* FROM `guests` JOIN `plates` \
|
||||
ON plates.guest_id = guests.id WHERE \
|
||||
(guests.favorite = 'sushi' OR plates.content = 'sushi');
|
||||
{% endhighlight %}
|
||||
|
||||
|
||||
There are five basic JOINs in SQL land, and in this context they mean:
|
||||
|
@ -46,6 +48,7 @@ which in Rails 3 has been deprecated in favor of just
|
|||
[scope](http://apidock.com/rails/ActiveRecord/NamedScope/ClassMethods/scope),
|
||||
I'd write code something like this:
|
||||
|
||||
{% highlight ruby %}
|
||||
class Guest < ActiveRecord::Base
|
||||
has_one :plate
|
||||
# ...
|
||||
|
@ -54,6 +57,7 @@ I'd write code something like this:
|
|||
:joins => :plate
|
||||
}}
|
||||
end
|
||||
{% endhighlight %}
|
||||
|
||||
Underneath the hood, ActiveRecord generates a query *almost* exactly like the
|
||||
one above with one subtle difference. "`JOIN`" is instead an "`INNER JOIN`"
|
||||
|
@ -65,6 +69,7 @@ The "solution" is to use a `LEFT JOIN`, which is unfortunately rather gnarly.
|
|||
There may be a better way to perform alternate JOINs in ActiveRecord, but I
|
||||
don't yet of one:
|
||||
|
||||
{% highlight ruby %}
|
||||
class Guest < ActiveRecord::Base
|
||||
has_one :plate
|
||||
# ...
|
||||
|
@ -73,6 +78,7 @@ don't yet of one:
|
|||
:joins => "LEFT JOIN `plates` ON plates.guest_id = guests.id"
|
||||
}}
|
||||
end
|
||||
{% endhighlight %}
|
||||
|
||||
Basically if you want to use anything other than a simple `INNER JOIN`, you've
|
||||
got to enter it in yourself. At a certain point ActiveRecord throws up its
|
||||
|
|
|
@ -99,9 +99,9 @@ h3 {
|
|||
}
|
||||
|
||||
.highlight pre {
|
||||
background: #eee;
|
||||
/* background: #eee; conflicts with the monokai theme */
|
||||
border: 1px solid #ccc;
|
||||
padding: 15px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.update {
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
.hll { background-color: #49483e }
|
||||
.c { color: #75715e } /* Comment */
|
||||
.err { color: #960050; background-color: #1e0010 } /* Error */
|
||||
.k { color: #66d9ef } /* Keyword */
|
||||
.l { color: #ae81ff } /* Literal */
|
||||
.n { color: #f8f8f2 } /* Name */
|
||||
.o { color: #f92672 } /* Operator */
|
||||
.p { color: #f8f8f2 } /* Punctuation */
|
||||
.cm { color: #75715e } /* Comment.Multiline */
|
||||
.cp { color: #75715e } /* Comment.Preproc */
|
||||
.c1 { color: #75715e } /* Comment.Single */
|
||||
.cs { color: #75715e } /* Comment.Special */
|
||||
.ge { font-style: italic } /* Generic.Emph */
|
||||
.gs { font-weight: bold } /* Generic.Strong */
|
||||
.kc { color: #66d9ef } /* Keyword.Constant */
|
||||
.kd { color: #66d9ef } /* Keyword.Declaration */
|
||||
.kn { color: #f92672 } /* Keyword.Namespace */
|
||||
.kp { color: #66d9ef } /* Keyword.Pseudo */
|
||||
.kr { color: #66d9ef } /* Keyword.Reserved */
|
||||
.kt { color: #66d9ef } /* Keyword.Type */
|
||||
.ld { color: #e6db74 } /* Literal.Date */
|
||||
.m { color: #ae81ff } /* Literal.Number */
|
||||
.s { color: #e6db74 } /* Literal.String */
|
||||
.na { color: #a6e22e } /* Name.Attribute */
|
||||
.nb { color: #f8f8f2 } /* Name.Builtin */
|
||||
.nc { color: #a6e22e } /* Name.Class */
|
||||
.no { color: #66d9ef } /* Name.Constant */
|
||||
.nd { color: #a6e22e } /* Name.Decorator */
|
||||
.ni { color: #f8f8f2 } /* Name.Entity */
|
||||
.ne { color: #a6e22e } /* Name.Exception */
|
||||
.nf { color: #a6e22e } /* Name.Function */
|
||||
.nl { color: #f8f8f2 } /* Name.Label */
|
||||
.nn { color: #f8f8f2 } /* Name.Namespace */
|
||||
.nx { color: #a6e22e } /* Name.Other */
|
||||
.py { color: #f8f8f2 } /* Name.Property */
|
||||
.nt { color: #f92672 } /* Name.Tag */
|
||||
.nv { color: #f8f8f2 } /* Name.Variable */
|
||||
.ow { color: #f92672 } /* Operator.Word */
|
||||
.w { color: #f8f8f2 } /* Text.Whitespace */
|
||||
.mf { color: #ae81ff } /* Literal.Number.Float */
|
||||
.mh { color: #ae81ff } /* Literal.Number.Hex */
|
||||
.mi { color: #ae81ff } /* Literal.Number.Integer */
|
||||
.mo { color: #ae81ff } /* Literal.Number.Oct */
|
||||
.sb { color: #e6db74 } /* Literal.String.Backtick */
|
||||
.sc { color: #e6db74 } /* Literal.String.Char */
|
||||
.sd { color: #e6db74 } /* Literal.String.Doc */
|
||||
.s2 { color: #e6db74 } /* Literal.String.Double */
|
||||
.se { color: #ae81ff } /* Literal.String.Escape */
|
||||
.sh { color: #e6db74 } /* Literal.String.Heredoc */
|
||||
.si { color: #e6db74 } /* Literal.String.Interpol */
|
||||
.sx { color: #e6db74 } /* Literal.String.Other */
|
||||
.sr { color: #e6db74 } /* Literal.String.Regex */
|
||||
.s1 { color: #e6db74 } /* Literal.String.Single */
|
||||
.ss { color: #e6db74 } /* Literal.String.Symbol */
|
||||
.bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
|
||||
.vc { color: #f8f8f2 } /* Name.Variable.Class */
|
||||
.vg { color: #f8f8f2 } /* Name.Variable.Global */
|
||||
.vi { color: #f8f8f2 } /* Name.Variable.Instance */
|
||||
.il { color: #ae81ff } /* Literal.Number.Integer.Long */
|
Loading…
Reference in New Issue