Skip to content

Commit 4029085

Browse files
committed
Initial commit
0 parents  commit 4029085

File tree

135 files changed

+13356
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+13356
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output/

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'nanoc3/tasks'

Rules

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env ruby
2+
3+
# A few helpful tips about the Rules file:
4+
#
5+
# * The order of rules is important: for each item, only the first matching
6+
# rule is applied.
7+
#
8+
# * Item identifiers start and end with a slash (e.g. “/about/” for the file
9+
# “content/about.html”). To select all children, grandchildren, … of an
10+
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
11+
# because “*” matches zero or more characters.
12+
13+
require "cgi"
14+
15+
class Nanoc3::Filter
16+
class CodeBlocks < Nanoc3::Filter
17+
LANGUAGES = { "ruby" => "ruby", "sql" => "sql", "javascript" => "javascript",
18+
"css" => "css", "plain" => "plain", "erb" => "ruby; html-script: true",
19+
"html" => "xml", "xml" => "xml", "shell" => "plain", "yaml" => "yaml" }
20+
21+
def run(content, params={})
22+
@string = content.dup
23+
24+
@output = ""
25+
@pending = ""
26+
27+
languages = LANGUAGES.keys.join("|")
28+
29+
until @string.empty?
30+
match = scan_until /(\+(\S.*?\S?)\+|<(#{languages})(?: filename=["']([^"']*)["'])?>|\z)/m
31+
32+
@pending << match.pre_match
33+
34+
if match[2] # +foo+
35+
@pending << "<notextile><tt>#{CGI.escapeHTML(match[2])}</tt></notextile>" if match[2]
36+
elsif match[3] # <language>
37+
flush
38+
generate_brushes match[3], LANGUAGES[match[3]], match[4]
39+
end
40+
end
41+
42+
flush
43+
44+
@output
45+
end
46+
47+
def scan_until(regex)
48+
match = @string.match(regex)
49+
return unless match
50+
@string = match.post_match
51+
match
52+
end
53+
54+
def generate_brushes(tag, replace, filename)
55+
match = scan_until %r{</#{tag}>}
56+
@output << %{<div class="code_container">\n}
57+
@output << %{<div class="filename">#{filename}</div>\n} if filename
58+
@output << %{<pre class="brush: #{replace}; gutter: false; toolbar: false">\n} <<
59+
CGI.escapeHTML(match.pre_match) << %{</pre></div>}
60+
end
61+
62+
def flush
63+
@output << @pending
64+
@pending = ""
65+
end
66+
end
67+
end
68+
69+
Nanoc3::Filter.register 'CodeBlocks', :code_blocks
70+
71+
72+
73+
compile '/assets/*' do
74+
# don’t filter or layout
75+
end
76+
77+
compile '/images/*' do
78+
end
79+
80+
filters = {
81+
:markdown => :kramdown,
82+
:md => :kramdown,
83+
:html => :erb
84+
}
85+
86+
compile '*' do
87+
filter :code_blocks
88+
filter filters[item[:extension].to_sym] || item[:extension].to_sym
89+
layout 'default'
90+
end
91+
92+
route '*' do
93+
p [item.identifier, item[:extension], item.binary?]
94+
if item.binary? || item[:extension] == 'css' || item[:extension] =~ /\.js$/
95+
# /foo/ -> /foo.ext
96+
p item.identifier.chop + '.' + item[:extension]
97+
item.identifier.chop + '.' + item[:extension]
98+
else
99+
# /foo/ -> /foo/index.html
100+
item.identifier + 'index.html'
101+
end
102+
end
103+
104+
layout '*', :erb
105+

config.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# A list of file extensions that nanoc will consider to be textual rather than
2+
# binary. If an item with an extension not in this list is found, the file
3+
# will be considered as binary.
4+
text_extensions: [ 'css', 'erb', 'haml', 'htm', 'html', 'js', 'less', 'markdown', 'md', 'php', 'rb', 'sass', 'scss', 'txt', 'xhtml', 'xml' ]
5+
6+
# The path to the directory where all generated files will be written to. This
7+
# can be an absolute path starting with a slash, but it can also be path
8+
# relative to the site directory.
9+
output_dir: output
10+
11+
# A list of index filenames, i.e. names of files that will be served by a web
12+
# server when a directory is requested. Usually, index files are named
13+
# “index.hml”, but depending on the web server, this may be something else,
14+
# such as “default.htm”. This list is used by nanoc to generate pretty URLs.
15+
index_filenames: [ 'index.html' ]
16+
17+
# Whether or not to generate a diff of the compiled content when compiling a
18+
# site. The diff will contain the differences between the compiled content
19+
# before and after the last site compilation.
20+
enable_output_diff: false
21+
22+
# The data sources where nanoc loads its data from. This is an array of
23+
# hashes; each array element represents a single data source. By default,
24+
# there is only a single data source that reads data from the “content/” and
25+
# “layout/” directories in the site directory.
26+
data_sources:
27+
-
28+
# The type is the identifier of the data source. By default, this will be
29+
# `filesystem_unified`.
30+
type: filesystem_unified
31+
32+
# The path where items should be mounted (comparable to mount points in
33+
# Unix-like systems). This is “/” by default, meaning that items will have
34+
# “/” prefixed to their identifiers. If the items root were “/en/”
35+
# instead, an item at content/about.html would have an identifier of
36+
# “/en/about/” instead of just “/about/”.
37+
items_root: /
38+
39+
# The path where layouts should be mounted. The layouts root behaves the
40+
# same as the items root, but applies to layouts rather than items.
41+
layouts_root: /
42+
43+
# Configuration for the “watch” command, which watches a site for changes and
44+
# recompiles if necessary.
45+
watcher:
46+
# A list of directories to watch for changes. When editing this, make sure
47+
# that the “output/” and “tmp/” directories are _not_ included in this list,
48+
# because recompiling the site will cause these directories to change, which
49+
# will cause the site to be recompiled, which will cause these directories
50+
# to change, which will cause the site to be recompiled again, and so on.
51+
dirs_to_watch: [ 'content', 'layouts', 'lib' ]
52+
53+
# A list of single files to watch for changes. As mentioned above, don’t put
54+
# any files from the “output/” or “tmp/” directories in here.
55+
files_to_watch: [ 'config.yaml', 'Rules' ]
56+
57+
# When to send notifications (using Growl or notify-send).
58+
notify_on_compilation_success: true
59+
notify_on_compilation_failure: true

content/ajax/ajax-and-forms.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
chapter : ajax
3+
section : 4
4+
title : Ajax and Forms
5+
attribution: jQuery Fundamentals
6+
---
7+
## Ajax and Forms
8+
9+
jQuery’s ajax capabilities can be especially useful when dealing with forms.
10+
The [jQuery Form Plugin](http://jquery.malsup.com/form/) is a well-tested tool
11+
for adding Ajax capabilities to forms, and you should generally use it for
12+
handling forms with Ajax rather than trying to roll your own solution for
13+
anything remotely complex. That said, there are a two jQuery methods you
14+
should know that relate to form processing in jQuery: `$.fn.serialize` and
15+
`$.fn.serializeArray`.
16+
17+
<div class="example" markdown="1">
18+
Turning form data into a query string
19+
20+
$('#myForm').serialize();
21+
</div>
22+
23+
<div class="example" markdown="1">
24+
Creating an array of objects containing form data
25+
26+
$('#myForm').serializeArray();
27+
28+
// creates a structure like this:
29+
[
30+
{ name : 'field1', value : 123 },
31+
{ name : 'field2', value : 'hello world' }
32+
]
33+
</div>

content/ajax/ajax-events.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
chapter : ajax
3+
section : 6
4+
title : Ajax Events
5+
attribution: jQuery Fundamentals
6+
---
7+
## Ajax Events
8+
9+
Often, you’ll want to perform an operation whenever an Ajax requests starts or
10+
stops, such as showing or hiding a loading indicator. Rather than defining
11+
this behavior inside every Ajax request, you can bind Ajax events to elements
12+
just like you'd bind other events. For a complete list of Ajax events, visit
13+
[http://docs.jquery.com/Ajax_Events](http://docs.jquery.com/Ajax_Events "Ajax
14+
Events documentation on docs.jquery.com").
15+
16+
Setting up a loading indicator using Ajax Events
17+
18+
<javascript>
19+
$('#loading_indicator')
20+
.ajaxStart(function() { $(this).show(); })
21+
.ajaxStop(function() { $(this).hide(); });
22+
</javascript>

content/ajax/ajax-excercises.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
chapter : ajax
3+
section : 7
4+
title : Exercises
5+
attribution: jQuery Fundamentals
6+
---
7+
## Exercises
8+
9+
### Load External Content
10+
11+
Open the file `/exercises/index.html` in your browser. Use the file
12+
`/exercises/js/load.js`. Your task is to load the content of a blog item when
13+
a user clicks on the title of the item.
14+
15+
1. Create a target div after the headline for each blog post and store a
16+
reference to it on the headline element using `$.fn.data`.
17+
18+
2. Bind a click event to the headline that will use the $.fn.load method to
19+
load the appropriate content from /exercises/data/blog.html into the target
20+
div. Don't forget to prevent the default action of the click event.
21+
22+
Note that each blog headline in index.html includes a link to the post. You'll
23+
need to leverage the href of that link to get the proper content from
24+
blog.html. Once you have the href, here's one way to process it into an ID
25+
that you can use as a selector in `$.fn.load`:
26+
27+
<div class="example" markdown="1">
28+
var href = 'blog.html#post1';
29+
var tempArray = href.split('#');
30+
var id = '#' + tempArray[1];
31+
</div>
32+
33+
Remember to make liberal use of `console.log` to make sure you're on the right
34+
path!
35+
36+
### Load Content Using JSON
37+
38+
Open the file `/exercises/index.html` in your browser. Use the file
39+
`/exercises/js/specials.js`. Your task is to show the user details about the
40+
special for a given day when the user selects a day from the select dropdown.
41+
42+
1. Append a target div after the form that's inside the #specials element;
43+
this will be where you put information about the special once you receive
44+
it.
45+
46+
2. Bind to the change event of the select element; when the user changes the
47+
selection, send an Ajax request to `/exercises/data/specials.json`.
48+
49+
3. When the request returns a response, use the value the user selected in the
50+
select (hint: `$.fn.val`) to look up information about the special in the
51+
JSON response.
52+
53+
4. Add some HTML about the special to the target div you created.
54+
55+
5. Finally, because the form is now Ajax-enabled, remove the submit button
56+
from the form.
57+
58+
Note that we're loading the JSON every time the user changes their selection.
59+
How could we change the code so we only make the request once, and then use a
60+
cached response when the user changes their choice in the select?

content/ajax/ajax-overview.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
chapter : ajax
3+
section : 1
4+
title : Overview
5+
attribution: jQuery Fundamentals
6+
---
7+
## Overview
8+
9+
The XMLHttpRequest method (XHR) allows browsers to communicate with the server
10+
without requiring a page reload. This method, also known as Ajax (Asynchronous
11+
JavaScript and XML), allows for web pages that provide rich, interactive
12+
experiences.
13+
14+
Ajax requests are triggered by JavaScript code; your code sends a request to a
15+
URL, and when it receives a response, a callback function can be triggered to
16+
handle the response. Because the request is asynchronous, the rest of your
17+
code continues to execute while the request is being processed, so it’s
18+
imperative that a callback be used to handle the response.
19+
20+
jQuery provides Ajax support that abstracts away painful browser differences.
21+
It offers both a full-featured $.ajax() method, and simple convenience methods
22+
such as `$.get()`, `$.getScript()`, `$.getJSON()`, `$.post()`, and
23+
`$().load()`.
24+
25+
Most jQuery applications don’t in fact use XML, despite the name “Ajax”;
26+
instead, they transport data as plain HTML or JSON (JavaScript Object
27+
Notation).
28+
29+
In general, Ajax does not work across domains. Exceptions are services that
30+
provide JSONP (JSON with Padding) support, which allow limited cross-domain
31+
functionality.

0 commit comments

Comments
 (0)