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.
- checksums.yaml +15 -0
- data/lib/generators/survey/USAGE +5 -0
- data/lib/generators/survey/metamodels/app.rb +88 -0
- data/lib/generators/survey/metamodels/base.rb +120 -0
- data/lib/generators/survey/metamodels/main.rb +12 -0
- data/lib/generators/survey/metamodels/model.rb +140 -0
- data/lib/generators/survey/metamodels/style.rb +202 -0
- data/lib/generators/survey/metamodels/types.rb +10 -0
- data/lib/generators/survey/metamodels/validation.rb +28 -0
- data/lib/generators/survey/metamodels/view.rb +384 -0
- data/lib/generators/survey/survey_generator.rb +276 -0
- data/lib/generators/survey/templates/app/app.tpl +15 -0
- data/lib/generators/survey/templates/app/assets/assets.tpl +10 -0
- data/lib/generators/survey/templates/app/assets/javascripts/application.tpl +32 -0
- data/lib/generators/survey/templates/app/assets/stylesheets/static_stylesheet.tpl +337 -0
- data/lib/generators/survey/templates/app/assets/stylesheets/stylesheet.tpl +128 -0
- data/lib/generators/survey/templates/app/assets/stylesheets/survey_stylesheet.tpl +102 -0
- data/lib/generators/survey/templates/app/controllers/application_controller.tpl +15 -0
- data/lib/generators/survey/templates/app/controllers/controllers.tpl +12 -0
- data/lib/generators/survey/templates/app/controllers/sessions_controller.tpl +26 -0
- data/lib/generators/survey/templates/app/controllers/static_pages_controller.tpl +14 -0
- data/lib/generators/survey/templates/app/controllers/survey_controller.tpl +105 -0
- data/lib/generators/survey/templates/app/controllers/users_controller.tpl +82 -0
- data/lib/generators/survey/templates/app/helpers/application_helper.tpl +26 -0
- data/lib/generators/survey/templates/app/helpers/helpers.tpl +9 -0
- data/lib/generators/survey/templates/app/helpers/sessions_helper.tpl +60 -0
- data/lib/generators/survey/templates/app/helpers/survey_helper.tpl +25 -0
- data/lib/generators/survey/templates/app/helpers/users_helper.tpl +14 -0
- data/lib/generators/survey/templates/app/models/answer.tpl +20 -0
- data/lib/generators/survey/templates/app/models/models.tpl +10 -0
- data/lib/generators/survey/templates/app/models/question.tpl +20 -0
- data/lib/generators/survey/templates/app/models/survey.tpl +17 -0
- data/lib/generators/survey/templates/app/models/user.tpl +28 -0
- data/lib/generators/survey/templates/app/models/validator.tpl +47 -0
- data/lib/generators/survey/templates/app/views/form/checkbox_group.tpl +13 -0
- data/lib/generators/survey/templates/app/views/form/choice_question.tpl +10 -0
- data/lib/generators/survey/templates/app/views/form/dropdown.tpl +15 -0
- data/lib/generators/survey/templates/app/views/form/element.tpl +43 -0
- data/lib/generators/survey/templates/app/views/form/form.tpl +35 -0
- data/lib/generators/survey/templates/app/views/form/group.tpl +14 -0
- data/lib/generators/survey/templates/app/views/form/horizontal_radio_button_group.tpl +7 -0
- data/lib/generators/survey/templates/app/views/form/image.tpl +10 -0
- data/lib/generators/survey/templates/app/views/form/pagination.tpl +60 -0
- data/lib/generators/survey/templates/app/views/form/radio_button_group.tpl +10 -0
- data/lib/generators/survey/templates/app/views/form/table.tpl +54 -0
- data/lib/generators/survey/templates/app/views/form/textfield.tpl +47 -0
- data/lib/generators/survey/templates/app/views/layouts/application.tpl +25 -0
- data/lib/generators/survey/templates/app/views/layouts/footer.tpl +28 -0
- data/lib/generators/survey/templates/app/views/layouts/header.tpl +32 -0
- data/lib/generators/survey/templates/app/views/layouts/shim.tpl +7 -0
- data/lib/generators/survey/templates/app/views/layouts/static_element.tpl +52 -0
- data/lib/generators/survey/templates/app/views/questions/question.tpl +8 -0
- data/lib/generators/survey/templates/app/views/sessions/new.tpl +28 -0
- data/lib/generators/survey/templates/app/views/shared/error_messages.tpl +16 -0
- data/lib/generators/survey/templates/app/views/shared/static_page.tpl +5 -0
- data/lib/generators/survey/templates/app/views/surveys/index.tpl +25 -0
- data/lib/generators/survey/templates/app/views/surveys/survey.tpl +14 -0
- data/lib/generators/survey/templates/app/views/users/edit.tpl +19 -0
- data/lib/generators/survey/templates/app/views/users/fields.tpl +24 -0
- data/lib/generators/survey/templates/app/views/users/index.tpl +17 -0
- data/lib/generators/survey/templates/app/views/users/new.tpl +15 -0
- data/lib/generators/survey/templates/app/views/users/show.tpl +17 -0
- data/lib/generators/survey/templates/app/views/users/user.tpl +11 -0
- data/lib/generators/survey/templates/app/views/views.tpl +30 -0
- data/lib/generators/survey/templates/config/application.tpl +26 -0
- data/lib/generators/survey/templates/config/config.tpl +8 -0
- data/lib/generators/survey/templates/config/routes.tpl +57 -0
- data/lib/generators/survey/templates/db/db.tpl +9 -0
- data/lib/generators/survey/templates/db/migrate/create_answers.tpl +20 -0
- data/lib/generators/survey/templates/db/migrate/create_questions.tpl +20 -0
- data/lib/generators/survey/templates/db/migrate/create_surveys.tpl +20 -0
- data/lib/generators/survey/templates/db/migrate/create_users.tpl +22 -0
- data/lib/generators/survey/templates/main.tpl +11 -0
- data/lib/survey_on_rails/utils/builder.rb +56 -0
- data/lib/survey_on_rails/utils/string.rb +22 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzViYWEzNzg5ZGRkZThmZTg2NTM3MTJlNjcxOGQ3MjBmMzJlMTRhNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Y2IyMWNlNDNmNzc5ODcyMjdiNGVhNmU2MmMwNGEyZWU3NzQzMTJjMA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YWMzNmQwNzQ1MzEzZjhlMGM2ZjE1Y2NhNzQ0YTRjYzYwZmMwZGVkOTk3MTI1
|
10
|
+
MGIzZTI3NDc1NDAyMjQyM2M5M2I4OWNlM2RlY2EzYTIxZWE3NzQxOTU5MGIw
|
11
|
+
NjcyYTVlODkzMTJhOTI4MWE0NWY2OTVhYWNiMmVmM2E4ZGIzYTI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Njc3NGNjNDVjYzUxMzU3N2NjNDU2NzUxYzA5NGI2ZGU0MWVkNGI3NGYyNjBi
|
14
|
+
ZDgzZDk1ZjJhZjFiNzMxMWYyMjlkZTEzMDdkZTA2Yjc0MzNiZDE3YWJkM2Vk
|
15
|
+
MTIwMzA1YmY2N2RkYWE3YmViNTM4NmVkOWU4NTg3NjIxYTlmZDg=
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module SurveyMetamodel extend RGen::MetamodelBuilder::ModuleExtension
|
2
|
+
class View < Base
|
3
|
+
contains_many 'forms', Form, 'view'
|
4
|
+
|
5
|
+
contains_one 'header', Header, 'view'
|
6
|
+
contains_one 'footer', Footer, 'view'
|
7
|
+
contains_many 'static_pages', StaticPage, 'view'
|
8
|
+
contains_many 'styles', StaticStyle, 'view'
|
9
|
+
end
|
10
|
+
|
11
|
+
class Model < Base
|
12
|
+
contains_many 'surveys', Survey, 'model'
|
13
|
+
end
|
14
|
+
|
15
|
+
class Application < Element
|
16
|
+
contains_one 'view', View, 'app'
|
17
|
+
contains_one 'model', Model, 'app'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module SurveyMetamodel
|
22
|
+
module Application::ClassModule
|
23
|
+
def view_forms
|
24
|
+
view.forms if !view.nil? and !view.forms.nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_elements
|
28
|
+
elems = view.form_elements
|
29
|
+
all_elems = (view_forms + elems)
|
30
|
+
elems.each do |elem|
|
31
|
+
all_elems << elem.elements if ((elem.is_a?(Group) or elem.is_a?(Page)) and !elem.is_a?(Image))
|
32
|
+
end
|
33
|
+
return all_elems
|
34
|
+
end
|
35
|
+
|
36
|
+
def preprocessing
|
37
|
+
model.survey_questions.each { |question| question.init } if !model.nil?
|
38
|
+
if !view.nil?
|
39
|
+
view.static_pages.each { |static_page| static_page.create_page_file }
|
40
|
+
view.header.elements.each { |element| element.init }
|
41
|
+
view.header.elements.each { |element| element.init }
|
42
|
+
view_forms.each do |form|
|
43
|
+
form.init
|
44
|
+
form.set_model_element
|
45
|
+
form.set_page_elements
|
46
|
+
end
|
47
|
+
view.form_elements.each do |element|
|
48
|
+
element.init
|
49
|
+
element.set_model_element
|
50
|
+
end
|
51
|
+
check_for_inconsistencies
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def check_for_inconsistencies
|
56
|
+
all_elements.each do |element1|
|
57
|
+
all_elements.each do |element2|
|
58
|
+
if !element1.model_element.nil? and !element2.model_element.nil?
|
59
|
+
if ((element1.model_element == element2.model_element) and (element1 != element2))
|
60
|
+
raise "View element is already associated to a model element (name='#{element1.name}')!"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
module Model::ClassModule
|
70
|
+
def survey_questions
|
71
|
+
surveys.questions if !surveys.nil? and !surveys.questions.nil?
|
72
|
+
end
|
73
|
+
|
74
|
+
def question_rules
|
75
|
+
survey_questions.rules if !survey_questions.nil? and !survey_questions.rules.nil?
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
module View::ClassModule
|
80
|
+
def form_elements
|
81
|
+
forms.elements if !forms.nil? and !forms.elements.nil?
|
82
|
+
end
|
83
|
+
|
84
|
+
def form_inputs
|
85
|
+
form_elements.select { |q| q.is_a?(Input) }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module SurveyMetamodel extend RGen::MetamodelBuilder::ModuleExtension
|
2
|
+
class Base < RGen::MetamodelBuilder::MMBase
|
3
|
+
abstract
|
4
|
+
has_attr 'class_name', String, :unsettable => true
|
5
|
+
end
|
6
|
+
|
7
|
+
class Element < Base
|
8
|
+
abstract
|
9
|
+
has_attr 'name', String
|
10
|
+
has_attr 'title', String
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module SurveyMetamodel
|
15
|
+
module Base::ClassModule
|
16
|
+
def class_name?
|
17
|
+
!class_name.blank?
|
18
|
+
end
|
19
|
+
|
20
|
+
def real_class_name
|
21
|
+
self.class_name = snake_class if !class_name?
|
22
|
+
return self.class_name
|
23
|
+
end
|
24
|
+
|
25
|
+
def snake_class
|
26
|
+
self.class.name.class_name
|
27
|
+
end
|
28
|
+
|
29
|
+
def snake_base_class
|
30
|
+
self.class.superclass.name.class_name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Element::ClassModule
|
35
|
+
def snake_name
|
36
|
+
plural_name.underscore
|
37
|
+
end
|
38
|
+
|
39
|
+
def snake_name_singular
|
40
|
+
name.underscore
|
41
|
+
end
|
42
|
+
|
43
|
+
def camel_name
|
44
|
+
plural_name.camelize
|
45
|
+
end
|
46
|
+
|
47
|
+
def file_name
|
48
|
+
(plural_name.split('').any? { |c| c =~ /^[0-9]$/ })? plural_name.gsub!('_', ''): plural_name
|
49
|
+
end
|
50
|
+
|
51
|
+
def name?
|
52
|
+
!name.blank?
|
53
|
+
end
|
54
|
+
|
55
|
+
def title?
|
56
|
+
!title.blank?
|
57
|
+
end
|
58
|
+
|
59
|
+
def has_name
|
60
|
+
return !(self.is_a?(Group) or self.is_a?(Image) or self.is_a?(Page) or self.is_a?(SurveyManagement) or self.is_a?(UserManagement))
|
61
|
+
end
|
62
|
+
|
63
|
+
def init
|
64
|
+
set_name
|
65
|
+
set_title
|
66
|
+
|
67
|
+
if self.is_a?(ChoiceQuestion)
|
68
|
+
init_all(choices)
|
69
|
+
elsif self.is_a?(Matrix)
|
70
|
+
init_all(rows)
|
71
|
+
init_all(columns)
|
72
|
+
elsif self.is_a?(Group) or (self.is_a?(Page) and !self.elements.empty?)
|
73
|
+
init_all(elements)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def set_name
|
80
|
+
self.name = unique_name if !name?
|
81
|
+
end
|
82
|
+
|
83
|
+
def set_title
|
84
|
+
self.title = unique_title if !title?
|
85
|
+
end
|
86
|
+
|
87
|
+
def init_all(collection)
|
88
|
+
collection.each { |element| element.init } if !collection.nil?
|
89
|
+
end
|
90
|
+
|
91
|
+
def plural_name
|
92
|
+
name.pluralize
|
93
|
+
end
|
94
|
+
|
95
|
+
def unique_name
|
96
|
+
uuid = SecureRandom.uuid[0..4]
|
97
|
+
return "#{real_class_name}_#{uuid}"
|
98
|
+
end
|
99
|
+
|
100
|
+
def unique_title
|
101
|
+
name.camelize if !name?
|
102
|
+
end
|
103
|
+
|
104
|
+
def init_with(new_name)
|
105
|
+
{ :name => "#{new_name.to_underscore}", :title => "#{new_name}" }
|
106
|
+
end
|
107
|
+
|
108
|
+
def choices_by_s(string)
|
109
|
+
choices_by_a(string.split(","))
|
110
|
+
end
|
111
|
+
|
112
|
+
def choices_by_a(array)
|
113
|
+
tmp_choices = Array.new
|
114
|
+
array.each do |choice|
|
115
|
+
tmp_choices << Choice.new(init_with(choice.strip))
|
116
|
+
end
|
117
|
+
return tmp_choices
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'rgen/metamodel_builder'
|
3
|
+
|
4
|
+
module SurveyMetamodel extend RGen::MetamodelBuilder::ModuleExtension
|
5
|
+
require "types"
|
6
|
+
require "base"
|
7
|
+
require "style"
|
8
|
+
require "validation"
|
9
|
+
require "model"
|
10
|
+
require "view"
|
11
|
+
require "app"
|
12
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
module SurveyMetamodel extend RGen::MetamodelBuilder::ModuleExtension
|
2
|
+
class ModelElement < Element
|
3
|
+
abstract
|
4
|
+
end
|
5
|
+
|
6
|
+
class Survey < ModelElement
|
7
|
+
has_attr 'author', String
|
8
|
+
contains_many 'questions', ModelElement, 'survey'
|
9
|
+
end
|
10
|
+
|
11
|
+
class Dependency < Base
|
12
|
+
has_attr 'requires', String
|
13
|
+
has_attr 'value', String
|
14
|
+
end
|
15
|
+
|
16
|
+
class Question < ModelElement
|
17
|
+
abstract
|
18
|
+
contains_many 'rules', ValidationRule, 'question'
|
19
|
+
contains_many 'dependencies', Dependency, 'question'
|
20
|
+
end
|
21
|
+
|
22
|
+
class Text < Question
|
23
|
+
end
|
24
|
+
|
25
|
+
class Choice < ModelElement
|
26
|
+
end
|
27
|
+
|
28
|
+
class ChoiceQuestion < Question
|
29
|
+
abstract
|
30
|
+
has_attr 'choices_s', String
|
31
|
+
contains_many 'choices', Choice, 'question'
|
32
|
+
end
|
33
|
+
|
34
|
+
class MultipleChoice < ChoiceQuestion
|
35
|
+
end
|
36
|
+
|
37
|
+
class SingleChoice < ChoiceQuestion
|
38
|
+
end
|
39
|
+
|
40
|
+
class RatingScale < ChoiceQuestion
|
41
|
+
has_attr 'type', RatingScaleType
|
42
|
+
|
43
|
+
has_attr 'min', Integer
|
44
|
+
has_attr 'max', Integer
|
45
|
+
end
|
46
|
+
|
47
|
+
class Row < ModelElement
|
48
|
+
end
|
49
|
+
|
50
|
+
class Column < ModelElement
|
51
|
+
end
|
52
|
+
|
53
|
+
class Matrix < Question
|
54
|
+
has_attr 'type', MatrixType
|
55
|
+
|
56
|
+
has_attr 'rows_s', String
|
57
|
+
contains_many 'rows', Row, 'matrix'
|
58
|
+
has_attr 'columns_s', String
|
59
|
+
contains_many 'columns', Column, 'matrix'
|
60
|
+
|
61
|
+
has_attr 'choices_s', String
|
62
|
+
contains_many 'choices', Choice, 'matrix'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module SurveyMetamodel
|
67
|
+
LIKERT_SCALE = ["Strongly disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"]
|
68
|
+
|
69
|
+
module Dependency::ClassModule
|
70
|
+
def condition
|
71
|
+
return "(!params[:#{requires}].blank? and params[:#{requires}][:content] == '#{value}')"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
module Question::ClassModule
|
76
|
+
def conditions
|
77
|
+
conditions_a = Array.new
|
78
|
+
dependencies.each do |dependency|
|
79
|
+
conditions_a << dependency.condition
|
80
|
+
end
|
81
|
+
return "(#{conditions_a.join(" and ")})"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
module RatingScale::ClassModule
|
86
|
+
def real_choices
|
87
|
+
if type == :numerical
|
88
|
+
choices2 = Array.new
|
89
|
+
(min..max).each { |i| choices2 << Choice.new(:name => "#{self.name}_choice_#{i}", :title => "#{i}") }
|
90
|
+
choices2
|
91
|
+
elsif type == :likert
|
92
|
+
choices_by_a(LIKERT_SCALE)
|
93
|
+
elsif self.is_a?(RatingScale)
|
94
|
+
choices
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
module ChoiceQuestion::ClassModule
|
100
|
+
def real_choices
|
101
|
+
if self.is_a?(ChoiceQuestion)
|
102
|
+
if !choices_s.blank? and choices.empty?
|
103
|
+
choices_by_s(choices_s)
|
104
|
+
else
|
105
|
+
choices
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
module Matrix::ClassModule
|
112
|
+
def real_rows
|
113
|
+
if !rows_s.blank? and rows.empty?
|
114
|
+
choices_by_s(rows_s)
|
115
|
+
else
|
116
|
+
rows
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def real_columns
|
121
|
+
if type == :likert
|
122
|
+
choices_by_s(LIKERT_SCALE.join(','))
|
123
|
+
elsif self.is_a?(Matrix)
|
124
|
+
if !columns_s.blank? and columns.empty?
|
125
|
+
choices_by_s(columns_s)
|
126
|
+
else
|
127
|
+
columns
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def real_choices
|
133
|
+
if !choices_s.blank? and choices.empty?
|
134
|
+
choices_by_s(choices_s)
|
135
|
+
else
|
136
|
+
choices
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,202 @@
|
|
1
|
+
module SurveyMetamodel extend RGen::MetamodelBuilder::ModuleExtension
|
2
|
+
class CustomStyle < Base
|
3
|
+
has_attr 'property', String
|
4
|
+
has_attr 'value', String
|
5
|
+
end
|
6
|
+
|
7
|
+
class Style < Base
|
8
|
+
abstract
|
9
|
+
|
10
|
+
has_attr 'margin', Integer
|
11
|
+
has_attr 'padding', Integer
|
12
|
+
has_attr 'foreground', Color
|
13
|
+
has_attr 'background', Color
|
14
|
+
has_attr 'font_size', Integer
|
15
|
+
has_attr 'font_style', FontStyle
|
16
|
+
has_attr 'font_weight', FontWeight
|
17
|
+
has_attr 'horizontal_alignment', HorizontalAlignment
|
18
|
+
has_attr 'vertical_alignment', VerticalAlignment
|
19
|
+
|
20
|
+
contains_many 'styles', CustomStyle, 'association'
|
21
|
+
end
|
22
|
+
|
23
|
+
class ElementStyle < Style
|
24
|
+
end
|
25
|
+
|
26
|
+
class StaticStyle < Style
|
27
|
+
has_attr 'element_names', String
|
28
|
+
has_attr 'element_types', String
|
29
|
+
end
|
30
|
+
|
31
|
+
class StyleElement < Element
|
32
|
+
abstract
|
33
|
+
contains_one 'style', ElementStyle, 'element'
|
34
|
+
has_attr 'custom_html', String
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module SurveyMetamodel
|
39
|
+
module CustomStyle::ClassModule
|
40
|
+
def property?
|
41
|
+
!property.blank?
|
42
|
+
end
|
43
|
+
|
44
|
+
def value?
|
45
|
+
!value.blank?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module Style::ClassModule
|
50
|
+
def margin?
|
51
|
+
!margin.nil? and margin != 0
|
52
|
+
end
|
53
|
+
|
54
|
+
def padding?
|
55
|
+
!padding.nil? and margin != 0
|
56
|
+
end
|
57
|
+
|
58
|
+
def foreground?
|
59
|
+
!foreground.nil?
|
60
|
+
end
|
61
|
+
|
62
|
+
def background?
|
63
|
+
!background.nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
def font_size?
|
67
|
+
!font_size.nil? and margin != 0
|
68
|
+
end
|
69
|
+
|
70
|
+
def font_style?
|
71
|
+
!font_style.nil?
|
72
|
+
end
|
73
|
+
|
74
|
+
def font_weight?
|
75
|
+
!font_weight.nil?
|
76
|
+
end
|
77
|
+
|
78
|
+
def horizontal_align?
|
79
|
+
!horizontal_align.nil?
|
80
|
+
end
|
81
|
+
|
82
|
+
def vertical_align?
|
83
|
+
!vertical_align.nil?
|
84
|
+
end
|
85
|
+
|
86
|
+
#See HTML color table: http://www.w3schools.com/html/html_colornames.asp
|
87
|
+
def color(color)
|
88
|
+
if color == :blue
|
89
|
+
"#0000FF"
|
90
|
+
elsif color == :red
|
91
|
+
"#FF0000"
|
92
|
+
elsif color == :yellow
|
93
|
+
"#FFFF00"
|
94
|
+
elsif color == :gray
|
95
|
+
"#808080"
|
96
|
+
elsif color == :green
|
97
|
+
"#008000"
|
98
|
+
elsif color == :white
|
99
|
+
"#FFFFFF"
|
100
|
+
elsif color == :black
|
101
|
+
"#000000"
|
102
|
+
elsif color == :lightGray
|
103
|
+
"#D3D3D3"
|
104
|
+
elsif color == :darkGray
|
105
|
+
"#A9A9A9"
|
106
|
+
else
|
107
|
+
"#FFFFFF"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def style
|
112
|
+
if font_style == :normal
|
113
|
+
"normal"
|
114
|
+
elsif font_style == :italic
|
115
|
+
"italic"
|
116
|
+
elsif font_style == :oblique
|
117
|
+
"oblique"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def weight
|
122
|
+
if font_weight == :normal
|
123
|
+
"normal"
|
124
|
+
elsif font_weight == :bold
|
125
|
+
"italic"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def horizontal_align
|
130
|
+
if horizontal_alignment == :left
|
131
|
+
"left"
|
132
|
+
elsif horizontal_alignment == :center
|
133
|
+
"center"
|
134
|
+
elsif horizontal_alignment == :right
|
135
|
+
"right"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def vertical_align
|
140
|
+
if vertical_alignment == :top
|
141
|
+
"top"
|
142
|
+
elsif vertical_alignment == :middle
|
143
|
+
"middle"
|
144
|
+
elsif vertical_alignment == :bottom
|
145
|
+
"bottom"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
module StaticStyle::ClassModule
|
151
|
+
def names
|
152
|
+
names = Array.new
|
153
|
+
if element_names? and !element_types?
|
154
|
+
names = self.element_names.split(',')
|
155
|
+
elsif !element_names? and element_types?
|
156
|
+
names = self.element_types.split(',')
|
157
|
+
elsif element_names? and element_types?
|
158
|
+
names = self.element_names.split(',') + self.element_types.split(',')
|
159
|
+
end
|
160
|
+
return names.each {|s| s.strip! }
|
161
|
+
end
|
162
|
+
|
163
|
+
def element_names?
|
164
|
+
!element_names.blank?
|
165
|
+
end
|
166
|
+
|
167
|
+
def element_types?
|
168
|
+
!element_types.blank?
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
module StyleElement::ClassModule
|
173
|
+
def has_style?(element)
|
174
|
+
return true if style?
|
175
|
+
|
176
|
+
container = nil
|
177
|
+
if !self.group.nil?
|
178
|
+
container = self.group
|
179
|
+
elsif self.is_a?(Input)
|
180
|
+
container = self
|
181
|
+
end
|
182
|
+
|
183
|
+
(!container.form.view.styles.select { |s| s.element_name == element.name }.empty?)
|
184
|
+
end
|
185
|
+
|
186
|
+
def style?
|
187
|
+
!style.nil?
|
188
|
+
end
|
189
|
+
|
190
|
+
def content
|
191
|
+
if custom_html?
|
192
|
+
custom_html
|
193
|
+
elsif title?
|
194
|
+
title
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def content?
|
199
|
+
!content.blank?
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module SurveyMetamodel extend RGen::MetamodelBuilder::ModuleExtension
|
2
|
+
Color = RGen::MetamodelBuilder::DataTypes::Enum.new(:name => "Color", :literals => [:blue, :red, :yellow, :gray, :green, :white, :black, :lightGray, :darkGray])
|
3
|
+
FontStyle = RGen::MetamodelBuilder::DataTypes::Enum.new(:name => "FontStyle", :literals => [:normal, :italic, :oblique])
|
4
|
+
FontWeight = RGen::MetamodelBuilder::DataTypes::Enum.new(:name => "FontWeight", :literals => [:normal, :bold])
|
5
|
+
HorizontalAlignment = RGen::MetamodelBuilder::DataTypes::Enum.new(:name => "HorizontalAlignment", :literals => [:left, :center, :right])
|
6
|
+
VerticalAlignment = RGen::MetamodelBuilder::DataTypes::Enum.new(:name => "VerticalAlignment", :literals => [:top, :middle, :bottom])
|
7
|
+
TextFieldType = RGen::MetamodelBuilder::DataTypes::Enum.new(:name => "TextFieldType", :literals => [:small, :normal, :multiLine])
|
8
|
+
RatingScaleType = RGen::MetamodelBuilder::DataTypes::Enum.new(:name => "RatingScaleType", :literals => [:normal, :numerical, :likert])
|
9
|
+
MatrixType = RGen::MetamodelBuilder::DataTypes::Enum.new(:name => "MatrixType", :literals => [:singleChoice, :multipleChoice, :text, :likert])
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SurveyMetamodel extend RGen::MetamodelBuilder::ModuleExtension
|
2
|
+
class ValidationRule < Base
|
3
|
+
abstract
|
4
|
+
end
|
5
|
+
|
6
|
+
class RegexRule < ValidationRule
|
7
|
+
has_attr 'regex', String
|
8
|
+
end
|
9
|
+
|
10
|
+
class NumberRule < ValidationRule
|
11
|
+
end
|
12
|
+
|
13
|
+
class FloatNumberRule < ValidationRule
|
14
|
+
end
|
15
|
+
|
16
|
+
class PresenceRule < ValidationRule
|
17
|
+
end
|
18
|
+
|
19
|
+
class LengthRule < ValidationRule
|
20
|
+
has_attr 'min', Integer
|
21
|
+
has_attr 'max', Integer
|
22
|
+
end
|
23
|
+
|
24
|
+
class RangeRule < ValidationRule
|
25
|
+
has_attr 'min', Float
|
26
|
+
has_attr 'max', Float
|
27
|
+
end
|
28
|
+
end
|