forked from mocra/custom_google_forms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
google form is now being stripped and displayed
- Loading branch information
Showing
19 changed files
with
193 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class OperateFormController < ApplicationController | ||
def show | ||
slug = params[:slug].first | ||
if @google_form = GoogleForm.find_by_slug(slug) | ||
form_html = @google_form.fetch_form_page | ||
|
||
doc = Nokogiri::HTML(form_html) | ||
doc.xpath("//*[@style]").remove_attr('style') | ||
doc.xpath("//link").each { |n| n.unlink } | ||
doc.xpath("//style").each { |n| n.unlink } | ||
|
||
css_node = doc.create_element('link') | ||
css_node["href"] = "/stylesheets/style.css" | ||
doc.xpath("//head").first.add_child(css_node) | ||
render :text => doc.to_html | ||
else | ||
redirect_to 'http://mocra.com' | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module OperateFormHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
class GoogleForm < ActiveRecord::Base | ||
|
||
def fetch_form_page | ||
form_url = "http://spreadsheets.google.com/viewform?formkey=#{formkey}" | ||
open(form_url).read | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "open-uri" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
Given /^I have a Google Form with slug "([^\"]*)"$/ do |slug| | ||
pending # express the regexp above with the code you wish you had | ||
steps <<-CUCUMBER | ||
Given I am on the new forms page | ||
When I fill in "Slug" with "#{slug}" | ||
And I fill in "Form Key" with "dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA" | ||
And I press "Create" | ||
Then I should see "You can view the published form here:" | ||
CUCUMBER | ||
|
||
sample_form = File.read(File.join(Rails.root, "features", "fixtures", "sample_form.html")) | ||
|
||
FakeWeb.register_uri(:get, "http://spreadsheets.google.com/viewform?formkey=dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA", :body => sample_form) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Then /^I should see (no|\d+) "([^\"]*)" elements?$/ do |count, element| | ||
if count == "no" | ||
page.should_not have_xpath("//#{element}") | ||
else | ||
count = count.to_i | ||
page.should have_xpath("//#{element}") | ||
doc = Nokogiri::HTML(page.body) | ||
doc.xpath("//#{element}").length.should == count | ||
end | ||
end | ||
|
||
Then /^I should see no "([^\"]*)" attributes$/ do |attribute| | ||
page.should_not have_xpath("//*[@#{attribute}]") | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
|
||
features/filling_in_form.feature:6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'spec_helper' | ||
|
||
describe OperateFormController do | ||
|
||
#Delete these examples and add some real ones | ||
it "should use OperateFormController" do | ||
controller.should be_an_instance_of(OperateFormController) | ||
end | ||
|
||
|
||
describe "GET 'show'" do | ||
it "should be successful" do | ||
get 'show' | ||
response.should be_success | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe OperateFormHelper do | ||
|
||
#Delete this example and add some real ones or delete this file | ||
it "should be included in the object returned by #helper" do | ||
included_modules = (class << helper; self; end).send :included_modules | ||
included_modules.should include(OperateFormHelper) | ||
end | ||
|
||
end |