rest_in_peace 0.1.1 → 0.2.0

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/Rakefile CHANGED
@@ -10,11 +10,12 @@ begin
10
10
  gem.email = "chinmaygarde@gmail.com"
11
11
  gem.homepage = "http://github.com/chinmaygarde/rest_in_peace"
12
12
  gem.authors = ["Chinmay Garde"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
13
  gem.add_development_dependency "sinatra", ">= 0.9.4"
15
14
  gem.add_development_dependency "datamapper", ">= 0.10.2"
16
- gem.add_development_dependency "builder", ">= 2.2.2"
15
+ gem.add_development_dependency "builder"
17
16
  gem.add_development_dependency "taps", ">= 0.2.26"
17
+ gem.add_development_dependency "bundler", ">= 0.9.11"
18
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
18
19
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
20
  end
20
21
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -0,0 +1,9 @@
1
+ class ControllerViewBinding
2
+
3
+ attr_accessor :controller_name, :dependent_entity
4
+
5
+ def get_binding
6
+ binding
7
+ end
8
+
9
+ end
@@ -0,0 +1,23 @@
1
+ class ModelViewBinding
2
+
3
+ attr_accessor :model_name, :columns, :associations, :statements
4
+
5
+ def get_binding
6
+ binding
7
+ end
8
+
9
+ def convert_associations_to_datamapper_statements
10
+ @statements = Array.new unless @statements
11
+ @associations.each do |entity_name, entity_type|
12
+ case entity_type
13
+ when "has_many"
14
+ @statements << "has n, :#{entity_name.pluralize}"
15
+ when "belongs_to"
16
+ @statements << "belongs_to :#{entity_name}"
17
+ when "has_and_belongs_to_many"
18
+ # TODO
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,25 @@
1
+ class ViewBinding
2
+
3
+ attr_accessor :view_name, :fields, :html_tags
4
+
5
+ def get_binding
6
+ binding
7
+ end
8
+
9
+ def map_fields_to_html_tags
10
+ @html_tags = Hash.new
11
+ @fields.each do |key, value|
12
+ @html_tags[key] = tag_for_field_type(value)
13
+ end
14
+ end
15
+
16
+ def tag_for_field_type(type)
17
+ case type
18
+ when "string"
19
+ "text" #for now, only text inputs will work. Really need to think this through.
20
+ else
21
+ "text"
22
+ end
23
+ end
24
+
25
+ end
@@ -29,7 +29,9 @@ class Generator
29
29
 
30
30
  File.open(File.join(settings.project_root, "README"), "w") << File.open(File.join(settings.template_directory, "readme.txt.erb")).read
31
31
 
32
- File.open(File.join(settings.project_root, ".gems"), "w") << File.open(File.join(settings.template_directory, "gems")).read
32
+ FileUtils.cp(File.join(settings.template_directory, "Gemfile"), settings.project_root)
33
+
34
+ FileUtils.cp(File.join(settings.template_directory, "config.yml"), settings.config_directory)
33
35
 
34
36
  File.open(File.join(settings.view_directory, "layouts", "application.html.erb"), "w") << File.open(File.join(settings.template_directory, "html", "layout.html.erb")).read
35
37
 
@@ -44,32 +46,33 @@ class Generator
44
46
  migration_file = File.open(File.join(settings.script_directory, "migrate"), "w")
45
47
  migration_file << File.open(File.join(settings.template_directory, "script", "migrate")).read
46
48
 
47
- File.chmod(0755, define_file.path, server_file.path, migration_file.path)
49
+ cloud_file = File.open(File.join(settings.script_directory, "cloud"), "w")
50
+ cloud_file << File.open(File.join(settings.template_directory, "script", "cloud")).read
51
+
52
+ File.chmod(0755, define_file.path, server_file.path, migration_file.path, cloud_file.path)
48
53
 
49
54
  puts "Your project is six feet under at #{settings.project_root}"
50
55
  end
51
56
 
52
57
  def generate_scaffold(*args)
53
- generate_model(*args)
54
- generate_controller(args[0])
55
- generate_views(*args)
56
- end
57
-
58
- def generate_model(*args)
59
-
60
- model_name = args[0]
61
- columns = Hash.new
62
-
63
- (1 .. (args.length - 1)).each do |i|
64
- key_value = args[i].split(':')
65
- columns[key_value[0]] = key_value[1]
66
- end
58
+
59
+ # TODO: Throw proper error messages
60
+ arguments = parse_arguments(*args)
67
61
 
68
- b = ModelViewBinding.new
69
- b.model_name = model_name
70
- b.columns = columns
62
+ generate_model(arguments["entity"], arguments["columns"], arguments["associations"])
63
+ generate_controller(arguments["entity"], arguments["associations"])
64
+ generate_views(arguments["entity"], arguments["columns"])
65
+ end
71
66
 
72
- model_string = ERB.new(File.open( File.join(settings.template_directory, "model.rb.erb") ).read ).result(b.get_binding)
67
+ def generate_model(model_name, columns, associations)
68
+
69
+ model_binding = ModelViewBinding.new
70
+ model_binding.model_name = model_name
71
+ model_binding.columns = columns
72
+ model_binding.associations = associations
73
+ model_binding.convert_associations_to_datamapper_statements
74
+
75
+ model_string = ERB.new(File.open( File.join(settings.template_directory, "model.rb.erb") ).read ).result(model_binding.get_binding)
73
76
 
74
77
  file_path = File.join(settings.model_directory, "#{model_name.capitalize}.rb")
75
78
 
@@ -84,10 +87,16 @@ class Generator
84
87
 
85
88
  end
86
89
 
87
- def generate_controller(name)
90
+ def generate_controller(name, associations)
88
91
 
89
92
  b = ControllerViewBinding.new
90
93
  b.controller_name = name
94
+ b.dependent_entity = Array.new
95
+ associations.each do |associated_entity, association_type|
96
+ if association_type == "has_many"
97
+ b.dependent_entity << associated_entity
98
+ end
99
+ end
91
100
 
92
101
  controller_string = ERB.new(File.open( File.join(settings.template_directory, "controller.rb.erb") ).read).result(b.get_binding)
93
102
  file_path = File.join(settings.controller_directory, "#{name.capitalize}Controller.rb")
@@ -104,9 +113,8 @@ class Generator
104
113
  end
105
114
 
106
115
 
107
- def generate_views(*args)
108
- model_name = args[0].downcase
109
-
116
+ def generate_views(model_name, columns)
117
+
110
118
  directory = File.join(settings.view_directory, model_name)
111
119
  if File.exists?(directory)
112
120
  puts "Views for this model already exist. Skipping generation"
@@ -114,18 +122,9 @@ class Generator
114
122
 
115
123
  v = ViewBinding.new
116
124
  v.view_name = model_name
117
- v.fields = Hash.new
118
- (1 .. (args.length - 1)).each do |i|
119
- key_value = args[i].split(':')
120
- v.fields[key_value[0]] = key_value[1]
121
- end
125
+ v.fields = columns
122
126
  v.map_fields_to_html_tags
123
127
 
124
- (1 .. (args.length - 1)).each do |i|
125
- key_value = args[i].split(':')
126
- v.fields[key_value[0]] = key_value[1]
127
- end
128
-
129
128
  FileUtils.mkdir(directory)
130
129
  index_file = File.open(File.join(directory, "index.erb"), "w")
131
130
  index_file << ERB.new(File.open(File.join(settings.template_directory, "html" ,"index.html.erb")).read).result(v.get_binding)
@@ -143,11 +142,9 @@ class Generator
143
142
  new_file << ERB.new(File.open(File.join(settings.template_directory, "html" ,"new.html.erb")).read).result(v.get_binding)
144
143
  new_file.close
145
144
 
146
- puts "Views Created."
145
+ puts "Views for #{model_name.capitalize} Created."
147
146
 
148
147
  end
149
-
150
-
151
148
  end
152
149
 
153
150
 
@@ -181,20 +178,18 @@ class Generator
181
178
  end
182
179
  end
183
180
 
184
- app_file << line("Sinatra::Base.set :public, File.join(File.dirname(File.dirname(__FILE__)), 'public')")
181
+ app_file << line("Sinatra::Base.set :public, File.join(File.dirname(__FILE__), 'public')")
185
182
 
186
183
  controller_names.each do |controller|
187
184
  app_file << line("map \"/#{controller.downcase.gsub("controller", "")}\" do")
188
- #app_file << line("Sinatra::Base.set :public, File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'public'))", 1)
189
- #app_file << line("p File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'public'))", 1)
190
- app_file << line("DataMapper.setup(:default, \"sqlite3://#{settings.database_directory.gsub(settings.project_root + "/", "")}/development.sqlite3\")" , 1)
191
- app_file << line("controller = #{controller.gsub("controller", "Controller")}.new(File.dirname(File.dirname(__FILE__)))", 1)
185
+ app_file << line("DataMapper.setup(:default, ENV['DATABASE_URL'] || \"sqlite3://#{settings.database_directory}/development.sqlite3\")" , 1)
186
+ app_file << line("controller = #{controller.gsub("controller", "Controller")}.new(File.dirname(__FILE__))", 1)
192
187
  app_file << line("run controller", 1)
193
188
  app_file << line("end")
194
189
  end
195
190
 
196
191
  app_file << line("map \"/public\" do")
197
- app_file << line("run RIPController.new(File.dirname(File.dirname(__FILE__)))", 1)
192
+ app_file << line("run RIPController.new(File.dirname(__FILE__))", 1)
198
193
  app_file << line("end")
199
194
 
200
195
  app_file.close
@@ -203,6 +198,36 @@ class Generator
203
198
 
204
199
  private
205
200
 
201
+ def parse_arguments(*args)
202
+ arguments = Hash.new
203
+
204
+ # First argument has to be entity name
205
+ arguments["entity"] = args[0].downcase
206
+
207
+
208
+ columns = Hash.new
209
+ associations = Hash.new
210
+
211
+ # Iterate over rest of the arguments
212
+ (1 .. (args.length - 1)).each do |index|
213
+ key_value = args[index].split(':')
214
+ key_value[0] = key_value[0].downcase
215
+ key_value[1] = key_value[1].downcase.singularize
216
+
217
+ # Check if argument is part a known association
218
+ if key_value[0] == "has_many" || key_value[0] == "belongs_to" || key_value[0] == "has_and_belongs_to_many"
219
+ associations[key_value[1]] = key_value[0] # Key is the name of the entity
220
+ else
221
+ columns[key_value[0]] = key_value[1]
222
+ end
223
+ end
224
+
225
+ arguments["columns"] = columns
226
+ arguments["associations"] = associations
227
+
228
+ return arguments
229
+ end
230
+
206
231
  def line(str, indent=0)
207
232
  out_str = ""
208
233
  indent.times do
@@ -212,49 +237,3 @@ class Generator
212
237
  end
213
238
 
214
239
  end
215
-
216
- class ModelViewBinding
217
-
218
- attr_accessor :model_name, :columns
219
-
220
- def get_binding
221
- binding
222
- end
223
-
224
- end
225
-
226
- class ControllerViewBinding
227
-
228
- attr_accessor :controller_name
229
-
230
- def get_binding
231
- binding
232
- end
233
-
234
- end
235
-
236
- class ViewBinding
237
-
238
- attr_accessor :view_name, :fields, :html_tags
239
-
240
- def get_binding
241
- binding
242
- end
243
-
244
- def map_fields_to_html_tags
245
- @html_tags = Hash.new
246
- @fields.each do |key, value|
247
- @html_tags[key] = tag_for_field_type(value)
248
- end
249
- end
250
-
251
- def tag_for_field_type(type)
252
- case type
253
- when "string"
254
- "text" #for now, only text inputs will work. Really need to think this through.
255
- else
256
- "text"
257
- end
258
- end
259
-
260
- end
@@ -12,7 +12,7 @@ class Migration
12
12
  end
13
13
  end
14
14
  DataMapper.setup(:default, "sqlite3://#{settings.database_directory}/development.sqlite3")
15
- DataMapper.auto_migrate!
15
+ DataMapper.auto_upgrade!
16
16
  puts "All #{count} Migrations Complete"
17
17
  end
18
18
 
@@ -21,6 +21,11 @@ class ProjectSettings
21
21
  # Gem Specific Paths
22
22
  self.template_directory = File.join("#{File.dirname(__FILE__)}", "templates")
23
23
 
24
+ self
25
+ end
26
+
27
+ def get_config_options
28
+ YAML::load(File.open(File.join(self.config_directory, "config.yml"), "r").read)
24
29
  end
25
30
 
26
31
  end
@@ -0,0 +1,99 @@
1
+ require 'grit'
2
+ class RIPCloud
3
+
4
+ def initialize(project_root)
5
+ @settings = ProjectSettings.new(project_root)
6
+ end
7
+
8
+ def deploy
9
+
10
+ create_rackup_config
11
+
12
+ migrate_databases
13
+
14
+ repo = create_git_repository
15
+
16
+ if commit_latest_changes(repo)
17
+
18
+ puts "Changes committed to git repository"
19
+
20
+ create_heroku_application unless heroku_remote_exists?
21
+
22
+ push_changes_to_heroku
23
+
24
+ sync_databases
25
+
26
+ else
27
+ puts "Failed to make commit to Git repository"
28
+ end
29
+
30
+ end
31
+
32
+ def create_rackup_config
33
+ ServerManager.new(@settings.project_root).create_rackup_config
34
+ end
35
+
36
+ def migrate_databases
37
+
38
+ Migration.new.migrate(@settings.project_root)
39
+
40
+ end
41
+
42
+ def heroku_remote_exists?
43
+
44
+ exists = true # Pessimistic, dont want to create Heroku apps left and right
45
+
46
+ Dir.chdir(@settings.project_root) do
47
+ remotes = `git remote show`
48
+ exists = false if remotes.match("heroku").to_s != "heroku"
49
+ end
50
+
51
+ exists
52
+
53
+ end
54
+
55
+ def create_git_repository
56
+
57
+ unless File.exists?(File.join(@settings.project_root, ".git"))
58
+
59
+ Dir.chdir(@settings.project_root) do
60
+ system("git init")
61
+ end
62
+
63
+ else
64
+ puts "Git repository already exists"
65
+ end
66
+
67
+ repo = Grit::Repo.new(@settings.project_root)
68
+
69
+ end
70
+
71
+ def commit_latest_changes(repo)
72
+ repo.add(@settings.project_root)
73
+ repo.commit_all("Rest in Peace: Deployment to Heroku at #{Time.now.to_s}")
74
+ end
75
+
76
+ def create_heroku_application
77
+
78
+ Dir.chdir(@settings.project_root) do
79
+ heroku_app = @settings.get_config_options["heroku_app"] || ""
80
+ system "heroku create #{heroku_app} --stack bamboo-ree-1.8.7"
81
+ end
82
+
83
+ end
84
+
85
+ def push_changes_to_heroku
86
+
87
+ Dir.chdir(@settings.project_root) do
88
+ system "git push heroku master"
89
+ end
90
+
91
+ end
92
+
93
+ def sync_databases
94
+ Dir.chdir(@settings.project_root) do
95
+ system "heroku db:push sqlite://#{@settings.database_directory}/development.sqlite3"
96
+ end
97
+ end
98
+
99
+ end
@@ -21,9 +21,13 @@ class RIPController < Sinatra::Base
21
21
  end
22
22
  end
23
23
 
24
- def to_html(view, controller=self)
24
+ def to_html(view, entity = self.class.to_s)
25
+ # Check if the view to be displayed is the default one for the controller
26
+ if entity != self.class.to_s
27
+ @parent_entity = self.class.to_s.downcase.gsub("controller", "").strip
28
+ end
25
29
  content_type("text/html")
26
- Sinatra::Base.set(:views, File.join(@settings.view_directory, controller.class.to_s.downcase.gsub("controller", "")))
30
+ Sinatra::Base.set(:views, File.join(@settings.view_directory, entity.downcase.gsub("controller", "").strip))
27
31
  @yield = erb(view)
28
32
  ERB.new(File.open(File.join(@settings.view_directory, "layouts", "application.html.erb")).read).result(binding)
29
33
  end
@@ -1,18 +1,25 @@
1
1
  class ServerManager
2
2
 
3
- def start_server(project_root)
4
-
5
- settings = ProjectSettings.new(project_root)
3
+ def initialize(project_root)
4
+ @settings = ProjectSettings.new(project_root)
5
+ end
6
6
 
7
- Generator.new(project_root).generate_rackup_config
7
+ def start_server
8
+
9
+ create_rackup_config
10
+
11
+ config_options = @settings.get_config_options
8
12
 
9
13
  puts "--------------------------------------------------------------------------------"
14
+ puts "-------------------- Dead man walking at localhost:#{config_options["server_port"]} ------------------------"
10
15
  puts "--------------------------------------------------------------------------------"
11
- puts "-------------------- Dead man walking at localhost:4567 ------------------------"
12
- puts "--------------------------------------------------------------------------------"
13
- puts "--------------------------------------------------------------------------------"
14
- system "rackup #{File.join(settings.project_root, "config.ru")} -p 4567 -s webrick"
15
16
 
17
+ system "rackup #{File.join(@settings.project_root, "config.ru")} -p #{config_options["server_port"]} -s #{config_options["server_adapter"]}"
18
+
19
+ end
20
+
21
+ def create_rackup_config
22
+ Generator.new(@settings.project_root).generate_rackup_config
16
23
  end
17
24
 
18
25
  end
@@ -0,0 +1,7 @@
1
+ source :gemcutter
2
+ gem "rest_in_peace"
3
+ gem "datamapper"
4
+ gem "sinatra"
5
+ gem "builder"
6
+ gem "data_objects"
7
+ gem "do_postgres"
@@ -0,0 +1,4 @@
1
+ server_adapter: webrick
2
+ server_port: 4567
3
+ database_adapter: sqlite
4
+ # heroku_app: my_rip_app
@@ -1,52 +1,118 @@
1
1
  class <%= @controller_name.capitalize %>Controller < RIPController
2
+
3
+ <% @dependent_entity.each do |entity| %>
4
+
5
+ # Show all <%= entity.pluralize %> for a particular <%= @controller_name %>
6
+ # HTTP GET at /<%= @controller_name %>/1/<%= entity %>
7
+ get "/:id/<%= entity %>/?" do
8
+ @<%= entity.pluralize %> = <%= @controller_name.capitalize %>.get(params[:id]).<%= entity.pluralize %>
9
+ #to_xml(@<%= @controller_name %>)
10
+ to_html(:index,"<%= entity %>")
11
+ end
12
+
13
+ # Show a page where you can fill in details for adding a new <%= entity %> for a <%= @controller_name %>
14
+ # HTTP GET at /<%= @controller_name %>/1/<%= entity %>/new
15
+ get "/:id/<%= entity %>/new" do
16
+ @<%= entity %> = <%= entity.capitalize %>.new
17
+ to_html(:new, "<%= entity %>")
18
+ end
19
+
20
+ # Show the edit page for a particular <%= entity %> of a <%= @controller_name %>
21
+ # HTTP GET at /<%= @controller_name %>/1/<%= entity %>/1/edit
22
+ get "/:id/<%= entity %>/:id2/edit" do
23
+ @<%= entity %> = <%= @controller_name.capitalize %>.get(params[:id]).<%= entity.pluralize %>.get(params[:id2])
24
+ #to_xml(@<%= @controller_name %>)
25
+ to_html(:edit, "<%= entity %>")
26
+ end
27
+
28
+ # Add a new <%= entity %> for a particular <%= @controller_name %>
29
+ # HTTP POST at /<%= @controller_name %>/1/<%= entity %>
30
+ post "/:id/<%= entity %>" do
31
+ @<%= entity %> = <%= entity.capitalize %>.new
32
+ @<%= entity %>.attributes = params[:<%= entity %>]
33
+ @<%= entity %>.save
34
+ #to_xml(@<%= entity %>)
35
+ to_html(:show, "<%= entity %>")
36
+ end
37
+
38
+ # Edit a particular <%= entity %> for a <%= @controller_name %>
39
+ # HTTP PUT at /<%= @controller_name %>/1/<%= entity %>/1
40
+ put "/:id/<%= entity %>/:id2/?" do
41
+ @<%= entity %> = <%= @controller_name.capitalize %>.get(params[:id]).<%= entity.pluralize %>.get(params[:id2])
42
+ @<%= entity %>.update(params[:<%= entity %>])
43
+ #to_xml(@<%= entity %>)
44
+ to_html(:show, "<%= entity %>")
45
+ end
46
+
47
+ # Delete a particular <%= entity %> for a <%= @controller_name %>
48
+ # HTTP DELETE at /<%= @controller_name %>/1/<%= entity %>/1
49
+ delete "/:id/<%= entity/:id2 %>" do
50
+ @<%= entity %> = <%= entity.capitalize %>.get(params[:id]).<%= entity.pluralize %>.get(params[:id2])
51
+ @<%= entity %>.destroy!
52
+ #to_xml(<%= entity %>)
53
+ to_html(:index, "<%= entity %>")
54
+ end
55
+ <% end %>
2
56
 
3
- # HTTP GET
57
+ # Shows list of all <%= @controller_name.pluralize %>
58
+ # HTTP GET at /<%= @controller_name %>
4
59
  get "/?" do
5
- @<%= @controller_name.downcase %>s = <%= @controller_name.capitalize %>.all
6
- #to_xml(<%= @controller_name.downcase %>s)
7
- to_html(:index)
60
+ @<%= @controller_name.pluralize %> = <%= @controller_name.capitalize %>.all
61
+ #to_xml(@<%= @controller_name.pluralize %>)
62
+ to_html(:index)
8
63
  end
9
64
 
65
+ # Show a page where you can fill in details for adding a new <%= @controller_name %>
66
+ # HTTP GET at /<%= @controller_name %>/new
10
67
  get "/new" do
11
- @<%= @controller_name.downcase %> = <%= @controller_name.capitalize %>.new
12
- #to_xml(<%= @controller_name.downcase %>)
13
- to_html(:new)
68
+ @<%= @controller_name %> = <%= @controller_name.capitalize %>.new
69
+ to_html(:new)
14
70
  end
15
71
 
72
+ # Show a particular <%= @controller_name %>
73
+ # HTTP GET at /<%= @controller_name %>/1
16
74
  get "/:id" do
17
- @<%= @controller_name.downcase %> = <%= @controller_name.capitalize %>.get(params[:id])
18
- #to_xml(<%= @controller_name.downcase %>)
19
- to_html(:show)
75
+ @<%= @controller_name %> = <%= @controller_name.capitalize %>.get(params[:id])
76
+ #to_xml(@<%= @controller_name %>)
77
+ to_html(:show)
20
78
  end
21
-
79
+
80
+ # Show the edit page for a particular <%= @controller_name %>
81
+ # HTTP GET at /<%= @controller_name %>/1/edit
22
82
  get "/:id/edit" do
23
- @<%= @controller_name.downcase %> = <%= @controller_name.capitalize %>.get(params[:id])
24
- #to_xml(<%= @controller_name.downcase %>)
25
- to_html(:edit)
83
+ @<%= @controller_name %> = <%= @controller_name.capitalize %>.get(params[:id])
84
+ #to_xml(@<%= @controller_name %>)
85
+ to_html(:edit)
26
86
  end
27
87
 
28
- # HTTP POST
88
+
89
+ # Add a new <%= @controller_name %>
90
+ # HTTP POST at /<%= @controller_name %>
29
91
  post "/?" do
30
- @<%= @controller_name.downcase %> = <%= @controller_name.capitalize %>.new
31
- @<%= @controller_name.downcase %>.attributes = params[:<%= @controller_name.downcase %>]
32
- @<%= @controller_name.downcase %>.save
33
- #to_xml(<%= @controller_name.downcase %>)
34
- to_html(:show)
92
+ @<%= @controller_name %> = <%= @controller_name.capitalize %>.new
93
+ @<%= @controller_name %>.attributes = params[:<%= @controller_name %>]
94
+ @<%= @controller_name %>.save
95
+ #to_xml(@<%= @controller_name %>)
96
+ to_html(:show)
35
97
  end
36
-
37
- # HTTP PUT
38
- put "/:id" do
39
- @<%= @controller_name.downcase %> = <%= @controller_name.capitalize %>.get(params[:id])
40
- @<%= @controller_name.downcase %>.update(params[:<%= @controller_name.downcase %>])
41
- #to_xml(<%= @controller_name.downcase %>)
42
- to_html(:show)
98
+
99
+ # Edit a <%= @controller_name %>
100
+ # HTTP PUT at /<%= @controller_name %>/1
101
+ put "/:id/?" do
102
+ @<%= @controller_name %> = <%= @controller_name.capitalize %>.get(params[:id])
103
+ @<%= @controller_name %>.update(params[:<%= @controller_name %>])
104
+ #to_xml(@<%= @controller_name %>)
105
+ to_html(:show)
43
106
  end
44
107
 
45
- # HTTP DELETE
108
+
109
+ # Delete a <%= @controller_name %>
110
+ # HTTP DELETE at /<%= @controller_name %>/1
46
111
  delete "/:id" do
47
- @<%= @controller_name.downcase %> = <%= @controller_name.capitalize %>.get(params[:id])
48
- @<%= @controller_name.downcase %>.destroy!
49
- #to_xml(<%= @controller_name.downcase %>)
50
- to_html(:index)
112
+ @<%= @controller_name %> = <%= @controller_name.capitalize %>.get(params[:id])
113
+ @<%= @controller_name %>.destroy!
114
+ #to_xml(<%= @controller_name %>)
115
+ to_html(:index)
51
116
  end
117
+
52
118
  end
@@ -1,5 +1,9 @@
1
1
  <h1>Editing <%= @view_name %></h1>
2
- <form action="/<%= @view_name %>/<%%= params[:id] %>" method="post" accept-charset="utf-8">
2
+ <%% if @parent_entity %>
3
+ <form action="/<%%= @parent_entity %>/<%%= params[:id] %>/<%= @view_name %>/<%%= params[:id] %>" method="post" accept-charset="utf-8">
4
+ <%% else %>
5
+ <form action="/<%= @view_name %>/<%%= params[:id] %>" method="post" accept-charset="utf-8">
6
+ <%% end %>
3
7
  <input type="hidden" id="_method" name="_method" value="put" />
4
8
  <% @html_tags.each do |key, value| %>
5
9
  <p>
@@ -6,7 +6,7 @@
6
6
  <% end %>
7
7
 
8
8
  </tr>
9
- <%% <%= "@#{@view_name}s.each do |#{@view_name}|" %> %>
9
+ <%% <%= "@#{@view_name.downcase.pluralize}.each do |#{@view_name.downcase}|" %> %>
10
10
  <tr>
11
11
  <% @html_tags.each do |key, value| %>
12
12
  <td><%%= <%= "#{@view_name}.#{key}" %> %></td>
@@ -15,5 +15,9 @@
15
15
  <%% end %>
16
16
  </table>
17
17
  <p>
18
- <a href="/<%= @view_name %>/new">Add new <%= @view_name.capitalize %></a>
18
+ <%% if @parent_entity %>
19
+ <a href="/<%%= @parent_entity %>/<%%= params[:id] %>/<%= @view_name %>/new">Add new <%= @view_name.capitalize %></a>
20
+ <%% else %>
21
+ <a href="/<%= @view_name %>/new">Add new <%= @view_name.capitalize %></a>
22
+ <%% end %>
19
23
  </p>
@@ -1,11 +1,20 @@
1
1
  <h1>New <%= @view_name %></h1>
2
- <form action="/<%= @view_name %>" method="post" accept-charset="utf-8">
2
+ <%% if @parent_entity %>
3
+ <form action="/<%%= @parent_entity %>/<%%= params[:id] %>/<%= @view_name %>" method="post" accept-charset="utf-8">
4
+ <input type="hidden" id="<%= "#{@view_name}" %><%%= "_#{@parent_entity}_id" %>" name="<%= "#{@view_name}" %><%%= "[#{@parent_entity}_id]" %>" value="<%%= params[:id] %>" />
5
+ <%% else %>
6
+ <form action="/<%= @view_name %>" method="post" accept-charset="utf-8">
7
+ <%% end %>
3
8
  <% @html_tags.each do |key, value| %>
4
9
  <p>
5
10
  <label for="<%= key %>"><%= key.capitalize %></label><br />
6
11
  <input type="<%= value %>" name="<%= "#{@view_name}[#{key}]" %>" value="" id="<%= "#{@view_name}_#{key}" %>">
7
- </p>
12
+ </p>
8
13
  <% end %>
9
14
  <p><input type="submit" value="Submit &rarr;"></p>
10
- <a href="/<%= @view_name %>">Back</a>
15
+ <%% if @parent_entity %>
16
+ <a href="/<%%= @parent_entity %>/<%%= params[:id] %>/<%= @view_name %>">Back</a>
17
+ <%% else %>
18
+ <a href="/<%= @view_name %>">Back</a>
19
+ <%% end %>
11
20
  </form>
@@ -5,5 +5,10 @@
5
5
  <%= key.capitalize %>: <%%= <%= "@#{@view_name}.#{key}" %> %>
6
6
  </p>
7
7
  <% end %>
8
- <a href="/<%= @view_name %>">Back</a> |
9
- <a href="/<%= @view_name %>/<%%= params[:id] %>/edit">Edit</a>
8
+ <%% if @parent_entity %>
9
+ <a href=/<%%= @parent_entity %>/<%%= params[:id] %>"/<%= @view_name %>">Back</a> |
10
+ <a href="/<%%= @parent_entity %>/<%%= params[:id] %>/<%= @view_name %>/<%%= params[:id] %>/edit">Edit</a>
11
+ <%% else %>
12
+ <a href="/<%= @view_name %>">Back</a> |
13
+ <a href="/<%= @view_name %>/<%%= params[:id] %>/edit">Edit</a>
14
+ <%% end %>
@@ -1,9 +1,11 @@
1
1
  class <%= @model_name.capitalize %>
2
2
 
3
3
  include DataMapper::Resource
4
-
5
- property :id, Serial
4
+ property :id, Serial
6
5
  <% @columns.each do |key, value| %>
7
6
  property :<%= key %>, <%= value.capitalize %>
8
7
  <% end %>
8
+ <% @statements.each do |statement| %>
9
+ <%= statement %>
10
+ <% end %>
9
11
  end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'rest_in_peace'
4
+ project_root = File.dirname(File.dirname(__FILE__))
5
+ RIPCloud.new(project_root).deploy
@@ -2,4 +2,4 @@
2
2
  require 'rubygems'
3
3
  require 'rest_in_peace'
4
4
  project_root = File.dirname(File.dirname(__FILE__))
5
- ServerManager.new.start_server(project_root)
5
+ ServerManager.new(project_root).start_server
data/lib/rest_in_peace.rb CHANGED
@@ -1,9 +1,16 @@
1
1
  require 'datamapper'
2
2
  require 'sinatra/base'
3
3
  require 'rest_in_peace/rip_controller'
4
+ require 'active_support'
4
5
  autoload :Generator, 'rest_in_peace/generator'
5
6
  autoload :Builder, 'builder'
6
7
  autoload :ProjectSettings, 'rest_in_peace/project_settings'
7
8
  autoload :ERB, 'erb'
8
9
  autoload :ServerManager, 'rest_in_peace/server_manager'
9
- autoload :Migration, 'rest_in_peace/migration'
10
+ autoload :Migration, 'rest_in_peace/migration'
11
+ autoload :ModelViewBinding, 'rest_in_peace/bindings/model_view_binding'
12
+ autoload :ControllerViewBinding, 'rest_in_peace/bindings/controller_view_binding'
13
+ autoload :ViewBinding, 'rest_in_peace/bindings/view_binding'
14
+ autoload :Bundler, 'bundler'
15
+ autoload :YAML, 'yaml'
16
+ autoload :RIPCloud, 'rest_in_peace/rip_cloud'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rest_in_peace}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chinmay Garde"]
12
- s.date = %q{2010-03-16}
12
+ s.date = %q{2010-04-25}
13
13
  s.default_executable = %q{rip}
14
14
  s.description = %q{Minimal web framework with a focus on simplicity. Powered by Sinatra and DataMapper}
15
15
  s.email = %q{chinmaygarde@gmail.com}
@@ -26,13 +26,18 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "bin/rip",
28
28
  "lib/rest_in_peace.rb",
29
+ "lib/rest_in_peace/bindings/controller_view_binding.rb",
30
+ "lib/rest_in_peace/bindings/model_view_binding.rb",
31
+ "lib/rest_in_peace/bindings/view_binding.rb",
29
32
  "lib/rest_in_peace/generator.rb",
30
33
  "lib/rest_in_peace/migration.rb",
31
34
  "lib/rest_in_peace/project_settings.rb",
35
+ "lib/rest_in_peace/rip_cloud.rb",
32
36
  "lib/rest_in_peace/rip_controller.rb",
33
37
  "lib/rest_in_peace/server_manager.rb",
38
+ "lib/rest_in_peace/templates/Gemfile",
39
+ "lib/rest_in_peace/templates/config.yml",
34
40
  "lib/rest_in_peace/templates/controller.rb.erb",
35
- "lib/rest_in_peace/templates/gems",
36
41
  "lib/rest_in_peace/templates/html/edit.html.erb",
37
42
  "lib/rest_in_peace/templates/html/index.html.erb",
38
43
  "lib/rest_in_peace/templates/html/layout.html.erb",
@@ -41,6 +46,7 @@ Gem::Specification.new do |s|
41
46
  "lib/rest_in_peace/templates/image/favicon.ico",
42
47
  "lib/rest_in_peace/templates/model.rb.erb",
43
48
  "lib/rest_in_peace/templates/readme.txt.erb",
49
+ "lib/rest_in_peace/templates/script/cloud",
44
50
  "lib/rest_in_peace/templates/script/define",
45
51
  "lib/rest_in_peace/templates/script/migrate",
46
52
  "lib/rest_in_peace/templates/script/server",
@@ -64,24 +70,27 @@ Gem::Specification.new do |s|
64
70
  s.specification_version = 3
65
71
 
66
72
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
68
73
  s.add_development_dependency(%q<sinatra>, [">= 0.9.4"])
69
74
  s.add_development_dependency(%q<datamapper>, [">= 0.10.2"])
70
- s.add_development_dependency(%q<builder>, [">= 2.2.2"])
75
+ s.add_development_dependency(%q<builder>, [">= 0"])
71
76
  s.add_development_dependency(%q<taps>, [">= 0.2.26"])
77
+ s.add_development_dependency(%q<bundler>, [">= 0.9.11"])
78
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
72
79
  else
73
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
74
80
  s.add_dependency(%q<sinatra>, [">= 0.9.4"])
75
81
  s.add_dependency(%q<datamapper>, [">= 0.10.2"])
76
- s.add_dependency(%q<builder>, [">= 2.2.2"])
82
+ s.add_dependency(%q<builder>, [">= 0"])
77
83
  s.add_dependency(%q<taps>, [">= 0.2.26"])
84
+ s.add_dependency(%q<bundler>, [">= 0.9.11"])
85
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
78
86
  end
79
87
  else
80
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
81
88
  s.add_dependency(%q<sinatra>, [">= 0.9.4"])
82
89
  s.add_dependency(%q<datamapper>, [">= 0.10.2"])
83
- s.add_dependency(%q<builder>, [">= 2.2.2"])
90
+ s.add_dependency(%q<builder>, [">= 0"])
84
91
  s.add_dependency(%q<taps>, [">= 0.2.26"])
92
+ s.add_dependency(%q<bundler>, [">= 0.9.11"])
93
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
85
94
  end
86
95
  end
87
96
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Chinmay Garde
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-16 00:00:00 +05:30
17
+ date: 2010-04-25 00:00:00 +05:30
18
18
  default_executable: rip
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
21
+ name: sinatra
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
@@ -26,11 +26,13 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 0
29
- version: "0"
29
+ - 9
30
+ - 4
31
+ version: 0.9.4
30
32
  type: :development
31
33
  version_requirements: *id001
32
34
  - !ruby/object:Gem::Dependency
33
- name: sinatra
35
+ name: datamapper
34
36
  prerelease: false
35
37
  requirement: &id002 !ruby/object:Gem::Requirement
36
38
  requirements:
@@ -38,13 +40,13 @@ dependencies:
38
40
  - !ruby/object:Gem::Version
39
41
  segments:
40
42
  - 0
41
- - 9
42
- - 4
43
- version: 0.9.4
43
+ - 10
44
+ - 2
45
+ version: 0.10.2
44
46
  type: :development
45
47
  version_requirements: *id002
46
48
  - !ruby/object:Gem::Dependency
47
- name: datamapper
49
+ name: builder
48
50
  prerelease: false
49
51
  requirement: &id003 !ruby/object:Gem::Requirement
50
52
  requirements:
@@ -52,27 +54,25 @@ dependencies:
52
54
  - !ruby/object:Gem::Version
53
55
  segments:
54
56
  - 0
55
- - 10
56
- - 2
57
- version: 0.10.2
57
+ version: "0"
58
58
  type: :development
59
59
  version_requirements: *id003
60
60
  - !ruby/object:Gem::Dependency
61
- name: builder
61
+ name: taps
62
62
  prerelease: false
63
63
  requirement: &id004 !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  segments:
68
+ - 0
68
69
  - 2
69
- - 2
70
- - 2
71
- version: 2.2.2
70
+ - 26
71
+ version: 0.2.26
72
72
  type: :development
73
73
  version_requirements: *id004
74
74
  - !ruby/object:Gem::Dependency
75
- name: taps
75
+ name: bundler
76
76
  prerelease: false
77
77
  requirement: &id005 !ruby/object:Gem::Requirement
78
78
  requirements:
@@ -80,11 +80,23 @@ dependencies:
80
80
  - !ruby/object:Gem::Version
81
81
  segments:
82
82
  - 0
83
- - 2
84
- - 26
85
- version: 0.2.26
83
+ - 9
84
+ - 11
85
+ version: 0.9.11
86
86
  type: :development
87
87
  version_requirements: *id005
88
+ - !ruby/object:Gem::Dependency
89
+ name: thoughtbot-shoulda
90
+ prerelease: false
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ type: :development
99
+ version_requirements: *id006
88
100
  description: Minimal web framework with a focus on simplicity. Powered by Sinatra and DataMapper
89
101
  email: chinmaygarde@gmail.com
90
102
  executables:
@@ -102,13 +114,18 @@ files:
102
114
  - VERSION
103
115
  - bin/rip
104
116
  - lib/rest_in_peace.rb
117
+ - lib/rest_in_peace/bindings/controller_view_binding.rb
118
+ - lib/rest_in_peace/bindings/model_view_binding.rb
119
+ - lib/rest_in_peace/bindings/view_binding.rb
105
120
  - lib/rest_in_peace/generator.rb
106
121
  - lib/rest_in_peace/migration.rb
107
122
  - lib/rest_in_peace/project_settings.rb
123
+ - lib/rest_in_peace/rip_cloud.rb
108
124
  - lib/rest_in_peace/rip_controller.rb
109
125
  - lib/rest_in_peace/server_manager.rb
126
+ - lib/rest_in_peace/templates/Gemfile
127
+ - lib/rest_in_peace/templates/config.yml
110
128
  - lib/rest_in_peace/templates/controller.rb.erb
111
- - lib/rest_in_peace/templates/gems
112
129
  - lib/rest_in_peace/templates/html/edit.html.erb
113
130
  - lib/rest_in_peace/templates/html/index.html.erb
114
131
  - lib/rest_in_peace/templates/html/layout.html.erb
@@ -117,6 +134,7 @@ files:
117
134
  - lib/rest_in_peace/templates/image/favicon.ico
118
135
  - lib/rest_in_peace/templates/model.rb.erb
119
136
  - lib/rest_in_peace/templates/readme.txt.erb
137
+ - lib/rest_in_peace/templates/script/cloud
120
138
  - lib/rest_in_peace/templates/script/define
121
139
  - lib/rest_in_peace/templates/script/migrate
122
140
  - lib/rest_in_peace/templates/script/server
@@ -1 +0,0 @@
1
- rest_in_peace --version '0.1.1'