w2tags 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/COPYING +340 -0
  2. data/LICENSE +6 -0
  3. data/MIT-LICENSE +18 -0
  4. data/Manifest.txt +95 -0
  5. data/README.rdoc +264 -0
  6. data/Rakefile +23 -0
  7. data/VERSION +1 -0
  8. data/bin/w2tags +143 -0
  9. data/doc/ERB.HOT.rdoc +82 -0
  10. data/doc/FAQ.rdoc +81 -0
  11. data/doc/HAML.rdoc +310 -0
  12. data/doc/HOT.rdoc +137 -0
  13. data/doc/History.rdoc +757 -0
  14. data/doc/W2TAGS.rdoc +150 -0
  15. data/example/common.hot +11 -0
  16. data/example/from_readme.erb +78 -0
  17. data/example/from_readme.w2erb +64 -0
  18. data/example/from_w2tags.erb +32 -0
  19. data/example/from_w2tags.w2erb +32 -0
  20. data/example/rails_basic.hot +10 -0
  21. data/hot/erb.hot +156 -0
  22. data/hot/erb_form.hot +42 -0
  23. data/hot/erb_head.hot +15 -0
  24. data/hot/erb_jquery.hot +8 -0
  25. data/hot/erb_merb.hot +12 -0
  26. data/hot/erb_table.hot +43 -0
  27. data/hot/html.hot +31 -0
  28. data/hot/jquery.hot +88 -0
  29. data/hot/nvelocity.hot +23 -0
  30. data/hot/rails/sc_zebra.hot +10 -0
  31. data/hot/rails/scaffold.hot +15 -0
  32. data/hot/vm.hot +9 -0
  33. data/hot/vm2.hot +34 -0
  34. data/hot/vm_crud.hot +34 -0
  35. data/hot/vm_popup.hot +74 -0
  36. data/hot/xul.hot +114 -0
  37. data/lib/w2tags/block/plain_text.rb +57 -0
  38. data/lib/w2tags/block/remark.rb +37 -0
  39. data/lib/w2tags/block/sass.rb +66 -0
  40. data/lib/w2tags/merb_hook.rb +15 -0
  41. data/lib/w2tags/parser.rb +975 -0
  42. data/lib/w2tags/rails_hook.rb +15 -0
  43. data/lib/w2tags/sinatra_hook.rb +50 -0
  44. data/lib/w2tags.rb +100 -0
  45. data/plugins//w2tags//README +2 -0
  46. data/plugins//w2tags//generators//w2scaffold//USAGE +29 -0
  47. data/plugins//w2tags//generators//w2scaffold//templates//controller.rb +85 -0
  48. data/plugins//w2tags//generators//w2scaffold//templates//functional_test.rb +45 -0
  49. data/plugins//w2tags//generators//w2scaffold//templates//helper.rb +2 -0
  50. data/plugins//w2tags//generators//w2scaffold//templates//helper_test.rb +4 -0
  51. data/plugins//w2tags//generators//w2scaffold//templates//layout.html.erb +17 -0
  52. data/plugins//w2tags//generators//w2scaffold//templates//style.css +54 -0
  53. data/plugins//w2tags//generators//w2scaffold//templates//view_edit.html.erb +18 -0
  54. data/plugins//w2tags//generators//w2scaffold//templates//view_edit.html.w2erb +17 -0
  55. data/plugins//w2tags//generators//w2scaffold//templates//view_index.html.erb +24 -0
  56. data/plugins//w2tags//generators//w2scaffold//templates//view_index.html.w2erb +14 -0
  57. data/plugins//w2tags//generators//w2scaffold//templates//view_new.html.erb +17 -0
  58. data/plugins//w2tags//generators//w2scaffold//templates//view_new.html.w2erb +16 -0
  59. data/plugins//w2tags//generators//w2scaffold//templates//view_show.html.erb +10 -0
  60. data/plugins//w2tags//generators//w2scaffold//templates//view_show.html.w2erb +9 -0
  61. data/plugins//w2tags//generators//w2scaffold//w2scaffold_generator.rb +106 -0
  62. data/plugins//w2tags//install.rb +1 -0
  63. data/spec/spec_helper.rb +17 -0
  64. data/spec/w2tags_spec.rb +8 -0
  65. data/tasks/ann.rake +81 -0
  66. data/tasks/bones.rake +21 -0
  67. data/tasks/gem.rake +126 -0
  68. data/tasks/git.rake +41 -0
  69. data/tasks/manifest.rake +49 -0
  70. data/tasks/notes.rake +28 -0
  71. data/tasks/post_load.rake +39 -0
  72. data/tasks/rdoc.rake +51 -0
  73. data/tasks/rubyforge.rake +57 -0
  74. data/tasks/setup.rb +268 -0
  75. data/tasks/spec.rake +55 -0
  76. data/tasks/svn.rake +48 -0
  77. data/tasks/test.rake +38 -0
  78. data/test/enlightning.hot +3 -0
  79. data/test/feature.hot +28 -0
  80. data/test/parser_test.rb +203 -0
  81. data/test/tricky.hot +8 -0
  82. data/test/vars.hot +30 -0
  83. data/test/w2tags_basic_usability.rb +187 -0
  84. data/test/w2tags_enlightning.rb +42 -0
  85. data/test/w2tags_form.rb +32 -0
  86. data/test/w2tags_hot.rb +85 -0
  87. data/test/w2tags_hot_var.rb +115 -0
  88. data/test/w2tags_no_parsing.rb +37 -0
  89. metadata +163 -0
@@ -0,0 +1,15 @@
1
+ module ActionView
2
+ if Object::RAILS_ENV != "development"
3
+ puts 'W2Tags Only RUN on (RAILS_ENV == "development")'
4
+ else
5
+ puts 'W2Tags Hooked on Rails 2.3.2 & Up!'
6
+ class ReloadableTemplate < Template
7
+ W2TAGS = W2Tags::Parser.new
8
+ def mtime
9
+ src = filename.gsub(/\.erb$/,'.w2erb')
10
+ W2TAGS.parse_file(src,false,true)
11
+ File.mtime(filename)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,50 @@
1
+ module Sinatra
2
+ if Sinatra::VERSION < '0.9'
3
+ if Sinatra::Application.default_options[:env] != :development
4
+ puts 'W2Tags Only RUN on (Sinatra::Application.default_options[:env] == :development)'
5
+ else
6
+ puts 'W2Tags Hooked on Sinatra < 0.9.x!'
7
+
8
+ module W2TagsHooked
9
+ W2TAGS = W2Tags::Parser.new
10
+ def read_template_file(renderer, template, options, scream = true)
11
+ path = File.join(
12
+ options[:views_directory] || Sinatra.application.options.views,
13
+ "#{template}.#{renderer}"
14
+ )
15
+ src = path.gsub(path[/(\.\w+)$/,1],'.w2'<<$1[1,9])
16
+ W2TAGS.parse_file(src,false,true)
17
+ super
18
+ end
19
+ end
20
+
21
+ class EventContext
22
+ include W2TagsHooked
23
+ end
24
+ end
25
+ elsif Sinatra::VERSION > '0.9'
26
+
27
+ if Sinatra::Application.environment != :development
28
+ puts 'W2Tags Only RUN on (Sinatra::Application.environment == :development)'
29
+ else
30
+ puts 'W2Tags Hooked on Sinatra > 0.9.x!'
31
+
32
+ module W2TagsHooked
33
+ W2TAGS = W2Tags::Parser.new
34
+ def lookup_template(engine, template, options={})
35
+ case template
36
+ when Symbol
37
+ path= template_path(engine, template, options)
38
+ src = path.gsub(path[/(\.\w+)$/,1],'.w2'<<$1[1,9])
39
+ W2TAGS.parse_file(src,false,true)
40
+ end
41
+ super
42
+ end
43
+ end
44
+
45
+ class Base
46
+ include W2TagsHooked
47
+ end
48
+ end
49
+ end
50
+ end
data/lib/w2tags.rb ADDED
@@ -0,0 +1,100 @@
1
+ dir = File.dirname(__FILE__)
2
+ Dir["#{dir}/w2tags/block/*.rb"].each{|f|require f}
3
+ $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
4
+
5
+ # = W2TAGS (Way to Tags)
6
+ #
7
+ # W2TAGS is a shortcut of tags, macros, and it is very simple describer for HTML
8
+ # its not to become a replacement for inline tamplating engine, it best use for
9
+ # developement (sinatra / rails / merb) and the result is an "erb" file to be
10
+ # execute by erb or erubis (the fastest templating engine).
11
+ #
12
+ # It focus on how developer can code and generate dynamic content with
13
+ # DRY philosophy, easy to understand and in a very clean way.
14
+ #
15
+ # == Features
16
+ #
17
+ # * Mimics HAML syntax (inherit features define in HAML)
18
+ # * Extended syntax for Next Tag, Variable, Constanta
19
+ # * HOT file is patern for put in repetitif code and leter can be call it
20
+ # * HOT Variable interpolation, make it code really DRY
21
+ #
22
+ # == Using W2TAGS
23
+ #
24
+ # some of the guide are inside
25
+ # * README.rdoc
26
+ # * doc/W2TAGS.rdoc
27
+ # * doc/HAML.rdoc
28
+ # * doc/FAQ.rdoc
29
+ # * doc/HOT.rdoc
30
+
31
+ module W2Tags
32
+ Dir = File.dirname(__FILE__)
33
+ VERSION = File.read(Dir + '/../VERSION').strip unless defined?(VERSION)
34
+
35
+ #split string with aditional option escape charaters'\'
36
+ def self.splitter(data,deli=';')
37
+ tg_esc = data.split("\\"+deli)
38
+ if tg_esc.size > 1
39
+ tg_esc = tg_esc.collect {|x|x.split(deli)}
40
+ result = tg_esc.shift
41
+ while tg_esc != []
42
+ token = tg_esc[0]
43
+ result[-1,1] = result[-1,1][0] +';'+ token[0,1][0]
44
+ result = result + token[1,99]
45
+ tg_esc.shift
46
+ end
47
+ else
48
+ result = data.split(deli)
49
+ end
50
+ result
51
+ end
52
+
53
+ #hot files is a collection of w2tags function
54
+ #example of the function that will translate by this method
55
+ #
56
+ # >>body
57
+ # <body>
58
+ # <</
59
+ # </body>
60
+ #
61
+ #and example of use that function
62
+ # @body()
63
+ # @div!Hello Tags
64
+ # ./
65
+ #
66
+ #it will produce
67
+ # <body>
68
+ # <div>Hello Tags</div>
69
+ # </body>
70
+ def self.read_filehot(fhot)
71
+ hot_new = {}
72
+ hot = ("\n"+IO.read(fhot)).delete("\r").split(/\n\>\>/)
73
+ hot.shift
74
+ hot.each do |item|
75
+ item.gsub!(/\n([ \t]*)$/,'') #remove blank lines
76
+ ends = item.split(/\n\<\<\/[^\n]*\n/) #hots | ends
77
+ mems = ends[0].split(/\n\!~[^\n]*\n/) #hots | mems
78
+ khot = mems[0].split("\n") #key | hot
79
+ keys = khot.shift.rstrip #hots = mems[0].gsub(keys+"\n",'')
80
+ hots = khot.join("\n")
81
+ hot = [nil,nil]
82
+ hot[0]= proc do |this|
83
+ this.chg_mem_hot(mems[1]) if this!= nil
84
+ hots
85
+ end
86
+ if ends.size>1
87
+ hot[1] = [ends[1]]
88
+ # tend = splitter(ends[1])
89
+ # if tend.size==1
90
+ # hot[1] = [tend]
91
+ # else
92
+ # hot[1] = tend.collect {|x|"</#{x}>"}
93
+ # end
94
+ end
95
+ hot_new[keys] = hot
96
+ end
97
+ hot_new
98
+ end
99
+ end
100
+ require 'w2tags/parser'
@@ -0,0 +1,2 @@
1
+ Scaffold with w2tags Generator
2
+ ====
@@ -0,0 +1,29 @@
1
+ Description:
2
+ Scaffolds an entire resource, from model and migration to controller and
3
+ views, along with a full test suite. The resource is ready to use as a
4
+ starting point for your RESTful, resource-oriented application.
5
+
6
+ Pass the name of the model (in singular form), either CamelCased or
7
+ under_scored, as the first argument, and an optional list of attribute
8
+ pairs.
9
+
10
+ Attribute pairs are column_name:sql_type arguments specifying the
11
+ model's attributes. Timestamps are added by default, so you don't have to
12
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
13
+
14
+ You don't have to think up every attribute up front, but it helps to
15
+ sketch out a few so you can start working with the resource immediately.
16
+
17
+ For example, 'scaffold post title:string body:text published:boolean'
18
+ gives you a model with those three attributes, a controller that handles
19
+ the create/show/update/destroy, forms to create and edit your posts, and
20
+ an index that lists them all, as well as a map.resources :posts
21
+ declaration in config/routes.rb.
22
+
23
+ If you want to remove all the generated files, run
24
+ 'script/destroy scaffold ModelName'.
25
+
26
+ Examples:
27
+ `./script/generate w2scaffold post`
28
+ `./script/generate w2scaffold post title:string body:text published:boolean`
29
+ `./script/generate w2scaffold purchase order_id:integer amount:decimal`
@@ -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 %>.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,45 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+ test "should get index" do
5
+ get :index
6
+ assert_response :success
7
+ assert_not_nil assigns(:<%= table_name %>)
8
+ end
9
+
10
+ test "should get new" do
11
+ get :new
12
+ assert_response :success
13
+ end
14
+
15
+ test "should create <%= file_name %>" do
16
+ assert_difference('<%= class_name %>.count') do
17
+ post :create, :<%= file_name %> => { }
18
+ end
19
+
20
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
21
+ end
22
+
23
+ test "should show <%= file_name %>" do
24
+ get :show, :id => <%= table_name %>(:one).to_param
25
+ assert_response :success
26
+ end
27
+
28
+ test "should get edit" do
29
+ get :edit, :id => <%= table_name %>(:one).to_param
30
+ assert_response :success
31
+ end
32
+
33
+ test "should update <%= file_name %>" do
34
+ put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
35
+ assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
36
+ end
37
+
38
+ test "should destroy <%= file_name %>" do
39
+ assert_difference('<%= class_name %>.count', -1) do
40
+ delete :destroy, :id => <%= table_name %>(:one).to_param
41
+ end
42
+
43
+ assert_redirected_to <%= table_name %>_path
44
+ end
45
+ end
@@ -0,0 +1,2 @@
1
+ module <%= controller_class_name %>Helper
2
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>HelperTest < ActionView::TestCase
4
+ 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,54 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ .fieldWithErrors {
20
+ padding: 2px;
21
+ background-color: red;
22
+ display: table;
23
+ }
24
+
25
+ #errorExplanation {
26
+ width: 400px;
27
+ border: 2px solid red;
28
+ padding: 7px;
29
+ padding-bottom: 12px;
30
+ margin-bottom: 20px;
31
+ background-color: #f0f0f0;
32
+ }
33
+
34
+ #errorExplanation h2 {
35
+ text-align: left;
36
+ font-weight: bold;
37
+ padding: 5px 5px 5px 15px;
38
+ font-size: 12px;
39
+ margin: -7px;
40
+ background-color: #c00;
41
+ color: #fff;
42
+ }
43
+
44
+ #errorExplanation p {
45
+ color: #333;
46
+ margin-bottom: 0;
47
+ padding: 5px;
48
+ }
49
+
50
+ #errorExplanation ul li {
51
+ font-size: 12px;
52
+ list-style: square;
53
+ }
54
+
@@ -0,0 +1,18 @@
1
+ <h1>Editing <%= singular_name %></h1>
2
+
3
+ <%% form_for(@<%= singular_name %>) do |f| %>
4
+ <%%= f.error_messages %>
5
+
6
+ <% for attribute in attributes -%>
7
+ <p>
8
+ <%%= f.label :<%= attribute.name %> %><br />
9
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
10
+ </p>
11
+ <% end -%>
12
+ <p>
13
+ <%%= f.submit 'Update' %>
14
+ </p>
15
+ <%% end %>
16
+
17
+ <%%= link_to 'Show', @<%= singular_name %> %> |
18
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,17 @@
1
+ %h1 Editing <%= singular_name %>
2
+
3
+ -- form_for(@<%= singular_name %>) do |f|
4
+ = f.error_messages
5
+
6
+ <% for attribute in attributes -%>
7
+ %p
8
+ = f.label :<%= attribute.name %>
9
+ %br
10
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
11
+ <% end -%>
12
+
13
+ %p
14
+ = f.submit 'Update'
15
+
16
+ = link_to 'Show', @<%= singular_name %>
17
+ = link_to 'Back', <%= plural_name %>_path
@@ -0,0 +1,24 @@
1
+ <h1>Listing <%= plural_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
+ <%% @<%= plural_name %>.each do |<%= singular_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_name %>', new_<%= singular_name %>_path %>
@@ -0,0 +1,14 @@
1
+ !hot!scaffold
2
+ %h1 Listing <%= plural_name %>
3
+ &rec=<%= singular_name %>
4
+ &fld=<%= attributes.collect {|f|f.name}.join(";") %>
5
+ %table
6
+ %tr
7
+ -th &fld!
8
+
9
+ -each_tr @<%= plural_name %>;&rec!
10
+ -td= &fld!
11
+ -td_link_crud
12
+ %br
13
+
14
+ = link_to "New &rec!", new_&rec!_path
@@ -0,0 +1,17 @@
1
+ <h1>New <%= singular_name %></h1>
2
+
3
+ <%% form_for(@<%= singular_name %>) do |f| %>
4
+ <%%= f.error_messages %>
5
+
6
+ <% for attribute in attributes -%>
7
+ <p>
8
+ <%%= f.label :<%= attribute.name %> %><br />
9
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
10
+ </p>
11
+ <% end -%>
12
+ <p>
13
+ <%%= f.submit 'Create' %>
14
+ </p>
15
+ <%% end %>
16
+
17
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,16 @@
1
+ %h1 New <%= singular_name %>
2
+
3
+ -- form_for(@<%= singular_name %>) do |f|
4
+ = f.error_messages
5
+
6
+ <% for attribute in attributes -%>
7
+ %p
8
+ = f.label :<%= attribute.name %>
9
+ %br
10
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
11
+ <% end -%>
12
+
13
+ %p
14
+ = f.submit 'Create'
15
+
16
+ = link_to 'Back', <%= plural_name %>_path
@@ -0,0 +1,10 @@
1
+ <% for attribute in attributes -%>
2
+ <p>
3
+ <b><%= attribute.column.human_name %>:</b>
4
+ <%%=h @<%= singular_name %>.<%= attribute.name %> %>
5
+ </p>
6
+
7
+ <% end -%>
8
+
9
+ <%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
10
+ <%%= link_to 'Back', <%= plural_name %>_path %>
@@ -0,0 +1,9 @@
1
+ <% for attribute in attributes -%>
2
+ %p
3
+ %b <%= attribute.column.human_name %>:
4
+ = h @<%= singular_name %>.<%= attribute.name %>
5
+
6
+ <% end -%>
7
+
8
+ = link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>)
9
+ = link_to 'Back', <%= plural_name %>_path
@@ -0,0 +1,106 @@
1
+ class W2scaffoldGenerator < Rails::Generator::NamedBase
2
+ default_options :skip_timestamps => false, :skip_migration => false, :force_plural => false
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
+ alias_method :controller_file_name, :controller_underscore_name
14
+ alias_method :controller_table_name, :controller_plural_name
15
+
16
+ def initialize(runtime_args, runtime_options = {})
17
+ super
18
+
19
+ if @name == @name.pluralize && !options[:force_plural]
20
+ logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural."
21
+ @name = @name.singularize
22
+ end
23
+
24
+ @controller_name = @name.pluralize
25
+
26
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
27
+ @controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
28
+ @controller_singular_name=base_name.singularize
29
+ if @controller_class_nesting.empty?
30
+ @controller_class_name = @controller_class_name_without_nesting
31
+ else
32
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
33
+ end
34
+ end
35
+
36
+ def manifest
37
+ record do |m|
38
+ # Check for class naming collisions.
39
+ m.class_collisions("#{controller_class_name}Controller", "#{controller_class_name}Helper")
40
+ m.class_collisions(class_name)
41
+
42
+ # Controller, helper, views, test and stylesheets directories.
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
+ m.directory(File.join('test/functional', controller_class_path))
49
+ m.directory(File.join('test/unit', class_path))
50
+ m.directory(File.join('test/unit/helpers', class_path))
51
+ m.directory(File.join('public/stylesheets', class_path))
52
+
53
+ for action in scaffold_views
54
+ m.template(
55
+ "view_#{action}.html.erb",
56
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb")
57
+ )
58
+ m.template(
59
+ "view_#{action}.html.w2erb",
60
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.w2erb")
61
+ )
62
+ end
63
+
64
+ # Layout and stylesheet.
65
+ m.template('layout.html.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb"))
66
+ m.template('style.css', 'public/stylesheets/scaffold.css')
67
+
68
+ m.template(
69
+ 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
70
+ )
71
+
72
+ m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
73
+ m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
74
+ m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb"))
75
+
76
+ m.route_resources controller_file_name
77
+
78
+ m.dependency 'model', [name] + @args, :collision => :skip
79
+ end
80
+ end
81
+
82
+ protected
83
+ # Override with your own usage banner.
84
+ def banner
85
+ "Usage: #{$0} scaffold ModelName [field:type, field:type]"
86
+ end
87
+
88
+ def add_options!(opt)
89
+ opt.separator ''
90
+ opt.separator 'Options:'
91
+ opt.on("--skip-timestamps",
92
+ "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
93
+ opt.on("--skip-migration",
94
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
95
+ opt.on("--force-plural",
96
+ "Forces the generation of a plural ModelName") { |v| options[:force_plural] = v }
97
+ end
98
+
99
+ def scaffold_views
100
+ %w[ index show new edit ]
101
+ end
102
+
103
+ def model_name
104
+ class_name.demodulize
105
+ end
106
+ end
@@ -0,0 +1 @@
1
+ puts IO.read(File.join(File.dirname(__FILE__), 'README'))
@@ -0,0 +1,17 @@
1
+ # $Id$
2
+
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), %w[.. lib w2tags]))
5
+
6
+ Spec::Runner.configure do |config|
7
+ # == Mock Framework
8
+ #
9
+ # RSpec uses it's own mocking framework by default. If you prefer to
10
+ # use mocha, flexmock or RR, uncomment the appropriate line:
11
+ #
12
+ # config.mock_with :mocha
13
+ # config.mock_with :flexmock
14
+ # config.mock_with :rr
15
+ end
16
+
17
+ # EOF