Skip to content

Commit 6f47de1

Browse files
author
Ruoran Wang
committedJun 21, 2012
add contact page and google_form plugin
1 parent e0a3a1f commit 6f47de1

File tree

7 files changed

+113
-0
lines changed

7 files changed

+113
-0
lines changed
 

‎Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ group :development do
1313
gem 'rb-fsevent', '~> 0.9'
1414
gem 'stringex', '~> 1.4.0'
1515
gem 'liquid', '~> 2.3.0'
16+
gem 'nokogiri', '~> 1.5.0'
1617
end
1718

1819
gem 'sinatra', '~> 1.3.2'

‎Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ GEM
2828
liquid (2.3.0)
2929
maruku (0.6.0)
3030
syntax (>= 1.0.0)
31+
nokogiri (1.5.4)
3132
posix-spawn (0.3.6)
3233
pygments.rb (0.2.12)
3334
rubypython (~> 0.5.3)
@@ -59,6 +60,7 @@ DEPENDENCIES
5960
haml (~> 3.1.6)
6061
jekyll (~> 0.11.2)
6162
liquid (~> 2.3.0)
63+
nokogiri (~> 1.5.0)
6264
pygments.rb (~> 0.2.12)
6365
rack (~> 1.4.1)
6466
rake (~> 0.9.2)

‎plugins/google_form.rb

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Title: Google Form
2+
# Authors: Arshad http://donothackcore.com
3+
# Description: A filter to embed Google Forms in Octopress
4+
#
5+
# Syntax {% google_form formkey [message] %}
6+
#
7+
# Examples:
8+
# {% google_form dGVfY3MwcklDcjVrZERGYlRoZWdJQnc6MQ Thank you. I'll get back to you shortly %}
9+
#
10+
require 'open-uri'
11+
require 'nokogiri'
12+
13+
module Jekyll
14+
15+
class GoogleForm < Liquid::Tag
16+
@url = ''
17+
@formkey = ''
18+
@message= ''
19+
@formhtml = ''
20+
21+
def initialize(tag_name, markup, tokens)
22+
if markup =~ /([a-zA-Z0-9]*)?\s(.+)/
23+
@formkey = $1
24+
@message = $2
25+
26+
#url of the Google Form
27+
@url = "https://docs.google.com/spreadsheet/embeddedform?formkey=#{@formkey}"
28+
29+
#parse the HTML and get the form markup only
30+
doc = Nokogiri::HTML(open(@url))
31+
form = doc.xpath("//form").first.unlink
32+
33+
@formhtml = form.to_html
34+
end
35+
super
36+
end
37+
38+
def render(context)
39+
if @formhtml
40+
html = '<div class="google-form-wrapper">'
41+
html += "<p class='success-msg'>#{@message}</p>"
42+
html += @formhtml
43+
html += '</div>'
44+
else
45+
"Error processing input, expected syntax: {% google_form formkey [message] %}"
46+
end
47+
end
48+
end
49+
end
50+
51+
Liquid::Template.register_tag('google_form', Jekyll::GoogleForm)

‎source/_includes/custom/head.html

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
22
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
33
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
4+
5+
<!-- Google Form for Contact Page -->
6+
<!-- jQuery -->
7+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
8+
<script type="text/javascript">
9+
// Avoid conflict with ender.js.
10+
jQuery.noConflict();
11+
</script>
12+
<!-- jQuery Form Plugin -->
13+
<script src="http://malsup.github.com/jquery.form.js"></script>
14+
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
15+
<script src="{{ root_url }}/javascripts/google_form.js"></script>
16+
<!-- Google Form for Contact Page End here -->
17+

‎source/_includes/custom/navigation.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<li><a href="{{ root_url }}/blog/our-team">Our Team</a></li>
44
<li><a href="{{ root_url }}/blog/archives">Archives</a></li>
55
<li><a href="{{ root_url }}/blog/about">About</a></li>
6+
<li><a href="{{ root_url }}/blog/contact">Contact</a></li>
67
</ul>

‎source/blog/contact/index.markdown

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
layout: page
3+
title: "contact"
4+
published: true
5+
sharing: false
6+
date: '2010-06-21 15:11:20'
7+
footer: true
8+
---
9+
10+
11+
{% google_form dFFjMlBtZ3NqLXI0bVc4bWh1NVN6Qmc6MQ Thank you. We will get back to your shortly. %}

‎source/javascripts/google_form.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
jQuery(document).ready(function() {
2+
//clean up empty tags
3+
jQuery('.google-form-wrapper p, .google-form-wrapper br')
4+
.filter(function() {
5+
return jQuery(this).html() == '';
6+
})
7+
.remove();
8+
9+
//add required class to required elements
10+
jQuery('.google-form-wrapper form')
11+
.find('.ss-item-required input, .ss-item-required textarea')
12+
.filter(function() {
13+
return jQuery(this).attr('name').match(/entry\.\d\.single/);
14+
})
15+
.addClass('required');
16+
17+
//validate the form
18+
jQuery('.google-form-wrapper form').validate({
19+
submitHandler: function(form) {
20+
jQuery(form)
21+
.ajaxSubmit({
22+
error : function (data) { //This is strangely working on error only
23+
jQuery(form)
24+
.hide(200, function() {
25+
jQuery(this)
26+
.prev('.success-msg')
27+
.fadeIn('slow')
28+
})
29+
}
30+
})
31+
}
32+
});
33+
});

0 commit comments

Comments
 (0)
Please sign in to comment.