rest_in_peace 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg
2
+ pkg/*
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Chinmay Garde
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,31 @@
1
+ ReST in Peace
2
+ =============
3
+
4
+ Minimal web framework with a focus on simplicity. Powered by Sinatra and DataMapper.
5
+
6
+ Setup
7
+ -----
8
+
9
+ Get the Gem
10
+
11
+ gem install rest_in_peace
12
+
13
+ Getting Started
14
+ ---------------
15
+
16
+ 1. Generate the project skeleton
17
+ rip blogger
18
+
19
+ 2. Move into the project directory
20
+ cd blogger
21
+
22
+ 3. Generate model and controller
23
+ script/define Post title:string body:string
24
+
25
+ 4. Migrate database
26
+ script/migrate
27
+
28
+ 5. Start server
29
+ script/server
30
+
31
+ 6. Browse to http://localhost:4567/post
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rest_in_peace"
8
+ gem.summary = %Q{ReST in Peace}
9
+ gem.description = %Q{Minimal web framework with a focus on simplicity. Powered by Sinatra and DataMapper}
10
+ gem.email = "chinmaygarde@gmail.com"
11
+ gem.homepage = "http://github.com/chinmaygarde/rest_in_peace"
12
+ gem.authors = ["Chinmay Garde"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.add_development_dependency "datamapper", ">= 0.10.2"
15
+ gem.add_development_dependency "builder", ">= 2.2.2"
16
+ gem.add_development_dependency "sinatra", ">= 0.9.4"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "rest_in_peace #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/rip ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'rest_in_peace'
4
+ Generator.new(*ARGV).generate_project
@@ -0,0 +1,258 @@
1
+ class Generator
2
+
3
+ attr_accessor :settings
4
+
5
+ def initialize(root_dir)
6
+ self.settings = ProjectSettings.new(root_dir)
7
+ end
8
+
9
+ def generate_project
10
+
11
+ if File.exists?(settings.project_root)
12
+ puts "A project with that name already exists. Move that project or change the name of the new one."
13
+ return
14
+ end
15
+
16
+ FileUtils.mkdir(settings.project_root)
17
+ FileUtils.mkdir(settings.app_directory)
18
+ FileUtils.mkdir(settings.controller_directory)
19
+ FileUtils.mkdir(settings.model_directory)
20
+ FileUtils.mkdir(settings.view_directory)
21
+ FileUtils.mkdir(settings.log_directory)
22
+ FileUtils.mkdir(settings.config_directory)
23
+ FileUtils.mkdir(settings.script_directory)
24
+ FileUtils.mkdir(settings.database_directory)
25
+ FileUtils.mkdir(settings.public_directory)
26
+ FileUtils.mkdir(File.join(settings.public_directory, "stylesheets"))
27
+ FileUtils.mkdir(File.join(settings.view_directory, "layouts"))
28
+ FileUtils.cp(File.join(settings.template_directory, "image", "favicon.ico"), settings.public_directory)
29
+
30
+ File.open(File.join(settings.project_root, "README"), "w") << File.open(File.join(settings.template_directory, "readme.txt.erb")).read
31
+
32
+ File.open(File.join(settings.view_directory, "layouts", "application.html.erb"), "w") << File.open(File.join(settings.template_directory, "html", "layout.html.erb")).read
33
+
34
+ File.open(File.join(settings.public_directory, "stylesheets", "main.css"), "w") << File.open(File.join(settings.template_directory, "stylesheet", "main.css")).read
35
+
36
+ define_file = File.open(File.join(settings.script_directory, "define"), "w")
37
+ define_file << File.open(File.join(settings.template_directory, "script", "define")).read
38
+
39
+ server_file = File.open(File.join(settings.script_directory, "server"), "w")
40
+ server_file << File.open(File.join(settings.template_directory, "script", "server")).read
41
+
42
+ migration_file = File.open(File.join(settings.script_directory, "migrate"), "w")
43
+ migration_file << File.open(File.join(settings.template_directory, "script", "migrate")).read
44
+
45
+ File.chmod(0755, define_file.path, server_file.path, migration_file.path)
46
+
47
+ puts "Your project is six feet under at #{settings.project_root}"
48
+ end
49
+
50
+ def generate_scaffold(*args)
51
+ generate_model(*args)
52
+ generate_controller(args[0])
53
+ generate_views(*args)
54
+ end
55
+
56
+ def generate_model(*args)
57
+
58
+ model_name = args[0]
59
+ columns = Hash.new
60
+
61
+ (1 .. (args.length - 1)).each do |i|
62
+ key_value = args[i].split(':')
63
+ columns[key_value[0]] = key_value[1]
64
+ end
65
+
66
+ b = ModelViewBinding.new
67
+ b.model_name = model_name
68
+ b.columns = columns
69
+
70
+ model_string = ERB.new(File.open( File.join(settings.template_directory, "model.rb.erb") ).read ).result(b.get_binding)
71
+
72
+ file_path = File.join(settings.model_directory, "#{model_name.capitalize}.rb")
73
+
74
+ if File.exists?(file_path)
75
+ puts "Model #{model_name.capitalize}.rb already exists. Migration Skipped."
76
+ else
77
+ puts "Model #{model_name.capitalize}.rb created."
78
+ outfile = File.open(file_path, "w")
79
+ outfile << model_string
80
+ outfile.close
81
+ end
82
+
83
+ end
84
+
85
+ def generate_controller(name)
86
+
87
+ b = ControllerViewBinding.new
88
+ b.controller_name = name
89
+
90
+ controller_string = ERB.new(File.open( File.join(settings.template_directory, "controller.rb.erb") ).read).result(b.get_binding)
91
+ file_path = File.join(settings.controller_directory, "#{name.capitalize}Controller.rb")
92
+
93
+ if(File.exists?(file_path))
94
+ puts "Controller #{name.capitalize}Controller.rb already exists. Migration Skipped."
95
+ else
96
+ puts "Controller #{name.capitalize}Controller.rb created."
97
+ outfile = File.open(file_path, "w")
98
+ outfile << controller_string
99
+ outfile.close
100
+ end
101
+
102
+ end
103
+
104
+
105
+ def generate_views(*args)
106
+ model_name = args[0].downcase
107
+
108
+ directory = File.join(settings.view_directory, model_name)
109
+ if File.exists?(directory)
110
+ puts "Views for this model already exist. Skipping generation"
111
+ else
112
+
113
+ v = ViewBinding.new
114
+ v.view_name = model_name
115
+ v.fields = Hash.new
116
+ (1 .. (args.length - 1)).each do |i|
117
+ key_value = args[i].split(':')
118
+ v.fields[key_value[0]] = key_value[1]
119
+ end
120
+ v.map_fields_to_html_tags
121
+
122
+ (1 .. (args.length - 1)).each do |i|
123
+ key_value = args[i].split(':')
124
+ v.fields[key_value[0]] = key_value[1]
125
+ end
126
+
127
+ FileUtils.mkdir(directory)
128
+ index_file = File.open(File.join(directory, "index.erb"), "w")
129
+ index_file << ERB.new(File.open(File.join(settings.template_directory, "html" ,"index.html.erb")).read).result(v.get_binding)
130
+ index_file.close
131
+
132
+ show_file = File.open(File.join(directory, "show.erb"), "w")
133
+ show_file << ERB.new(File.open(File.join(settings.template_directory, "html" ,"show.html.erb")).read).result(v.get_binding)
134
+ show_file.close
135
+
136
+ edit_file = File.open(File.join(directory, "edit.erb"), "w")
137
+ edit_file << ERB.new(File.open(File.join(settings.template_directory, "html" ,"edit.html.erb")).read).result(v.get_binding)
138
+ edit_file.close
139
+
140
+ new_file = File.open(File.join(directory, "new.erb"), "w")
141
+ new_file << ERB.new(File.open(File.join(settings.template_directory, "html" ,"new.html.erb")).read).result(v.get_binding)
142
+ new_file.close
143
+
144
+ puts "Views Created."
145
+
146
+ end
147
+
148
+
149
+ end
150
+
151
+
152
+ def generate_rackup_config
153
+
154
+ app_file = File.open(File.join(settings.config_directory, "config.ru"), "w")
155
+
156
+ app_file << line("require 'datamapper'")
157
+ app_file << line("require 'rest_in_peace'")
158
+ app_file << line("require 'sinatra/base'")
159
+ app_file << line("require 'builder'")
160
+
161
+ # Require all models
162
+ Dir.foreach(settings.model_directory) do |m|
163
+ file_path = File.join(settings.model_directory, m)
164
+ full_path = File.expand_path(file_path)
165
+
166
+ if File.extname(full_path) == ".rb"
167
+ app_file << line("require '#{full_path}'")
168
+ end
169
+ end
170
+
171
+ controller_names = []
172
+ # Load all controllers
173
+ Dir.foreach(settings.controller_directory) do |c|
174
+ file_path = File.join(settings.controller_directory, c)
175
+ full_path = File.expand_path(file_path)
176
+ if File.extname(full_path) == ".rb"
177
+ app_file << line("require '#{full_path}'")
178
+ controller_names << File.basename(full_path, File.extname(full_path)).capitalize
179
+ end
180
+ end
181
+
182
+ app_file << line("Sinatra::Base.set :public, File.join(File.dirname(File.dirname(__FILE__)), 'public')")
183
+
184
+ controller_names.each do |controller|
185
+ app_file << line("map \"/#{controller.downcase.gsub("controller", "")}\" do")
186
+ #app_file << line("Sinatra::Base.set :public, File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'public'))", 1)
187
+ #app_file << line("p File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'public'))", 1)
188
+ app_file << line("DataMapper.setup(:default, \"sqlite3://#{settings.database_directory}/development.sqlite3\")" , 1)
189
+ app_file << line("controller = #{controller.gsub("controller", "Controller")}.new(File.dirname(File.dirname(__FILE__)))", 1)
190
+ app_file << line("run controller", 1)
191
+ app_file << line("end")
192
+ end
193
+
194
+ app_file << line("map \"/public\" do")
195
+ app_file << line("run RIPController.new(File.dirname(File.dirname(__FILE__)))", 1)
196
+ app_file << line("end")
197
+
198
+ app_file.close
199
+
200
+ end
201
+
202
+ private
203
+
204
+ def line(str, indent=0)
205
+ out_str = ""
206
+ indent.times do
207
+ out_str = out_str + "\t"
208
+ end
209
+ out_str = out_str + str + "\n"
210
+ end
211
+
212
+ end
213
+
214
+ class ModelViewBinding
215
+
216
+ attr_accessor :model_name, :columns
217
+
218
+ def get_binding
219
+ binding
220
+ end
221
+
222
+ end
223
+
224
+ class ControllerViewBinding
225
+
226
+ attr_accessor :controller_name
227
+
228
+ def get_binding
229
+ binding
230
+ end
231
+
232
+ end
233
+
234
+ class ViewBinding
235
+
236
+ attr_accessor :view_name, :fields, :html_tags
237
+
238
+ def get_binding
239
+ binding
240
+ end
241
+
242
+ def map_fields_to_html_tags
243
+ @html_tags = Hash.new
244
+ @fields.each do |key, value|
245
+ @html_tags[key] = tag_for_field_type(value)
246
+ end
247
+ end
248
+
249
+ def tag_for_field_type(type)
250
+ case type
251
+ when "string"
252
+ "text" #for now, only text inputs will work. Really need to think this through.
253
+ else
254
+ "text"
255
+ end
256
+ end
257
+
258
+ end
@@ -0,0 +1,19 @@
1
+ class Migration
2
+
3
+ def migrate(project_root)
4
+ settings = ProjectSettings.new(project_root)
5
+ count = 0
6
+ Dir.foreach(settings.model_directory) do |m|
7
+ file_path = File.join(settings.model_directory, m)
8
+ full_path = File.expand_path(file_path)
9
+ if File.extname(full_path) == ".rb"
10
+ require "#{full_path}"
11
+ count = count + 1
12
+ end
13
+ end
14
+ DataMapper.setup(:default, "sqlite3://#{settings.database_directory}/development.sqlite3")
15
+ DataMapper.auto_migrate!
16
+ puts "All #{count} Migrations Complete"
17
+ end
18
+
19
+ end
@@ -0,0 +1,26 @@
1
+ class ProjectSettings
2
+
3
+ attr_accessor :project_root, :app_directory, :controller_directory, :model_directory,
4
+ :view_directory, :log_directory, :config_directory, :template_directory,
5
+ :script_directory, :database_directory, :public_directory
6
+
7
+ def initialize(root_dir)
8
+
9
+ # Project Specific Paths
10
+ self.project_root = File.expand_path(root_dir)
11
+ self.public_directory = File.join(root_dir, "public")
12
+ self.app_directory = File.join(root_dir, "app")
13
+ self.controller_directory = File.join(app_directory, "controllers")
14
+ self.model_directory = File.join(app_directory, "models")
15
+ self.view_directory = File.join(app_directory, "views")
16
+ self.log_directory = File.join(project_root, "log")
17
+ self.config_directory = File.join(project_root, "config")
18
+ self.script_directory = File.join(project_root, "script")
19
+ self.database_directory = File.join(project_root, "db")
20
+
21
+ # Gem Specific Paths
22
+ self.template_directory = File.join("#{File.dirname(__FILE__)}", "templates")
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,43 @@
1
+ class RIPController < Sinatra::Base
2
+ set :method_override, true
3
+
4
+ def initialize(project_root)
5
+ @settings = ProjectSettings.new(project_root)
6
+ end
7
+
8
+ # Converts an entity to its XML representation
9
+ def to_xml(entities)
10
+ content_type("text/xml")
11
+ xml = Builder::XmlMarkup.new
12
+ xml.instruct!
13
+ if entities.class.to_s == "DataMapper::Collection" # Bad idea!, problem to be solved another day :)
14
+ xml.results do
15
+ entities.each do |entity|
16
+ convert_entity(entity, xml)
17
+ end
18
+ end
19
+ else
20
+ convert_entity(entities, xml)
21
+ end
22
+ end
23
+
24
+ def to_html(view, controller=self)
25
+ content_type("text/html")
26
+ Sinatra::Base.set(:views, File.join(@settings.view_directory, controller.class.to_s.downcase.gsub("controller", "")))
27
+ @yield = erb(view)
28
+ ERB.new(File.open(File.join(@settings.view_directory, "layouts", "application.html.erb")).read).result(binding)
29
+ end
30
+
31
+ private
32
+
33
+ def convert_entity(entity, xml)
34
+ xml.tag!(entity.class.to_s.downcase) do |b|
35
+ entity.instance_variables.each do |v|
36
+ unless v.match(/@_*/).to_s == "@_"
37
+ b.tag!(v.gsub("@", ""), entity.instance_variable_get(v))
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,18 @@
1
+ class ServerManager
2
+
3
+ def start_server(project_root)
4
+
5
+ settings = ProjectSettings.new(project_root)
6
+
7
+ Generator.new(project_root).generate_rackup_config
8
+
9
+ puts "--------------------------------------------------------------------------------"
10
+ puts "--------------------------------------------------------------------------------"
11
+ puts "-------------------- Dead man walking at localhost:4567 ------------------------"
12
+ puts "--------------------------------------------------------------------------------"
13
+ puts "--------------------------------------------------------------------------------"
14
+ system "rackup #{File.join(settings.config_directory, "config.ru")} -p 4567 -s webrick"
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,52 @@
1
+ class <%= @controller_name.capitalize %>Controller < RIPController
2
+
3
+ # HTTP GET
4
+ get "/?" do
5
+ @<%= @controller_name.downcase %>s = <%= @controller_name.capitalize %>.all
6
+ #to_xml(<%= @controller_name.downcase %>s)
7
+ to_html(:index)
8
+ end
9
+
10
+ get "/new" do
11
+ @<%= @controller_name.downcase %> = <%= @controller_name.capitalize %>.new
12
+ #to_xml(<%= @controller_name.downcase %>)
13
+ to_html(:new)
14
+ end
15
+
16
+ get "/:id" do
17
+ @<%= @controller_name.downcase %> = <%= @controller_name.capitalize %>.get(params[:id])
18
+ #to_xml(<%= @controller_name.downcase %>)
19
+ to_html(:show)
20
+ end
21
+
22
+ get "/:id/edit" do
23
+ @<%= @controller_name.downcase %> = <%= @controller_name.capitalize %>.get(params[:id])
24
+ #to_xml(<%= @controller_name.downcase %>)
25
+ to_html(:edit)
26
+ end
27
+
28
+ # HTTP POST
29
+ 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)
35
+ 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)
43
+ end
44
+
45
+ # HTTP DELETE
46
+ 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)
51
+ end
52
+ end
@@ -0,0 +1,11 @@
1
+ <h1>Editing <%= @view_name %></h1>
2
+ <form action="/<%= @view_name %>/<%%= params[:id] %>" method="post" accept-charset="utf-8">
3
+ <input type="hidden" id="_method" name="_method" value="put" />
4
+ <% @html_tags.each do |key, value| %>
5
+ <p>
6
+ <label for="<%= key %>"><%= key.capitalize %></label><br />
7
+ <input type="<%= value %>" name="<%= "#{@view_name}[#{key}]" %>" value="<%%= <%= "@#{@view_name}.#{key}" %> %>" id="<%= "#{@view_name}_#{key}" %>">
8
+ </p>
9
+ <% end %>
10
+ <p><input type="submit" value="Edit &rarr;"></p>
11
+ </form>
@@ -0,0 +1,19 @@
1
+ <h1>Index: <%= @view_name.capitalize %></h1>
2
+ <table border="0">
3
+ <tr>
4
+ <% @html_tags.each do |key, value| %>
5
+ <th><%= key.capitalize %></th>
6
+ <% end %>
7
+
8
+ </tr>
9
+ <%% <%= "@#{@view_name}s.each do |#{@view_name}|" %> %>
10
+ <tr>
11
+ <% @html_tags.each do |key, value| %>
12
+ <td><%%= <%= "#{@view_name}.#{key}" %> %></td>
13
+ <% end %>
14
+ </tr>
15
+ <%% end %>
16
+ </table>
17
+ <p>
18
+ <a href="/<%= @view_name %>/new">Add new <%= @view_name.capitalize %></a>
19
+ </p>
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7
+ <link rel="shortcut icon" href="/public/favicon.ico" type="image/x-icon">
8
+ <title>ReST in Peace</title>
9
+ <link rel="stylesheet" href="/public/stylesheets/main.css" type="text/css" media="screen" charset="utf-8">
10
+ </head>
11
+ <body>
12
+ <div id="mainLayout">
13
+ <%= @yield %>
14
+ </div>
15
+ </body>
16
+ </html>
@@ -0,0 +1,11 @@
1
+ <h1>New <%= @view_name %></h1>
2
+ <form action="/<%= @view_name %>" method="post" accept-charset="utf-8">
3
+ <% @html_tags.each do |key, value| %>
4
+ <p>
5
+ <label for="<%= key %>"><%= key.capitalize %></label><br />
6
+ <input type="<%= value %>" name="<%= "#{@view_name}[#{key}]" %>" value="" id="<%= "#{@view_name}_#{key}" %>">
7
+ </p>
8
+ <% end %>
9
+ <p><input type="submit" value="Submit &rarr;"></p>
10
+ <a href="/<%= @view_name %>">Back</a>
11
+ </form>
@@ -0,0 +1,9 @@
1
+ <h1>Showing <%= @view_name.capitalize %></h1>
2
+
3
+ <% @html_tags.each do |key, value| %>
4
+ <p>
5
+ <%= key.capitalize %>: <%%= <%= "@#{@view_name}.#{key}" %> %>
6
+ </p>
7
+ <% end %>
8
+ <a href="/<%= @view_name %>">Back</a> |
9
+ <a href="/<%= @view_name %>/<%%= params[:id] %>/edit">Edit</a>
@@ -0,0 +1,9 @@
1
+ class <%= @model_name.capitalize %>
2
+
3
+ include DataMapper::Resource
4
+
5
+ property :id, Serial
6
+ <% @columns.each do |key, value| %>
7
+ property :<%= key %>, <%= value.capitalize %>
8
+ <% end %>
9
+ end
@@ -0,0 +1 @@
1
+ This is a new ReST in Peace project.
@@ -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
+ Generator.new(project_root).generate_scaffold(*ARGV)
@@ -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
+ Migration.new.migrate(project_root)
@@ -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
+ ServerManager.new.start_server(project_root)
@@ -0,0 +1,178 @@
1
+ body
2
+ {
3
+ background-color:#DDEEF6;
4
+ color: #DDEEF6;
5
+ }
6
+
7
+ body, p, ol, ul, td
8
+ {
9
+ font-family: verdana, arial, helvetica, sans-serif;
10
+ font-size: 14px;
11
+ line-height: 18px;
12
+ }
13
+ input
14
+ {
15
+ width:250px;
16
+ font-size:18px;
17
+ background-color:#FFF;
18
+ -moz-border-radius:5px;
19
+ -webkit-border-radius:5px;
20
+ padding:8px;
21
+ }
22
+ pre {
23
+ background-color: #eee;
24
+ padding: 10px;
25
+ font-size: 11px;
26
+ }
27
+
28
+ a { color: #AADDFF; text-decoration:none;}
29
+ a:visited { color: #AADDFF; text-decoration:none;}
30
+ a:hover { color: #AADDFF; text-decoration:none;}
31
+
32
+ table th
33
+ {
34
+ padding-left:8px;
35
+ text-align:left;
36
+ font-size:15px;
37
+ }
38
+ table td
39
+ {
40
+ font-size:14px;
41
+ padding:8px;
42
+ }
43
+ #loginLogout
44
+ {
45
+ float:right;
46
+ }
47
+ #mainLayout
48
+ {
49
+ -moz-border-radius:25px;
50
+ -webkit-border-radius:25px;
51
+ margin:0px auto;
52
+ padding:25px;
53
+ width:80%;
54
+ border:thin;
55
+ border-color:#FFF;
56
+ background-color:#002233;
57
+ }
58
+ #navBar
59
+ {
60
+ height: 50px;
61
+ margin:0px auto;
62
+ width:80%;
63
+ border:thin;
64
+ border-color:#FFF;
65
+ }
66
+ #navBar ul
67
+ {
68
+ padding:0px;
69
+ float:right;
70
+ }
71
+ #navBar li
72
+ {
73
+ -moz-border-radius:10px;
74
+ -webkit-border-radius:10px;
75
+ padding:10px;
76
+ display:inline;
77
+ background-color:#002233;
78
+ }
79
+ #navBar a
80
+ {
81
+ padding:10px;
82
+ }
83
+ #navBar li:hover
84
+ {
85
+ color:#002233;
86
+ background-color:#aaddff;
87
+ }
88
+ #navBar li a:hover
89
+ {
90
+ color:#002233;
91
+ }
92
+ #achievement #achievement_distance
93
+ {
94
+ float: right;
95
+ }
96
+ #checkpoint
97
+ {
98
+ padding: 10px 0px 10px 0px;
99
+ }
100
+ #user
101
+ {
102
+ padding: 10px 0px 10px 0px;
103
+ }
104
+ #user #avatar
105
+ {
106
+ float:left;
107
+ padding:20px;
108
+ }
109
+ #user #actions
110
+ {
111
+ float: right;
112
+ }
113
+ #friendship
114
+ {
115
+ padding: 10px 0px 10px 0px;
116
+ }
117
+ #friendship #actions
118
+ {
119
+ float: right;
120
+ }
121
+ #quest
122
+ {
123
+ padding: 10px 0px 10px 0px;
124
+ }
125
+ #quest #summary
126
+ {
127
+ float: right;
128
+ }
129
+ .pagination
130
+ {
131
+ padding:8px;
132
+ }
133
+ .pagination .current
134
+ {
135
+ font-size:18px;
136
+ }
137
+ #flash
138
+ {
139
+ font-size:14px;
140
+ color:#0F0;
141
+ }
142
+ .fieldWithErrors {
143
+ padding: 2px;
144
+ background-color: red;
145
+ display: table;
146
+ }
147
+
148
+ #errorExplanation {
149
+ width: 400px;
150
+ border: 2px solid red;
151
+ padding: 7px;
152
+ padding-bottom: 12px;
153
+ margin-bottom: 20px;
154
+ background-color: #f0f0f0;
155
+ color: #000;
156
+ }
157
+
158
+ #errorExplanation h2 {
159
+ text-align: left;
160
+ font-weight: bold;
161
+ padding: 5px 5px 5px 15px;
162
+ font-size: 12px;
163
+ margin: -7px;
164
+ background-color: #c00;
165
+ color: #fff;
166
+ }
167
+
168
+ #errorExplanation p {
169
+ color: #333;
170
+ margin-bottom: 0;
171
+ padding: 5px;
172
+ }
173
+
174
+ #errorExplanation ul li {
175
+ font-size: 12px;
176
+ list-style: square;
177
+ }
178
+
@@ -0,0 +1,9 @@
1
+ require 'datamapper'
2
+ require 'sinatra/base'
3
+ require 'rest_in_peace/rip_controller'
4
+ autoload :Generator, 'rest_in_peace/generator'
5
+ autoload :Builder, 'builder'
6
+ autoload :ProjectSettings, 'rest_in_peace/project_settings'
7
+ autoload :ERB, 'erb'
8
+ autoload :ServerManager, 'rest_in_peace/server_manager'
9
+ autoload :Migration, 'rest_in_peace/migration'
@@ -0,0 +1,83 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rest_in_peace}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chinmay Garde"]
12
+ s.date = %q{2010-03-16}
13
+ s.default_executable = %q{rip}
14
+ s.description = %q{Minimal web framework with a focus on simplicity. Powered by Sinatra and DataMapper}
15
+ s.email = %q{chinmaygarde@gmail.com}
16
+ s.executables = ["rip"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.markdown"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bin/rip",
28
+ "lib/rest_in_peace.rb",
29
+ "lib/rest_in_peace/generator.rb",
30
+ "lib/rest_in_peace/migration.rb",
31
+ "lib/rest_in_peace/project_settings.rb",
32
+ "lib/rest_in_peace/rip_controller.rb",
33
+ "lib/rest_in_peace/server_manager.rb",
34
+ "lib/rest_in_peace/templates/controller.rb.erb",
35
+ "lib/rest_in_peace/templates/html/edit.html.erb",
36
+ "lib/rest_in_peace/templates/html/index.html.erb",
37
+ "lib/rest_in_peace/templates/html/layout.html.erb",
38
+ "lib/rest_in_peace/templates/html/new.html.erb",
39
+ "lib/rest_in_peace/templates/html/show.html.erb",
40
+ "lib/rest_in_peace/templates/image/favicon.ico",
41
+ "lib/rest_in_peace/templates/model.rb.erb",
42
+ "lib/rest_in_peace/templates/readme.txt.erb",
43
+ "lib/rest_in_peace/templates/script/define",
44
+ "lib/rest_in_peace/templates/script/migrate",
45
+ "lib/rest_in_peace/templates/script/server",
46
+ "lib/rest_in_peace/templates/stylesheet/main.css",
47
+ "rest_in_peace.gemspec",
48
+ "test/helper.rb",
49
+ "test/test_rested_db.rb"
50
+ ]
51
+ s.homepage = %q{http://github.com/chinmaygarde/rest_in_peace}
52
+ s.rdoc_options = ["--charset=UTF-8"]
53
+ s.require_paths = ["lib"]
54
+ s.rubygems_version = %q{1.3.6}
55
+ s.summary = %q{ReST in Peace}
56
+ s.test_files = [
57
+ "test/helper.rb",
58
+ "test/test_rested_db.rb"
59
+ ]
60
+
61
+ if s.respond_to? :specification_version then
62
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
+ s.specification_version = 3
64
+
65
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
66
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
67
+ s.add_development_dependency(%q<datamapper>, [">= 0.10.2"])
68
+ s.add_development_dependency(%q<builder>, [">= 2.2.2"])
69
+ s.add_development_dependency(%q<sinatra>, [">= 0.9.4"])
70
+ else
71
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
72
+ s.add_dependency(%q<datamapper>, [">= 0.10.2"])
73
+ s.add_dependency(%q<builder>, [">= 2.2.2"])
74
+ s.add_dependency(%q<sinatra>, [">= 0.9.4"])
75
+ end
76
+ else
77
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
78
+ s.add_dependency(%q<datamapper>, [">= 0.10.2"])
79
+ s.add_dependency(%q<builder>, [">= 2.2.2"])
80
+ s.add_dependency(%q<sinatra>, [">= 0.9.4"])
81
+ end
82
+ end
83
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rest_in_peace'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRestedDb < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rest_in_peace
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Chinmay Garde
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-16 00:00:00 +05:30
18
+ default_executable: rip
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: datamapper
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ - 10
42
+ - 2
43
+ version: 0.10.2
44
+ type: :development
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: builder
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 2
55
+ - 2
56
+ - 2
57
+ version: 2.2.2
58
+ type: :development
59
+ version_requirements: *id003
60
+ - !ruby/object:Gem::Dependency
61
+ name: sinatra
62
+ prerelease: false
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ - 9
70
+ - 4
71
+ version: 0.9.4
72
+ type: :development
73
+ version_requirements: *id004
74
+ description: Minimal web framework with a focus on simplicity. Powered by Sinatra and DataMapper
75
+ email: chinmaygarde@gmail.com
76
+ executables:
77
+ - rip
78
+ extensions: []
79
+
80
+ extra_rdoc_files:
81
+ - LICENSE
82
+ - README.markdown
83
+ files:
84
+ - .gitignore
85
+ - LICENSE
86
+ - README.markdown
87
+ - Rakefile
88
+ - VERSION
89
+ - bin/rip
90
+ - lib/rest_in_peace.rb
91
+ - lib/rest_in_peace/generator.rb
92
+ - lib/rest_in_peace/migration.rb
93
+ - lib/rest_in_peace/project_settings.rb
94
+ - lib/rest_in_peace/rip_controller.rb
95
+ - lib/rest_in_peace/server_manager.rb
96
+ - lib/rest_in_peace/templates/controller.rb.erb
97
+ - lib/rest_in_peace/templates/html/edit.html.erb
98
+ - lib/rest_in_peace/templates/html/index.html.erb
99
+ - lib/rest_in_peace/templates/html/layout.html.erb
100
+ - lib/rest_in_peace/templates/html/new.html.erb
101
+ - lib/rest_in_peace/templates/html/show.html.erb
102
+ - lib/rest_in_peace/templates/image/favicon.ico
103
+ - lib/rest_in_peace/templates/model.rb.erb
104
+ - lib/rest_in_peace/templates/readme.txt.erb
105
+ - lib/rest_in_peace/templates/script/define
106
+ - lib/rest_in_peace/templates/script/migrate
107
+ - lib/rest_in_peace/templates/script/server
108
+ - lib/rest_in_peace/templates/stylesheet/main.css
109
+ - rest_in_peace.gemspec
110
+ - test/helper.rb
111
+ - test/test_rested_db.rb
112
+ has_rdoc: true
113
+ homepage: http://github.com/chinmaygarde/rest_in_peace
114
+ licenses: []
115
+
116
+ post_install_message:
117
+ rdoc_options:
118
+ - --charset=UTF-8
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ requirements: []
136
+
137
+ rubyforge_project:
138
+ rubygems_version: 1.3.6
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: ReST in Peace
142
+ test_files:
143
+ - test/helper.rb
144
+ - test/test_rested_db.rb