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/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -19,6 +19,19 @@ merb_generators/stage/templates/app/views/%controller_file_name%/edit.html.erb
|
|
19
19
|
merb_generators/stage/templates/app/views/%controller_file_name%/index.html.erb
|
20
20
|
merb_generators/stage/templates/app/views/%controller_file_name%/new.html.erb
|
21
21
|
merb_generators/stage/templates/app/views/%controller_file_name%/show.html.erb
|
22
|
+
rails_generators/stage/USAGE
|
23
|
+
rails_generators/stage/stage_generator.rb
|
24
|
+
rails_generators/stage/templates/controller.rb
|
25
|
+
rails_generators/stage/templates/data_partial.html.erb
|
26
|
+
rails_generators/stage/templates/form_partial.html.erb
|
27
|
+
rails_generators/stage/templates/helper.rb
|
28
|
+
rails_generators/stage/templates/layout.html.erb
|
29
|
+
rails_generators/stage/templates/migration.rb
|
30
|
+
rails_generators/stage/templates/model.rb
|
31
|
+
rails_generators/stage/templates/view_edit.html.erb
|
32
|
+
rails_generators/stage/templates/view_index.html.erb
|
33
|
+
rails_generators/stage/templates/view_new.html.erb
|
34
|
+
rails_generators/stage/templates/view_show.html.erb
|
22
35
|
script/console
|
23
36
|
script/destroy
|
24
37
|
script/generate
|
@@ -34,5 +47,9 @@ test/test_stage_generator.rb
|
|
34
47
|
website/index.html
|
35
48
|
website/index.txt
|
36
49
|
website/javascripts/rounded_corners_lite.inc.js
|
50
|
+
website/merb.html
|
51
|
+
website/merb.txt
|
52
|
+
website/rails.html
|
53
|
+
website/rails.txt
|
37
54
|
website/stylesheets/screen.css
|
38
55
|
website/template.html.erb
|
data/README.txt
CHANGED
@@ -3,20 +3,20 @@
|
|
3
3
|
|
4
4
|
== DESCRIPTION:
|
5
5
|
|
6
|
-
Stage is a code template generator that utilizes helpers as presenters to reduce ruby code used in views.
|
7
|
-
|
6
|
+
Stage is a code template generator that utilizes helpers as presenters to reduce ruby code used in views. Of course, contributions are welcome if you like the concept. I would especially like to hear of any code reduction suggestions.
|
8
7
|
|
9
8
|
== FEATURES/PROBLEMS:
|
10
9
|
|
11
|
-
|
12
|
-
Need to add a confirm script to the delete link.
|
10
|
+
Both: The helper methods could generate more precise form helpers. Just outputs text fields.
|
13
11
|
|
14
|
-
|
12
|
+
Merb: Need to add resource to router.rb
|
15
13
|
|
16
14
|
|
17
15
|
== REQUIREMENTS:
|
18
16
|
|
19
17
|
Merb + DataMapper
|
18
|
+
-- or --
|
19
|
+
RubyOnRails
|
20
20
|
|
21
21
|
== INSTALL:
|
22
22
|
|
data/lib/stage/version.rb
CHANGED
@@ -0,0 +1,99 @@
|
|
1
|
+
class StageGenerator < Rails::Generator::NamedBase
|
2
|
+
default_options :skip_timestamps => false, :skip_migration => false, :skip_fixture => true
|
3
|
+
|
4
|
+
attr_reader :controller_name,
|
5
|
+
:controller_class_path,
|
6
|
+
:controller_file_path,
|
7
|
+
:controller_class_nesting,
|
8
|
+
:controller_class_nesting_depth,
|
9
|
+
:controller_class_name,
|
10
|
+
:controller_underscore_name,
|
11
|
+
:controller_singular_name,
|
12
|
+
:controller_plural_name,
|
13
|
+
:singular_title_name,
|
14
|
+
:plural_title_name
|
15
|
+
alias_method :controller_file_name, :controller_underscore_name
|
16
|
+
alias_method :controller_table_name, :controller_plural_name
|
17
|
+
|
18
|
+
def initialize(runtime_args, runtime_options = {})
|
19
|
+
super
|
20
|
+
|
21
|
+
@controller_name = @name.pluralize
|
22
|
+
|
23
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
24
|
+
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
25
|
+
@controller_singular_name= base_name.singularize
|
26
|
+
if @controller_class_nesting.empty?
|
27
|
+
@controller_class_name = @controller_class_name_without_nesting
|
28
|
+
else
|
29
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
30
|
+
end
|
31
|
+
|
32
|
+
@singular_title_name = @controller_singular_name.humanize
|
33
|
+
@plural_title_name = @controller_plural_name.humanize
|
34
|
+
end
|
35
|
+
|
36
|
+
def manifest
|
37
|
+
record do |m|
|
38
|
+
# Check for class naming collisions.
|
39
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
40
|
+
m.class_collisions(class_path, "#{class_name}")
|
41
|
+
|
42
|
+
# Controller, helper, views
|
43
|
+
m.directory(File.join("app","models", class_path))
|
44
|
+
m.directory(File.join("app","controllers", controller_class_path))
|
45
|
+
m.directory(File.join("app","helpers", controller_class_path))
|
46
|
+
m.directory(File.join("app","views", controller_class_path, controller_file_name))
|
47
|
+
m.directory(File.join("app","views","layouts", controller_class_path))
|
48
|
+
|
49
|
+
for action in stage_views
|
50
|
+
m.template(
|
51
|
+
"view_#{action}.html.erb",
|
52
|
+
File.join("app","views", controller_class_path, controller_file_name, "#{action}.html.erb")
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
m.template("form_partial.html.erb",
|
57
|
+
File.join("app","views", controller_class_path, controller_file_name, "_form.html.erb"))
|
58
|
+
|
59
|
+
m.template("data_partial.html.erb", File.join("app","views",controller_class_path, controller_file_name, "_data.html.erb"))
|
60
|
+
|
61
|
+
m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
62
|
+
|
63
|
+
m.template("controller.rb", File.join("app","controllers", controller_class_path, "#{controller_file_name}_controller.rb"))
|
64
|
+
|
65
|
+
m.template("helper.rb", File.join("app","helpers", controller_class_path, "#{controller_file_name}_helper.rb"))
|
66
|
+
|
67
|
+
unless options[:skip_migration]
|
68
|
+
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
69
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
70
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
71
|
+
end
|
72
|
+
|
73
|
+
m.route_resources controller_file_name
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
protected
|
78
|
+
# Override with your own usage banner.
|
79
|
+
def banner
|
80
|
+
"Usage: #{$0} stage ModelName [field:type, field:type]"
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_options!(opt)
|
84
|
+
opt.separator ""
|
85
|
+
opt.separator "Options:"
|
86
|
+
opt.on("--skip-timestamps",
|
87
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
88
|
+
opt.on("--skip-migration",
|
89
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
90
|
+
end
|
91
|
+
|
92
|
+
def stage_views
|
93
|
+
%w[ index show new edit ]
|
94
|
+
end
|
95
|
+
|
96
|
+
def model_name
|
97
|
+
class_name.demodulize
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
# GET /<%= table_name %>
|
3
|
+
# GET /<%= table_name %>.xml
|
4
|
+
def index
|
5
|
+
@<%= table_name %> = <%= class_name %>.find(:all)
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.xml { render :xml => @<%= table_name %> }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /<%= table_name %>/1
|
14
|
+
# GET /<%= table_name %>/1.xml
|
15
|
+
def show
|
16
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.xml { render :xml => @<%= file_name %> }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /<%= table_name %>/new
|
25
|
+
# GET /<%= table_name %>/new.xml
|
26
|
+
def new
|
27
|
+
@<%= file_name %> = <%= class_name %>.new
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html # new.html.erb
|
31
|
+
format.xml { render :xml => @<%= file_name %> }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /<%= table_name %>/1/edit
|
36
|
+
def edit
|
37
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST /<%= table_name %>
|
41
|
+
# POST /<%= table_name %>.xml
|
42
|
+
def create
|
43
|
+
@<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
if @<%= file_name %>.save
|
47
|
+
flash[:notice] = '<%= class_name %> was successfully created.'
|
48
|
+
format.html { redirect_to(@<%= file_name %>) }
|
49
|
+
format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
|
50
|
+
else
|
51
|
+
format.html { render :action => "new" }
|
52
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# PUT /<%= table_name %>/1
|
58
|
+
# PUT /<%= table_name %>/1.xml
|
59
|
+
def update
|
60
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
61
|
+
|
62
|
+
respond_to do |format|
|
63
|
+
if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
64
|
+
flash[:notice] = '<%= class_name %> was successfully updated.'
|
65
|
+
format.html { redirect_to(@<%= file_name %>) }
|
66
|
+
format.xml { head :ok }
|
67
|
+
else
|
68
|
+
format.html { render :action => "edit" }
|
69
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# DELETE /<%= table_name %>/1
|
75
|
+
# DELETE /<%= table_name %>/1.xml
|
76
|
+
def destroy
|
77
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
78
|
+
@<%= file_name %>.destroy
|
79
|
+
|
80
|
+
respond_to do |format|
|
81
|
+
format.html { redirect_to(<%= table_name %>_url) }
|
82
|
+
format.xml { head :ok }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%%
|
2
|
+
submit_label = "Update"
|
3
|
+
submit_label = "Create" if @<%= singular_name%>.new_record?
|
4
|
+
-%>
|
5
|
+
|
6
|
+
<%%= error_messages_for :<%= singular_name %> %>
|
7
|
+
|
8
|
+
<%% form_for(@<%= singular_name %>) do |f| %>
|
9
|
+
<%%= render :partial => "data" %>
|
10
|
+
<p> <%%= f.submit submit_label %> </p>
|
11
|
+
<%% end %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module <%= controller_class_name %>Helper
|
2
|
+
<% for attribute in attributes -%>
|
3
|
+
def <%= singular_name %>_<%= attribute.name %>_value
|
4
|
+
if @action_name == "show"
|
5
|
+
h @<%= singular_name %>.<%= attribute.name %>
|
6
|
+
else
|
7
|
+
text_field_tag "<%= singular_name%>[<%= attribute.name %>]", @<%= singular_name %>.<%= attribute.name %>
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
<% end -%>
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
+
<title><%= controller_class_name %>: <%%= controller.action_name %></title>
|
8
|
+
<%%= stylesheet_link_tag 'scaffold' %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<p style="color: green"><%%= flash[:notice] %></p>
|
13
|
+
|
14
|
+
<%%= yield %>
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= table_name %> do |t|
|
4
|
+
<% for attribute in attributes -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
|
+
<% end -%>
|
7
|
+
<% unless options[:skip_timestamps] %>
|
8
|
+
t.timestamps
|
9
|
+
<% end -%>
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :<%= table_name %>
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<h1>Listing <%= plural_title_name %></h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<% for attribute in attributes -%>
|
6
|
+
<th><%= attribute.column.human_name %></th>
|
7
|
+
<% end -%>
|
8
|
+
</tr>
|
9
|
+
|
10
|
+
<%% for <%= singular_name %> in @<%= plural_name %> %>
|
11
|
+
<tr>
|
12
|
+
<% for attribute in attributes -%>
|
13
|
+
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
14
|
+
<% end -%>
|
15
|
+
<td><%%= link_to 'Show', <%= singular_name %> %></td>
|
16
|
+
<td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
|
17
|
+
<td><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
|
18
|
+
</tr>
|
19
|
+
<%% end %>
|
20
|
+
</table>
|
21
|
+
|
22
|
+
<br />
|
23
|
+
|
24
|
+
<%%= link_to 'New <%= singular_title_name %>', new_<%= singular_name %>_path %>
|
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require File.dirname(__FILE__) + '/test_helper'
|
3
|
+
rescue LoadError
|
4
|
+
require 'test/unit'
|
5
|
+
end
|
2
6
|
require 'fileutils'
|
3
7
|
|
4
8
|
# Must set before requiring generator libs.
|
@@ -10,6 +14,11 @@ if defined?(APP_ROOT)
|
|
10
14
|
else
|
11
15
|
APP_ROOT = app_root
|
12
16
|
end
|
17
|
+
if defined?(RAILS_ROOT)
|
18
|
+
RAILS_ROOT.replace(app_root)
|
19
|
+
else
|
20
|
+
RAILS_ROOT = app_root
|
21
|
+
end
|
13
22
|
|
14
23
|
begin
|
15
24
|
require 'rubigen'
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
|
2
2
|
|
3
|
+
require 'rails_generator'
|
4
|
+
|
3
5
|
class TestStageGenerator < Test::Unit::TestCase
|
4
6
|
include RubiGen::GeneratorTestHelper
|
5
7
|
|
6
8
|
def setup
|
7
9
|
bare_setup
|
8
10
|
end
|
9
|
-
|
11
|
+
|
10
12
|
def teardown
|
11
13
|
bare_teardown
|
12
14
|
end
|
13
|
-
|
15
|
+
|
14
16
|
# Some generator-related assertions:
|
15
17
|
# assert_generated_file(name, &block) # block passed the file contents
|
16
18
|
# assert_directory_exists(name)
|
@@ -24,20 +26,20 @@ class TestStageGenerator < Test::Unit::TestCase
|
|
24
26
|
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
|
25
27
|
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
|
26
28
|
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
27
|
-
|
29
|
+
|
28
30
|
def test_generator_without_options
|
29
31
|
name = "myapp"
|
30
32
|
run_generator('stage', [name], sources)
|
31
33
|
assert_generated_file("some_file")
|
32
34
|
end
|
33
|
-
|
35
|
+
|
34
36
|
private
|
35
37
|
def sources
|
36
38
|
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
|
37
39
|
]
|
38
40
|
end
|
39
|
-
|
41
|
+
|
40
42
|
def generator_path
|
41
|
-
"
|
43
|
+
"rails_generators"
|
42
44
|
end
|
43
45
|
end
|