stage 0.2.0 → 0.3.1
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/History.txt +6 -0
- data/Manifest.txt +17 -0
- data/README.txt +5 -5
- data/lib/stage/version.rb +2 -2
- data/rails_generators/stage/USAGE +5 -0
- data/rails_generators/stage/stage_generator.rb +99 -0
- data/rails_generators/stage/templates/controller.rb +85 -0
- data/rails_generators/stage/templates/data_partial.html.erb +6 -0
- data/rails_generators/stage/templates/form_partial.html.erb +11 -0
- data/rails_generators/stage/templates/helper.rb +12 -0
- data/rails_generators/stage/templates/layout.html.erb +17 -0
- data/rails_generators/stage/templates/migration.rb +16 -0
- data/rails_generators/stage/templates/model.rb +2 -0
- data/rails_generators/stage/templates/view_edit.html.erb +6 -0
- data/rails_generators/stage/templates/view_index.html.erb +24 -0
- data/rails_generators/stage/templates/view_new.html.erb +5 -0
- data/rails_generators/stage/templates/view_show.html.erb +4 -0
- data/test/test_generator_helper.rb +10 -1
- data/test/test_stage_generator.rb +8 -6
- data/website/index.html +5 -155
- data/website/index.txt +5 -147
- data/website/merb.html +244 -0
- data/website/merb.txt +173 -0
- data/website/rails.html +275 -0
- data/website/rails.txt +204 -0
- metadata +21 -2
data/website/merb.txt
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
h1. stage
|
2
|
+
|
3
|
+
h1. → 'stage'
|
4
|
+
|
5
|
+
h2. Merb Instructions
|
6
|
+
|
7
|
+
h2. Installing
|
8
|
+
|
9
|
+
<pre syntax="ruby">sudo gem install stage</pre>
|
10
|
+
|
11
|
+
h2. Demonstration of usage
|
12
|
+
|
13
|
+
<pre syntax="ruby">
|
14
|
+
$ merb-gen stage page title:string content:text
|
15
|
+
exists app
|
16
|
+
exists app/controllers
|
17
|
+
exists app/helpers
|
18
|
+
exists app/models
|
19
|
+
exists app/views
|
20
|
+
create app/views/pages
|
21
|
+
create app/controllers/pages.rb
|
22
|
+
create app/helpers/pages_helper.rb
|
23
|
+
create app/models/page.rb
|
24
|
+
create app/views/pages/_data.html.erb
|
25
|
+
create app/views/pages/_form.html.erb
|
26
|
+
create app/views/pages/edit.html.erb
|
27
|
+
create app/views/pages/index.html.erb
|
28
|
+
create app/views/pages/new.html.erb
|
29
|
+
create app/views/pages/show.html.erb
|
30
|
+
</pre>
|
31
|
+
|
32
|
+
The controller generated:
|
33
|
+
<pre syntax="ruby">
|
34
|
+
class Pages < Application
|
35
|
+
before :find_page, :only => [:show, :edit, :update, :delete]
|
36
|
+
|
37
|
+
def index
|
38
|
+
@pages = Page.all
|
39
|
+
display @pages
|
40
|
+
end
|
41
|
+
|
42
|
+
def show
|
43
|
+
display @page
|
44
|
+
end
|
45
|
+
|
46
|
+
def new
|
47
|
+
only_provides :html
|
48
|
+
@page = Page.new
|
49
|
+
render
|
50
|
+
end
|
51
|
+
|
52
|
+
def edit
|
53
|
+
only_provides :html
|
54
|
+
render
|
55
|
+
end
|
56
|
+
|
57
|
+
def create
|
58
|
+
@page = Page.new(params[:page])
|
59
|
+
if @page.save
|
60
|
+
redirect url(:page, @page)
|
61
|
+
else
|
62
|
+
render :new
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def update
|
67
|
+
if @page.update_attributes(params[:page])
|
68
|
+
redirect url(:page, @page)
|
69
|
+
else
|
70
|
+
raise BadRequest
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete
|
75
|
+
if @page.destroy!
|
76
|
+
redirect url(:page)
|
77
|
+
else
|
78
|
+
raise BadRequest
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def find_page
|
84
|
+
@page = Page.first(params[:id])
|
85
|
+
raise NotFound unless @page
|
86
|
+
end
|
87
|
+
end
|
88
|
+
</pre>
|
89
|
+
|
90
|
+
The edit page:
|
91
|
+
<pre syntax="ruby">
|
92
|
+
<h1>Editing page</h1>
|
93
|
+
|
94
|
+
<%= partial "form" %>
|
95
|
+
|
96
|
+
<%= link_to 'Show', url(:page, @page) %> |
|
97
|
+
<%= link_to 'Back', url(:pages) %>
|
98
|
+
</pre>
|
99
|
+
|
100
|
+
The form partial:
|
101
|
+
<pre syntax="ruby">
|
102
|
+
<%
|
103
|
+
submit_label = "Update"
|
104
|
+
submit_label = "Create" if @page.new_record?
|
105
|
+
-%>
|
106
|
+
|
107
|
+
<%= error_messages_for @page %>
|
108
|
+
|
109
|
+
<% form_for(:page, :action => url(:page,@page)) do %>
|
110
|
+
<%= partial :data %>
|
111
|
+
<p> <%= submit_button submit_label %> </p>
|
112
|
+
<% end %>
|
113
|
+
</pre>
|
114
|
+
|
115
|
+
The data partial (the show view calls this directly):
|
116
|
+
<pre syntax="ruby">
|
117
|
+
<p>
|
118
|
+
<b>Title</b><br />
|
119
|
+
<%= page_title_value %>
|
120
|
+
</p>
|
121
|
+
|
122
|
+
<p>
|
123
|
+
<b>Content</b><br />
|
124
|
+
<%= page_content_value %>
|
125
|
+
</p>
|
126
|
+
</pre>
|
127
|
+
|
128
|
+
As you can see, there are <model>_<field>_value methods. These are defined in the pages helper:
|
129
|
+
<pre syntax="ruby">
|
130
|
+
module Merb
|
131
|
+
module PagesHelper
|
132
|
+
def page_title_value
|
133
|
+
if @action_name == "show"
|
134
|
+
@page.title
|
135
|
+
else
|
136
|
+
text_field :name => "page[title]", :value => @page.title
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def page_content_value
|
141
|
+
if @action_name == "show"
|
142
|
+
@page.content
|
143
|
+
else
|
144
|
+
text_field :name => "page[content]", :value => @page.content
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
</pre>
|
150
|
+
|
151
|
+
I need to get more precise with the form helpers, but for now this will do.
|
152
|
+
|
153
|
+
h2. Forum
|
154
|
+
|
155
|
+
"http://groups.google.com/group/stonean_stage?hl=en":http://groups.google.com/group/stonean_stage?hl=en
|
156
|
+
|
157
|
+
|
158
|
+
h2. How to submit patches
|
159
|
+
|
160
|
+
The Clone URL: git://github.com/stonean/stage.git
|
161
|
+
|
162
|
+
Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
|
163
|
+
|
164
|
+
I'm new to git and this whole opensource project admin gig, so please be patient with my stumbling around.
|
165
|
+
|
166
|
+
h2. License
|
167
|
+
|
168
|
+
This code is free to use under the terms of the MIT license.
|
169
|
+
|
170
|
+
h2. Contact
|
171
|
+
|
172
|
+
Comments and suggestions are welcome via the "forum":http://groups.google.com/group/stonean_stage?hl=en
|
173
|
+
|
data/website/rails.html
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
+
<title>
|
8
|
+
stage
|
9
|
+
</title>
|
10
|
+
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
|
+
<style>
|
12
|
+
|
13
|
+
</style>
|
14
|
+
<script type="text/javascript">
|
15
|
+
window.onload = function() {
|
16
|
+
settings = {
|
17
|
+
tl: { radius: 10 },
|
18
|
+
tr: { radius: 10 },
|
19
|
+
bl: { radius: 10 },
|
20
|
+
br: { radius: 10 },
|
21
|
+
antiAlias: true,
|
22
|
+
autoPad: true,
|
23
|
+
validTags: ["div"]
|
24
|
+
}
|
25
|
+
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
26
|
+
versionBox.applyCornersToAll();
|
27
|
+
}
|
28
|
+
</script>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="main">
|
32
|
+
|
33
|
+
<h1>stage</h1>
|
34
|
+
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/stage"; return false'>
|
35
|
+
<p>Get Version</p>
|
36
|
+
<a href="http://rubyforge.org/projects/stage" class="numbers">0.3.1</a>
|
37
|
+
</div>
|
38
|
+
<h1>→ ‘stage’</h1>
|
39
|
+
|
40
|
+
|
41
|
+
<h1>Rails instructions</h1>
|
42
|
+
|
43
|
+
|
44
|
+
<h2>Installing</h2>
|
45
|
+
|
46
|
+
|
47
|
+
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">stage</span></pre></p>
|
48
|
+
|
49
|
+
|
50
|
+
<h2>Demonstration of usage</h2>
|
51
|
+
|
52
|
+
|
53
|
+
<p><pre class='syntax'>
|
54
|
+
<span class="global">$ </span><span class="punct">./</span><span class="ident">script</span><span class="punct">/</span><span class="ident">generate</span> <span class="ident">stage</span> <span class="ident">product</span> <span class="ident">name</span><span class="symbol">:string</span> <span class="ident">cost</span><span class="symbol">:integer</span> <span class="ident">weight</span><span class="symbol">:integer</span>
|
55
|
+
<span class="ident">exists</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">models</span><span class="punct">/</span>
|
56
|
+
<span class="ident">exists</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">controllers</span><span class="punct">/</span>
|
57
|
+
<span class="ident">exists</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">helpers</span><span class="punct">/</span>
|
58
|
+
<span class="ident">create</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">views</span><span class="punct">/</span><span class="ident">products</span>
|
59
|
+
<span class="ident">exists</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">views</span><span class="punct">/</span><span class="ident">layouts</span><span class="punct">/</span>
|
60
|
+
<span class="ident">create</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">views</span><span class="punct">/</span><span class="ident">products</span><span class="punct">/</span><span class="ident">index</span><span class="punct">.</span><span class="ident">html</span><span class="punct">.</span><span class="ident">erb</span>
|
61
|
+
<span class="ident">create</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">views</span><span class="punct">/</span><span class="ident">products</span><span class="punct">/</span><span class="ident">show</span><span class="punct">.</span><span class="ident">html</span><span class="punct">.</span><span class="ident">erb</span>
|
62
|
+
<span class="ident">create</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">views</span><span class="punct">/</span><span class="ident">products</span><span class="punct">/</span><span class="ident">new</span><span class="punct">.</span><span class="ident">html</span><span class="punct">.</span><span class="ident">erb</span>
|
63
|
+
<span class="ident">create</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">views</span><span class="punct">/</span><span class="ident">products</span><span class="punct">/</span><span class="ident">edit</span><span class="punct">.</span><span class="ident">html</span><span class="punct">.</span><span class="ident">erb</span>
|
64
|
+
<span class="ident">create</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">views</span><span class="punct">/</span><span class="ident">products</span><span class="punct">/</span><span class="ident">_form</span><span class="punct">.</span><span class="ident">html</span><span class="punct">.</span><span class="ident">erb</span>
|
65
|
+
<span class="ident">create</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">views</span><span class="punct">/</span><span class="ident">products</span><span class="punct">/</span><span class="ident">_data</span><span class="punct">.</span><span class="ident">html</span><span class="punct">.</span><span class="ident">erb</span>
|
66
|
+
<span class="ident">create</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">models</span><span class="punct">/</span><span class="ident">product</span><span class="punct">.</span><span class="ident">rb</span>
|
67
|
+
<span class="ident">create</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">controllers</span><span class="punct">/</span><span class="ident">products_controller</span><span class="punct">.</span><span class="ident">rb</span>
|
68
|
+
<span class="ident">create</span> <span class="ident">app</span><span class="punct">/</span><span class="ident">helpers</span><span class="punct">/</span><span class="ident">products_helper</span><span class="punct">.</span><span class="ident">rb</span>
|
69
|
+
<span class="ident">create</span> <span class="ident">db</span><span class="punct">/</span><span class="ident">migrate</span>
|
70
|
+
<span class="ident">create</span> <span class="ident">db</span><span class="punct">/</span><span class="ident">migrate</span><span class="punct">/</span><span class="number">001_</span><span class="ident">create_products</span><span class="punct">.</span><span class="ident">rb</span>
|
71
|
+
<span class="ident">route</span> <span class="ident">map</span><span class="punct">.</span><span class="ident">resources</span> <span class="symbol">:products</span>
|
72
|
+
</pre></p>
|
73
|
+
|
74
|
+
|
75
|
+
<p>The controller generated:
|
76
|
+
<pre class='syntax'>
|
77
|
+
<span class="keyword">class </span><span class="class">PagesController</span> <span class="punct"><</span> <span class="constant">ApplicationController</span>
|
78
|
+
<span class="comment"># GET /pages</span>
|
79
|
+
<span class="comment"># GET /pages.xml</span>
|
80
|
+
<span class="keyword">def </span><span class="method">index</span>
|
81
|
+
<span class="attribute">@pages</span> <span class="punct">=</span> <span class="constant">Page</span><span class="punct">.</span><span class="ident">find</span><span class="punct">(</span><span class="symbol">:all</span><span class="punct">)</span>
|
82
|
+
|
83
|
+
<span class="ident">respond_to</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">format</span><span class="punct">|</span>
|
84
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">html</span> <span class="comment"># index.html.erb</span>
|
85
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">xml</span> <span class="punct">{</span> <span class="ident">render</span> <span class="symbol">:xml</span> <span class="punct">=></span> <span class="attribute">@pages</span> <span class="punct">}</span>
|
86
|
+
<span class="keyword">end</span>
|
87
|
+
<span class="keyword">end</span>
|
88
|
+
|
89
|
+
<span class="comment"># GET /pages/1</span>
|
90
|
+
<span class="comment"># GET /pages/1.xml</span>
|
91
|
+
<span class="keyword">def </span><span class="method">show</span>
|
92
|
+
<span class="attribute">@page</span> <span class="punct">=</span> <span class="constant">Page</span><span class="punct">.</span><span class="ident">find</span><span class="punct">(</span><span class="ident">params</span><span class="punct">[</span><span class="symbol">:id</span><span class="punct">])</span>
|
93
|
+
|
94
|
+
<span class="ident">respond_to</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">format</span><span class="punct">|</span>
|
95
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">html</span> <span class="comment"># show.html.erb</span>
|
96
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">xml</span> <span class="punct">{</span> <span class="ident">render</span> <span class="symbol">:xml</span> <span class="punct">=></span> <span class="attribute">@page</span> <span class="punct">}</span>
|
97
|
+
<span class="keyword">end</span>
|
98
|
+
<span class="keyword">end</span>
|
99
|
+
|
100
|
+
<span class="comment"># GET /pages/new</span>
|
101
|
+
<span class="comment"># GET /pages/new.xml</span>
|
102
|
+
<span class="keyword">def </span><span class="method">new</span>
|
103
|
+
<span class="attribute">@page</span> <span class="punct">=</span> <span class="constant">Page</span><span class="punct">.</span><span class="ident">new</span>
|
104
|
+
|
105
|
+
<span class="ident">respond_to</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">format</span><span class="punct">|</span>
|
106
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">html</span> <span class="comment"># new.html.erb</span>
|
107
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">xml</span> <span class="punct">{</span> <span class="ident">render</span> <span class="symbol">:xml</span> <span class="punct">=></span> <span class="attribute">@page</span> <span class="punct">}</span>
|
108
|
+
<span class="keyword">end</span>
|
109
|
+
<span class="keyword">end</span>
|
110
|
+
|
111
|
+
<span class="comment"># GET /pages/1/edit</span>
|
112
|
+
<span class="keyword">def </span><span class="method">edit</span>
|
113
|
+
<span class="attribute">@page</span> <span class="punct">=</span> <span class="constant">Page</span><span class="punct">.</span><span class="ident">find</span><span class="punct">(</span><span class="ident">params</span><span class="punct">[</span><span class="symbol">:id</span><span class="punct">])</span>
|
114
|
+
<span class="keyword">end</span>
|
115
|
+
|
116
|
+
<span class="comment"># POST /pages</span>
|
117
|
+
<span class="comment"># POST /pages.xml</span>
|
118
|
+
<span class="keyword">def </span><span class="method">create</span>
|
119
|
+
<span class="attribute">@page</span> <span class="punct">=</span> <span class="constant">Page</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">params</span><span class="punct">[</span><span class="symbol">:page</span><span class="punct">])</span>
|
120
|
+
|
121
|
+
<span class="ident">respond_to</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">format</span><span class="punct">|</span>
|
122
|
+
<span class="keyword">if</span> <span class="attribute">@page</span><span class="punct">.</span><span class="ident">save</span>
|
123
|
+
<span class="ident">flash</span><span class="punct">[</span><span class="symbol">:notice</span><span class="punct">]</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">Page was successfully created.</span><span class="punct">'</span>
|
124
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">html</span> <span class="punct">{</span> <span class="ident">redirect_to</span><span class="punct">(</span><span class="attribute">@page</span><span class="punct">)</span> <span class="punct">}</span>
|
125
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">xml</span> <span class="punct">{</span> <span class="ident">render</span> <span class="symbol">:xml</span> <span class="punct">=></span> <span class="attribute">@page</span><span class="punct">,</span> <span class="symbol">:status</span> <span class="punct">=></span> <span class="symbol">:created</span><span class="punct">,</span> <span class="symbol">:location</span> <span class="punct">=></span> <span class="attribute">@page</span> <span class="punct">}</span>
|
126
|
+
<span class="keyword">else</span>
|
127
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">html</span> <span class="punct">{</span> <span class="ident">render</span> <span class="symbol">:action</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">new</span><span class="punct">"</span> <span class="punct">}</span>
|
128
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">xml</span> <span class="punct">{</span> <span class="ident">render</span> <span class="symbol">:xml</span> <span class="punct">=></span> <span class="attribute">@page</span><span class="punct">.</span><span class="ident">errors</span><span class="punct">,</span> <span class="symbol">:status</span> <span class="punct">=></span> <span class="symbol">:unprocessable_entity</span> <span class="punct">}</span>
|
129
|
+
<span class="keyword">end</span>
|
130
|
+
<span class="keyword">end</span>
|
131
|
+
<span class="keyword">end</span>
|
132
|
+
|
133
|
+
<span class="comment"># PUT /pages/1</span>
|
134
|
+
<span class="comment"># PUT /pages/1.xml</span>
|
135
|
+
<span class="keyword">def </span><span class="method">update</span>
|
136
|
+
<span class="attribute">@page</span> <span class="punct">=</span> <span class="constant">Page</span><span class="punct">.</span><span class="ident">find</span><span class="punct">(</span><span class="ident">params</span><span class="punct">[</span><span class="symbol">:id</span><span class="punct">])</span>
|
137
|
+
|
138
|
+
<span class="ident">respond_to</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">format</span><span class="punct">|</span>
|
139
|
+
<span class="keyword">if</span> <span class="attribute">@page</span><span class="punct">.</span><span class="ident">update_attributes</span><span class="punct">(</span><span class="ident">params</span><span class="punct">[</span><span class="symbol">:page</span><span class="punct">])</span>
|
140
|
+
<span class="ident">flash</span><span class="punct">[</span><span class="symbol">:notice</span><span class="punct">]</span> <span class="punct">=</span> <span class="punct">'</span><span class="string">Page was successfully updated.</span><span class="punct">'</span>
|
141
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">html</span> <span class="punct">{</span> <span class="ident">redirect_to</span><span class="punct">(</span><span class="attribute">@page</span><span class="punct">)</span> <span class="punct">}</span>
|
142
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">xml</span> <span class="punct">{</span> <span class="ident">head</span> <span class="symbol">:ok</span> <span class="punct">}</span>
|
143
|
+
<span class="keyword">else</span>
|
144
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">html</span> <span class="punct">{</span> <span class="ident">render</span> <span class="symbol">:action</span> <span class="punct">=></span> <span class="punct">"</span><span class="string">edit</span><span class="punct">"</span> <span class="punct">}</span>
|
145
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">xml</span> <span class="punct">{</span> <span class="ident">render</span> <span class="symbol">:xml</span> <span class="punct">=></span> <span class="attribute">@page</span><span class="punct">.</span><span class="ident">errors</span><span class="punct">,</span> <span class="symbol">:status</span> <span class="punct">=></span> <span class="symbol">:unprocessable_entity</span> <span class="punct">}</span>
|
146
|
+
<span class="keyword">end</span>
|
147
|
+
<span class="keyword">end</span>
|
148
|
+
<span class="keyword">end</span>
|
149
|
+
|
150
|
+
<span class="comment"># DELETE /pages/1</span>
|
151
|
+
<span class="comment"># DELETE /pages/1.xml</span>
|
152
|
+
<span class="keyword">def </span><span class="method">destroy</span>
|
153
|
+
<span class="attribute">@page</span> <span class="punct">=</span> <span class="constant">Page</span><span class="punct">.</span><span class="ident">find</span><span class="punct">(</span><span class="ident">params</span><span class="punct">[</span><span class="symbol">:id</span><span class="punct">])</span>
|
154
|
+
<span class="attribute">@page</span><span class="punct">.</span><span class="ident">destroy</span>
|
155
|
+
|
156
|
+
<span class="ident">respond_to</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">format</span><span class="punct">|</span>
|
157
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">html</span> <span class="punct">{</span> <span class="ident">redirect_to</span><span class="punct">(</span><span class="ident">pages_url</span><span class="punct">)</span> <span class="punct">}</span>
|
158
|
+
<span class="ident">format</span><span class="punct">.</span><span class="ident">xml</span> <span class="punct">{</span> <span class="ident">head</span> <span class="symbol">:ok</span> <span class="punct">}</span>
|
159
|
+
<span class="keyword">end</span>
|
160
|
+
<span class="keyword">end</span>
|
161
|
+
<span class="keyword">end</span>
|
162
|
+
</pre></p>
|
163
|
+
|
164
|
+
|
165
|
+
<p>The edit page:
|
166
|
+
<pre class='syntax'>
|
167
|
+
<span class="punct"><</span><span class="ident">h1</span><span class="punct">></span><span class="constant">Editing</span> <span class="constant">Page</span><span class="punct"></</span><span class="regex">h1>
|
168
|
+
|
169
|
+
<%= render :partial => "form" %>
|
170
|
+
|
171
|
+
<%= link_to 'Show', @page %> |
|
172
|
+
<%= link_to 'Back', pages_path %><span class="normal">
|
173
|
+
</span></span></pre></p>
|
174
|
+
|
175
|
+
|
176
|
+
<p>The form partial:
|
177
|
+
<pre class='syntax'>
|
178
|
+
<span class="punct"><%</span>
|
179
|
+
<span class="ident">submit_label</span> <span class="punct">=</span> <span class="punct">"</span><span class="string">Update</span><span class="punct">"</span>
|
180
|
+
<span class="ident">submit_label</span> <span class="punct">=</span> <span class="punct">"</span><span class="string">Create</span><span class="punct">"</span> <span class="keyword">if</span> <span class="attribute">@page</span><span class="punct">.</span><span class="ident">new_record?</span>
|
181
|
+
<span class="punct">-%></span><span class="string">
|
182
|
+
|
183
|
+
<%= error_messages_for @page %</span><span class="punct">></span>
|
184
|
+
|
185
|
+
<span class="punct"><%</span> <span class="ident">form_for</span><span class="punct">(</span><span class="symbol">:page</span><span class="punct">,</span> <span class="symbol">:action</span> <span class="punct">=></span> <span class="ident">url</span><span class="punct">(</span><span class="symbol">:page</span><span class="punct">,</span><span class="attribute">@page</span><span class="punct">))</span> <span class="keyword">do</span> <span class="punct">%></span><span class="string">
|
186
|
+
<%= partial :data %</span><span class="punct">></span>
|
187
|
+
<span class="punct"><</span><span class="ident">p</span><span class="punct">></span> <span class="punct"><%=</span><span class="string"> submit_button submit_label %> </p>
|
188
|
+
<% end %><span class="normal">
|
189
|
+
</span></span></pre></p>
|
190
|
+
|
191
|
+
|
192
|
+
<p>The data partial (the show view calls this directly):
|
193
|
+
<pre class='syntax'>
|
194
|
+
<span class="punct"><</span><span class="ident">p</span><span class="punct">></span>
|
195
|
+
<span class="punct"><</span><span class="ident">b</span><span class="punct">></span><span class="constant">Title</span><span class="punct"></</span><span class="regex">b><br </span><span class="punct">/></span>
|
196
|
+
<span class="punct"><%=</span><span class="string"> page_title_value %>
|
197
|
+
</p>
|
198
|
+
<p>
|
199
|
+
<b>Content</b><br />
|
200
|
+
<%</span><span class="punct">=</span> <span class="ident">page_content_value</span> <span class="punct">%></span><span class="string">
|
201
|
+
</p</span><span class="punct">></span>
|
202
|
+
</pre></p>
|
203
|
+
|
204
|
+
|
205
|
+
<p>As you can see, there are <model>_<field>_value methods. These are defined in the pages helper:
|
206
|
+
<pre class='syntax'>
|
207
|
+
<span class="keyword">module </span><span class="module">PagesHelper</span>
|
208
|
+
<span class="keyword">def </span><span class="method">page_title_value</span>
|
209
|
+
<span class="keyword">if</span> <span class="attribute">@action_name</span> <span class="punct">==</span> <span class="punct">"</span><span class="string">show</span><span class="punct">"</span>
|
210
|
+
<span class="ident">h</span> <span class="attribute">@page</span><span class="punct">.</span><span class="ident">title</span>
|
211
|
+
<span class="keyword">else</span>
|
212
|
+
<span class="ident">text_field_tag</span> <span class="punct">"</span><span class="string">page[title]</span><span class="punct">",</span> <span class="attribute">@page</span><span class="punct">.</span><span class="ident">title</span>
|
213
|
+
<span class="keyword">end</span>
|
214
|
+
<span class="keyword">end</span>
|
215
|
+
|
216
|
+
<span class="keyword">def </span><span class="method">page_content_value</span>
|
217
|
+
<span class="keyword">if</span> <span class="attribute">@action_name</span> <span class="punct">==</span> <span class="punct">"</span><span class="string">show</span><span class="punct">"</span>
|
218
|
+
<span class="ident">h</span> <span class="attribute">@page</span><span class="punct">.</span><span class="ident">content</span>
|
219
|
+
<span class="keyword">else</span>
|
220
|
+
<span class="ident">text_field_tag</span> <span class="punct">"</span><span class="string">page[content]</span><span class="punct">",</span> <span class="attribute">@page</span><span class="punct">.</span><span class="ident">content</span>
|
221
|
+
<span class="keyword">end</span>
|
222
|
+
<span class="keyword">end</span>
|
223
|
+
|
224
|
+
<span class="keyword">end</span>
|
225
|
+
</pre></p>
|
226
|
+
|
227
|
+
|
228
|
+
<p>I need to get more precise with the form helpers, but for now this will do.</p>
|
229
|
+
|
230
|
+
|
231
|
+
<h2>Forum</h2>
|
232
|
+
|
233
|
+
|
234
|
+
<p><a href="http://groups.google.com/group/stonean_stage?hl=en">http://groups.google.com/group/stonean_stage?hl=en</a></p>
|
235
|
+
|
236
|
+
|
237
|
+
<h2>How to submit patches</h2>
|
238
|
+
|
239
|
+
|
240
|
+
<p>The Clone <span class="caps">URL</span>: git://github.com/stonean/stage.git</p>
|
241
|
+
|
242
|
+
|
243
|
+
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
|
244
|
+
|
245
|
+
|
246
|
+
<p>I’m new to git and this whole opensource project admin gig, so please be patient with my stumbling around.</p>
|
247
|
+
|
248
|
+
|
249
|
+
<h2>License</h2>
|
250
|
+
|
251
|
+
|
252
|
+
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
253
|
+
|
254
|
+
|
255
|
+
<h2>Contact</h2>
|
256
|
+
|
257
|
+
|
258
|
+
<p>Comments and suggestions are welcome via the <a href="http://groups.google.com/group/stonean_stage?hl=en">forum</a></p>
|
259
|
+
<p class="coda">
|
260
|
+
26th April 2008<br>
|
261
|
+
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
262
|
+
</p>
|
263
|
+
</div>
|
264
|
+
|
265
|
+
<script type="text/javascript">
|
266
|
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
267
|
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
268
|
+
</script>
|
269
|
+
<script type="text/javascript">
|
270
|
+
var pageTracker = _gat._getTracker("UA-4186995-1");
|
271
|
+
pageTracker._initData();
|
272
|
+
pageTracker._trackPageview();
|
273
|
+
</script>
|
274
|
+
</body>
|
275
|
+
</html>
|
data/website/rails.txt
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
h1. stage
|
2
|
+
|
3
|
+
h1. → 'stage'
|
4
|
+
|
5
|
+
h1. Rails instructions
|
6
|
+
|
7
|
+
h2. Installing
|
8
|
+
|
9
|
+
<pre syntax="ruby">sudo gem install stage</pre>
|
10
|
+
|
11
|
+
h2. Demonstration of usage
|
12
|
+
|
13
|
+
<pre syntax="ruby">
|
14
|
+
$ ./script/generate stage product name:string cost:integer weight:integer
|
15
|
+
exists app/models/
|
16
|
+
exists app/controllers/
|
17
|
+
exists app/helpers/
|
18
|
+
create app/views/products
|
19
|
+
exists app/views/layouts/
|
20
|
+
create app/views/products/index.html.erb
|
21
|
+
create app/views/products/show.html.erb
|
22
|
+
create app/views/products/new.html.erb
|
23
|
+
create app/views/products/edit.html.erb
|
24
|
+
create app/views/products/_form.html.erb
|
25
|
+
create app/views/products/_data.html.erb
|
26
|
+
create app/models/product.rb
|
27
|
+
create app/controllers/products_controller.rb
|
28
|
+
create app/helpers/products_helper.rb
|
29
|
+
create db/migrate
|
30
|
+
create db/migrate/001_create_products.rb
|
31
|
+
route map.resources :products
|
32
|
+
</pre>
|
33
|
+
|
34
|
+
The controller generated:
|
35
|
+
<pre syntax="ruby">
|
36
|
+
class PagesController < ApplicationController
|
37
|
+
# GET /pages
|
38
|
+
# GET /pages.xml
|
39
|
+
def index
|
40
|
+
@pages = Page.find(:all)
|
41
|
+
|
42
|
+
respond_to do |format|
|
43
|
+
format.html # index.html.erb
|
44
|
+
format.xml { render :xml => @pages }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# GET /pages/1
|
49
|
+
# GET /pages/1.xml
|
50
|
+
def show
|
51
|
+
@page = Page.find(params[:id])
|
52
|
+
|
53
|
+
respond_to do |format|
|
54
|
+
format.html # show.html.erb
|
55
|
+
format.xml { render :xml => @page }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# GET /pages/new
|
60
|
+
# GET /pages/new.xml
|
61
|
+
def new
|
62
|
+
@page = Page.new
|
63
|
+
|
64
|
+
respond_to do |format|
|
65
|
+
format.html # new.html.erb
|
66
|
+
format.xml { render :xml => @page }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# GET /pages/1/edit
|
71
|
+
def edit
|
72
|
+
@page = Page.find(params[:id])
|
73
|
+
end
|
74
|
+
|
75
|
+
# POST /pages
|
76
|
+
# POST /pages.xml
|
77
|
+
def create
|
78
|
+
@page = Page.new(params[:page])
|
79
|
+
|
80
|
+
respond_to do |format|
|
81
|
+
if @page.save
|
82
|
+
flash[:notice] = 'Page was successfully created.'
|
83
|
+
format.html { redirect_to(@page) }
|
84
|
+
format.xml { render :xml => @page, :status => :created, :location => @page }
|
85
|
+
else
|
86
|
+
format.html { render :action => "new" }
|
87
|
+
format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# PUT /pages/1
|
93
|
+
# PUT /pages/1.xml
|
94
|
+
def update
|
95
|
+
@page = Page.find(params[:id])
|
96
|
+
|
97
|
+
respond_to do |format|
|
98
|
+
if @page.update_attributes(params[:page])
|
99
|
+
flash[:notice] = 'Page was successfully updated.'
|
100
|
+
format.html { redirect_to(@page) }
|
101
|
+
format.xml { head :ok }
|
102
|
+
else
|
103
|
+
format.html { render :action => "edit" }
|
104
|
+
format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# DELETE /pages/1
|
110
|
+
# DELETE /pages/1.xml
|
111
|
+
def destroy
|
112
|
+
@page = Page.find(params[:id])
|
113
|
+
@page.destroy
|
114
|
+
|
115
|
+
respond_to do |format|
|
116
|
+
format.html { redirect_to(pages_url) }
|
117
|
+
format.xml { head :ok }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
</pre>
|
122
|
+
|
123
|
+
The edit page:
|
124
|
+
<pre syntax="ruby">
|
125
|
+
<h1>Editing Page</h1>
|
126
|
+
|
127
|
+
<%= render :partial => "form" %>
|
128
|
+
|
129
|
+
<%= link_to 'Show', @page %> |
|
130
|
+
<%= link_to 'Back', pages_path %>
|
131
|
+
</pre>
|
132
|
+
|
133
|
+
The form partial:
|
134
|
+
<pre syntax="ruby">
|
135
|
+
<%
|
136
|
+
submit_label = "Update"
|
137
|
+
submit_label = "Create" if @page.new_record?
|
138
|
+
-%>
|
139
|
+
|
140
|
+
<%= error_messages_for @page %>
|
141
|
+
|
142
|
+
<% form_for(:page, :action => url(:page,@page)) do %>
|
143
|
+
<%= partial :data %>
|
144
|
+
<p> <%= submit_button submit_label %> </p>
|
145
|
+
<% end %>
|
146
|
+
</pre>
|
147
|
+
|
148
|
+
The data partial (the show view calls this directly):
|
149
|
+
<pre syntax="ruby">
|
150
|
+
<p>
|
151
|
+
<b>Title</b><br />
|
152
|
+
<%= page_title_value %>
|
153
|
+
</p>
|
154
|
+
<p>
|
155
|
+
<b>Content</b><br />
|
156
|
+
<%= page_content_value %>
|
157
|
+
</p>
|
158
|
+
</pre>
|
159
|
+
|
160
|
+
As you can see, there are <model>_<field>_value methods. These are defined in the pages helper:
|
161
|
+
<pre syntax="ruby">
|
162
|
+
module PagesHelper
|
163
|
+
def page_title_value
|
164
|
+
if @action_name == "show"
|
165
|
+
h @page.title
|
166
|
+
else
|
167
|
+
text_field_tag "page[title]", @page.title
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def page_content_value
|
172
|
+
if @action_name == "show"
|
173
|
+
h @page.content
|
174
|
+
else
|
175
|
+
text_field_tag "page[content]", @page.content
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
</pre>
|
181
|
+
|
182
|
+
I need to get more precise with the form helpers, but for now this will do.
|
183
|
+
|
184
|
+
h2. Forum
|
185
|
+
|
186
|
+
"http://groups.google.com/group/stonean_stage?hl=en":http://groups.google.com/group/stonean_stage?hl=en
|
187
|
+
|
188
|
+
|
189
|
+
h2. How to submit patches
|
190
|
+
|
191
|
+
The Clone URL: git://github.com/stonean/stage.git
|
192
|
+
|
193
|
+
Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
|
194
|
+
|
195
|
+
I'm new to git and this whole opensource project admin gig, so please be patient with my stumbling around.
|
196
|
+
|
197
|
+
h2. License
|
198
|
+
|
199
|
+
This code is free to use under the terms of the MIT license.
|
200
|
+
|
201
|
+
h2. Contact
|
202
|
+
|
203
|
+
Comments and suggestions are welcome via the "forum":http://groups.google.com/group/stonean_stage?hl=en
|
204
|
+
|