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,57 @@
1
+ <% indent = 1 %>
2
+
3
+ <% define 'static' do %>
4
+ <% file "config/routes.rb" do %>
5
+ <% expand 'start' %>
6
+ <% expand 'end', :indent => indent %>
7
+ <% end %>
8
+ <% end %>
9
+
10
+ <% define 'dynamic', :for => View do %>
11
+ <% file "config/routes.rb" do %>
12
+ <% expand 'start' %>
13
+ <% expand 'static_pages', :indent => indent %><% nl %>
14
+ <% expand 'forms', :indent => indent %><% nl %>
15
+ <% expand 'end', :indent => indent %>
16
+ <% end %>
17
+ <% end %>
18
+
19
+ <% define 'start' do %>
20
+ <%= Rails.application.class.parent_name %>::Application.routes.draw do<% iinc %>
21
+ <% expand 'survey_management', :indent => indent %><% nl %>
22
+ <% expand 'user_management', :indent => indent %><% nl %>
23
+ <% end %>
24
+
25
+ <% define 'survey_management' do %>
26
+ resources :surveys, :only => [:index]
27
+ <% end %>
28
+
29
+ <% define 'user_management' do %>
30
+ resources :users
31
+ resources :sessions, :only => [:new, :create, :destroy]
32
+
33
+ <% nl %>
34
+ match '/signup', :to => 'users#new'
35
+ match '/signin', :to => 'sessions#new'
36
+ match '/signout', :to => 'sessions#destroy', :via => :delete
37
+ <% end %>
38
+
39
+ <% define 'static_pages', :for => View do %>
40
+ <% static_pages.each do |static_page| %>
41
+ <% if static_page.root %>
42
+ root :to => 'static_pages#<%= static_page.name %>'
43
+ <% else %>
44
+ match '/<%= static_page.name %>', :to => 'static_pages#<%= static_page.name %>'
45
+ <% end %>
46
+ <% end %>
47
+ <% end %>
48
+
49
+ <% define 'forms', :for => View do %>
50
+ <% forms.each do |form| %>
51
+ resources :<%= form.snake_name %>, :only => [:index, :create]
52
+ <% end %>
53
+ <% end %>
54
+
55
+ <% define 'end' do %>
56
+ <% idec %>end
57
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <% define 'static' do %>
2
+ <% expand 'migrate/create_answers::create_answers' %>
3
+ <% expand 'migrate/create_surveys::create_surveys' %>
4
+ <% expand 'migrate/create_questions::create_questions' %>
5
+ <% expand 'migrate/create_users::create_users' %>
6
+ <% end %>
7
+
8
+ <% define 'dynamic' do %>
9
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <% define 'create_answers' do %>
2
+ <% file "db/migrate/#{DateTime.new(Time.now.year, Time.now.month, Time.now.day, 0, 0, 4).to_s(:number)}_create_answers.rb" do %>
3
+ class CreateAnswers < ActiveRecord::Migration<% iinc %>
4
+ def change<% iinc %>
5
+ create_table :answers do |t|<% iinc %>
6
+ t.string :name
7
+ t.string :title
8
+ t.string :content
9
+ t.integer :question_id
10
+
11
+ <% nl %>
12
+ t.timestamps
13
+ <% idec %>end
14
+
15
+ <% nl %>
16
+ add_index :answers, [:question_id, :created_at]
17
+ <% idec %>end
18
+ <% idec %>end
19
+ <% end %>
20
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <% define 'create_questions' do %>
2
+ <% file "db/migrate/#{DateTime.new(Time.now.year, Time.now.month, Time.now.day, 0, 0, 3).to_s(:number)}_create_questions.rb" do %>
3
+ class CreateQuestions < ActiveRecord::Migration<% iinc %>
4
+ def change<% iinc %>
5
+ create_table :questions do |t|<% iinc %>
6
+ t.string :name
7
+ t.string :title
8
+ t.string :content
9
+ t.integer :survey_id
10
+
11
+ <% nl %>
12
+ t.timestamps
13
+ <% idec %>end
14
+
15
+ <% nl %>
16
+ add_index :questions, [:survey_id, :created_at]
17
+ <% idec %>end
18
+ <% idec %>end
19
+ <% end %>
20
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <% define 'create_surveys' do %>
2
+ <% file "db/migrate/#{DateTime.new(Time.now.year, Time.now.month, Time.now.day, 0, 0, 2).to_s(:number)}_create_surveys.rb" do %>
3
+ class CreateSurveys < ActiveRecord::Migration<% iinc %>
4
+ def change<% iinc %>
5
+ create_table :surveys do |t|<% iinc %>
6
+ t.string :name
7
+ t.string :title
8
+ t.string :author
9
+ t.integer :user_id
10
+
11
+ <% nl %>
12
+ t.timestamps
13
+ <% idec %>end
14
+
15
+ <% nl %>
16
+ add_index :surveys, [:user_id, :created_at]
17
+ <% idec %>end
18
+ <% idec %>end
19
+ <% end %>
20
+ <% end %>
@@ -0,0 +1,22 @@
1
+ <% define 'create_users' do %>
2
+ <% file "db/migrate/#{DateTime.new(Time.now.year, Time.now.month, Time.now.day, 0, 0, 1).to_s(:number)}_create_users.rb" do %>
3
+ class CreateUsers < ActiveRecord::Migration<% iinc %>
4
+ def change<% iinc %>
5
+ create_table :users do |t|<% iinc %>
6
+ t.string :name
7
+ t.string :email
8
+ t.string :remember_token
9
+ t.string :password_digest
10
+ t.boolean :admin, default: false
11
+
12
+ <% nl %>
13
+ t.timestamps
14
+ <% idec %>end
15
+
16
+ <% nl %>
17
+ add_index :users, :remember_token
18
+ add_index :users, :email, unique: true
19
+ <% idec %>end
20
+ <% idec %>end
21
+ <% end %>
22
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <% define 'static' do %>
2
+ <% expand 'app/app::static' %>
3
+ <% expand 'config/config::static' %>
4
+ <% expand 'db/db::static' %>
5
+ <% end %>
6
+
7
+ <% define 'dynamic' do %>
8
+ <% expand 'app/app::dynamic' %>
9
+ <% expand 'config/config::dynamic' %>
10
+ <% expand 'db/db::dynamic' %>
11
+ <% end %>
@@ -0,0 +1,56 @@
1
+ require 'rgen/environment'
2
+ require 'rgen/model_builder'
3
+ require 'metamodels/main'
4
+
5
+ module SurveyOnRails
6
+ module Builder
7
+ include SurveyMetamodel
8
+
9
+ $environment = nil
10
+
11
+ MODEL_VIEW_MAPPING = {
12
+ Text => Textfield,
13
+ MultipleChoice => CheckboxGroup,
14
+ SingleChoice => RadioButtonGroup,
15
+ RatingScale => HorizontalRadioButtonGroup,
16
+ Matrix => Table
17
+ }
18
+
19
+ def self.build(&block)
20
+ aliases = {}
21
+ source = block.source_location.first
22
+ if source.end_with?("model.rb")
23
+ $environment = RGen::Environment.new
24
+ File.open(source, 'r') do |file|
25
+ while line = file.gets
26
+ line.strip!
27
+ class_, name = nil
28
+ MODEL_VIEW_MAPPING.each do |key, value|
29
+ if line.start_with?(key.name.split('::').last.camelize(:lower))
30
+ class_ = value
31
+ if line.include?(":name")
32
+ name = line.split(":name").second.strip.delete(",").delete("=").delete(">").delete("\"").split(' ').first.delete(")")
33
+ elsif line.include?("name:")
34
+ name = line.split("name:").second.strip.delete(",").delete("\"").split(' ').first.delete(")")
35
+ else
36
+ name = line.split(' ').second.delete(",").delete("\"")
37
+ end
38
+ break
39
+ end
40
+ end
41
+ $environment << add_model_element(name, class_) if !class_.blank? and !name.blank?
42
+ end
43
+ end
44
+ end
45
+
46
+ model = RGen::ModelBuilder.build(SurveyMetamodel, $environment, nil, &block)
47
+ return model
48
+ end
49
+
50
+ def self.add_model_element(name, class_)
51
+ return Class.new do
52
+ class_eval("class SurveyMetamodel::#{name.to_s.capitalize} < #{class_.to_s}; end")
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,22 @@
1
+ class String
2
+ def class_name
3
+ self.split('::').last.uncapitalize.underscore
4
+ end
5
+
6
+ def to_underscore
7
+ self.gsub(/::/, '/').
8
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
9
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
10
+ tr("-", "_").
11
+ downcase.
12
+ gsub(/(\W)/, '_').
13
+ split('_').
14
+ map(&:capitalize).
15
+ join('').
16
+ underscore
17
+ end
18
+
19
+ def uncapitalize
20
+ (self.length >= 1)? (self[0].downcase + self[1..self.length]): self.downcase
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: survey_on_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ platform: ruby
6
+ authors:
7
+ - Dkemp04
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A generator for surveys based on model-driven development with RGen.
14
+ email: dkemp04@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/generators/survey/metamodels/app.rb
20
+ - lib/generators/survey/metamodels/base.rb
21
+ - lib/generators/survey/metamodels/main.rb
22
+ - lib/generators/survey/metamodels/model.rb
23
+ - lib/generators/survey/metamodels/style.rb
24
+ - lib/generators/survey/metamodels/types.rb
25
+ - lib/generators/survey/metamodels/validation.rb
26
+ - lib/generators/survey/metamodels/view.rb
27
+ - lib/generators/survey/survey_generator.rb
28
+ - lib/generators/survey/templates/app/app.tpl
29
+ - lib/generators/survey/templates/app/assets/assets.tpl
30
+ - lib/generators/survey/templates/app/assets/javascripts/application.tpl
31
+ - lib/generators/survey/templates/app/assets/stylesheets/static_stylesheet.tpl
32
+ - lib/generators/survey/templates/app/assets/stylesheets/stylesheet.tpl
33
+ - lib/generators/survey/templates/app/assets/stylesheets/survey_stylesheet.tpl
34
+ - lib/generators/survey/templates/app/controllers/application_controller.tpl
35
+ - lib/generators/survey/templates/app/controllers/controllers.tpl
36
+ - lib/generators/survey/templates/app/controllers/sessions_controller.tpl
37
+ - lib/generators/survey/templates/app/controllers/static_pages_controller.tpl
38
+ - lib/generators/survey/templates/app/controllers/survey_controller.tpl
39
+ - lib/generators/survey/templates/app/controllers/users_controller.tpl
40
+ - lib/generators/survey/templates/app/helpers/application_helper.tpl
41
+ - lib/generators/survey/templates/app/helpers/helpers.tpl
42
+ - lib/generators/survey/templates/app/helpers/sessions_helper.tpl
43
+ - lib/generators/survey/templates/app/helpers/survey_helper.tpl
44
+ - lib/generators/survey/templates/app/helpers/users_helper.tpl
45
+ - lib/generators/survey/templates/app/models/answer.tpl
46
+ - lib/generators/survey/templates/app/models/models.tpl
47
+ - lib/generators/survey/templates/app/models/question.tpl
48
+ - lib/generators/survey/templates/app/models/survey.tpl
49
+ - lib/generators/survey/templates/app/models/user.tpl
50
+ - lib/generators/survey/templates/app/models/validator.tpl
51
+ - lib/generators/survey/templates/app/views/form/checkbox_group.tpl
52
+ - lib/generators/survey/templates/app/views/form/choice_question.tpl
53
+ - lib/generators/survey/templates/app/views/form/dropdown.tpl
54
+ - lib/generators/survey/templates/app/views/form/element.tpl
55
+ - lib/generators/survey/templates/app/views/form/form.tpl
56
+ - lib/generators/survey/templates/app/views/form/group.tpl
57
+ - lib/generators/survey/templates/app/views/form/horizontal_radio_button_group.tpl
58
+ - lib/generators/survey/templates/app/views/form/image.tpl
59
+ - lib/generators/survey/templates/app/views/form/pagination.tpl
60
+ - lib/generators/survey/templates/app/views/form/radio_button_group.tpl
61
+ - lib/generators/survey/templates/app/views/form/table.tpl
62
+ - lib/generators/survey/templates/app/views/form/textfield.tpl
63
+ - lib/generators/survey/templates/app/views/layouts/application.tpl
64
+ - lib/generators/survey/templates/app/views/layouts/footer.tpl
65
+ - lib/generators/survey/templates/app/views/layouts/header.tpl
66
+ - lib/generators/survey/templates/app/views/layouts/shim.tpl
67
+ - lib/generators/survey/templates/app/views/layouts/static_element.tpl
68
+ - lib/generators/survey/templates/app/views/questions/question.tpl
69
+ - lib/generators/survey/templates/app/views/sessions/new.tpl
70
+ - lib/generators/survey/templates/app/views/shared/error_messages.tpl
71
+ - lib/generators/survey/templates/app/views/shared/static_page.tpl
72
+ - lib/generators/survey/templates/app/views/surveys/index.tpl
73
+ - lib/generators/survey/templates/app/views/surveys/survey.tpl
74
+ - lib/generators/survey/templates/app/views/users/edit.tpl
75
+ - lib/generators/survey/templates/app/views/users/fields.tpl
76
+ - lib/generators/survey/templates/app/views/users/index.tpl
77
+ - lib/generators/survey/templates/app/views/users/new.tpl
78
+ - lib/generators/survey/templates/app/views/users/show.tpl
79
+ - lib/generators/survey/templates/app/views/users/user.tpl
80
+ - lib/generators/survey/templates/app/views/views.tpl
81
+ - lib/generators/survey/templates/config/application.tpl
82
+ - lib/generators/survey/templates/config/config.tpl
83
+ - lib/generators/survey/templates/config/routes.tpl
84
+ - lib/generators/survey/templates/db/db.tpl
85
+ - lib/generators/survey/templates/db/migrate/create_answers.tpl
86
+ - lib/generators/survey/templates/db/migrate/create_questions.tpl
87
+ - lib/generators/survey/templates/db/migrate/create_surveys.tpl
88
+ - lib/generators/survey/templates/db/migrate/create_users.tpl
89
+ - lib/generators/survey/templates/main.tpl
90
+ - lib/generators/survey/USAGE
91
+ - lib/survey_on_rails/utils/builder.rb
92
+ - lib/survey_on_rails/utils/string.rb
93
+ homepage: http://rubygems.org/gems/survey_generator
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.0.7
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A generator for surveys based on model-driven development with RGen.
116
+ test_files: []