survey_on_rails 0.3.2

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.
Files changed (76) hide show
  1. checksums.yaml +15 -0
  2. data/lib/generators/survey/USAGE +5 -0
  3. data/lib/generators/survey/metamodels/app.rb +88 -0
  4. data/lib/generators/survey/metamodels/base.rb +120 -0
  5. data/lib/generators/survey/metamodels/main.rb +12 -0
  6. data/lib/generators/survey/metamodels/model.rb +140 -0
  7. data/lib/generators/survey/metamodels/style.rb +202 -0
  8. data/lib/generators/survey/metamodels/types.rb +10 -0
  9. data/lib/generators/survey/metamodels/validation.rb +28 -0
  10. data/lib/generators/survey/metamodels/view.rb +384 -0
  11. data/lib/generators/survey/survey_generator.rb +276 -0
  12. data/lib/generators/survey/templates/app/app.tpl +15 -0
  13. data/lib/generators/survey/templates/app/assets/assets.tpl +10 -0
  14. data/lib/generators/survey/templates/app/assets/javascripts/application.tpl +32 -0
  15. data/lib/generators/survey/templates/app/assets/stylesheets/static_stylesheet.tpl +337 -0
  16. data/lib/generators/survey/templates/app/assets/stylesheets/stylesheet.tpl +128 -0
  17. data/lib/generators/survey/templates/app/assets/stylesheets/survey_stylesheet.tpl +102 -0
  18. data/lib/generators/survey/templates/app/controllers/application_controller.tpl +15 -0
  19. data/lib/generators/survey/templates/app/controllers/controllers.tpl +12 -0
  20. data/lib/generators/survey/templates/app/controllers/sessions_controller.tpl +26 -0
  21. data/lib/generators/survey/templates/app/controllers/static_pages_controller.tpl +14 -0
  22. data/lib/generators/survey/templates/app/controllers/survey_controller.tpl +105 -0
  23. data/lib/generators/survey/templates/app/controllers/users_controller.tpl +82 -0
  24. data/lib/generators/survey/templates/app/helpers/application_helper.tpl +26 -0
  25. data/lib/generators/survey/templates/app/helpers/helpers.tpl +9 -0
  26. data/lib/generators/survey/templates/app/helpers/sessions_helper.tpl +60 -0
  27. data/lib/generators/survey/templates/app/helpers/survey_helper.tpl +25 -0
  28. data/lib/generators/survey/templates/app/helpers/users_helper.tpl +14 -0
  29. data/lib/generators/survey/templates/app/models/answer.tpl +20 -0
  30. data/lib/generators/survey/templates/app/models/models.tpl +10 -0
  31. data/lib/generators/survey/templates/app/models/question.tpl +20 -0
  32. data/lib/generators/survey/templates/app/models/survey.tpl +17 -0
  33. data/lib/generators/survey/templates/app/models/user.tpl +28 -0
  34. data/lib/generators/survey/templates/app/models/validator.tpl +47 -0
  35. data/lib/generators/survey/templates/app/views/form/checkbox_group.tpl +13 -0
  36. data/lib/generators/survey/templates/app/views/form/choice_question.tpl +10 -0
  37. data/lib/generators/survey/templates/app/views/form/dropdown.tpl +15 -0
  38. data/lib/generators/survey/templates/app/views/form/element.tpl +43 -0
  39. data/lib/generators/survey/templates/app/views/form/form.tpl +35 -0
  40. data/lib/generators/survey/templates/app/views/form/group.tpl +14 -0
  41. data/lib/generators/survey/templates/app/views/form/horizontal_radio_button_group.tpl +7 -0
  42. data/lib/generators/survey/templates/app/views/form/image.tpl +10 -0
  43. data/lib/generators/survey/templates/app/views/form/pagination.tpl +60 -0
  44. data/lib/generators/survey/templates/app/views/form/radio_button_group.tpl +10 -0
  45. data/lib/generators/survey/templates/app/views/form/table.tpl +54 -0
  46. data/lib/generators/survey/templates/app/views/form/textfield.tpl +47 -0
  47. data/lib/generators/survey/templates/app/views/layouts/application.tpl +25 -0
  48. data/lib/generators/survey/templates/app/views/layouts/footer.tpl +28 -0
  49. data/lib/generators/survey/templates/app/views/layouts/header.tpl +32 -0
  50. data/lib/generators/survey/templates/app/views/layouts/shim.tpl +7 -0
  51. data/lib/generators/survey/templates/app/views/layouts/static_element.tpl +52 -0
  52. data/lib/generators/survey/templates/app/views/questions/question.tpl +8 -0
  53. data/lib/generators/survey/templates/app/views/sessions/new.tpl +28 -0
  54. data/lib/generators/survey/templates/app/views/shared/error_messages.tpl +16 -0
  55. data/lib/generators/survey/templates/app/views/shared/static_page.tpl +5 -0
  56. data/lib/generators/survey/templates/app/views/surveys/index.tpl +25 -0
  57. data/lib/generators/survey/templates/app/views/surveys/survey.tpl +14 -0
  58. data/lib/generators/survey/templates/app/views/users/edit.tpl +19 -0
  59. data/lib/generators/survey/templates/app/views/users/fields.tpl +24 -0
  60. data/lib/generators/survey/templates/app/views/users/index.tpl +17 -0
  61. data/lib/generators/survey/templates/app/views/users/new.tpl +15 -0
  62. data/lib/generators/survey/templates/app/views/users/show.tpl +17 -0
  63. data/lib/generators/survey/templates/app/views/users/user.tpl +11 -0
  64. data/lib/generators/survey/templates/app/views/views.tpl +30 -0
  65. data/lib/generators/survey/templates/config/application.tpl +26 -0
  66. data/lib/generators/survey/templates/config/config.tpl +8 -0
  67. data/lib/generators/survey/templates/config/routes.tpl +57 -0
  68. data/lib/generators/survey/templates/db/db.tpl +9 -0
  69. data/lib/generators/survey/templates/db/migrate/create_answers.tpl +20 -0
  70. data/lib/generators/survey/templates/db/migrate/create_questions.tpl +20 -0
  71. data/lib/generators/survey/templates/db/migrate/create_surveys.tpl +20 -0
  72. data/lib/generators/survey/templates/db/migrate/create_users.tpl +22 -0
  73. data/lib/generators/survey/templates/main.tpl +11 -0
  74. data/lib/survey_on_rails/utils/builder.rb +56 -0
  75. data/lib/survey_on_rails/utils/string.rb +22 -0
  76. metadata +116 -0
@@ -0,0 +1,105 @@
1
+ <% define 'static' do %>
2
+ <% file "app/controllers/surveys_controller.rb" do %>
3
+ class SurveysController < ApplicationController<% iinc %>
4
+ before_filter :signed_in_user, only: [ :index ]
5
+ before_filter :admin_user, only: [ :index ]
6
+
7
+ <% nl %>
8
+ def index<% iinc %>
9
+ @surveys = Survey.paginate(:page => params[:page], :per_page => 10).order('created_at DESC')
10
+ <% idec %>end
11
+
12
+ <% nl %>
13
+ private<% iinc %>
14
+
15
+ <% nl %>
16
+ def admin_user<% iinc %>
17
+ redirect_to(root_path) unless current_user.admin?
18
+ <% idec %>end
19
+ <% idec %><% idec %>end
20
+ <% end %>
21
+ <% end %>
22
+
23
+ <% define 'dynamic', :for => Form do %>
24
+ <% file "app/controllers/#{file_name}_controller.rb" do %>
25
+ class <%= camel_name %>Controller < ApplicationController<% iinc %>
26
+ before_filter :signed_in_user, only: [ :index, :create ]
27
+
28
+ <% nl %>
29
+ def index<% iinc %>
30
+ synchronize_with_cache
31
+
32
+ <% nl %>
33
+ set_page
34
+ if params.nil?<% iinc %>
35
+ @<%= snake_name_singular %> = Survey.new
36
+ <% idec %>else<% iinc %>
37
+ @<%= snake_name_singular %> = Survey.new(params[:survey])
38
+ <% idec %>end
39
+ <% idec %>end
40
+
41
+ <% nl %>
42
+ def create<% iinc %>
43
+ synchronize_with_cache
44
+ prepare_params
45
+
46
+ <% nl %>
47
+ if params[:page].to_i != <%= actual_pages_number %><% iinc %>
48
+ flash[:notice] = "Changes have been saved!"
49
+ redirect_to <%= snake_name %>_path(:page => params[:page])
50
+ <% idec %>else<% iinc %>
51
+ @<%= snake_name_singular %> = Survey.new(params[:survey])
52
+
53
+ <% nl %>
54
+ <% input_elements.each do |element| %>
55
+ <% if element.has_model_element? %>
56
+ build_question(:<%= element.name %>, params<% if element.is_mandatory? %>, true<% end %>)
57
+ <% end %>
58
+ <% end %>
59
+
60
+ <% nl %>
61
+ if @<%= snake_name_singular %>.save<% iinc %>
62
+ flash[:success] = "Thank you for the participation in the survey '#{@<%= snake_name_singular %>.title}'!"
63
+ Rails.cache.delete("params")
64
+ redirect_to root_path
65
+ <% idec %>else<% iinc %>
66
+ set_page
67
+ render 'index'
68
+ <% idec %>end
69
+ <% idec %>end
70
+ <% idec %>end
71
+
72
+ <% nl %>
73
+ private<% iinc %>
74
+
75
+ def set_page<% iinc %>
76
+ @page = (!params[:page].nil?)? "page" + params[:page].to_s: "page1"
77
+ <% idec %>end
78
+
79
+ <% nl %>
80
+ def synchronize_with_cache(should_prepare = false)<% iinc %>
81
+ params.reverse_merge!(Rails.cache.read("params")) if Rails.cache.exist?("params")
82
+ Rails.cache.write("params", params)
83
+ <% idec %>end
84
+
85
+ <% nl %>
86
+ def prepare_params<% iinc %>
87
+ <% input_elements.each do |element| %>
88
+ <% if element.has_model_element? %>
89
+ <% if element.is_a?(CheckboxGroup) and element.dropdown %>
90
+ params[:<%= element.name %>][:content] = (params[:<%= element.name %>][:content]).join(', ') if (!params[:<%= element.name %>].blank? and !params[:<%= element.name %>][:content].blank?)
91
+ <% elsif (element.is_a?(CheckboxGroup) and !element.dropdown) or (element.is_a?(Table) and (element.type == :multipleChoice or element.type == :singleChoice or element.type == :likert or element.type == :text)) %>
92
+ params[:<%= element.name %>][:content] = <%= element.params_s %> if !params[:<%= element.name %>].blank?
93
+ <% end %>
94
+ <% end %>
95
+ <% end %>
96
+ return params
97
+ <% idec %>end
98
+
99
+ <% nl %>
100
+ def build_question(name, params, is_mandatory = false)<% iinc %>
101
+ @<%= snake_name_singular %>.questions.build(params[name]) if (!params[name].blank? and (is_mandatory or !(params[name][:content]).blank?))
102
+ <% idec %>end
103
+ <% idec %><% idec %>end
104
+ <% end %>
105
+ <% end %>
@@ -0,0 +1,82 @@
1
+ <% define 'users_controller' do %>
2
+ <% file "app/controllers/users_controller.rb" do %>
3
+ class UsersController < ApplicationController<% iinc %>
4
+ before_filter :signed_in_user, only: [:index, :edit, :update, :destroy]
5
+ before_filter :correct_user, only: [:edit, :update]
6
+ before_filter :admin_user, only: :destroy
7
+
8
+ <% nl %>
9
+ def index<% iinc %>
10
+ @users = User.paginate(page: params[:page])
11
+ <% idec %>end
12
+
13
+ <% nl %>
14
+ def show<% iinc %>
15
+ @user = User.find(params[:id])
16
+ <% idec %>end
17
+
18
+ <% nl %>
19
+ def new<% iinc %>
20
+ if signed_in?<% iinc %>
21
+ redirect_to root_url
22
+ <% idec %>else<% iinc %>
23
+ @user = User.new
24
+ <% idec %>end
25
+ <% idec %>end
26
+
27
+ <% nl %>
28
+ def create<% iinc %>
29
+ if signed_in?<% iinc %>
30
+ redirect_to root_url
31
+ <% idec %>else<% iinc %>
32
+ @user = User.new(params[:user])
33
+ if @user.save<% iinc %>
34
+ sign_in @user
35
+ flash[:success] = "Welcome to the Sample App!"
36
+ redirect_to @user
37
+ <% idec %>else<% iinc %>
38
+ render 'new'
39
+ <% idec %>end
40
+ <% idec %>end
41
+ <% idec %>end
42
+
43
+ <% nl %>
44
+ def edit
45
+ end
46
+
47
+ <% nl %>
48
+ def update<% iinc %>
49
+ if @user.update_attributes(params[:user])<% iinc %>
50
+ flash[:success] = "Profile updated"
51
+ sign_in @user
52
+ redirect_to @user
53
+ <% idec %>else<% iinc %>
54
+ render 'edit'
55
+ <% idec %>end
56
+ <% idec %>end
57
+
58
+ <% nl %>
59
+ def destroy<% iinc %>
60
+ if current_user.id != params[:id]<% iinc %>
61
+ User.find(params[:id]).destroy
62
+ flash[:success] = "User destroyed."
63
+ <% idec %>end
64
+ redirect_to users_url
65
+ <% idec %>end
66
+
67
+ <% nl %>
68
+ private<% iinc %>
69
+
70
+ <% nl %>
71
+ def correct_user<% iinc %>
72
+ @user = User.find(params[:id])
73
+ redirect_to(root_path) unless current_user?(@user)
74
+ <% idec %>end
75
+
76
+ <% nl %>
77
+ def admin_user<% iinc %>
78
+ redirect_to(root_path) unless current_user.admin?
79
+ <% idec %>end
80
+ <% idec %><% idec %>end
81
+ <% end %>
82
+ <% end %>
@@ -0,0 +1,26 @@
1
+ <% define 'application_helper', :for => Application do %>
2
+ <% file "app/helpers/application_helper.rb" do %>
3
+ module ApplicationHelper<% iinc %>
4
+ def full_title(page_title)<% iinc %>
5
+ base_title = "<%= title %>"
6
+ if page_title.empty?<% iinc %>
7
+ base_title
8
+ <% idec %>else<% iinc %>
9
+ "#{base_title} | #{page_title}"
10
+ <% idec %>end
11
+ <% idec %>end
12
+
13
+ private<% iinc %>
14
+ <% nl %>
15
+ def link_disabled(caption)<% iinc %>
16
+ return content_tag("li", :class => "disabled") do<% iinc %>
17
+ link_to("#{caption}".html_safe, "")
18
+ <% idec %>end
19
+ <% idec %>end
20
+
21
+ def link_enabled(caption)<% iinc %>
22
+ "#{caption}".html_safe
23
+ <% idec %>end
24
+ <% idec %><% idec %>end
25
+ <% end %>
26
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% define 'static' do %>
2
+ <% expand 'sessions_helper::sessions_helper' %>
3
+ <% expand 'users_helper::users_helper' %>
4
+ <% end %>
5
+
6
+ <% define 'dynamic' do %>
7
+ <% expand 'application_helper::application_helper' %>
8
+ <% expand 'survey_helper::survey_helper', :foreach => view.forms %>
9
+ <% end %>
@@ -0,0 +1,60 @@
1
+ <% define 'sessions_helper' do %>
2
+ <% file "app/helpers/sessions_helper.rb" do %>
3
+ module SessionsHelper<% iinc %>
4
+
5
+ <% nl %>
6
+ def sign_in(user)<% iinc %>
7
+ cookies.permanent[:remember_token] = user.remember_token
8
+ self.current_user = user
9
+ <% idec %>end
10
+
11
+ <% nl %>
12
+ def signed_in?<% iinc %>
13
+ !current_user.nil?
14
+ <% idec %>end
15
+
16
+ <% nl %>
17
+ def sign_out<% iinc %>
18
+ self.current_user = nil
19
+ cookies.delete(:remember_token)
20
+ <% idec %>end
21
+
22
+ <% nl %>
23
+ def current_user=(user)<% iinc %>
24
+ @current_user = user
25
+ <% idec %>end
26
+
27
+ <% nl %>
28
+ def current_user<% iinc %>
29
+ @current_user ||= User.find_by_remember_token(cookies[:remember_token])
30
+ <% idec %>end
31
+
32
+ <% nl %>
33
+ def current_user?(user)<% iinc %>
34
+ user == current_user
35
+ <% idec %>end
36
+
37
+ <% nl %>
38
+ def signed_in_user<% iinc %>
39
+ unless signed_in?<% iinc %>
40
+ store_location
41
+ redirect_to signin_url, notice: "Please sign in."
42
+ <% idec %>end
43
+ <% idec %>end
44
+
45
+ <% nl %>
46
+ private<% iinc %>
47
+
48
+ <% nl %>
49
+ def redirect_back_or(default)<% iinc %>
50
+ redirect_to(session[:return_to] || default)
51
+ session.delete(:return_to)
52
+ <% idec %>end
53
+
54
+ <% nl %>
55
+ def store_location<% iinc %>
56
+ session[:return_to] = request.url
57
+ <% idec %>end
58
+ <% idec %><% idec %>end
59
+ <% end %>
60
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <% define 'survey_helper', :for => Form do %>
2
+ <% file "app/helpers/#{file_name}_helper.rb" do %>
3
+ module <%= camel_name %>Helper<% iinc %>
4
+ def <%= snake_name %>_page_link(page)<% iinc %>
5
+ link_to_unless(params[:page].to_i == page.to_i, link_enabled(page.to_s), <%= snake_name %>_path(:page => page)) do<% iinc %>
6
+ link_disabled(page.to_s)
7
+ <% idec %>end
8
+ <% idec %>end
9
+
10
+ <% nl %>
11
+ def <%= snake_name %>_prev_link<% iinc %>
12
+ link_to_if(params[:page].to_i > 1, link_enabled("&larr; Previous"), <%= snake_name %>_path(:page => params[:page].to_i - 1)) do<% iinc %>
13
+ link_disabled("&larr; Previous")
14
+ <% idec %>end
15
+ <% idec %>end
16
+
17
+ <% nl %>
18
+ def <%= snake_name %>_next_link<% iinc %>
19
+ link_to_if(params[:page].to_i < <%= pages_number %>, link_enabled("Next &rarr;"), <%= snake_name %>_path(:page => params[:page].to_i + 1)) do<% iinc %>
20
+ link_disabled("Next &rarr;")
21
+ <% idec %>end
22
+ <% idec %>end
23
+ <% idec %><% idec %>end
24
+ <% end %>
25
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <% define 'users_helper' do %>
2
+ <% file "app/helpers/users_helper.rb" do %>
3
+ module UsersHelper<% iinc %>
4
+
5
+ <% nl %>
6
+ #Returns the Gravatar (http:/gravatar.com/) for the given user.
7
+ def gravatar_for(user, size)<% iinc %>
8
+ gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
9
+ gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
10
+ image_tag(gravatar_url, alt: user.name, class: "gravatar")
11
+ <% idec %>end
12
+ <% idec %>end
13
+ <% end %>
14
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <% define 'answer' do %>
2
+ <% file "app/models/answer.rb" do %>
3
+ require 'validator'
4
+
5
+ <% nl %>
6
+ class Answer < ActiveRecord::Base<% iinc %>
7
+ attr_accessible :name, :title, :content, :question_id
8
+
9
+ <% nl %>
10
+ belongs_to :question
11
+
12
+ <% nl %>
13
+ validates :name, :presence => true
14
+ validates :title, :presence => true
15
+ validates :content, :presence => true
16
+ include ActiveModel::Validations
17
+ validates_with QuestionValidator
18
+ <% idec %>end
19
+ <% end %>
20
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <% define 'static' do %>
2
+ <% expand 'answer::answer' %>
3
+ <% expand 'question::question' %>
4
+ <% expand 'survey::survey' %>
5
+ <% expand 'user::user' %>
6
+ <% end %>
7
+
8
+ <% define 'dynamic' do %>
9
+ <% expand 'validator::validator', :for => view %>
10
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <% define 'question' do %>
2
+ <% file "app/models/question.rb" do %>
3
+ require 'validator'
4
+
5
+ <% nl %>
6
+ class Question < ActiveRecord::Base<% iinc %>
7
+ attr_accessible :name, :title, :content, :survey_id
8
+
9
+ <% nl %>
10
+ belongs_to :survey
11
+ has_many :answers, :dependent => :destroy
12
+
13
+ <% nl %>
14
+ validates :name, :presence => true
15
+ validates :title, :presence => true
16
+ include ActiveModel::Validations
17
+ validates_with QuestionValidator
18
+ <% idec %>end
19
+ <% end %>
20
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <% define 'survey' do %>
2
+ <% file "app/models/survey.rb" do %>
3
+ class Survey < ActiveRecord::Base<% iinc %>
4
+ attr_accessible :name, :title, :author, :user_id
5
+
6
+ <% nl %>
7
+ has_many :questions, :dependent => :destroy
8
+ accepts_nested_attributes_for :questions, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true
9
+
10
+ <% nl %>
11
+ validates :name, :presence => true
12
+ validates :title, :presence => true
13
+ validates :author, :presence => true
14
+ validates :questions, :length => { :minimum => 1, :message => "have to be filled!" }
15
+ <% idec %>end
16
+ <% end %>
17
+ <% end %>
@@ -0,0 +1,28 @@
1
+ <% define 'user' do %>
2
+ <% file "app/models/user.rb" do %>
3
+ class User < ActiveRecord::Base<% iinc %>
4
+ attr_accessible :name, :email, :password, :password_confirmation
5
+ has_secure_password
6
+ has_many :surveys, dependent: :destroy
7
+
8
+ <% nl %>
9
+ before_save { email.downcase! }
10
+ before_save :create_remember_token
11
+
12
+ <% nl %>
13
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
14
+ validates :name, presence: true, length: { maximum: 50 }
15
+ validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
16
+ validates :password, presence: true, length: { minimum: 6 }
17
+ validates :password_confirmation, presence: true
18
+
19
+ <% nl %>
20
+ private<% iinc %>
21
+
22
+ <% nl %>
23
+ def create_remember_token<% iinc %>
24
+ self.remember_token = SecureRandom.urlsafe_base64
25
+ <% idec %>end
26
+ <% idec %><% idec %>end
27
+ <% end %>
28
+ <% end %>
@@ -0,0 +1,47 @@
1
+ <% define 'validator', :for => View do %>
2
+ <% file "app/models/validator.rb" do %>
3
+ class QuestionValidator < ActiveModel::Validator<% iinc %>
4
+ def validate(record)<% iinc %>
5
+ <% forms.each do |form| %>
6
+ <% form.input_elements.each do |element| %>
7
+ <% if element.has_model_element? and element.rules.count > 0 %>
8
+ if record.name == "<%= element.name %>"<% iinc %>
9
+ <% element.rules.each do |rule| %>
10
+ <% expand 'rule', rule %>
11
+ <% end %>
12
+ <% idec %>end
13
+ <% end %>
14
+ <% end %>
15
+ <% end %>
16
+ <% idec %>end
17
+ <% idec %>end
18
+ <% end %>
19
+ <% end %>
20
+
21
+ <% define 'rule' do |rule| %>
22
+ <% if rule.is_a?(RegexRule) %>
23
+ unless record.content.to_s =~ <%= rule.regex %><% iinc %>
24
+ record.errors[:content] << " of '<%= rule.question.title %>' has to match the regular expression '<%= rule.regex %>'!"
25
+ <% idec %>end
26
+ <% elsif rule.is_a?(NumberRule) %>
27
+ unless record.content.to_s =~ /^\d+$/<% iinc %>
28
+ record.errors[:content] << " of '<%= rule.question.title %>' has to be a number!"
29
+ <% idec %>end
30
+ <% elsif rule.is_a?(FloatNumberRule) %>
31
+ unless record.content.to_s =~ /^\d+??(?:\.\d{0,2})?$/<% iinc %>
32
+ record.errors[:content] << " of '<%= rule.question.title %>' has to be a floating point number!"
33
+ <% idec %>end
34
+ <% elsif rule.is_a?(PresenceRule) %>
35
+ unless !record.content.to_s.blank?<% iinc %>
36
+ record.errors[:content] << " of '<%= rule.question.title %>' cannot be blank!"
37
+ <% idec %>end
38
+ <% elsif rule.is_a?(LengthRule) %>
39
+ unless record.content.to_s.length >= <%= rule.min %> and record.content.to_s.length <= <%= rule.max %> <% iinc %>
40
+ record.errors[:content] << " of '<%= rule.question.title %>' has to have between <%= rule.min %> and <%=rule.max %> letters!"
41
+ <% idec %>end
42
+ <% elsif rule.is_a?(RangeRule) %>
43
+ unless (record.content.to_s =~ /^\d+$/) and (record.content.to_i >= <%= rule.min %> and record.content.to_i <= <%= rule.max %>)<% iinc %>
44
+ record.errors[:content] << " of '<%= rule.question.title %>' has to be a number between <%= rule.min %> and <%=rule.max %>!"
45
+ <% idec %>end
46
+ <% end %>
47
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <% define 'checkbox_group', :for => CheckboxGroup do %>
2
+ <% if dropdown %>
3
+ <% expand 'choice_question::dropdown', name, real_class_name, choices, true %>
4
+ <% else %>
5
+ <% choices.each do |choice| %>
6
+ <span class="<%= choice.name %>"><% iinc %>
7
+ <%%= check_box_tag "<%= name %>_<%= choice.name %>", "<%= choice.title %>", (!params[:<%= name %>_<%= choice.name %>].nil? and (params[:<%= name %>_<%= choice.name %>] == "<%= choice.title %>")) %>
8
+ <%%= label_tag "<%= choice.title %>", nil, :class => "checkbox inline" %>
9
+ <% idec %></span>
10
+ <br />
11
+ <% end %>
12
+ <% end %>
13
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <% define 'dropdown' do |name, class_name, choices, multiple| %>
2
+ <% expand 'dropdown::dropdown', name, name, "(params[:#{name}][:content] if !params[:#{name}].nil?)", class_name, choices, multiple %>
3
+ <% end %>
4
+
5
+ <% define 'choice' do |choice, style| %>
6
+ <span class="<%= choice.name %><% if !style.nil? %> <%= style %><% end %>"><% iinc %>
7
+ <%%= radio_button_tag "<%= name %>[content]", "<%= choice.title %>", (!params[:<%= name %>].nil? and (params[:<%= name %>][:content] == "<%= choice.title %>")) %>
8
+ <%%= label_tag "<%= choice.title %>", nil, :class =>"radio inline no_padding" %>
9
+ <% idec %></span>
10
+ <% end %>
@@ -0,0 +1,15 @@
1
+ <% define 'dropdown' do |name, param, default, class_name, choices, multiple| %>
2
+ <%%= select_tag "<%= param %>[content]<% if multiple %>[]<% end %>", <% expand 'params', name, default, class_name, choices, multiple %> %>
3
+ <% end %>
4
+
5
+ <% define 'table_dropdown' do |name, param, default, class_name, choices, multiple| %>
6
+ <%%= select_tag "<%= param %>", <% expand 'params', name, default, class_name, choices, multiple %> %>
7
+ <% end %>
8
+
9
+ <% define 'params' do |name, default, class_name, choices, multiple| %>
10
+ options_for_select([<% expand 'choices', choices %>], <%= default %>), :multiple => <%= multiple %>, :class => "span3 select <%= class_name %> <%= name %>"<% nows %><% nonl %>
11
+ <% end %>
12
+
13
+ <% define 'choices' do |choices| %>
14
+ <%= choices.map { |c| "\"" + c.title + "\"" }.join(", ") %><% nonl %><% nows %>
15
+ <% end %>
@@ -0,0 +1,43 @@
1
+ <% define 'element' do |element, i| %>
2
+ <% if element.has_valid_model_element? %>
3
+ <% nl %>
4
+ <% if element.has_label? %>
5
+ <% if element.dependencies? %><%% if <%= element.conditions %> %><% iinc %><% end %>
6
+ <%%= hidden_field_tag "<%= element.name %>[name]", "<%= element.name %>" %>
7
+ <%%= hidden_field_tag "<%= element.name %>[title]", "<%= element.title %>" %>
8
+ <div class="span10 input <%= element.real_class_name %> <%= element.name %>"><% iinc %>
9
+ <%%= label_tag '', "<%= element.number_title(i) %>", :class => "question<% if element.info? %> inline<%end%>" %>
10
+ <% expand 'info', element %>
11
+ <% end %>
12
+
13
+ <% if element.is_a?(Textfield) %>
14
+ <% expand 'textfield::textfield', :for => element %>
15
+ <% elsif element.is_a?(CheckboxGroup) %>
16
+ <% expand 'checkbox_group::checkbox_group', :for => element %>
17
+ <% elsif element.is_a?(RadioButtonGroup) %>
18
+ <% expand 'radio_button_group::radio_button_group', :for => element %>
19
+ <% elsif element.is_a?(HorizontalRadioButtonGroup) %>
20
+ <% expand 'horizontal_radio_button_group::horizontal_radio_button_group', :for => element %>
21
+ <% elsif element.is_a?(Table) %>
22
+ <% expand 'table::table', :for => element %>
23
+ <% elsif element.is_a?(Page) %>
24
+ <%# Do Nothing %>
25
+ <% elsif element.is_a?(Image) %>
26
+ <% expand 'image::image', :for => element %>
27
+ <% elsif element.is_a?(Group) %>
28
+ <% expand 'group::group', element, i %>
29
+ <% end %>
30
+
31
+ <% if element.has_label? %>
32
+ <% idec %></div>
33
+ <% if element.dependencies? %><% idec %><%% end %><% end %>
34
+ <% end %>
35
+ <% end %>
36
+ <% end %>
37
+
38
+ <% define 'info' do |element| %>
39
+ <% if element.info? %>
40
+ <%%= link_to image_tag("info.png", :size => "20x20", alt: "info"), '#', :class => "info", :rel => "popover", :title => "Information", :"data-content" => "<%= element.info %>" %>
41
+ <br />
42
+ <% end %>
43
+ <% end %>
@@ -0,0 +1,35 @@
1
+ <% define 'form', :for => Form do %>
2
+ <% file "app/views/#{file_name}/index.html.erb" do %>
3
+ <%% provide(:title, "<%= title.capitalize %>") %>
4
+ <h1><%= title %></h1>
5
+ <div class="author">by <%= author %></div>
6
+
7
+ <% nl %>
8
+ <div class="row"><% iinc %>
9
+ <div class="span10 offset1"><% iinc %>
10
+ <%%= form_tag(<%= snake_name %>_path + "?page=" + params[:page].to_s) do %><% iinc %>
11
+ <%%= render 'shared/error_messages', object: @<%= snake_name_singular %> %>
12
+
13
+ <% nl %>
14
+ <%%= hidden_field_tag "survey[name]", "<%= name %>" %>
15
+ <%%= hidden_field_tag "survey[title]", "<%= title %>" %>
16
+ <%%= hidden_field_tag "survey[author]", "<%= author %>" %>
17
+ <%% if signed_in? %><% iinc %>
18
+ <%%= hidden_field_tag "survey[user_id]", current_user.id %>
19
+ <% idec %><%% end %>
20
+
21
+ <% expand 'pagination::pages_nav', :indent => 0 %>
22
+ <%%= render 'pages_nav' %>
23
+
24
+ <% nl %>
25
+ <div><% iinc %>
26
+ <%%= render @page %>
27
+ <% idec %></div>
28
+
29
+ <% nl %>
30
+ <%%= render 'pages_nav' %>
31
+ <% idec %><%% end %>
32
+ <% idec %></div>
33
+ <% idec %></div>
34
+ <% end %>
35
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <% define 'group' do |group, i| %>
2
+ <div class="span10"><% iinc %>
3
+ <fieldset class="group-border <%= group.name %>" id="group"><% iinc %>
4
+ <legend><% iinc %>
5
+ <%= group.number_title(-1) %>
6
+ <% idec %></legend>
7
+
8
+ <% group.elements.each do |elem| %>
9
+ <% expand 'element::element', elem, i %>
10
+ <% i = i + 1 %>
11
+ <% end %>
12
+ <% idec %></fieldset>
13
+ <% idec %></div>
14
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% define 'horizontal_radio_button_group', :for => HorizontalRadioButtonGroup do %>
2
+ <div class="inline"><% iinc %>
3
+ <% choices.each do |choice| %>
4
+ <% expand 'choice_question::choice', choice, "inline_choice" %>
5
+ <% end %>
6
+ <% idec %></div>
7
+ <% end %>z
@@ -0,0 +1,10 @@
1
+ <% define 'image', :for => Image do %>
2
+ <% if url? %>
3
+ <%%= link_to <% expand 'image_tag' %>, '<%= url %>' %>
4
+ <% else %>
5
+ <%%= <% expand 'image_tag' %> %>
6
+ <% end %>
7
+ <br />
8
+ <% end %>
9
+
10
+ <% define 'image_tag', :for => Image do %>image_tag("<%= source %>", alt: "<%= title %>", :class => "img-polaroid")<% end %>