survey_generator 0.0.2 → 0.0.3

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjljNjRmMWI0MDUwOGEzNDJlMDM0MGY0YTc1YzIwODQ3N2E2ZjA5Ng==
4
+ OTkyNWY1NWMwZTRhNzM1ZTkwMTYxMWFmMzcwODc5NDFhZDY1ZmVmNw==
5
5
  data.tar.gz: !binary |-
6
- ODc2Yzc4NDA2ZDhiZDRlODNiNTA3NTJhYTZhMDgyNmY2NzRhZDU1MQ==
6
+ OTEzZTdlOGY1MDg1OWI5NjczMTBjOGI2YWZkMGMxMDg3YzFhMmFlNw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjM5ZWM2NzM0N2FkNzBhNWI3ZDAzYjM3NjNhNGM2MTRmN2QwYjI2NWVmODg4
10
- ZWRlNjZjOTY3ODZkZjcxNDg2OWU2YWRmZjc4NzJmZTkxOTk0MzJlZDNiNDY0
11
- YTE3YjZhOWUwMTNmMTM3NjI2Y2RmYmUwYTc4NmEzY2M2NmIxODc=
9
+ YzJlMTYyODgwMjFhZjExOWI5NzZlYjE1YjI3MDEwZWIwNmVkMzNhMzZlZDE1
10
+ ZDE2MDI1MmRiODAwMzRhZDNjNjI0ZWY2YWY1ZGU4MDNiMDVhMDMzOTg2OGE4
11
+ OGE3ZDJmZjJlODA1ZjEwYzEyOGU0ZGQzYmMyNDEyNTRkNjIwNGU=
12
12
  data.tar.gz: !binary |-
13
- ZmVjZjBmNmY4ODUzNTgzZDhlNzRkM2I4NjBjZTNlY2QxMDQ3ZjllYjk4Zjc0
14
- ZmFiNzJlMjQ0MTRiYTc3OGQ1NWYxMWM1NDA3NTRkNDdlZjdjZTZiYmJhMzBj
15
- YTcyOTY3YjkzMTI1YjU4OGJiMTYzN2NlNzY5ZjJiNmU2OTg0ZWE=
13
+ M2RjMzlhYWE3ZTYwYTcxOWRiMjU2YmI1YWU3ZmIwNGY4NjA2Zjg5ODVhOTdl
14
+ ODc2MjJhMmIzYWVkZThiZjMwYTI1YTZiY2M1NzMxMzU3NGIwNDRhYjM5MjIz
15
+ YWZhM2NjZGI0ZTM0YTQ0MTg5ZmEzOGRlYTQwYTZmNWE0YzY2N2U=
@@ -0,0 +1,21 @@
1
+ require 'rgen/metamodel_builder'
2
+
3
+ module SurveyMetamodel extend RGen::MetamodelBuilder::ModuleExtension
4
+ class Survey < RGen::MetamodelBuilder::MMBase
5
+ has_attr 'name', String
6
+ has_attr 'title', String
7
+ has_attr 'author', String
8
+ end
9
+
10
+ class Page < RGen::MetamodelBuilder::MMBase
11
+ has_attr 'name', String
12
+ has_attr 'number', Integer
13
+ end
14
+ Survey.contains_many 'page', Page, 'page'
15
+
16
+ class Field < RGen::MetamodelBuilder::MMBase
17
+ has_attr 'name', String
18
+ has_attr 'content', String
19
+ end
20
+ Page.contains_many 'field', Field, 'field'
21
+ end
@@ -0,0 +1,15 @@
1
+ require 'rgen/model_builder'
2
+ require 'metamodels/survey_metamodel'
3
+
4
+ MODEL = RGen::ModelBuilder.build(SurveyMetamodel) {
5
+ survey(name: "Comment", title: "Title1", author: "Author1") {
6
+ page(name: "Page1", number: 1) {
7
+ field name: "Test11", content: "Content11"
8
+ field name: "Test12", content: "Content12"
9
+ }
10
+ page(name: "Page2", number: 2) {
11
+ field name: "Test21", content: "Content21"
12
+ field name: "Test22", content: "Content22"
13
+ }
14
+ }
15
+ }
@@ -1,18 +1,19 @@
1
- $:.unshift File.dirname(__FILE__) + "/.."
2
- $:.unshift File.dirname(__FILE__) + "."
1
+ #$:.unshift File.dirname(__FILE__) + "/.."
2
+ #$:.unshift File.dirname(__FILE__) + "."
3
3
 
4
- require 'metamodels/survey_metamodel'
5
- require 'models/survey_model'
4
+ root = Rails.root.to_s
5
+ require root + 'metamodels/survey_metamodel'
6
+ require root + 'models/survey_model'
6
7
  require 'rgen/template_language'
7
8
  require 'rgen/array_extensions'
8
9
 
9
10
  class SurveyGenerator < Rails::Generators::Base
10
- source_root File.expand_path('../templates', __FILE__)
11
+ source_root File.expand_path('/templates', __FILE__)
11
12
 
12
13
  def generate_survey
13
14
  root = Rails.root.to_s
14
15
  tc = RGen::TemplateLanguage::DirectoryTemplateContainer.new(SurveyMetamodel, root)
15
- tc.load(root + '/gen/templates')
16
+ tc.load(root + '/lib/generators/survey/templates')
16
17
  tc.expand('main::root', for: MODEL.first)
17
18
  end
18
19
  end
@@ -0,0 +1,32 @@
1
+ $:.unshift File.dirname(__FILE__) + "../../.."
2
+
3
+ require 'survey_generator'
4
+
5
+ # >---------------------------------[ Gems ]---------------------------------<
6
+
7
+ gem 'survey_generator'
8
+ gem 'rgen'
9
+ run 'bundle install'
10
+
11
+ # >---------------------------------[ Database ]---------------------------------<
12
+
13
+ generate(:model, "Survey", "title:string", "user_id:integer")
14
+ generate(:model, "Page", "title:string", "number:integer", "questionnary_id:integer")
15
+ generate(:model, "Field", "name:string", "content:string", "page_id:integer")
16
+ rake 'db:migrate'
17
+
18
+ # >---------------------------------[ Other ]---------------------------------<
19
+
20
+ run 'rm public/index.html'
21
+ generate(:controller, "StaticPages", "home", "help", "about", "contact", "--no-test-framework")
22
+ route "root to: 'staticPages#home'"
23
+
24
+ # >---------------------------------[ MDD ]---------------------------------<
25
+
26
+ generate(:survey)
27
+
28
+ # >---------------------------------[ Git ]---------------------------------<
29
+
30
+ git :init
31
+ git add: '.'
32
+ git commit: '-m "Initial import."'
@@ -0,0 +1,224 @@
1
+ # >---------------------------------------------------------------------------<
2
+ #
3
+ # _____ _ _ __ ___ _
4
+ # | __ \ (_) | \ \ / (_) | |
5
+ # | |__) |__ _ _| |___\ \ /\ / / _ ______ _ _ __ __| |
6
+ # | _ // _` | | / __|\ \/ \/ / | |_ / _` | '__/ _` |
7
+ # | | \ \ (_| | | \__ \ \ /\ / | |/ / (_| | | | (_| |
8
+ # |_| \_\__,_|_|_|___/ \/ \/ |_/___\__,_|_| \__,_|
9
+ #
10
+ # This template was generated by RailsWizard, the amazing and awesome Rails
11
+ # application template builder. Get started at http://railswizard.org
12
+ #
13
+ # >---------------------------------------------------------------------------<
14
+
15
+ # >----------------------------[ Initial Setup ]------------------------------<
16
+
17
+ initializer 'generators.rb', <<-RUBY
18
+ Rails.application.config.generators do |g|
19
+ end
20
+ RUBY
21
+
22
+ @recipes = ["activerecord", "capybara", "git", "heroku", "rspec"]
23
+
24
+ def recipes; @recipes end
25
+ def recipe?(name); @recipes.include?(name) end
26
+
27
+ def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
28
+ def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
29
+ def say_wizard(text); say_custom(@current_recipe || 'wizard', text) end
30
+
31
+ def ask_wizard(question)
32
+ ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
33
+ end
34
+
35
+ def yes_wizard?(question)
36
+ answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
37
+ case answer.downcase
38
+ when "yes", "y"
39
+ true
40
+ when "no", "n"
41
+ false
42
+ else
43
+ yes_wizard?(question)
44
+ end
45
+ end
46
+
47
+ def no_wizard?(question); !yes_wizard?(question) end
48
+
49
+ def multiple_choice(question, choices)
50
+ say_custom('question', question)
51
+ values = {}
52
+ choices.each_with_index do |choice,i|
53
+ values[(i + 1).to_s] = choice[1]
54
+ say_custom (i + 1).to_s + ')', choice[0]
55
+ end
56
+ answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
57
+ values[answer]
58
+ end
59
+
60
+ @current_recipe = nil
61
+ @configs = {}
62
+
63
+ @after_blocks = []
64
+ def after_bundler(&block); @after_blocks << [@current_recipe, block]; end
65
+ @after_everything_blocks = []
66
+ def after_everything(&block); @after_everything_blocks << [@current_recipe, block]; end
67
+ @before_configs = {}
68
+ def before_config(&block); @before_configs[@current_recipe] = block; end
69
+
70
+
71
+
72
+ # >-----------------------------[ ActiveRecord ]------------------------------<
73
+
74
+ @current_recipe = "activerecord"
75
+ @before_configs["activerecord"].call if @before_configs["activerecord"]
76
+ say_recipe 'ActiveRecord'
77
+
78
+ config = {}
79
+ config['database'] = multiple_choice("Which database are you using?", [["MySQL", "mysql"], ["Oracle", "oracle"], ["PostgreSQL", "postgresql"], ["SQLite", "sqlite3"], ["Frontbase", "frontbase"], ["IBM DB", "ibm_db"]]) if true && true unless config.key?('database')
80
+ config['auto_create'] = yes_wizard?("Automatically create database with default configuration?") if true && true unless config.key?('auto_create')
81
+ @configs[@current_recipe] = config
82
+
83
+ if config['database']
84
+ say_wizard "Configuring '#{config['database']}' database settings..."
85
+ old_gem = gem_for_database
86
+ @options = @options.dup.merge(:database => config['database'])
87
+ gsub_file 'Gemfile', "gem '#{old_gem}'", "gem '#{gem_for_database}'"
88
+ template "config/databases/#{@options[:database]}.yml", "config/database.yml.new"
89
+ run 'mv config/database.yml.new config/database.yml'
90
+ end
91
+
92
+ after_bundler do
93
+ rake "db:create:all" if config['auto_create']
94
+ end
95
+
96
+
97
+ # >-------------------------------[ Capybara ]--------------------------------<
98
+
99
+ @current_recipe = "capybara"
100
+ @before_configs["capybara"].call if @before_configs["capybara"]
101
+ say_recipe 'Capybara'
102
+
103
+
104
+ @configs[@current_recipe] = config
105
+
106
+ gem 'capybara', :group => [:development, :test]
107
+
108
+ after_bundler do
109
+ create_file "spec/support/capybara.rb", <<-RUBY
110
+ require 'capybara/rails'
111
+ require 'capybara/rspec'
112
+ RUBY
113
+
114
+ create_file "spec/requests/home_spec.rb", <<-RUBY
115
+ require 'spec_helper'
116
+
117
+ describe 'visiting the homepage' do
118
+ before do
119
+ visit '/'
120
+ end
121
+
122
+ it 'should have a body' do
123
+ page.should have_css('body')
124
+ end
125
+ end
126
+ RUBY
127
+ end
128
+
129
+
130
+ # >----------------------------------[ Git ]----------------------------------<
131
+
132
+ @current_recipe = "git"
133
+ @before_configs["git"].call if @before_configs["git"]
134
+ say_recipe 'Git'
135
+
136
+
137
+ @configs[@current_recipe] = config
138
+
139
+ after_everything do
140
+ git :init
141
+ git :add => '.'
142
+ git :commit => '-m "Initial import."'
143
+ end
144
+
145
+
146
+ # >--------------------------------[ Heroku ]---------------------------------<
147
+
148
+ @current_recipe = "heroku"
149
+ @before_configs["heroku"].call if @before_configs["heroku"]
150
+ say_recipe 'Heroku'
151
+
152
+ config = {}
153
+ config['create'] = yes_wizard?("Automatically create appname.heroku.com?") if true && true unless config.key?('create')
154
+ config['staging'] = yes_wizard?("Create staging app? (appname-staging.heroku.com)") if config['create'] && true unless config.key?('staging')
155
+ config['domain'] = ask_wizard("Specify custom domain (or leave blank):") if config['create'] && true unless config.key?('domain')
156
+ config['deploy'] = yes_wizard?("Deploy immediately?") if config['create'] && true unless config.key?('deploy')
157
+ @configs[@current_recipe] = config
158
+
159
+ heroku_name = app_name.gsub('_','')
160
+
161
+ after_everything do
162
+ if config['create']
163
+ say_wizard "Creating Heroku app '#{heroku_name}.heroku.com'"
164
+ while !system("heroku create #{heroku_name}")
165
+ heroku_name = ask_wizard("What do you want to call your app? ")
166
+ end
167
+ end
168
+
169
+ if config['staging']
170
+ staging_name = "#{heroku_name}-staging"
171
+ say_wizard "Creating staging Heroku app '#{staging_name}.heroku.com'"
172
+ while !system("heroku create #{staging_name}")
173
+ staging_name = ask_wizard("What do you want to call your staging app?")
174
+ end
175
+ git :remote => "rm heroku"
176
+ git :remote => "add production git@heroku.com:#{heroku_name}.git"
177
+ git :remote => "add staging git@heroku.com:#{staging_name}.git"
178
+ say_wizard "Created branches 'production' and 'staging' for Heroku deploy."
179
+ end
180
+
181
+ unless config['domain'].blank?
182
+ run "heroku addons:add custom_domains"
183
+ run "heroku domains:add #{config['domain']}"
184
+ end
185
+
186
+ git :push => "#{config['staging'] ? 'staging' : 'heroku'} master" if config['deploy']
187
+ end
188
+
189
+
190
+ # >---------------------------------[ RSpec ]---------------------------------<
191
+
192
+ @current_recipe = "rspec"
193
+ @before_configs["rspec"].call if @before_configs["rspec"]
194
+ say_recipe 'RSpec'
195
+
196
+
197
+ @configs[@current_recipe] = config
198
+
199
+ gem 'rspec-rails', '>= 2.0.1', :group => [:development, :test]
200
+
201
+ inject_into_file "config/initializers/generators.rb", :after => "Rails.application.config.generators do |g|\n" do
202
+ " g.test_framework = :rspec\n"
203
+ end
204
+
205
+ after_bundler do
206
+ generate 'rspec:install'
207
+ end
208
+
209
+
210
+
211
+
212
+
213
+ @current_recipe = nil
214
+
215
+ # >-----------------------------[ Run Bundler ]-------------------------------<
216
+
217
+ say_wizard "Running Bundler install. This will take a while."
218
+ run 'bundle install'
219
+ say_wizard "Running after Bundler callbacks."
220
+ @after_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call}
221
+
222
+ @current_recipe = nil
223
+ say_wizard "Running after everything callbacks."
224
+ @after_everything_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call}
@@ -0,0 +1,8 @@
1
+ <% define 'survey_controller', for: Survey do %>
2
+ <% file "app/controllers/" + name.pluralize.downcase + "_controller.rb" do %>
3
+ class <%= name %>Controller < ApplicationController
4
+ <%iinc%>def index
5
+ end
6
+ <%idec%>end
7
+ <% end %>
8
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% define 'root', for: Survey do %>
2
+ <% expand 'models/survey_model::survey_model' %>
3
+ <% expand 'controllers/survey_controller::survey_controller' %>
4
+ <% expand 'views/survey_view::survey_view' %>
5
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <% define 'survey_model', for: Survey do %>
2
+ <% file "app/models/" + name.downcase + ".rb" do %>
3
+ class <%= name %>Model < ActiveRecord::Base
4
+ <%iinc%>attr_accessible :<%= title %>, :<%= author %><%nl%>
5
+ <% expand 'survey_page', foreach: page %>
6
+ <%idec%>end
7
+ <% end %>
8
+ <% end %>
9
+
10
+ <% define 'survey_page', for: Page do %>
11
+ attr_accessible :<%= name %>
12
+ <% expand 'survey_field', foreach: field %>
13
+ <% end %>
14
+
15
+ <% define 'survey_field', for: Field do %>
16
+ attr_accessible :<%= name %>, :<%= content %>
17
+ <% end %>
@@ -0,0 +1,37 @@
1
+ <% define 'survey_form_view', for: Survey do %>
2
+ <% file "app/views/" + name.pluralize.downcase + "/_form.html.erb" do %>
3
+ <%% @post.tags.build %>
4
+ <%%= form_for(@post) do |post_form| %>
5
+ <%iinc%><%% if @post.errors.any? %>
6
+ <%iinc%><div id="errorExplanation">
7
+ <%iinc%><h2><%%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
8
+ <ul>
9
+ <%% @post.errors.full_messages.each do |msg| %>
10
+ <%iinc%><li><%%= msg %></li>
11
+ <%idec%><%% end %>
12
+ </ul>
13
+ <%idec%></div>
14
+ <%idec%><%% end %><%nl%>
15
+
16
+ <div class="field">
17
+ <%iinc%><%%= post_form.label :name %><br />
18
+ <%%= post_form.text_field :name %>
19
+ <%idec%></div>
20
+ <div class="field">
21
+ <%iinc%><%%= post_form.label :title %><br />
22
+ <%%= post_form.text_field :title %>
23
+ <%idec%></div>
24
+ <div class="field">
25
+ <%iinc%><%%= post_form.label :content %><br />
26
+ <%%= post_form.text_area :content %>
27
+ <%idec%></div>
28
+
29
+ <%nl%><h2>Tags</h2>
30
+ <%%= render :partial => 'tags/form', :locals => {:form => post_form} %><%nl%>
31
+
32
+ <div class="actions">
33
+ <%iinc%><%%= post_form.submit %>
34
+ <%idec%></div>
35
+ <%idec%><%% end %>
36
+ <% end %>
37
+ <% end %>
@@ -0,0 +1,30 @@
1
+ <% define 'survey_index_view', for: Survey do %>
2
+ <% file "app/views/" + name.pluralize.downcase + "/index.html.erb" do %>
3
+ <h1>Listing posts</h1><%nl%>
4
+ <table>
5
+ <%iinc%><tr>
6
+ <%iinc%><th>Name</th>
7
+ <th>Title</th>
8
+ <th>Content</th>
9
+ <th></th>
10
+ <th></th>
11
+ <th></th>
12
+ <%idec%></tr><%nl%>
13
+
14
+ <%% @posts.each do |post| %>
15
+ <%iinc%><tr>
16
+ <%iinc%><td><%%= post.name %></td>
17
+ <td><%%= post.title %></td>
18
+ <td><%%= post.content %></td>
19
+ <td><%%= link_to 'Show', post %></td>
20
+ <td><%%= link_to 'Edit', edit_post_path(post) %></td>
21
+ <td><%%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
22
+ <%idec%></tr>
23
+ <%idec%><%% end %>
24
+ <%idec%></table><%nl%>
25
+
26
+ <br /><%nl%>
27
+
28
+ <%% link_to 'New post', new_post_path %>
29
+ <% end %>
30
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <% define 'survey_view', for: Survey do %>
2
+ <% expand 'survey_index_view::survey_index_view' %>
3
+ <% expand 'survey_form_view::survey_form_view' %>
4
+ <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: survey_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dkemp04
@@ -16,7 +16,17 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - lib/generators/survey/metamodels/survey_metamodel.rb
20
+ - lib/generators/survey/models/survey_model.rb
19
21
  - lib/generators/survey/survey_generator.rb
22
+ - lib/generators/survey/templates/application/app_template.rb
23
+ - lib/generators/survey/templates/application/example_app_template.rb
24
+ - lib/generators/survey/templates/controllers/survey_controller.tpl
25
+ - lib/generators/survey/templates/main.tpl
26
+ - lib/generators/survey/templates/models/survey_model.tpl
27
+ - lib/generators/survey/templates/views/survey_form_view.tpl
28
+ - lib/generators/survey/templates/views/survey_index_view.tpl
29
+ - lib/generators/survey/templates/views/survey_view.tpl
20
30
  - lib/generators/survey/USAGE
21
31
  homepage: http://rubygems.org/gems/survey_generator
22
32
  licenses: []