surveyor 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +6 -0
- data/VERSION +1 -1
- data/app/controllers/surveyor_controller.rb +8 -6
- data/app/models/question.rb +2 -2
- data/app/models/question_group.rb +2 -2
- data/app/views/partials/_question.html.haml +12 -13
- data/app/views/partials/_question_group.html.haml +5 -7
- data/app/views/surveyor/edit.html.haml +5 -5
- data/generators/surveyor/templates/initializers/surveyor.rb +1 -0
- data/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +10 -7
- data/surveyor.gemspec +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -105,6 +105,12 @@ Surveyor depends on Rails 2.3 and the SASS style sheet language, part of HAML (h
|
|
105
105
|
|
106
106
|
# Changes
|
107
107
|
|
108
|
+
0.7.1
|
109
|
+
|
110
|
+
custom index page
|
111
|
+
custom classes and renderers
|
112
|
+
fixing typo in kitchen sink survey
|
113
|
+
|
108
114
|
0.7.0
|
109
115
|
|
110
116
|
* new kitchen sink survey with better documentation of DSL
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.1
|
@@ -23,6 +23,7 @@ class SurveyorController < ApplicationController
|
|
23
23
|
# Actions
|
24
24
|
def new
|
25
25
|
@surveys = Survey.find(:all)
|
26
|
+
redirect_to surveyor_default(:index) unless available_surveys_path == surveyor_default(:index)
|
26
27
|
end
|
27
28
|
def create
|
28
29
|
if (@survey = Survey.find_by_access_code(params[:survey_code])) && (@response_set = ResponseSet.create(:survey => @survey, :user_id => @current_user))
|
@@ -68,7 +69,7 @@ class SurveyorController < ApplicationController
|
|
68
69
|
format.html do
|
69
70
|
if saved && params[:finish]
|
70
71
|
flash[:notice] = "Completed survey"
|
71
|
-
redirect_to
|
72
|
+
redirect_to surveyor_default(:finish)
|
72
73
|
else
|
73
74
|
flash[:notice] = "Unable to update survey" if !saved and !saved.nil? # saved.nil? is true if there are no questions on the page (i.e. if it only contains a label)
|
74
75
|
redirect_to :action => "edit", :anchor => anchor_from(params[:section]), :params => {:section => section_id_from(params[:section])}
|
@@ -98,18 +99,19 @@ class SurveyorController < ApplicationController
|
|
98
99
|
end
|
99
100
|
|
100
101
|
# Extending surveyor
|
101
|
-
def
|
102
|
+
def surveyor_default(type = :finish)
|
102
103
|
# http://www.postal-code.com/mrhappy/blog/2007/02/01/ruby-comparing-an-objects-class-in-a-case-statement/
|
103
104
|
# http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/
|
104
|
-
case
|
105
|
+
case arg = Surveyor::Config["default.#{type.to_s}"]
|
105
106
|
when String
|
106
|
-
return
|
107
|
+
return arg
|
107
108
|
when Symbol
|
108
|
-
return self.send(
|
109
|
+
return self.send(arg)
|
109
110
|
else
|
110
|
-
return
|
111
|
+
return available_surveys_path
|
111
112
|
end
|
112
113
|
end
|
114
|
+
|
113
115
|
def extend_actions
|
114
116
|
# http://blog.mattwynne.net/2009/07/11/rails-tip-use-polymorphism-to-extend-your-controllers-at-runtime/
|
115
117
|
self.extend SurveyorControllerExtensions::Actions if Surveyor::Config['extend_controller'] && defined? SurveyorControllerExtensions::Actions
|
data/app/models/question.rb
CHANGED
@@ -35,8 +35,8 @@ class Question < ActiveRecord::Base
|
|
35
35
|
def triggered?(response_set)
|
36
36
|
dependent? ? self.dependency.met?(response_set) : true
|
37
37
|
end
|
38
|
-
def
|
39
|
-
dependent? ? triggered?(response_set) ?
|
38
|
+
def css_class(response_set)
|
39
|
+
[(dependent? ? "dependent" : nil), (triggered?(response_set) ? nil : "hidden"), custom_class].compact.join(" ")
|
40
40
|
end
|
41
41
|
|
42
42
|
def part_of_group?
|
@@ -23,8 +23,8 @@ class QuestionGroup < ActiveRecord::Base
|
|
23
23
|
def triggered?(response_set)
|
24
24
|
dependent? ? self.dependency.met?(response_set) : true
|
25
25
|
end
|
26
|
-
def
|
27
|
-
dependent? ? triggered?(response_set) ?
|
26
|
+
def css_class(response_set)
|
27
|
+
[(dependent? ? "dependent" : nil), (triggered?(response_set) ? nil : "hidden"), custom_class].compact.join(" ")
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
- renderer = question.renderer(question_group ||= nil)
|
2
|
-
- dep_class = question.dep_class(response_set)
|
3
2
|
- case renderer
|
4
3
|
- when :label
|
5
|
-
- div_for question, :class => "label #{
|
4
|
+
- div_for question, :class => "label #{question.css_class(response_set)}" do
|
6
5
|
%span.text= question.text
|
7
6
|
%span.help= question.help_text
|
8
7
|
- when :image
|
@@ -10,7 +9,7 @@
|
|
10
9
|
- when :dropdown, :slider
|
11
10
|
- if renderer == :slider
|
12
11
|
%script{:type => "text/javascript"}= "$(function(){$('#slider_#{question.id}').accessibleUISlider({width: 400, labels:#{question.answers.size} }).hide();});"
|
13
|
-
- div_for question, :class =>
|
12
|
+
- div_for question, :class => question.css_class(response_set) do
|
14
13
|
.number= next_number unless question.dependent?
|
15
14
|
%fieldset
|
16
15
|
%legend{:style => "display:inline;"}
|
@@ -23,19 +22,19 @@
|
|
23
22
|
= renderer == :slider ? select_tag("responses[#{question.id}][answer_id]", options, {:id => "slider_#{question.id}"}) : select_tag("responses[#{question.id}][answer_id]", ["<option value=''>Select one...</option>"].concat(options))
|
24
23
|
- when :grid_default
|
25
24
|
- reset_cycle("col")
|
26
|
-
- content_tag_for :tr, question, :class =>
|
25
|
+
- content_tag_for :tr, question, :class => question.css_class(response_set) do
|
27
26
|
%th.question_prefix
|
28
27
|
%span.text= split_text(question.text)[:prefix]
|
29
28
|
%span.help= question.help_text
|
30
29
|
= hidden_field_tag("responses[#{question.id}][question_id]", question.id)
|
31
30
|
- question.answers.each do |answer|
|
32
31
|
%td{:class => "#{cycle("column_highlight", "", :name => "col")}"}
|
33
|
-
.answer= render(:partial => "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => true})
|
32
|
+
.answer{:class => answer.custom_class}= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => true})
|
34
33
|
%th.question_postfix
|
35
34
|
%span.text= split_text(question.text)[:postfix]
|
36
35
|
- when :repeater_default, :repeater_dropdown
|
37
36
|
- disabled ||= false
|
38
|
-
- div_for question, :class => "#{disabled ? 'dis' : 'en'}abled #{
|
37
|
+
- div_for question, :class => "#{disabled ? 'dis' : 'en'}abled #{question.css_class(response_set)}" do
|
39
38
|
%span.text= question.text
|
40
39
|
%span.help= question.help_text
|
41
40
|
= hidden_field_tag("response_groups[#{question.id}][#{response_group}][response_group]", response_group)
|
@@ -43,23 +42,23 @@
|
|
43
42
|
%ol.answers
|
44
43
|
- if renderer == :repeater_default
|
45
44
|
- question.answers.each do |answer|
|
46
|
-
- content_tag_for :li, answer do
|
47
|
-
= render(:partial => "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id, response_group), :response_group => response_group, :hide_label => true, :disabled => disabled})
|
45
|
+
- content_tag_for :li, answer, :class => answer.custom_class do
|
46
|
+
= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id, response_group), :response_group => response_group, :hide_label => true, :disabled => disabled})
|
48
47
|
- else
|
49
48
|
%li.answer
|
50
49
|
- options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id, response_group).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
|
51
50
|
= select_tag("response_groups[#{question.id}][#{response_group}][answer_id]", ["<option value=''>Select one...</option>"].concat(options), :disabled => disabled)
|
52
51
|
- when :inline_default, :inline_dropdown
|
53
|
-
- div_for question, :class => "inline #{
|
52
|
+
- div_for question, :class => "inline #{question.css_class(response_set)}" do
|
54
53
|
= hidden_field_tag("responses[#{question.id}][question_id]", question.id)
|
55
54
|
- if renderer == :inline_default
|
56
55
|
- question.answers.each do |answer|
|
57
|
-
.answer= render(:partial => "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => answer.hide_label})
|
56
|
+
.answer{:class => answer.custom_class}= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => answer.hide_label})
|
58
57
|
- else
|
59
58
|
- options = question.answers.collect{|a| "<option #{ (response_set.response_for(question.id, a.id).selected?)? "selected='selected'" : nil } value ='#{a.id}'>#{a.text}</option>" }
|
60
59
|
= select_tag("responses[#{question.id}][answer_id]", ["<option value=''>Select one...</option>"].concat(options))
|
61
60
|
- else # :default, :inline
|
62
|
-
- div_for question, :class =>
|
61
|
+
- div_for question, :class => question.css_class(response_set) do
|
63
62
|
.number= next_number unless question.dependent?
|
64
63
|
%fieldset
|
65
64
|
%legend
|
@@ -68,5 +67,5 @@
|
|
68
67
|
= hidden_field_tag("responses[#{question.id}][question_id]", question.id)
|
69
68
|
%ol.answers{:class => renderer == :inline ? "inline" : nil}
|
70
69
|
- question.answers.each do |answer|
|
71
|
-
- content_tag_for :li, answer do
|
72
|
-
= render(:partial => "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => answer.hide_label})
|
70
|
+
- content_tag_for :li, answer, :class => answer.custom_class do
|
71
|
+
= render(:partial => answer.custom_renderer || "/partials/answer", :locals => {:answer => answer, :question => question, :response_obj => @response_set.response_for(question.id, answer.id), :hide_label => answer.hide_label})
|
@@ -1,8 +1,6 @@
|
|
1
1
|
- renderer = question_group.renderer
|
2
|
-
- dep_class = question_group.dep_class(response_set)
|
3
2
|
- locals = {:question_group => question_group, :response_set => response_set, :hide_label => true}
|
4
|
-
|
5
|
-
- div_for question_group, :class => dep_class do
|
3
|
+
- div_for question_group, :class => question_group.css_class(response_set) do
|
6
4
|
.head
|
7
5
|
.number= next_number
|
8
6
|
%span.text= question_group.text
|
@@ -19,7 +17,7 @@
|
|
19
17
|
%th{:class => "#{cycle("column_highlight", "", :name => "column_highlight")}"}= answer.text
|
20
18
|
%tbody
|
21
19
|
- group_questions.each_with_index do |question, i|
|
22
|
-
= render(:partial => "/partials/question", :locals => locals.merge({:question => question}))
|
20
|
+
= render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question}))
|
23
21
|
- if i%10 == 9
|
24
22
|
%th= " "
|
25
23
|
- reset_cycle("column_highlight")
|
@@ -30,12 +28,12 @@
|
|
30
28
|
- (response_set.count_group_responses(group_questions) + 3).times do |group_number|
|
31
29
|
%li.repeater
|
32
30
|
- group_questions.each do |question|
|
33
|
-
= render(:partial => "/partials/question", :locals => locals.merge({:question => question, :response_group => group_number, :disabled => false}))
|
31
|
+
= render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question, :response_group => group_number, :disabled => false}))
|
34
32
|
%li.repeater
|
35
33
|
- group_questions.each do |question|
|
36
|
-
= render(:partial => "/partials/question", :locals => locals.merge({:question => question, :response_group => 9999, :disabled => true}))
|
34
|
+
= render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question, :response_group => 9999, :disabled => true}))
|
37
35
|
= submit_tag("<= add row", :name => "section[#{group_questions.first.survey_section_id}]question_group_#{question_group.id}", :class => "add_row")
|
38
36
|
- else # :inline
|
39
37
|
%ul
|
40
38
|
- group_questions.each do |question|
|
41
|
-
%li{:class => question_group.renderer == :inline ? "inline" : nil}= render(:partial => "/partials/question", :locals => locals.merge({:question => question}))
|
39
|
+
%li{:class => question_group.renderer == :inline ? "inline" : nil}= render(:partial => question.custom_renderer || "/partials/question", :locals => locals.merge({:question => question}))
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#surveyor
|
2
|
-
- form_tag(update_my_survey_path, :method => :put, :id => "survey_form") do
|
2
|
+
- form_tag(update_my_survey_path, :method => :put, :id => "survey_form", :class => @survey.custom_class) do
|
3
3
|
= hidden_field_tag :current_section_id, @section.id
|
4
4
|
- unless @sections.size < 3
|
5
5
|
#menu
|
@@ -15,19 +15,19 @@
|
|
15
15
|
.title Follow-up questions from your answers on the previous page
|
16
16
|
-# @dependents.each_with_index do |question, index|
|
17
17
|
= dependency_explanation_helper(question, @response_set)
|
18
|
-
= render(:partial => "/partials/question", :locals => {:question => question, :response_set => @response_set, :number => "D#{index+1}"})
|
19
|
-
- div_for @section do
|
18
|
+
= render(:partial => question.custom_renderer || "/partials/question", :locals => {:question => question, :response_set => @response_set, :number => "D#{index+1}"})
|
19
|
+
- div_for @section, :class => @section.custom_class do
|
20
20
|
%span.title= @section.title
|
21
21
|
.questions
|
22
22
|
- group_questions ||= []
|
23
23
|
- @questions.each_with_index do |question, index|
|
24
24
|
- unless question.part_of_group?
|
25
|
-
= render(:partial => "/partials/question", :locals => {:question => question, :response_set => @response_set})
|
25
|
+
= render(:partial => question.custom_renderer || "/partials/question", :locals => {:question => question, :response_set => @response_set})
|
26
26
|
- else # gather up the group questions
|
27
27
|
- group_questions << question
|
28
28
|
- if (index + 1 >= @questions.size) or (question.question_group_id != @questions[index + 1].question_group_id)
|
29
29
|
- # this is the last question of the section, or the group
|
30
|
-
= render(:partial => "/partials/question_group", :locals => {:question_group => question.question_group, :response_set => @response_set, :group_questions => group_questions})
|
30
|
+
= render(:partial => question.question_group.custom_renderer || "/partials/question_group", :locals => {:question_group => question.question_group, :response_set => @response_set, :group_questions => group_questions})
|
31
31
|
- group_questions = []
|
32
32
|
.next_section= next_section
|
33
33
|
|
@@ -2,6 +2,7 @@ Surveyor::Config.run do |config|
|
|
2
2
|
config['default.relative_url_root'] = nil # "surveys/" # should end with '/'
|
3
3
|
config['default.title'] = nil # "You can take these surveys:"
|
4
4
|
config['default.layout'] = nil # "surveyor_default"
|
5
|
+
config['default.index'] = nil # "/surveys" # or :index_path_method
|
5
6
|
config['default.finish'] = nil # "/surveys" # or :finish_path_method
|
6
7
|
config['use_restful_authentication'] = false # set to true to use restful authentication
|
7
8
|
config['extend_controller'] = false # set to true to extend SurveyorController
|
@@ -40,8 +40,8 @@ survey "“Kitchen Sink” survey" do
|
|
40
40
|
# :reference_identifier # usually from paper
|
41
41
|
# :data_export_identifier # data export
|
42
42
|
# :common_namespace # maping to a common vocab
|
43
|
-
# :
|
44
|
-
q "Get me started on an improv sketch", :reference_identifier => "improv_start", :data_export_identifier => "i_s", :common_namespace => "sketch comedy questions", :
|
43
|
+
# :common_identifier # maping to a common vocab
|
44
|
+
q "Get me started on an improv sketch", :reference_identifier => "improv_start", :data_export_identifier => "i_s", :common_namespace => "sketch comedy questions", :common_identifier => "get me started"
|
45
45
|
a "who", :string
|
46
46
|
a "what", :string
|
47
47
|
a "where", :string
|
@@ -49,11 +49,14 @@ survey "“Kitchen Sink” survey" do
|
|
49
49
|
# Various types of respones can be accepted
|
50
50
|
q "How many pets do you own?"
|
51
51
|
a :integer
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
|
53
|
+
# Surveys, sections, questions, groups, and answers also take a custom css class for covenience in custom styling
|
54
|
+
q "What is your address?", :custom_class => 'address'
|
55
|
+
a :text, :custom_class => 'mapper'
|
56
|
+
|
57
|
+
# Questions, groups, and answers take a custom renderer (a partial in the application's views dir)
|
58
|
+
# defaults are "/partials/question_group", "/partials/question", "/partials/answer", so the custom renderers should have a different name
|
59
|
+
q "Pick your favorite date AND time" #, :custom_renderer => "/partials/custom_question"
|
57
60
|
a :datetime
|
58
61
|
|
59
62
|
q "What time do you usually take a lunch break?"
|
data/surveyor.gemspec
CHANGED